﻿var currentMenu = null;
var currentAction = null;
var requestedAction = null;

function adjustHeight(id) {
	if( !navigator.userAgent.indexOf(/MSIE/) ) { return false; }
	var minHeight = 90;
	var oDiv = Browser.getObject(id);
	if( !oDiv ) { return false; }
	
	var oSize = Browser.getSize(oDiv);
	if( oSize[1] < minHeight ) {
		Browser.setSize(oDiv, oSize[0], minHeight);
	}
}

function preload() {
	var images = new Array('company', 'products' ,'downloads', 'support', 'resources', 'purchase', 'about-us', 'partners');
	for(k = 0; k < images.length; k++) {
		img = new Image();
		img.src = '/images/' + images[k] + '.gif';
	}
}


function show(menu) {
	if( menu == currentMenu ) { return true; }
	
	var img = Browser.getObject('menu-' + menu + '-img');
	if( !img ) return;
	
	if( currentMenu != null && currentMenu != menu) {
		hide(currentMenu);
	}
	
//	var menus = new Array('products' ,'downloads', 'support', 'resources', 'purchase', 'about-us', 'partners');

	//img.src = '/images/' + menu + '.gif';
	if( Browser.getObject('menu-'+menu) ) {
		var xy = Browser.getXY('menu-' + menu + '-img');
		var wh = Browser.getSize('menu-' + menu + '-img');
		
		Browser.setStyle('menu-' + menu, 'position', 'absolute');
		Browser.setStyle('menu-' + menu, 'zIndex', '100');
		if( menu != 'about-us' ) {
			Browser.setXY('menu-' + menu, xy[0], xy[1] + wh[1] - 1);
		}
		else {
			Browser.setXY('menu-' + menu, xy[0] + wh[0] - 170, xy[1] + wh[1] - 1);
		}
		Browser.setStyle('menu-' + menu, 'display', 'block');
		currentMenu = menu;
		currentAction = 'show';
	}
}
function controlMenu(menu, action){
	if(currentMenu != menu){
		var func = action+"('"+menu+"');"
		eval(func);
	}
	if(requestedAction =='hide'){
		setTimeout('reset()',100);
	}
	requestedAction = action;
}

function reset(){
	if(requestedAction == 'hide' && requestedAction != currentAction){
		var func = requestedAction+"('"+currentMenu+"');"
		eval(func);
	}
}

function hide(menu) {
	var img = Browser.getObject('menu-'+menu+'-img');
	if( !img ) return;
	
	//img.src = '/images/' + menu + '.gif';
	if( Browser.getObject('menu-' + menu) ) {
		Browser.setStyle('menu-' + menu, 'display', 'none');
		currentMenu = null;
		currentAction = 'hide';
	}
}

function toggle(id) {
	var idStyle = Browser.getStyle(id, 'display');
	if( !idStyle ) { return false; }
	
	if( idStyle == 'block' ) {
		Browser.setStyle(id, 'display', 'none');
	}
	else if ( idStyle == 'none' ) {
		Browser.setStyle(id, 'display', 'block');
	}
}

var activeid = '';
function toggleReset(id) {
	var idStyle = Browser.getStyle(id, 'display');
	if(activeid){Browser.setStyle(activeid, 'display', 'none');}
	if( !idStyle ) { return false; }
	
	if( idStyle == 'block' ) {
		Browser.setStyle(id, 'display', 'none');
	}
	else if ( idStyle == 'none' ) {
		Browser.setStyle(id, 'display', 'block');
	}
	activeid = id;
}


function toggleClass(obj, class1, class2) {
	var obj = Browser.getObject(obj);
	if( !obj ) { return false; }

	if( class1 != '' && obj.className.indexOf(class1) > -1 ) { 
		Browser.removeClass(obj, class1);
		if( class2 != '' ) { Browser.addClass(obj, class2); }
	}
	else if ( class2 != '' && obj.className.indexOf(class2) > -1 ) {
		Browser.removeClass(obj, class2);
		if( class1 != '' ) { Browser.addClass(obj, class1); }
	}
	else if( class1 == '' ) {
		Browser.addClass(obj, class2);
		return true;
	}
	else if ( class2 == '' ) {
		Browser.addClass(obj, class1);
		return true;
	}
	
}

function equalize(a, b) {
	var oA = Browser.getObject(a);
	var oB = Browser.getObject(b);
	if( !oA || !oB ) { return false; }

	var aSize = Browser.getSize(oA);
	var bSize = Browser.getSize(oB);
	
	var oSize = Math.max(aSize[1], bSize[1]);
	Browser.setStyle(oA, 'height', oSize + 'px');
	Browser.setStyle(oB, 'height', oSize + 'px');
}

function maximizeContent(otherContent) {
	var content = ( otherContent ) ? otherContent : 'content';

	var oContent = Browser.getSize(content);
	var oHeader = Browser.getSize('header-container');
	var menuHeight = 150;
	var oFooter = Browser.getSize('footer');
	var oDocument = Browser.getVisibleSize();

	var newSize = oDocument[1] - (oHeader[1] + menuHeight + oFooter[1]);

	if( newSize > oContent[1] ) {
		Browser.setStyle(content, 'height', newSize + 'px');
		return true;
	}
	
	return false;
	
}



function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  //window.open(theURL,winName,features);    
    //获取窗体的宽度
    features = features.toLowerCase();
    var width = features.lastIndexOf("width=");
    width = features.substring(width+6);
    var index = width.indexOf(",");
    width = width.substring(0,index);
    
    
    xposition=0; yposition=0;
    if ((parseInt(navigator.appVersion) >= 4 ))
    {
        xposition = (screen.width - width) / 2;
        yposition = (screen.height) / 2;
    }
    yposition = 0;
    
    theproperty = features     
    + "location=0," 
    + "menubar=0,"        
    + "status=0," 
    + "titlebar=0,"
    + "toolbar=0,"
    + "hotkeys=0,"
    + "screenx=" + xposition + "," //Netscape
    + "screeny=" + yposition + "," //Netscape
    + "left=" + xposition + "," //IE
    + "top=" + yposition; //IE 
    
    var win = window.open(theURL,winName,theproperty);
    win.focus();
}


