                                                                                                                
// ------------------------------ BEGIN FUNCTIONS ------------------------ //	 

// Tab functions on the FAQs and Charter Bus Options
function showListItem(x){
	selectOption = $(x).attr("rel");	
	if (selectOption == "viewAll"){
		$(".busOptions li").removeClass("selected");
		$("#busList div.listItem").show();
		$(x).addClass("selected");
	}else{
		$(".busOptions li").removeClass("selected");
		$("#busList div.listItem").hide();        
		$(x).addClass("selected");
		selectOption = $(x).attr("rel");
		$("#busList div.listItem[rel='"+selectOption+"']").show();
	}
}

// Search for the charter options link
function searchShowListItem(x){

	 $(".busOptions li[rel='"+x+"']").addClass("selected");
	 selectOption = $(".busOptions li[rel='"+x+"']").attr("rel");
	 $("#busList div.listItem[rel='"+selectOption+"']").show();
}


// Home page forms display when left top-navigation is clicked
function showForm(formRel, v){
	try{
		// Hide Defaults
		$(".services-top-navigation a").removeClass("selected"); 
		$(".getQuoteContainer").hide(); 
		$(".form-wrapper").hide(); 
		
		// Add selected states and forms
		$(v).addClass("selected");
		$("#form-container, div.form-wrapper[rel="+formRel+"]").show();	
	}catch(err){}
}

// ------------------------------ END FUNCTIONS ------------------------ //	 

          

// ----------------- PAGE LOAD  ------------------ //
$(function(){

/* url encoding just add the 'encode' class to <a>
*/
try{
$('.encode').each(function(){
   var url=$(this).attr('href').replace(/ /g,'+').replace(/%20/g,'+');
   $(this).attr('href',url);
});
}catch(e){}

// ~~~~ Slider Effect on Home Page ~~~~ //
try{
$("#slides").slides({
	effect: 'fade, fade',
play: 8000

  });
}catch(err){}

	// ~~~~ Selected states for sub in the forms page ~~~~ //
	try{
		var hiddenNav = $(".hiddenNav").attr("id");
		$(".services-top-navigation a[rel="+hiddenNav+"]").addClass("selected");
		$(".services-top-navigation a[rel="+hiddenNav+"]").parent("li").addClass("selected");
		$(".services-top-navigation a[rel="+hiddenNav+"]").parent().parent().parent("li").addClass("selected");
	}
	catch(err){} 
	
	
	// ~~~~ Hides sub top-navigation if none is present in main top-navigation ~~~~ //
	$(".top-navigation li ul").each(function(){
		var alphaExp = new RegExp(/[A-Za-z0-9_]/);
		var txt = $(this).text();
		if(alphaExp.test(txt) == false){
			$(this).hide().removeClass("subNav");
			$(this).siblings("a").children("span.subNavArrow").hide();
		}
	}); 
	
	
	// ~~~~ Navigation rollover effects  ~~~~ //	
	$(".top-navigation li.lvl1").mouseover(function () {
		$(this).children("ul.subNav").show();
		$(this).addClass("selected");
		$(this).children("a").addClass("selected");
	});
	
	$(".top-navigation li.lvl1").mouseout(function () {
		$(this).children("ul.subNav").hide();
		$(this).removeClass("selected");
		$(this).children("a").removeClass("selected");
	}); 
	
	// ~~~~ Removes BG of the last column ~~~~ //
	try{
		$(".columnContainer .column:last-child").addClass("lastColumn");
	}catch(err){}		
	
	// ~~~~ Adding Social icon text on rollover ~~~~ //
	try{	
		$(".social-network a").mouseover(function () {
			$(this).siblings(".ro-text").show();
		});
		
		$(".social-network a").mouseout(function () {
			$(this).siblings(".ro-text").hide();
		}); 
	}catch(err){}
	
	
	// ~~~~ OPTIONS BY LOCATION STATE POP-UP ~~~~ //
	try{
		$("#map .regionHover").hover(function(){
			var region = $(this).attr("id");
			$("div[rel="+region+"]").animate({opacity: "show"}, "slow");;
		}, function(){
			var region = $(this).attr("id");
			$("div[rel="+region+"]").animate({opacity: "hide"}, "fast");
		});				
	}catch(err){}
	
	
	// ~~~~ CHARTER BUS OPTIONS SELECT ~~~~ //	
	try{
	
var selectOption = "";
		selectOption = $(".busOptions li:first").attr("rel");
		$(".busOptions li:first").addClass("selected"); // selects first li	
		$("#busList div.listItem[rel='"+selectOption+"']").show();

	}catch(err){}
	
	
	// ~~~~ Removes the border on the bottom of the groups and events top-navigation ~~~~ //
	try{
		$(".services-top-navigation li:last, .services-top-navigation li:last a").css("border-bottom", "0px none")
	}catch(err){}
	
	// ~~~~ Reassigns background to the first top-navigation of the groups and events top-navigation ~~~~ //
	try{
		$(".services-top-navigation li.selected a[rel='Academic']").css("background-image", "url(/images/group-events-selected-first.gif)")
	}catch(err){}
	
	// ~~~~ Removes the final "|" on the cities page ~~~~ //
	/* 
		//... breaks in IE 7
		$('.cities').each(function(){
		var x = $(this).html();
		lastComma = x.lastIndexOf('<span class="divide">|</span>');
		alert(lastComma);
		x = x.substring(0, lastComma);
		
		$(this).html(x);
		});
	*/


// ~~~~ Removes the description in red if no text is there ~~~~ //

$(".description div, .paraCont").each(function(){	
var alphaExp = new RegExp(/[A-Za-z0-9_]/); 
var txt = $(this).text();
if(alphaExp.test(txt) == false){
$(this).hide();
}
});

    
// ~~~~ Passes the hubspot tracking id to the forms ~~~~ //

//Get cookie routine by Shelley Powers 
function get_cookie(Name) {
  var search = Name + "="
  var returnvalue = "";
  if (document.cookie.length > 0) {
    offset = document.cookie.indexOf(search)
    // if cookie exists
    if (offset != -1) { 
      offset += search.length
      // set index of beginning of value
      end = document.cookie.indexOf(";", offset);
      // set index of end of cookie value
      if (end == -1) end = document.cookie.length;
      returnvalue=unescape(document.cookie.substring(offset, end))
      }
   }
  return returnvalue;
}

//var hubspotCookieID = get_cookie("hubspotutk");   
//var iframeSrc = $("iframe").attr("src");
//if(iframeSrc.substring(30,38) != "rfqShort"){
  
//  $("div.form").find("iframe").attr("src",iframeSrc+"&hubspot="+hubspotCookieID);
//}
});
	
// ----------------------------- END OF PAGE LOAD ------------------------ //	
    
//Allows the forms to access the hubspot cookie
//document.domain = "busbank.com";

    

    

    

    

    

    

    
