﻿// JScript File

//------------------------------------------------------------------------------------------------------------
function SwitchImage(obj , image , lihover, lienbable){
		var objImageDiv = $(obj).children("a").children("div .img");
		var intNewPosition = GetX(obj,lienbable,lihover); 
		
		var CssOutSideImageSetting = {
			'background-image' : 'url(' + image + ')',
			'background-position' : intNewPosition + 'px 0px'
		}
		
		var CssImageSetting = {
			'background-image' : 'url(' + image + ')',
			'background-position' : intNewPosition + 'px 0px',
			'width' :'130px',
			'height' :'125px',
			'display' : 'none'
		}
		
		if(jQuery.browser.msie == false){
			if(objImageDiv.find("div").length == 0 ){
				var divFader = document.createElement('div');
				objImageDiv.append(divFader);
			}
			objImageDiv.find("div:first").css(CssImageSetting);
		}
		if(jQuery.browser.msie == false && lihover == true && lienbable == true){
			objImageDiv.find("div:first").fadeIn(400);
		}else{ 
			objImageDiv.css(CssOutSideImageSetting);
		}
	}
//------------------------------------------------------------------------------------------------------------	
	function GetX(objLi,lienbable,lihover){		
		var intXposition = 0; 
		if($(objLi).attr("class").indexOf("normalProduct") > -1){
				intXposition = -130;
		}
		
		if(lienbable == true){
			if(lihover == true){
				intXposition = intXposition - 520;
			}
		}else{
			intXposition = intXposition - 260;
		}
		
		return intXposition;
	}
//------------------------------------------------------------------------------------------------------------	
	function setupTitleBar(){
		if($('#titlebarpage').length > 0){
			$('#titlebarpage').height(42).css('overflow','hidden');
		}
		if($('#orinigalSecond').length > 0){
			$('#orinigalSecond').height(42).css('overflow','hidden');
		}
	}
	
	function HideLeftMenuAndProductHome(){
		//setup layout for product all list
		$("#c1menu").css("display","none");
		$("#fontarea01").css("display","none");
		$("#c4content").width(960);
		//move content title
		if(jQuery.browser.msie == true && jQuery.browser.version == '6.0'){
			if($("#c2font").length > 0){
				$("#t01").css("display","none");
			}
		}else{
			$("#c2font").css("margin-" + _strDivAlign, "-211px");
		}
	}
	
	function HideLeftMenu(){
		//setup layout for product all list
		$("#c1menu").css("display","none");
		if($("#c2ForProductAllList").length == 0){
			//image
			$("#t02").css("margin-" + _strDivAlign, "-218px");
		}
		
		if(jQuery.browser.msie == true && jQuery.browser.version == '6.0'){
			var CssSetting = {
				'margin-left' : '40px',
				'margin-right' : '40px',
				'width' : '860px'
			}
			$("#supportcontent").css(CssSetting);
			$("#support").width(860);
		}else{
			var CssReset = {
				'width' : '900px'
			}
			$("#supportcontent").css(CssReset);
			$("#support").width(900);
		}
	}
//------------------------------------------------------------------------------------------------------------	
	function SetupUsSiteOperatorButtons(){
		var divOperatorButtons = 'divOperatorButtons';
		var intClickedButtonIndex = -1;
		if($('#' + divOperatorButtons + ' ul li').length > 0){
			jQuery.each($('#' + divOperatorButtons + ' ul li'), function(i, val) {
				var objLi = $(this);
				
				//gery out all
				var CssSettingHover = {
					'background-position' : '0px 0px',
					'cursor' : 'pointer'
				}
				var CssSettingRelease = {
					'background-position' : '0px -42px',
					'cursor' : 'default'
				}
				objLi.css(CssSettingRelease);
				
				var onclickAttr = objLi.attr("onclick");
				if(onclickAttr != null){
					var onclickString = onclickAttr.toString();
					if(onclickString.indexOf('location') > -1){
						var strUrl = onclickString.replace("function","").replace("anonymous","").replace("onclick","").replace("event","");
						strUrl = strUrl.replace("window.location","").replace("location.href","");
						strUrl = strUrl.replace(/\=/g,"").replace(/\'/g,"").replace(/\"/g,"");
						strUrl = strUrl.replace(/[\r\n]/g,"");
						strUrl = strUrl.replace(/\{/g,"").replace(/\}/g,"").replace(/\(/g,"").replace(/\)/g,"").replace(/\;/g,"").replace(/\ /g,"");
							if(location.href.indexOf(strUrl) > -1){
								intClickedButtonIndex = i;
								objLi.css(CssSettingHover);
							}
					}
				}
				
				//setup hover
				objLi.hover(
					function(){
						objLi.css(CssSettingHover);
					},
					function(){
						if(intClickedButtonIndex != i){
							objLi.css(CssSettingRelease);
						}
					}
				);		
				
			});
		}
	}

//for sushiboat product all button --> called this function from flash file------------------------------------------
	function ShowAllProductButton(){
		if(DisplayProductAll == true){
			return 'N';
		}else{
			return 'Y';
		}
	}
//product page and product list-------------------------------------------------------------------------------
	function SetupVerticalDivs(DivName, query){
			
		var intBlockWidth = 0;
		var objBlock = $('#' + DivName);
		objBlock.hide();
		var intColumn = 0;

		if(typeof(objBlock.attr("class")) != 'undefined'){
			intColumn = objBlock.attr("class").replace(".Column","");
		}
		
		//ie6 need 20px for width
		var intIE6NeedMoreWidth = 0;
		if(jQuery.browser.msie == true && jQuery.browser.version == '6.0'){
			intIE6NeedMoreWidth = 20;
		}
		
		//show block
		

		//has column setting
		if(intColumn > 0){
			//setup div width 
			intBlockWidth = intColumn * 132 + intIE6NeedMoreWidth;
			objBlock.width(intBlockWidth);
		
			_intDivDisplay += 1;
			//setup boder-left color from column2
			if(_intDivDisplay > 1){
				objBlock.css("border-" + _strDivAlign,"solid 1px #eeeeee");
			}
			//store block width for each div
			
			
			//setup li
			 jQuery.each($('#' + DivName + ' ul li'), function(i, val) {
				var objLi = $(this);
				var objLink = objLi.children("a"); //$(this).children("a")
				var objDivImage = objLink.children("div:first"); //$(this).children("a").children("div:first")
				var objDivText = objLink.children("div .textpart"); //$(this).children("a").children("div:first")
				var isEable = true;
				
				var CssEnableSetting = {
					'outline' : 'none',
					'text-decoration' : 'none',
					'cursor' : 'pointer',
					'color' : '#000000'
				}
				
				var CssDisableSetting = {
					'outline' : 'none',
					'text-decoration' : 'none',
					'cursor' : 'default',
					'color' : '#ACA899'
				}
						
				//enable link
				objLink.attr("disabled", "");
				objLink.css(CssEnableSetting);
				objDivText.css(CssEnableSetting);
				
			    
				if(query != 'default' && objDivImage.attr("class").indexOf(query) == -1){			
						//disable link
						objLink.attr("disabled", "disabled");
						objLink.css(CssDisableSetting);
						objDivText.css(CssDisableSetting);
						isEable = false;
				}
				//setup href
				if(isEable == true){
					objLink.click(function(){ 
						if(pageTracker){
						
							var ProductName = objDivText.html().replace(/\ /g, '').toLowerCase();
							ProductName = ProductName.replace(/\(/g, '').replace(/\)/g, '').replace(/\-/g, '').replace(/\(/g, '');
							ProductName = ProductName.replace(/\™/g, '').replace(/\®/g, '').replace(/\htc/g, '');
							var UrlString = '/tracker/' + _strSiteFullName + '/product/alldevices/' + ProductName + '/clicks';

							pageTracker._trackPageview(UrlString);
							//_trackEvent() is another function
							//pageTracker._trackEvent('Product', 'Click', UrlString); 
						}
						location.href = objLink.attr("class");
						return false;
					});
				}else{
					objLink.click(function(){
						$(this).attr("href","javascript:void(0);");
					});
				}
				
				//get image----------------------------------------------------
				var strImageName = objLi.attr("class").replace(' .newProduct','').replace(' .normalProduct','').replace('.','')

				//setup default image
				SwitchImage(objLi,strImageName,false,isEable);
	
				objLi.unbind('mouseenter').unbind('mouseleave');
				//setup hover--------------------------------------------
				objLi.hover(
					function(){
						SwitchImage(this,strImageName,true,isEable);
					},
					function(){
						SwitchImage(this,strImageName,false,isEable);
					}
				);
			});
			
			//setup div height
			var intDivHeight = objBlock.height() + 20;
			 if(  intDivHeight > _intDivHeight){
				_intDivHeight = intDivHeight;
			 }
			
			//setup div background color (only 3 columns display, divB's background color will be grey)
			var intFixWidth = 54;
			if(jQuery.browser.msie == true && jQuery.browser.version == '6.0'){
				intFixWidth = intFixWidth - intIE6NeedMoreWidth;
			}
			
			switch (_intDivDisplay){
			case 1:
				$('#divCornerBlockA').width((intBlockWidth + intFixWidth) + 'px');
				$('#divCornerBlockB').css('display','none');
				break;
			case 2:
				var cssBoderAlign = "border-" + _strDivAlign;
				$('#divCornerBlockB').width((intBlockWidth + intFixWidth) + 'px');
				var CssSetting = {
					'display' : 'block',
					'background-color' : '#ffffff'
				}
				$('#divCornerBlockB').css(CssSetting).css(cssBoderAlign,'solid 1px #eeeeee');
				break;
			case 3:
				$('#divListB').css("background-color","#f5f5f5");
				var CssSetting = {
					'display' : 'block',
					'background-color' : '#f5f5f5',
					'border-left' : 'solid 1px #eeeeee',
					'border-right' : 'solid 1px #eeeeee'
				}
				$('#divCornerBlockB').css(CssSetting);
				break;
			}
			
			
			//show div
			objBlock.show();
		}
	}
	
//support & press product list------------------------------------------------------------------------------------------
	function SetupHorizontalDivs(DivName, query){
		
		var intBlockWidth = 0;
		var objBlock = $('#' + DivName);
		objBlock.hide();
		var intColumn = 0;

		if(typeof(objBlock.attr("class")) != 'undefined'){
			intColumn = objBlock.attr("class").replace(".Column","");
		}
		
		//ie6 need 20px for width
		var intIE6NeedMoreWidth = 0;
		if(jQuery.browser.msie == true && jQuery.browser.version == '6.0'){
			intIE6NeedMoreWidth = 20;
		}

		//has column setting
		if(intColumn > 0){
			//setup div width 
			intBlockWidth = intColumn * 132 + intIE6NeedMoreWidth;
			objBlock.width(intBlockWidth);
		
			_intDivDisplay += 1;
			
			//setup li
			 jQuery.each($('#' + DivName + ' ul li'), function(i, val) {
				var objLi = $(this);
				var objLink = objLi.children("a"); //$(this).children("a")
				var objDivImage = objLink.children("div:first"); //$(this).children("a").children("div:first")
				var objDivText = objLink.children("div .textpart"); //$(this).children("a").children("div:first")
				var isEable = true;
				
				var CssEnableSetting = {
					'outline' : 'none',
					'text-decoration' : 'none',
					'cursor' : 'pointer',
					'color' : '#000000'
				}
						
				//enable link
				objLink.attr("disabled", "");
				objLink.css(CssEnableSetting);
				objDivText.css(CssEnableSetting);
				
			    
				//setup href
				/*objLink.click(function(){
					var ProductName = objDivText.html().replace(/\ /g, '_').toLowerCase();
					pageTracker._trackPageview('/il_tracker/' + _strSiteFullName + '/' + _strFromPage + '_page_product_list/' + ProductName + '/clicks');
					$(this).attr("href",$(this).attr("class"));
				});*/
				
				objLink.click(function(){ 
						if(pageTracker){
						
							var ProductName = objDivText.html().replace(/\ /g, '').toLowerCase();
							ProductName = ProductName.replace(/\(/g, '').replace(/\)/g, '').replace(/\-/g, '').replace(/\(/g, '');
							ProductName = ProductName.replace(/\™/g, '').replace(/\®/g, '').replace(/\htc/g, '');
							var UrlString = '/tracker/' + _strSiteFullName + '/' + _strFromPage + '/alldevices/' + ProductName + '/clicks';

							pageTracker._trackPageview(UrlString);
							//_trackEvent() is another function
							//pageTracker._trackEvent('Product', 'Click', UrlString); 
						}
						location.href = objLink.attr("class");
						return false;
				});

				//get image----------------------------------------------------
				var strImageName = objLi.attr("class").replace(' .newProduct','').replace(' .normalProduct','').replace('.','')

				//setup default image
				SwitchImage(objLi,strImageName,false,isEable);
	
				objLi.unbind('mouseenter').unbind('mouseleave');
				//setup hover--------------------------------------------
				objLi.hover(
					function(){
						SwitchImage(this,strImageName,true,isEable);
					},
					function(){
						SwitchImage(this,strImageName,false,isEable);
					}
				);
			});
			
			//show div
			objBlock.show();
		}
	}

