/*	-------------------------------------------------------------
	lostart China
	Flash | Web | Design | Layout | Css
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	Description:	Generic Scripts / Functions
	Filename:		jsCore.js
	Version:		1.0
	Date:			Apr 10, 2007
	-------------------------------------------------------------	*/
	
	
/*	-------------------------------------------------------------
	function getCookie(), setCookie(), deleteCookie()
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	Description:	Yes, these functions are used for handling
					cookies.
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -	*/
		
		<!--
		function getCookie(CookieName) {
			var start = document.cookie.indexOf(CookieName + '=');
			var len = start + CookieName.length + 1;
			if ((!start) && (CookieName != document.cookie.substring(0,CookieName.length)))
				return null;
			if (start == -1)
				return null;
			var end = document.cookie.indexOf(';',len);
			if (end == -1) end = document.cookie.length;
				return unescape(document.cookie.substring(len,end));
		}

		/*function setCookie(CookieName,value,expires,path,domain,secure) {
			document.cookie = CookieName + "=" +escape(value) +
			( (expires) ? ";expires=" + expires : "") +
			( (path) ? ";path=" + path : "") + 
			( (domain) ? ";domain=" + domain : "") +
			( (secure) ? ";secure" : "");
		}*/
		function setCookie(name,value,days) {
			if (days) {
				var date = new Date();				
				date.setTime(date.getTime() + (days*24*60*60*1000));
				var expires = "; expires=" + date.toGMTString();
			}
			else var expires = "";
			document.cookie = name + "=" + value + expires + "; path=www.lostartchina.com";
		}

		function deleteCookie(CookieName,path,domain) {
			if (getCookie(CookieName))
				document.cookie =
				CookieName + '=' +
				( (path) ? ';path=' + path : '') +
				( (domain) ? ';domain=' + domain : '') +
				';expires=Thu, 01-Jan-1970 00:00:01 GMT';
		}
		//-->
	
/*	-------------------------------------------------------------
	function getBrowserWidth()
           function getBrowserHeight()
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	Description:	As odd as it may seem, this function returns
					the browser's width in pixels.
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	Credits:		Script found on Particle Tree
					http://www.particletree.com
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -	*/
	
		<!--
		function getBrowserWidth(){
			if (window.innerWidth){
				return window.innerWidth;}	
			else if (document.documentElement && document.documentElement.clientWidth != 0){
				return document.documentElement.clientWidth;	}
			else if (document.body){return document.body.clientWidth;}		
				return 0;
		}
		//-->
		
		function getBrowserHeight(){
			if (window.innerHeight){
				return window.innerHeight;}	
			else if (document.documentElement && document.documentElement.clientHeight != 0){
				return document.documentElement.clientHeight;	}
			else if (document.body){return document.body.clientHeight;}		
				return 0;
		}

/*	-------------------------------------------------------------
	function determineStyle()
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	Description:	With this here function we can swap styles.
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	Credits:		Script found on A List Apart
					http://www.alistapart.com
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -	*/
	
		<!--
		function determineStyle(){
			
			var browserHeight = getBrowserHeight();
				
			var i, a, main;
			
			if (browserHeight <= 740){
				for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
					if(a.getAttribute("rel").indexOf("style") != -1
					&& a.getAttribute("title")) {
						a.disabled = true;
						if(a.getAttribute("title") == "narrow") a.disabled = false;
					}
				}
			}
			
			if (browserHeight > 740){
				for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
					if(a.getAttribute("rel").indexOf("style") != -1
					&& a.getAttribute("title")) {
						a.disabled = true;
						if(a.getAttribute("title") == "wide") a.disabled = false;
					}
				}
			}
		}
		//-->
	

/*	-------------------------------------------------------------
	function setLinkAttributes()
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	Description:	setLinkAttributes finds ALL anchor links and
					can set new attributes. The following script
					specifically finds anchor links labeled as
					external, and add a terget="_blank". We do
					in order to validate in XHTML 1.1 Strict.
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	Credits:		Script found on Site Point (I think)
					http://www.sitepoint.com
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -	*/
	
		<!--
		function setLinkAttributes(switchLinks) {
			if (switchLinks == "true") {
				if (!document.getElementsByTagName) return;
				var anchors = document.getElementsByTagName("a");
					for (var i=0; i<anchors.length; i++) {
					var anchor = anchors[i];
					
					//if (anchor.getAttribute("href") && ( anchor.getAttribute("rel") == "external" || anchor.getAttribute("rel") == "nofollow" ) ) {
					//	anchor.target = "_blank";
					//}
					
					if (anchor.getAttribute("href") && ( anchor.getAttribute("rel") == "external" ) ) {
						anchor.target = "_blank";
					}
				}
			} else {
				if (!document.getElementsByTagName) return;
				var anchors = document.getElementsByTagName("a");
					for (var i=0; i<anchors.length; i++) {
					var anchor = anchors[i];
					
					if (anchor.getAttribute("href") && ( anchor.getAttribute("rel") == "external" || anchor.getAttribute("rel") == "nofollow" ) ) {
						anchor.target = "_self";
					}
				}
			}
		}
		
		function toggleLinkAttributes() {
			var ExpireLongTerm = new Date();
			var ExpireLongTermValue = new Date(ExpireLongTerm.getTime()+(1000 * 60 * 60 * 360000));
			
			if ( getCookie("externalLinks") == "true" ) {
				setLinkAttributes("false");
				setCookie("externalLinks","false",ExpireLongTermValue);
			} else if (getCookie("externalLinks") == "false") {
				setLinkAttributes("true");
				setCookie("externalLinks","true",ExpireLongTermValue);
			} else if ( !getCookie("externalLinks") ) {
				setLinkAttributes("true");
				setCookie("externalLinks","true",ExpireLongTermValue);
			}
		}
		//-->
	
	
/*	-------------------------------------------------------------
	function toTop()
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	Description:	This little functions performs a smooth
					scroll from the bottom to the top of the
					page.
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -	*/
		
		<!--
		var g_USER_AGENT = getAgent();
		
		// return NN4, NN5(Netscape 6+, Mozilla 1+?), IE4, IE5(IE5+), Unknown
		function getAgent(){
		  var userAgent = navigator.userAgent;
		  var charIndex;
		  var majorVersion;
		
		  charIndex = userAgent.indexOf("MSIE");
		  if(charIndex){
			majorVersion = userAgent.charAt(charIndex + 4 + 1);
			if(majorVersion > 4){
			  return("IE5");
			}
			else if(majorVersion == 4){
			  return("IE4");
			}
		  }
		
		  charIndex = userAgent.indexOf("Mozilla");
		  majorVersion = userAgent.charAt(charIndex + 7 + 1);
		  if(majorVersion > 4){
			return("NN5");
		  }
		  else if(majorVersion == 4){
			return("NN4");
		  }
		
		  return("Unknown");
		}
		/* USER_AGENT check end -------------------------------------------------- */
		
		function getWindowYOffset(){
		  if(g_USER_AGENT == "IE5" || g_USER_AGENT == "IE4"){
			return document.body.scrollTop;
		  }else if(g_USER_AGENT == "NN5" || g_USER_AGENT == "NN4"){
			return window.pageYOffset;
		  }else{
			return 0;
		  }
		}
		
		var waitTimer;
		function jumpTo(dstY, srcY, scrollRate, waitMillSec) {
		  if(waitTimer){
			clearTimeout(waitTimer);
		  }
		  if( ! dstY || dstY < 0 ){
			dstY = 0;
		  }
		  if( ! srcY ){
			srcY = 0 + getWindowYOffset();
		  }
		  if( ! scrollRate ){
			scrollRate = 5;
		  }
		  if( ! waitMillSec ){
			waitMillSec = 20;
		  }
		
		  srcY += (dstY - getWindowYOffset()) / scrollRate;
		  if(srcY < 0){
			srcY = 0;
		  }
		  posY = Math.floor(srcY);
		  window.scrollTo(0, posY);
		
		  if(posY != dstY){
			waitTimer = setTimeout("jumpTo("+ dstY +", "+ srcY +", "+ scrollRate +", "+ waitMillSec +")", waitMillSec);
		  }
		  else if(posY == dstY){
			clearTimeout(waitTimer);
		  }
		  else if(posY < 1){
			window.scroll(0, 0);
		  }
		}
		
		function toTop(){
		  jumpTo(0, 0, 7, 14);
		}
		//-->


	<!-- 
		function doOnResize () {
			determineStyle();
		}
		
		function doOnLoad () {
			determineStyle();
			//if ( getCookie("externalLinks") ) {
			//	setLinkAttributes( getCookie("externalLinks") );
			//}
			setLinkAttributes("true");
		}
			
	//-->
	
	function toggleDisplay(elem){
		el = document.getElementById(elem);
		if (el.style.display == 'block'){
			el.style.display = 'none';
		} else {
			el.style.display = 'block';
		}
	}
	
setCookie("lostartchina.com", "lostart China, flash, web, design, css, layout, lostartchina, lostart Chine, conception", 10);
	