/**
 * FileName:gs_scripts.js
 */

/**********************************************************
* Rollover
*/

function GsRollover(){
}
GsRollover.prototype = {
	initialize:function(clses){
		var len = clses.length;
		this.storedImg = new Array();
		var elems = new Array();
	
		for(var k=0; k<len; k++){
			elems = elems.concat(this.getElementsByClassName("img", clses[k]));
			elems = elems.concat(this.getElementsByClassName("input", clses[k]));
		}

		len = elems.length;
		for(var i=0; i<len; i++){

			var elem = elems[i];
			var imgSrc = elem.src;

			if(imgSrc.indexOf("-ovr.")>-1 || imgSrc.indexOf("-cur.")>-1){
				continue;
			}
			var ovrStr = this.imgOvrReplace(imgSrc, true)
			this.storedImg[imgSrc] = new Image();
			this.storedImg[imgSrc].src = ovrStr;

			elem.ins = this;
			elem.onmouseover = this.mouseOverEvent;
			elem.onmouseout = this.mouseOutEvent;

		}
	},
	getElementsByClassName:function(pTagName, pClassName){
		var res = new Array();
		var tags = document.getElementsByTagName(pTagName);
		var len = tags.length;
		for(var i=0; i<len; i++){
			var classes = tags[i].className;
			if(classes.indexOf(pClassName)>-1){
				res[res.length] = tags[i];
			}
		}
		return res;
	},
	mouseOverEvent:function (){
		this.src = this.ins.imgOvrReplace(this.src, true);
	},
	mouseOutEvent:function(){
		this.src = this.ins.imgOvrReplace(this.src, false);
	},
	imgOvrReplace:function(pSrc, pIsOvr){
		var srcStr = pSrc;
		if(pIsOvr){
			if(srcStr.indexOf("-ovr")>-1){
				return srcStr;
			}
			srcStr = this.strReplace(srcStr, ".gif", "-ovr.gif");
			srcStr = this.strReplace(srcStr, ".jpg", "-ovr.jpg");
			srcStr = this.strReplace(srcStr, ".png", "-ovr.png");
		}else{
			srcStr = this.strReplace(srcStr, "-ovr.gif", ".gif");
			srcStr = this.strReplace(srcStr, "-ovr.jpg", ".jpg");
			srcStr = this.strReplace(srcStr, "-ovr.png", ".png");
		}
		return srcStr;
	},
	strReplace:function (pStr, pKey, pAlt){
		return pStr.split(pKey).join(pAlt);
	}
}

/**********************************************************
* 
*/
var gsRollover = new GsRollover();


function gsRO(){
	gsRollover.initialize(arguments);
}

/**********************************************************
* current highLight
*/

function curHighLight(id){
	var url = window.location.pathname;
	var ary = url.split(".html")[0];
	var target = ary.split("/")[1];
	var target2 =  ary.split("/")[2];
	if(target == "sapari" && target2 == "product"){
		target = "products";
	}
	var parent = document.getElementById(id);
	var collection = parent.getElementsByTagName("img");
	var len = collection.length;
	for(var i = 0 ; i < len ; i++){
		if(target && collection[i].src.indexOf(target) != -1){
			collection[i].src = collection[i].src.split('.gif')[0] + "-ovr.gif";
		}
	}
}

/**********************************************************
* Listener
*/

function evtListener(obj,evtHand,func) {
	if(window.addEventListener){
		obj.addEventListener(evtHand,func,false);
	}else if(window.attachEvent){
		obj.attachEvent('on' + evtHand,func);
	}else{
		obj['on' + evtHand] = func;
	}
}

/**********************************************************
* Embed Flash
*/

var FLASH_MAJOR_VERSION = 9;
var FLASH_MINOR_VERSION = 0;
var FLASH_REVISION      = 45;
var DEFAULT_FLASH_DIRECTORY = "/gs_external/flash/";
var PLAYER_PRODUCTION_INSTALLER_DIR = "/gs_external/flash/";
var PLAYER_PRODUCTION_INSTALLER_FILE = "playerProductInstall.swf";
var isU6r65 = true;
/**
 *  
 */
document.write('<script language="V'+'BScript" type="text/vbscript">');
document.write('Function VBGetSwfVer(i)\n');
document.write('  on error resume next\n');
document.write('  Dim swControl, swVersion\n');
document.write('  swVersion = 0\n');
document.write('  set swControl = CreateObject("ShockwaveFlash.ShockwaveFlash." + CStr(i))\n');
document.write('  if (IsObject(swControl)) then\n');
document.write('    swVersion = swControl.GetVariable("$version")\n');
document.write('  end if\n');
document.write('  VBGetSwfVer = swVersion\n');
document.write('End Function\n');
document.write('</script>\n');
/**
 * 
 */
function GsSwfObj(){
	this.isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
	this.isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
	this.isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
	this.checkerVersion = {major:6, minor:0, revision:0};
}
GsSwfObj.prototype = {
	display:function(props){
		var majorVersion 	= (props.majorVersion)?props.majorVersion:FLASH_MAJOR_VERSION;
		var minorVersion 	= (props.minorVersion)?props.minorVersion:FLASH_MINOR_VERSION;
		var revision 			= (props.revision)?props.revision:FLASH_REVISION;
		DEFAULT_NOFLASH_HTML = (props.noflash)?props.noflash:DEFAULT_NOFLASH_HTML;

		var hasProductInstall = this.detect(this.checkerVersion.major, this.checkerVersion.minor, this.checkerVersion.revision);
		var hasReqestedVersion = this.detect(majorVersion, minorVersion, revision);

		var html = "";
		if ( hasProductInstall && !hasReqestedVersion ) {
			if(isU6r65){
				html = this.displayInstaller(props);
			}else{
				html = this.displayAlternateContent();
			}
		} else if (hasReqestedVersion) {
			html = this.displayContent(props);
		} else {
			html = this.displayAlternateContent();
		}
		document.write(html);
	},
	displayContent:function(props){
		return this.getObjectTags(props);
	},
	displayInstaller:function(props){
		return DEFAULT_NOFLASH_HTML;
		var obj = new Object();
		obj.MMredirectURL = window.location;
		obj.MMplayerType  = "ActiveX";
		obj.MMdoctitle    = "MMdoctitle";
		props.queries = obj; 
		props.dir = PLAYER_PRODUCTION_INSTALLER_DIR;
		props.src = PLAYER_PRODUCTION_INSTALLER_FILE; 
		return this.getObjectTags(props);
	},
	displayAlternateContent:function(){
		return DEFAULT_NOFLASH_HTML;
	},
	getObjectTags:function(props){
		var src 		= (props.src)?props.src:"";
		var width 		= (props.width)?props.width:"";
		var height		= (props.height)?props.height:"";
		var dir 		= (props.dir)?props.dir:DEFAULT_FLASH_DIRECTORY;
		var bgcolor 	= (props.bgcolor)?props.bgcolor:"#ffffff";
		var align		= (props.align)?props.align:"";
		var flashVers = (props.flashVers)?props.flashVers:"";
		var wmode	= (props.wmode)?props.wmode:"window";
		var fname	= (props.fname)?props.fname:"flashName";
		var queriesStr	= (props.queries)?this.queryObjToStr(props.queries):"";
		var flashvars 		= (props.flashvars)?props.flashvars:"";
		var allowScriptAccess 		= (props.allowScriptAccess)?props.allowScriptAccess:"sameDomain";

		var htmlStr = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+width+'" height="'+height+'" id="'+fname+'">';
		htmlStr += '<param name="movie" value="'+dir+src+queriesStr+flashVers+'">';
		htmlStr += '<param name="quality" value="high">';
		htmlStr += '<param name="bgcolor" value="'+bgcolor+'">';
		htmlStr += '<param name="wmode" value="'+wmode+'">';
		htmlStr += '<param name="flashvars" value="'+flashvars+'">';
		htmlStr += '<param name="allowScriptAccess" value="'+allowScriptAccess+'">';
		if(queriesStr.indexOf("MMplayerTypeEmbed")>-1){ queriesStr = queriesStr.split("ActiveX").join("PlugIn"); }
		htmlStr += '<embed src="'+dir+src+queriesStr+flashVers+'" quality="high" wmode="'+wmode+'" bgcolor="'+bgcolor+'" width="'+width+'" height="'+height+'" flashvars="'+flashvars+'" name="'+fname+'" aligh="middle" play="true" loop="false" quality="high" allowScriptAccess="'+allowScriptAccess+'" type="application/x-shockwave-flash">';
		htmlStr += '<\/embed>';
		htmlStr += '<\/object>';
		return htmlStr;
	},
	queryObjToStr:function(obj){
		if(!obj) return false;
		var queryArr = new Array();
		for(var tmp in obj){
			queryArr[queryArr.length] = tmp+"="+obj[tmp];
		}
		return (queryArr.length>0)?"?"+queryArr.join("&"):res;
	},
	GetSwfVer:function(){
		// NS/Opera version >= 3 check for Flash plugin in plugin array
		var flashVer = -1;
		
		if (navigator.plugins != null && navigator.plugins.length > 0) {
			if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
				var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
				var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;			
				var descArray = flashDescription.split(" ");
				var tempArrayMajor = descArray[2].split(".");
				var versionMajor = tempArrayMajor[0];
				var versionMinor = tempArrayMajor[1];
				if ( descArray[3] != "" ) {
					tempArrayMinor = descArray[3].split("r");
				} else {
					tempArrayMinor = descArray[4].split("r");
				}
				var versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;
				var flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
			}
		}
		// MSN/WebTV 2.6 supports Flash 4
		else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
		// WebTV 2.5 supports Flash 3
		else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
		// older WebTV supports Flash 2
		else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
		else if ( this.isIE && this.isWin && !this.isOpera ) {
			//flashVer = ControlVersion();
		}	
		return flashVer;
	},
	detect:function(reqMajorVer, reqMinorVer, reqRevision){
	 	reqVer = parseFloat(reqMajorVer + "." + reqRevision);
	   	// loop backwards through the versions until we find the newest version	
		for (i=25;i>0;i--) {	
			if (this.isIE && this.isWin && !this.isOpera) {versionStr = VBGetSwfVer(i);}
			else {versionStr = this.GetSwfVer(i);}
			if (versionStr == -1 ) {
				return false;
			} else if (versionStr != 0) {
				if(this.isIE && this.isWin && !this.isOpera) {
					tempArray = versionStr.split(" ");
					tempString = tempArray[1];
					versionArray = tempString .split(",");
				} else {
					versionArray = versionStr.split(".");
				}
				versionMajor = versionArray[0];
				versionMinor = versionArray[1];
				versionRevision = versionArray[2];
				//
				versionString = versionMajor + "." + versionRevision;
				versionNum = parseFloat(versionString);
				//
				if(versionMajor == reqMajorVer) {
					if(versionMinor == reqMinorVer) {return (versionRevision >= reqRevision);}
					else{return (versionMinor > reqMinorVer);}
				}else {
					// begin:modified 0902
					if(versionMajor>=7){
						isU6r65 = true;
					}else if(versionMajor==6){
						if(versionMinor>=1){
							isU6r65 = true;
						}else if(versionRevision>=65){
							isU6r65 = true;
						}else{
							isU6r65 = false;
						}
					}else{
						isU6r65 = false;
					}
					// end:modified 0902
					return (versionMajor > reqMajorVer);
				}
				//
			}
		}
	}
}
var gsSwfObj = new GsSwfObj();
