$(document).ready(function() {
	$("#storyTabs li").hover(function() {
		$(this).addClass("hover");
	},function(){
		$(this).removeClass("hover");
	});
	$("#contentListTabs li").hover(function() {
		$(this).addClass("hover");
	},function(){
		$(this).removeClass("hover");
	});
	$("#sectionTabs li").hover(function() {
		$(this).addClass("hover");
	},function(){
		$(this).removeClass("hover");
	});
	
	$("#gNav li").hover(function() {
		$(this).addClass("hover");
	},function(){
		$(this).removeClass("hover");
	});
	
	
	$('#contentListTabs ul').tabs();
	$('#personalTabs ul').tabs();
	$('.tabs-nav ul').tabs(1);
	
	
	$('.hfrButtons li a').hover(function() {
		// do nothing if already current
		if ($(this).attr("class") == "current") return(0);
		
		// Deactivate old
		$('.hfrButtons li a').removeClass("current");
		
		// Make this button current
		$(this).addClass("current");

		//$('.hfrPhotos').fadeOut(300);
		$('.hfrPhotos').hide(0);
		
		// Show the image
		var relatedImage =  $(this).attr("rel");
		//var relatedImage = "hfr2";
		$("#" + relatedImage).fadeIn(500);
		//alert("$(hfr1)" + $("hfr1"))
		
	},function(){
	  //Do nothing on mouse out
	});
	
	
	// Make the first current
	$('.hfrButtons li:first a').addClass("current");
	$('.hfrButtons li:first').addClass("first");
	$('.hfrPhotos').hide();
	$('.hfrPhotos:first').show();



	// Destination Map
	
	$("#destinationMapLarge_Map area").hover(function(e) {
		//var destinationLinkId = "dl_" + cleanDestinationTitle( $(this).attr("alt") );
		//$("#"+destinationLinkId).addClass("hover");
		$("#mapIndicate span").text($(this).attr("alt"));
		$("#mapIndicate").show();
	},function(){
		//var destinationLinkId = "dl_" + cleanDestinationTitle( $(this).attr("alt") );
		//$("#"+destinationLinkId).removeClass("hover");
		$("#mapIndicate").hide();
	});
	$("#destinationMapLarge_Map").mousemove(function(e){
		$("#mapIndicate").css("top", e.pageY-20);
		$("#mapIndicate").css("left", e.pageX+20);
    });
	
	// Photo Gallery
	$('.galleryPhoto:first').show();	
	$(".galleryPhoto").each(function(index){
		galleryCount++;
		$("#controlNumbers").append("<a href=\"javascript://\" id=\"photoNumber"+index+"\" onclick=\"showPhoto("+index+");\">"+galleryCount+"</a>");
		$(this).attr("id", "gallPhoto"+index);
	});
	$('#controlNumbers a:first').addClass("current");
	$("#controlNumbers").css("width", galleryCount*36+13);
	var firstHeight = parseInt( $("#gallPhoto"+currentPhoto+' img').attr("height") ) + 35;
	$('#photosArea').attr("height", firstHeight);
	
	//added by Saheel to sort rendering issues from  latest vibation JS file 
	$('#gSearch select').selectbox();
	$('#fLinksSearch select').selectbox();
	
	$("#gNavDestinations").hover(function() {
		$("#destinationPulldown").show();
	},function(){});
	//added uptill here Saheel

	
	$("#mapSm a").hover(function() {
		var targetOffset = $(this).parent().parent().parent().offset().top;
		$("#destinationPulldown").css("margin-left", 62);
		$("#destinationPulldown").css("top", targetOffset);
		$("#destinationPulldown").show();
		$("#destinationPulldown h3").show();
		
		$("#destinationPulldown").hover(function() {},
			function(){
				$("#destinationPulldown h3").hide();
				
				$(this).hide();
				$(this).css("margin-left", 0);
				$(this).css("top", '');
			});
		
	});
	
	
	
	$("#gNav a:contains('DESTINATIONS')").hover(function() {
		var targetOffset = $(this).parent().parent().parent().offset().top;
		$("#destinationPulldown").show();
		
		
		$("#destinationPulldown").hover(function() {},
			function(){
				$(this).hide();
			});
	});
	
});
var galleryCount = 0;
var currentPhoto = 0;
var fadeOutTime = 500;
var fadeInTime = 1000;
var animating = false;
function showPhoto(index){
	if (index == currentPhoto) return(0);
	if (animating) return(0);
	animating = true;

	hideCurrentPhoto();
	setNumberState(false);
	
	currentPhoto = index;
	
	var newHeight = getNextHeight();
	$('#photosArea').animate({ height: newHeight+"px" }, {duration: fadeOutTime});
		
	setTimeout("showPhotoPart2();", fadeOutTime)
}
function showPhotoPart2(){
	showCurrentPhoto();

	setNumberState(true);

	setTimeout("endAnimation();", fadeInTime)
}
function endAnimation(){
	animating = false;
}
function hideCurrentPhoto(){
	$("#gallPhoto"+currentPhoto ).fadeOut(fadeOutTime);
}
function showCurrentPhoto(){
	$("#gallPhoto"+currentPhoto ).fadeIn(fadeInTime);
}
function getNextHeight(){
	$("#gallPhoto"+currentPhoto ).show();
	var nextHeight = parseInt( $("#gallPhoto"+currentPhoto+" img").attr("height") ) + 35;
	$("#gallPhoto"+currentPhoto ).hide();
	return(nextHeight);
}

function setNumberState(currentState){
	if (currentState){
		$('#photoNumber'+currentPhoto).addClass("current");
	} else {
		$('#photoNumber'+currentPhoto).removeClass("current");
	}
}
function previousPhoto(){
	var nextPhoto = currentPhoto-1;
	if (nextPhoto < 0)
		nextPhoto = galleryCount-1;
		
	showPhoto(nextPhoto);
}
function nextPhoto(){
	var nextPhoto = currentPhoto+1;
	if (nextPhoto >= galleryCount)
		nextPhoto = 0;

	showPhoto(nextPhoto);
}



function cleanDestinationTitle(altText){
	altText = altText.replace(/ /g, "");
	altText = altText.replace(/\//g, "");
	return (altText);
}









// ----------------------------------------------
// StyleSwitcher functions written by Paul Sowden
// http://www.idontsmoke.co.uk/ss/
// - - - - - - - - - - - - - - - - - - - - - - -
// For the details, visit ALA:
// http://www.alistapart.com/stories/alternate/


function setActiveStyleSheet(title) {
var i, a, main;
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") == title) a.disabled = false;
}
}
}

function getActiveStyleSheet() {
var i, a;
for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
}
return null;
}

function getPreferredStyleSheet() {
var i, a;
for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
if(a.getAttribute("rel").indexOf("style") != -1
&& a.getAttribute("rel").indexOf("alt") == -1
&& a.getAttribute("title")
) return a.getAttribute("title");
}
return null;
}

function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
function initSizes() {
var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
if (title)
setActiveStyleSheet(title);
}


$(document).ready(function() {
	initSizes()
 });


window.onunload = function(e) {
var title = getActiveStyleSheet();
createCookie("style", title, 365);
}




