var highlightNewsNav_YAH = "#7A7979";
var highlightNewsNav_OFF = "#333";
var highlightNewsNav_OVER = "#eee";
var bottomAccordion;
var runningxmlhttpPost = false;
var runEventsApp = false;


$(document).ready(function() {
	$("#accordion").accordion({
			autoHeight: false,
			collapsible: true,
			active: false,
			speed: '50000'
	});
	$("#accordion div:nth-child(19)").css('display', 'none');	//document
	$("#accordion div:nth-child(21)").css('display', 'none');	//Make reservation
	$("#accordion div:nth-child(23)").css('display', 'none');	//FAQs
	$("#accordion div:nth-child(17)").css('display', 'none');
	$("#accordion div:nth-child(24)").css('display', 'none');
	$("#accordion div:nth-child(25)").css('display', 'none');
	//Count each element as 2 - one for the title, the second for the content
	fbFetch();
	
})
$(window).load(function () {
	promoSlider();
	
});
/* ~~~~~~~~~~[ news slider]~~~~~~~~~~~ */
function promoSlider(){
	$.ajax({
		url: '/O2NetDev/Applications/TransformDoc/default.aspx?XmlDoc=https://spreadsheets.google.com/feeds/list/0ArSi-WJzp-jxdGVPWS1UdzlYMExORTc5Y0JJM0RfZXc/od6/public/basic?alt=rss&XsltDoc=/xslt/promoSlider.xslt',
		success: function(data){
			$('#newsHeadlines').html(data);
		}
	});	
}
function runSlider(){
	$('#slider1').anythingSlider({
		theme           : 'minimalist-round',
		delay 			: 5000,
		hashTags            : false
	}); 	
}
/* ~~~~~~~~~~[ Breaking news ]~~~~~~~~~~~ */
function runBreakingNews(showId){
	
}
function gotoBreakingNews(showId){

}
function highlightNewsNav(obj,state){
}
/* ~~~~~~~~~~[ twitterFeed ]~~~~~~~~~~~ */
function twitterFeed(rssId,twitterId){
	//Works for PR feed and events panel
	if(document.getElementById('twitterFeed') && window.runningxmlhttpPost == false){
		//runningxmlhttpPost = true;
		//xmlhttpPost('/O2Net/Applications/TransformDoc/default.aspx?XmlDoc=http://twitter.com/statuses/user_timeline/' + rssId + '&XsltDoc=/xsltTemplate/twitterFeed.xslt&XmlVars=twitterId|' + twitterId,'twitterFeed');
	}else{
		//setTimeout('twitterFeed(\'' + rssId + '\',\'' + twitterId + '\')',500);
	}	
}
function twitterFeedSifr(){
	if(document.getElementById('twitterFollowLink')){
		//reDrawSifrFromHome();
		//Cufon.refresh();
	}else{
		//setTimeout('twitterFeedSifr()',250);
	}
}

/* ~~~~~~~~~~[ facebook feed ]~~~~~~~~~~~ */
var fbon = 0;
var fbsee = 0;
function fbFetch(){
	//Set Url of JSON data from the facebook graph api. make sure callback is set with a '?' to overcome the cross domain problems with JSON
	var url = "http://graph.facebook.com/AmericanCoachLimousine/posts?limit=10&callback=?";
	var html = "";
	html += '<div id="likebox">';
	html += '<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.facebook.com%2FAmericanCoachLimousine%3Fref%3Dts&amp;layout=box_count&amp;show_faces=false&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=65" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:65px;" allowTransparency="true"></iframe>';
	html += '<br />';
	html += '<div id="arrowLeft"><a href="javascript:void(0);" onClick="advanceFb(\'down\');"><img src="/images/content/fbfeed_arrowLeft.png" width="20" height="26" /></a></div>';
	html += '<div id="arrowRight"><a href="javascript:void(0);" onClick="advanceFb(\'up\');"><img src="/images/content/fbfeed_arrowRight.png" width="20" height="26" /></a></div>';
	
	html += '</div>';
	$.getJSON(url,function(json){
		fbon = 0;
		html += '<div id="fbfeed">';
		html += '<ul>';
	    	$.each(json.data,function(i,fb){
				if(window.fbsee == window.fbon){
					html += '<div id="countOn">' + window.fbon + '</div>';
					html += '<li>';
					if(fb.message != undefined){	
						html += '<a href="http://www.facebook.com/AmericanCoachLimousine">' + fb.message + '</a>';
					}	
					if(fb.picture != undefined){
						html += '<div class="fbpic"><a href="http://www.facebook.com/AmericanCoachLimousine"><img src="' + fb.picture + '"></a></div>';
					}	
					html += '<div class="fbdate">' + fb.created_time + '</div>';
					html += '</li>';
					
				}else{
					//html += window.fbsee + '-' + window.fbon + '<br />';
				}
				fbon = parseInt(window.fbon) + 1; 
	    	});
	    html += '</ul>';
		html += '</div>';
		

		$('#twitterFeed').animate({opacity:0}, 100, function(){
			$('#twitterFeed').html(html);
		});

	    $('#twitterFeed').animate({opacity:1}, 100);
	});
};

function advanceFb(direction){
	if(direction == 'up'){
		fbsee = parseInt(window.fbsee) + 1;
	}else{
		fbsee = parseInt(window.fbsee) - 1;
	}	
	if(window.fbsee < 0 || window.fbsee > 5){
		fbsee = 0;
	}
	fbFetch();
}

/* ~~~~~~~~~~[ ]~~~~~~~~~~~ */

/* ~~~~~~~~~~[ events ]~~~~~~~~~~~ */
function runEvents(pageConfig){

}
/* ~~~~~~~~~~[ Careers ]~~~~~~~~~~~ */
function goGetUrl(formName,selectName){

}
/* ~~~~~~~~~~[ Locator ]~~~~~~~~~~~ */
function explodeMapLocator(){

}
function compressExplodedMap(){
}

function corporateLogin(){
	if(document.getElementById('locator')){
		corporateLoginElements();
		if(getQueryVariable('Fail') == 'True'){
			corporateLoginFail();
		}		
	}else{
		setTimeout('corporateLogin()',10);
	}	

}
corporateLogin();
function corporateLoginFail(){
	document.getElementById('locator').style.background = "transparent url(/images/interface/corpLogin_fail_wht.png) no-repeat 0px 0px";
}
function resetLoginBackgroun(){
	document.getElementById('locator').style.background = "transparent url(/images/interface/corpLogin_wht.png) no-repeat 0px 0px";
}
function corporateLoginElements(){
	var htmlStr = "";
	var baseSite = "americancoach.orbisdesign.net";
	var returnString = "americancoach.orbisdesign.net";
	if(baseURL().indexOf('orbisdesign.net') == -1){
		baseSite = 		"www.americancoachlimousine.com";
	}		
	htmlStr += '<div id="loginOver">';
	htmlStr += '<form action="https://www.myfasttrak.com/webres/login.asp" name="mybiztrips2" method="post">';
	htmlStr += '<input Type="Hidden" name="cmdSubmit" value="Login">';
	htmlStr += '<div id="userNameTextBox">';
	htmlStr += '<input type="text" name="txtUserName" id="username" class="loginfield" onFocus="resetLoginBackgroun();" />';
	htmlStr += '</div>';
	htmlStr += '<div id="passWordTextBox">';
	htmlStr += '<input type="password" name="txtPassword" id="password" class="loginfield"" />';
	htmlStr += '</div>';
	htmlStr += '<input type="hidden" name="ReturnURL" value="http://' + baseSite + '/">';
	htmlStr += '<input type="hidden" name="LoginFailURL" value="http://' + baseSite + '/home_2.aspx?Fail=True">';
	htmlStr += '<div id="loginbutton">';
	htmlStr += '<input type="image" name="submit" id="submit" src="/images/trans.gif" width="105" height="20" alt="LOG IN" align="baseline" />';
	htmlStr += '</div>';
	htmlStr += '<div id="corporateLink">';
	htmlStr += '<a href="Corporate_7295.aspx"><img src="/images/trans.gif" width="150" height="20" alt="Visit Corporate Page" /></a>';
	htmlStr += '</div>';
	htmlStr += '</form>';	
	htmlStr += '</div>';
	document.getElementById('locator').innerHTML = htmlStr;
}

/* ~~~~~~~~~~[ About ]~~~~~~~~~~~ */
function loadAboutCopy(){
	if(document.getElementById('leftcontent')){
		document.getElementById('aboutText').innerHTML = document.getElementById('leftcontent').innerHTML;
	}else{
		setTimeout('loadAboutCopy()',10);
	}	
}
/* ~~~~~~~~~~[ Promo ]~~~~~~~~~~~ */
function promotion(totalPromos){
	if(getCookie('promotion') == null || getCookie('promotion') == undefined){
		SetGetCookie('promotion',1);
	}else{
		if(parseFloat(getCookie('promotion')) >= parseFloat(totalPromos)){
			SetGetCookie('promotion',1);
		}else{
			SetGetCookie('promotion',(parseFloat(getCookie('promotion'))+1));
		}
	}

	var promoShow = 'promo' + getCookie('promotion');
	if(getCookie('americanCoachLimousine.com_coupon') != null){
		var checkAd = document.getElementById(promoShow).innerHTML;
		if(checkAd.indexOf('promo_coupon') != -1){
			//Check cookie indicated they've already got the coupon, so skip this ad
			promotion(totalPromos);
		}else{
			document.getElementById(promoShow).style.display = 'block';	
		}
		
	}else{
		document.getElementById(promoShow).style.display = 'block';
	}
}
/* ~~~~~~~~~~[ coupon ]~~~~~~~~~~~ */
if(getQueryVariable('clearCoupon') == 'true'){
	delete_cookie ('americanCoachLimousine.com_coupon');
}	
function delete_cookie(cookie_name){
	var cookie_date = new Date ( );  // current date & time
	cookie_date.setTime ( cookie_date.getTime() - 1 );
	document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
}
function coupon(){
	var divParent = document.getElementById('col-a');		
	var newdiv = document.createElement('div');
	var divIdName = 'coupondiv';
	var htmlStr = "";

	newdiv.setAttribute('id',divIdName);

	htmlStr += '<div id="startCoupon">';
	htmlStr += '<div style="width:20px;position:absolute;margin:-45px 0 0 280px;"><a href="javascript:void(0);" onMouseDown="closeCoupon();"><img src="/images/trans.gif" width="15" height="15" /></a></div>';
	htmlStr += '<form name="couponSubmit">';
	htmlStr += '<div id="couponFirstName"><input type="text" name="First_Name" /></div>';
	htmlStr += '<div id="couponLastName"><input type="text" name="Last_Name" /></div>';
	htmlStr += '<div id="couponEmail"><input type="text" name="email" /></div>';
	htmlStr += '<div id="couponCheck"><input type="checkbox" name="Notify" value="true" checked="true" /></div>';
	htmlStr += '<div id="couponSubmit"><input type="button" value="Get Coupon" onClick="goCoupon();" /></div>';
	htmlStr += '<div class="couponHidden"><input type="test" name="Print_Coupon_Link" value="" /></div>';
	htmlStr += '<img name="ProcessForm" src="/images/trans.gif" width="1" height="1" border="0" />';
	htmlStr += '</form>';
	htmlStr += '</div>';

	newdiv.innerHTML = htmlStr;
	divParent.appendChild(newdiv);
	
	$import('/javascriptO2/date.js');
	$import('/javascript/requestvars_coupon.js');
	$import('/javascriptO2/FormFunctions.js');
	$import('/javascriptO2/FormProcess.js');
	$import('/javascriptO2/RequestVars.js');
	$import('/JavaScript/FormValidationVars_coupon.js');
}
function closeCoupon(){
	$("div#startCoupon").css("display","none");
}
var who = '';
var couponId;
var promoCode = '';

function goCoupon(){
	var thisMonth = Date.today().getMonth() + 1;
	var thisDate = Date.today().getDate();
	var thisYear = Date.today().getFullYear();
	var thisform = 'couponSubmit';
	var baseSite = "americancoach.orbisdesign.net";
	if(baseURL().indexOf('orbisdesign.net') == -1){
		baseSite = 		"www.americancoachlimousine.com";
	}	
	var printLink = "";	
	
	who = document.couponSubmit.First_Name.value + ' ' + document.couponSubmit.Last_Name.value;
	
	couponId = guid();
	promoCode = 'WS-' + thisMonth + '-' + thisDate + '-' + thisYear; 
	
	printLink = '<a href="' + baseSite + '/Coupon^8176.aspx?who=' + window.who + '&id=' + window.couponId + '&pcode=' + window.promoCode + '">Print Coupon</a>';
	
	document.couponSubmit.Print_Coupon_Link.value = printLink;
	
	var string = "";
	var els = document.forms[thisform].elements;
	for(var no=0;no<els.length;no++){
	    string+="Name: "+els[no].name + ", Value: "+els[no].value + "\n";
	}
	var ValidateVarsArray = ValidateVars.split('|');
	with (thisform){
		for (var i=0;i<ValidateVarsArray.length-1;i++) {
			var ValidateVarPieces = ValidateVarsArray[i].split('=');
			if(typeof(eval('document.' + thisform + '.' + ValidateVarPieces[1])) != 'undefined'){			
				if(eval(ValidateVarPieces[0] + '(document.' + thisform + '.' + ValidateVarPieces[1] + ',"' + ValidateVarPieces[2] + '")')==false){
					eval('document.' + thisform + '.' + ValidateVarPieces[1]).focus();
					return false;
				}else{
					//Everything is good 
					setTimeout('goCouponGetCoupon()',1000);
				}
			}else{
				alert('FormValidationVars ERROR: \r Trying to validate >>>' + ValidateVarPieces[1] + '<<< which is not in this form \r \r Check that the validation var is spelled correctly  \r Or \r Remove the validation check \r Or \r Add the form element that is missing');
				return false;
			}
		}	
	}
	
	GetAllInputs(thisform);
	ProcessInputs();
}
function goCouponGetCoupon(){
	window.location = '/Coupon_8176.aspx?who=' + window.who + '&id=' + window.couponId + '&pcode=' + window.promoCode;
}
function S4() {
   return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
}
function guid() {
   return (S4()+S4()+"-"+S4()+"-"+S4()+"-"+S4()+"-"+S4()+S4()+S4());
}
/* ~~~~~~~~~~[ common ]~~~~~~~~~~~ */
function xmlhttpPostComplete(){
	runningxmlhttpPost = false;
}
function reDrawSifrFromHome(){

}
function reDrawSifr(){
	//blank function for AJAX calls
}
function getStyle(el,styleProp)
{
	 /*
	  http://www.quirksmode.org/dom/getstyles.html
	  Pass styles in as style sheet declorations, IE wants javascript way
	 */ 
	 var x = document.getElementById(el);
	 if (x.currentStyle){
	  //ie
	  switch(styleProp)
	  {
	  case 'text-decoration':
	    styleProp = 'textDecoration';
	    break;    
	  default:
	  }
	  var y = x.currentStyle[styleProp];
	 }else if (window.getComputedStyle){
	  var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
	 }
	 return y;
} 
/* ~~~~~~~~~[non-used functions ] ~~~~~~ */
	// here to offset common home page calls

/* ~~~~~~~~~[ slideShowPro external link trigger ] ~~~~~~ */
function sspToggleDisplayMode() {
   	thisMovie("ssp").sspToggleDisplayMode();
}
function sspLoadAlbum(album,slide) {
   	thisMovie("ssp").sspLoadAlbum(album,slide);
	sspToggleDisplayMode();
	return false;
}
function sspLoadContent(slide) {
   	thisMovie("ssp").sspLoadContent(slide);
}
function thisMovie(movieName) {
	if (navigator.appName.indexOf("Microsoft") != -1) {
		return window[movieName]
	} else {
	    return document[movieName]
	}
}
function getQueryVariable(variable) {
	var query = window.location.search.substring(1);
	var vars = query.split("&");
	for (var i=0;i<vars.length;i++) {
		var pair = vars[i].split("=");
		if (pair[0] == variable) {
			return pair[1];
		}
  	}
	return "999";
}



function loadResPackageNav(){
	if(document.getElementById('header')){
		var divParent = document.getElementById('header');		
		var newdiv = document.createElement('div');
		var divIdName = 'resPkgNav';
		newdiv.setAttribute('id',divIdName);
		newdiv.innerHTML = resPackageNav('pkg');
		divParent.appendChild(newdiv);	
	}else{
		setTimeout('loadResPackageNav()',10);
	}
}

loadResPackageNav();

var loadedAirportResPanel = "null";

function resPackageNav(){
		var htmlStr = "";
		htmlStr += '<a href="javascript:void(0);" onClick="loadAirportResPanel();return false;" target="_blank">';
		htmlStr += '<img name="resPackageNavImg" src="/images/interface/homeButAirPortRes.png" width="244" height="27" />';
		htmlStr += '</a>';
		return htmlStr;
}
function loadAirportResPanel(){
	if(window.loadedAirportResPanel == "null"){
		var divParent = document.getElementById('header');		
		var newdiv = document.createElement('div');
		var divIdName = 'airportResPanel';
		document.images["resPackageNavImg"].src = '/images/interface/homeButAirPortResClose.png';
		loadedAirportResPanel = "on";
		newdiv.setAttribute('id',divIdName);
		newdiv.innerHTML = airportResPanel();
		divParent.appendChild(newdiv);
	}else if(window.loadedAirportResPanel == "off"){
		document.getElementById('airportResPanel').style.display = 'block';
		document.images["resPackageNavImg"].src = '/images/interface/homeButAirPortResClose.png';
		loadedAirportResPanel = "on";
	}else if(window.loadedAirportResPanel == "on"){
		document.getElementById('airportResPanel').style.display = 'none';
		document.images["resPackageNavImg"].src = '/images/interface/homeButAirPortRes.png';
		loadedAirportResPanel = "off";
	}	
}
function airportResPanel(){
	var htmlStr = "";
	htmlStr += '<div id="airButArriveOne">';
	htmlStr += '<a href="http://americancoachlimousine.hudsonltd.net/res?SELARV=ONEWAY">';
	htmlStr += '<img src="/images/interface/airportResBut_oneWay.png" />';
	htmlStr += '</a>';
	htmlStr += '</div>';
	
	htmlStr += '<div id="airButArriveRound">';
	htmlStr += '<a href="http://americancoachlimousine.hudsonltd.net/res?SELRTA=ROUNDTRIP">';
	htmlStr += '<img src="/images/interface/airportResBut_round.png" />';
	htmlStr += '</a>';
	htmlStr += '</div>';	
	
	htmlStr += '<div id="airButDepartOne">';
	htmlStr += '<a href="http://americancoachlimousine.hudsonltd.net/res?SELDEP=ONEWAY">';
	htmlStr += '<img src="/images/interface/airportResBut_oneWay.png" />';
	htmlStr += '</a>';
	htmlStr += '</div>';
		
	htmlStr += '<div id="airButDepartRound">';
	htmlStr += '<a href="http://americancoachlimousine.hudsonltd.net/res?SELRTD=ROUNDTRIP">';
	htmlStr += '<img src="/images/interface/airportResBut_round.png" />';
	htmlStr += '</a>';
	htmlStr += '</div>';		
	
	htmlStr += '<div id="airButHourly">';
	htmlStr += '<a href="http://americancoachlimousine.hudsonltd.net/res?SELHR=xxx">';
	htmlStr += '<img src="/images/interface/airportResBut_hourly.png" />';
	htmlStr += '</a>';
	htmlStr += '</div>';	
	
	htmlStr += '<div id="airButModify">';
	htmlStr += '<a href="http://americancoachlimousine.hudsonltd.net/res?SELECTRES=VERIFY">';
	htmlStr += '<img src="/images/interface/airportResBut_confirmCancel.png" />';
	htmlStr += '</a>';
	htmlStr += '</div>';	
	
	return htmlStr;
}
