/*	-------------------------------------------------------------
	Executive One Limousine | www.executiveonelimousine.com
	
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	Description:	Generic Scripts / Functions
	Filename:		jsLib.js
	Version:		0.1
	Date:			May 20, 2006
	-------------------------------------------------------------	*/
	


/*	-------------------------------------------------------------
	Macromedia Built-In Functions
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	Description:	Functions perform image pre-loads and image
					swaps for rollovers. 
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -	*/
	<!--
	
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->

/*	-------------------------------------------------------------
	function imgSwap(oImg)
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	Description:	Function swaps image from _r0 to _r1.
					
	Source:			Interaction Architect | www.interactionarchitect.com	
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -	*/
	<!--

function imgSwap(oImg)
{
   var strOver  = "_r1"    // image to be used with mouse over
   var strOff = "_r0"     // normal image
   var strImg = oImg.src
   if (strImg.indexOf(strOver) != -1) 
      oImg.src = strImg.replace(strOver,strOff)
   else
      oImg.src = strImg.replace(strOff,strOver)
}
//-->

/*	-------------------------------------------------------------
	function visoggle(divID, img)
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	Description:	Functions perform toogle indexed div between
					'hideMe' and 'showMe' class.
					
	Source:			
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -	*/
	<!--

// Changes the class of the given tag from classa to classb or back
 function classoggle(tag, classa, classb) {
     if (tag.className==classa){
         tag.className=classb;
     } else {
         tag.className=classa;
     }
 }
 
 // Toggles the class name of the indexed div between 'hideMe' and 'showMe'
 // and toggles the src attribute of the referenced img tag between openPicture and closePicture
 function visoggle(divID, img) {
     var d = document.getElementById(divID);
     classoggle(d, 'hideMe', 'showMe');
     if (img!=undefined && img != 'null') {
         if (img.src == closePicture){
             img.src = openPicture; 
         } else {
             img.src = closePicture;
         }
     }
 }
 
 // Toggles the indicated image and collapses all other ones
 function visoggleSolo(divID, prefix, img, anchor, tagName){
     var d = document.getElementById(divID);
     var isHid = d.className == 'hideMe';
     var noImg = img=='null';
     collapseAll(prefix, 0, noImg, tagName);
     if (isHid){
         if (noImg) {
             visoggle(divID);
         } else {
             visoggle(divID, img);
         }
     }
     if (anchor != 'null') { 
         location.hash=anchor;
     }
 }
 
 // Collapses and changes the image for all tags that start with the given prefix. Expands them if exp=1
 function collapseAll(start, exp, noImg, tagName) {
         var cTag = 'div';
         if(tagName != undefined && tagName!='null'){
             cTag = tagName;
         }//if
         var expand = exp==1;
         var doimages = true;
         if (noImg) {
             doimages = false;
         }//if
         if (expand) {
             if(doimages){
                 var newPic = openPicture;
                 var oldPic = closePicture;
             }//if
             var newClass = 'showMe';
         } else {
             if(doimages){
                 var newPic = closePicture;
                 var oldPic = openPicture;
             }//if
             var newClass = 'hideMe';
         }//else
         if(doimages){
             var allImgs = document.getElementsByTagName('img');
             for (i=0; i < allImgs.length; i++) {
                 if (allImgs[i].name.indexOf(start) == 0){
                     allImgs[i].src = newPic;
                 }//if
             }//for
         }//if
         var allDivs = document.getElementsByTagName(cTag);
         for (i=0; i < allDivs.length; i++) {
             if (allDivs[i].id.indexOf(start) == 0) {
                 allDivs[i].className = newClass
             }//if
         }//for

     }//function
 
//-->

/*	-------------------------------------------------------------
	function toTop()
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	Description:	Functions perform a smooth
					scroll from the bottom to the top of the
					page.
					
	Source:			UX Magazine | www.uxmag.com	
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -	*/

		<!--
		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 getCookie(), setCookie(), deleteCookie()
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	Description:	Yes, these functions are used for handling
					cookies.
	Source:		UX Magazine | http://www.uxmag.com
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -	*/
		
		<!--
		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 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()
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	Description:	As odd as it may seem, this function returns
					the browser's width in pixels.
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	Source:		UX Magazine | http://www.uxmag.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 determineStyle()
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	Description:	Function to swap styles.
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	Source:		UX Magazine | http://www.uxmag.com
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -	*/
	
		<!--
		function determineStyle(){
			
			var browserWidth = getBrowserWidth();
				
			var i, a, main;
			
			if (browserWidth <= 1025){
				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 (browserWidth > 1025){
				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.
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	Source:		UX Magazine | http://www.uxmag.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";
					}
				}
			} 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);
			}
		}
		//-->