// VIRTUAL TOURS PAGES


// Virtual tour tabbed menus
//____________________________________________________________________________


// Tabs using jQuery

$(document).ready(function(){

	$('#tabs ul li:first').addClass('active');
	
	$('#tabs ul li a').click(function(){
		$('#tabs ul li').removeClass('active');		
		var currentTab = $(this).attr('href');
		var currentTitle = $(this).parent().attr('title');
		loadSWF(currentTab, 'flashContent');		
		$(this).parent().addClass('active');
		$('#tour h2').text(currentTitle);
		return false;
	});
	
});


// Load the opening swf for when the page first loads
function loadFirstSWF() {
	if (swfobject.hasFlashPlayerVersion("9")) {
		var flashvars = {};
		var params = {};
		params.wmode = "transparent";
		var attributes = {};
		
		// Get location from url (this is the search engine friendly one so
		// swfobject.getQueryParamValue("Location") can't be used;		
		var url = window.location.href;  
		var str1 = url.split('loc-');
		var str2 = str1[1].split('\/');
		var location = str2[0];
		
		var url = "/images/locations/tours/" + location.toLowerCase() + "/" + location + "-reception.swf";
				
		swfobject.embedSWF(url, "flashContent", "550", "300", "9.0.0", false, flashvars, params, attributes);
	} else {	
		$('div#flashContent').show();		
	}	
}
swfobject.addDomLoadEvent(loadFirstSWF);



// Load other swfs when tabs are clicked

function loadSWF(url, targetID){
   //Check for existing SWF
   if(isObject(targetID)){   
      //replace object/element with a new div
      replaceSwfWithEmptyDiv(targetID);
   }
   //Embed SWF
   if (swfobject.hasFlashPlayerVersion("9")) { 
      var attributes = { data: url, width:"550", height:"300" };
      var params = {};
      params.wmode = "transparent";
      var obj = swfobject.createSWF(attributes, params, targetID);   
   }
}

//Support function: checks to see if target
//element is an object or embed element
function isObject(targetID){
   var isFound = false;
   var el = document.getElementById(targetID);  
   if(el && (el.nodeName === "OBJECT" || el.nodeName === "EMBED")){   
      isFound = true;   
   }   
   return isFound;
}

//Support function: creates an empty
//element to replace embedded SWF object
function replaceSwfWithEmptyDiv(targetID){
   var el = document.getElementById(targetID);   
   if(el){   
      var div = document.createElement("div");
      el.parentNode.insertBefore(div, el); 
      //Remove the SWF
      swfobject.removeSWF(targetID);  
      //Give the new DIV the old element's ID
      div.setAttribute("id", targetID);      
   }   
}

