$(document).ready(function(){
	// navigation drop downs
	$("#nav li:has(ul)").bind("mouseover", function(){
		$(this).find("ul").show();
	}).bind("mouseout", function(){
		$(this).find("ul").hide();
	});
	$("#nav a").bind("focus", function(){
		$(this).parents("li").find("ul").show();
	}).bind("blur", function(){
		$(this).parents("li").find("ul").hide();
	});
	$("#nav li:has(ul)").each(function() {
		$(this).css("z-index", 5000 - $(this).prevAll("li").length);
	});
	
	//home page carousel
	if ($("#carousel").length > 0) {
		$("#carousel .slide:gt(0)").hide();
		$("#carousel .pagi a.prev").bind("click", function(){
			clearTimeout(carouselTimer);
			$(this).closest(".slide").hide().prev(".slide").show();
			if ($("#carousel .slide:visible").length == 0) {
				$("#carousel .slide:last").show();
			}
			return false;
		});
		$("#carousel .pagi a.next").bind("click", function(){
			clearTimeout(carouselTimer);
			$(this).closest(".slide").hide().next(".slide").show();
			if ($("#carousel .slide:visible").length == 0) {
				$("#carousel .slide:first").show();
			}
			return false;
		});
		carouselTimer = setTimeout('stepCarousel()', 6000);
	}
	
	//home page belt
	if ($("#belt").length > 0) {
		$("#belt .pagi a.prev").bind("click", function(){
			if ($("#belt").find(":animated").length == 0) {
				$("#belt .slide:last").prependTo("#belt-inner");
				$("#belt-inner").animate({marginLeft:"-=238px"}, 0).animate({marginLeft:"+=238px"}, 1000);
			}
			return false;
		});
		$("#belt .pagi a.next").bind("click", function(){
			if ($("#belt").find(":animated").length == 0) {
				$("#belt-inner").animate({marginLeft:"-=238px"}, 1000, null, function(){
					$("#belt .slide:first").appendTo("#belt-inner");
					$("#belt-inner").animate({marginLeft:"+=238px"}, 0);
				});
			}
			
			
			return false;
		});
	}
	
	//home page world map 
	if ($("#world").length > 0) {
		$("#world area.area1").hover(function(){
			$("#world img.map").css("background-position", "0 -300px");
		}, function () {
			$("#world img.map").css("background-position", "0 0");
		});
		$("#world area.area2").hover(function(){
			$("#world img.map").css("background-position", "0 -600px");
		}, function () {
			$("#world img.map").css("background-position", "0 0");
		});
	}
	
	//tabs on superhotel
	if ($("#tabs").length > 0) {
		$("#tabs div.tab1, #tabs div.tab2").hide();
		$("#tabs li.tab0").addClass("selected").bind("click", function(){
			$("#tabs div.tab0").show();
			$("#tabs div.tab1, #tabs div.tab2").hide();
			$("#tabs li.tab0").addClass("selected");
			$("#tabs li.tab1, #tabs li.tab2").removeClass("selected");
			$("#tabs ul.tabs").css("background-position", "0 0");
		});
		$("#tabs li.tab1").bind("click", function(){
			$("#tabs div.tab1").show();
			$("#tabs div.tab0, #tabs div.tab2").hide();
			$("#tabs li.tab1").addClass("selected");
			$("#tabs li.tab0, #tabs li.tab2").removeClass("selected");
			$("#tabs ul.tabs").css("background-position", "0 -100px");
		});
		$("#tabs li.tab2").bind("click", function(){
			$("#tabs div.tab2").show();
			$("#tabs div.tab0, #tabs div.tab1").hide();
			$("#tabs li.tab2").addClass("selected");
			$("#tabs li.tab0, #tabs li.tab1").removeClass("selected");
			$("#tabs ul.tabs").css("background-position", "0 -200px");
			GetMap();
		});
		$("#tabs a.lightbox").lightBox({imageBtnClose:'/img/btn_lightbox-close.gif'});
	}
});

var carouselTimer;	
function stepCarousel(){
	$("#carousel .slide:visible").hide().next(".slide").show();
	if ($("#carousel .slide:visible").length == 0) {
		$("#carousel .slide:first").show();
	}
	carouselTimer = setTimeout('stepCarousel()', 6000);
}

/* Remove IE6 image flickering */
try {document.execCommand ('BackgroundImageCache', false, true);}
catch (error) {}
