﻿// 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 HideLeftMenuAndProductAll(){
		//Product all list
		if(ShowOperatorButtonsDivForProductAllPage == true){
			showOperatorButtons();
		}else{
			hideOperatorDiv();
		}
	}
	
	function HideLeftMenuAndShowContentTitle(){
		//Product main page
		showOperatorButtons();
		hideLeftNavigation();
	}

	function HideLeftMenuAndShowOperatorButtons(){
		//Operator page
		showOperatorButtons();
		hideLeftNavigation();
		$('#mainContentBar').css("display","none");
	}
	
	function showOperatorButtons(){
		var divProductOperator = 'divProductOperator';
		if($('.' + divProductOperator).length > 0){
			$('.' + divProductOperator).css("display","block");
		}
	}
	
	function hideOperatorDiv(){
		var divProductOperator = 'divProductOperator';
		if($('.' + divProductOperator).length > 0){
			$('.' + divProductOperator).css("display","none");
		}
	}
	
	function hideLeftNavigation(){
		$('#leftcontentarea').css("display","none");
		
		if(jQuery.browser.msie == true && jQuery.browser.version == '6.0'){
			var CssSetting = {
				'margin-left' : '10px',
				'margin-top' : '6px',
				'width' : '900px'
			}
			$("#subContentArea").css(CssSetting);
		}else{
			var CssSetting = {
				'margin-left' : '20px',
				'margin-top' : '6px',
				'width' : '900px'
			}
			$("#subContentArea").css(CssSetting);
		}
		
	}
//------------------------------------------------------------------------------------------------------------	
	function SetupUsSiteOperatorButtons(){
		//alert('SetupUsSiteOperatorButtons');
		var divProductOperator = 'divProductOperator';
		var intClickedButtonIndex = -1;
		//alert("length:" + $('.' + divProductOperator + ' ul li').length)
		if($('.' + divProductOperator + ' ul li').length > 0){
			jQuery.each($('.' + divProductOperator + ' 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' : '#82786f'
				}
				
				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:
				break;
			case 2:
				break;
			case 3:
				$('#divListB').css("background-color","#f5f5f5");
				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();
		}
	}
	
	
	//setup product news
	function ShowNews(){
		
		$('#subContentArea').width('500px');
		$('#maincontentarea').width('733px');
		
		var cssVisibleObj = {
			'display' : 'block'
		}
		$('#c3news').css(cssVisibleObj);

	}
	
	function HideNews(){
		var cssVisibleObj = {
			'display' : 'none'
		};
		$('#c3news').css(cssVisibleObj);
		var cssContent = {
			'width' : '700px'
		};
		$('#subContentArea').css(cssContent);
	}
	
	//setup product news in product_gallery.aspx------------------------------------------------
	function ShowNewsInGallery(){
		var cssContent = {
			'width' : '520px',
			'margin' :'0px',
			'padding' : '0px 0px 0px 6px',
			'overflow' : 'hidden'
		};
		$('#subContentArea').css(cssContent);
		
		var cssMainContent = {
			'width' : '733px',
			'float' : 'left'
		};
		$('#maincontentarea').css(cssMainContent);
		
		var cssVisibleObj = {
			'display' : 'block'
		};
		$('#c3news').css(cssVisibleObj);
	}
	
	function HideNewsInGallery(){
		var cssVisibleObj = {
			'display' : 'none'
		};
		$('#c3news').css(cssVisibleObj);
		
		var cssContent = {
			'width' : '720px',
			'margin' :'0px',
			'padding' : '0px'
		};
		$('#subContentArea').css(cssContent);
	}

//setup product news in product_press_review.aspx-------------------------------------------------
	function ShowNewsInReward(){
		var cssContent = {
			'width' : '520px',
			'margin' :'0px',
			'padding' : '0px 0px 0px 6px',
			'overflow' : 'hidden'
		};
		$('#subContentArea').css(cssContent);
		
		var cssMainContent = {
			'width' : '733px',
			'float' : 'left'
		};
		$('#maincontentarea').css(cssMainContent);
		
		var cssVisibleObj = {
			'display' : 'block'
		};
		$('#c3news').css(cssVisibleObj);
	}
	
	function HideNewsInReward(){
		var cssVisibleObj = {
			'display' : 'none'
		};
		$('#c3news').css(cssVisibleObj);
		
		var cssContent = {
			'width' : '720px',
			'margin' :'0px',
			'padding' : '0px'
		};
		$('#subContentArea').css(cssContent);
	}
