﻿// ***************************
// *****  Brand buttons  *****
// ***************************

	var allBrands = new Array;
	var brandsRevealed = false;
	var activeBrandIndex = null;
	var activeBrandTimeout = null;
	
	function revealBrands() {
		if(document.getElementById("homeBrandsPanel") && graphicVersion) {
			
			// store elements in objects
			var getBrandContainers = document.getElementById("homeBrandsPanel").getElementsByTagName("DD");
			for(i=0; i<getBrandContainers.length; i++) {
				allBrands[i] = new Object;
				allBrands[i].dd = getBrandContainers[i];
				allBrands[i].alink = getBrandContainers[i].getElementsByTagName("A")[0];
				allBrands[i].slide = getBrandContainers[i].getElementsByTagName("SPAN")[0];
			}
			
			// animate up
			setTimeout("slideBrandPhoto(3);",100);
			setTimeout("slideBrandPhoto(2);",200);
			setTimeout("slideBrandPhoto(4);",200);
			setTimeout("slideBrandPhoto(1);",300);
			setTimeout("slideBrandPhoto(5);",300);
			setTimeout("slideBrandPhoto(0);",400);
			setTimeout("slideBrandPhoto(6);",400);
			setTimeout("brandsRevealed = true;startHomeHeadlines()",900);
		}
	}
	
	function slideBrandPhoto(getIndex) {
		if($) {
			$(allBrands[getIndex].slide).animate({top:'10px'}, 500);
		} else {
			setPos(allBrands[getIndex].slide,0,0);
		}
	}
	
	function clickBrand(getIndex) {
		window.location = allBrands[getIndex].alink.href;
	}
	
	function overBrand(getIndex) {
		clearTimeout(activeBrandTimeout);
		if(graphicVersion && getIndex != activeBrandIndex) {
			activeBrandIndex = getIndex;
			for(i=0; i<allBrands.length; i++) {
				if(i == getIndex) {
					// move up
					if($) {
						$(allBrands[i].slide).stop(true,false);
						$(allBrands[i].slide).animate({top:'0px'}, 150);
					} else {
						setPos(allBrands[i].slide,0,0);
					}
				} else {
					// move down
					if($) {
						$(allBrands[i].slide).stop(true,false);
						$(allBrands[i].slide).animate({top:'10px'}, 150);
					} else {
						setPos(allBrands[i].slide,0,0);
					}
				}
			}
		}
	}
	
	function outBrand(getIndex) {
		activeBrandTimeout = setTimeout("doOutBrand();",200);
	}
	
	function doOutBrand() {
		if(graphicVersion) {
			for(i=0; i<allBrands.length; i++) {
				// move down
				if($) {
					$(allBrands[i].slide).stop(true,false);
					$(allBrands[i].slide).animate({top:'10px'}, 150);
				} else {
					setPos(allBrands[i].slide,0,0);
				}
			}
		}
		activeBrandIndex = null;
	}
	

// *******************************
// *****  Home Headline Bar  *****
// *******************************

	// array to store headline content
	var allHeadlines;
	var headlinesContainer;
	var headlineIndex = -1;

	function startHomeHeadlines() {
		headlinesContainer = document.getElementById("homeHeadlinesContainer");
		allHeadlines = headlinesContainer.getElementsByTagName("li");
		for(i=0;i<allHeadlines.length;i++) {
			if($) {
				$(allHeadlines[i]).fadeOut(0);
			} else {
				allHeadlines[i].style.display = "none";
			}
		}
		if($) {
			setTimeout("slideupHomeHeadlines()", 1000);
		} else {
			slideupHomeHeadlines();
		}
	}
	
	function slideupHomeHeadlines() {
		// slide up headlines container
		if($) {
			$(headlinesContainer).animate({top:'0px'}, 500, function() {			 
				// Animation complete.
				fadeInHeadline();
			});
		} else {
			setPos(headlinesContainer,0,0);
			fadeInHeadline();
		}
	}
	
	function fadeInHeadline() {
		headlineIndex +=1;
		if(headlineIndex >= allHeadlines.length) headlineIndex = 0;
		if($) {
			$(allHeadlines[headlineIndex]).fadeIn(200, function() {			 
				// Animation complete.
				if(allHeadlines.length > 1) setTimeout("fadeOutHeadline()",5000);
			});
		} else {
			allHeadlines[headlineIndex].style.display = "block";
			if(allHeadlines.length > 1) setTimeout("fadeOutHeadline()",5000);
		}
	}
	
	function fadeOutHeadline() {
		if($) {
			$(allHeadlines[headlineIndex]).fadeOut(200, function() {			 
				// Animation complete.
				setTimeout("fadeInHeadline()",200);
			});
		} else {
			allHeadlines[headlineIndex].style.display = "none";
			setTimeout("fadeInHeadline()",200);
		}
	}
	

// *************************************
// *****  Fading Image Panel Code  *****
// *************************************

	var homeImagesPath = new Array();
	var homeImagesDelay = new Array();
	
	var panelA;
	var panelB;
	var panelIndex = 0;
	var nextIndex = 1;
	var activePanel = "panelA";
	var inactivePanel = "panelB";
	var panelDelay = true;
	var panelDelayTimer = null;
	
	function getNextIndex() {
		nextIndex = panelIndex + 1;
		if(nextIndex >= homeImagesPath.length) nextIndex = 0;
	}
	
	function startImageRotator() {
		if(document.getElementById("homeImageA")) {
			panelA = document.getElementById("homeImageA");
			panelB = document.getElementById("homeImageB");
			// load panelB image
			loadNextImage();
		}
	}
	
	function loadNextImage() {
		panelDelayTimer = setTimeout("panelDelay = false;", homeImagesDelay[panelIndex] * 1000);
		panelDelay = true;
		if(activePanel == "panelA") {
			homeBGswap = panelB;
		} else {
			homeBGswap = panelA;
		}
		homeBGswap.innerHTML = "<img src='" + homeImagesPath[nextIndex] + "' width='1500' height='675' alt='background image' \/>";
		homeBGswap.getElementsByTagName("IMG")[0].onload = function() {
			setTimeout("swapPanels();", 1000);
		}
	}
	
	function swapPanels() {
		if(panelDelay) {
			setTimeout("swapPanels();", 200);
		} else {
			panelA = document.getElementById("homeImageA");
			panelB = document.getElementById("homeImageB");
			if(activePanel == "panelA") {
				if($) {
					$(panelA).fadeOut(2000, function() {			 
						// Animation complete.
						activePanel = "panelB";
						panelIndex = nextIndex;
						getNextIndex();
						loadNextImage();
					});
				} else {
					panelA.style.visibility = "hidden";
					activePanel = "panelB";
					panelIndex = nextIndex;
					getNextIndex();
					loadNextImage();
				}
			} else {
				if($) {
					$(panelA).fadeIn(2000, function() {
						// Animation complete.
						activePanel = "panelA";
						panelIndex = nextIndex;
						getNextIndex();
						loadNextImage();
					});
				} else {
					panelA.style.visibility = "visible";
					activePanel = "panelA";
					panelIndex = nextIndex;
					getNextIndex();
					loadNextImage();
				}
			}
		}
	}
	

// ***************************
// *****  Home Expander  *****
// ***************************

	var homeExpanded = false;
	
	function expandHomeContent(getLink) {
		if(homeExpanded) {
			if($) {
				$('#homeExpanderMask').animate({height: '0px'}, 200);
			} else {
				document.getElementById("homeExpanderMask").style.height = "0px";
				document.getElementById("homeExpanderMask").style.overflow = "hidden";
			}
			if(siteLanguage == "en") {
				document.getElementById("expandCollapse").innerHTML = "<a href='#' onclick='expandHomeContent();'>More info<span class='expanderArrowDown'><\/span><\/a>";
			} else {
				document.getElementById("expandCollapse").innerHTML = "<a href='#' onclick='expandHomeContent();'>更多信息<span class='expanderArrowDown'><\/span><\/a>";
			}
			homeExpanded = false;
		} else {
			expandHeight = parseFloat(document.getElementById("homeExpandedContent").offsetHeight);
			if($) {
				$('#homeExpanderMask').animate({height: expandHeight + 'px'}, 200);
			} else {
				document.getElementById("homeExpanderMask").style.height = "auto";
				document.getElementById("homeExpanderMask").style.overflow = "show";
			}
			if(siteLanguage == "en") {
				document.getElementById("expandCollapse").innerHTML = "<a href='#expandedContent' onclick='expandHomeContent();'>Hide info<span class='expanderArrowUp'><\/span><\/a>";
			} else {
				document.getElementById("expandCollapse").innerHTML = "<a href='#expandedContent' onclick='expandHomeContent();'>隐藏信息<span class='expanderArrowUp'><\/span><\/a>";
			}
			homeExpanded = true;
		}
	}
	
