function initTabs()
{
	var tabs = $("ul.tabset");
	//console.debug("hash %s len %d", location.hash, location.hash.length);
	tabs.find("a").each(function(a, domEl){
		if($(domEl).attr("href").indexOf("tab") == -1)
			$(domEl).attr("href", "#tab"+ (a+1));
		if($(domEl).css("background-image") == "none"){
			$(domEl).css("text-indent", 0);
		}
		
		if(a == 0){
			$(domEl).parents("li").addClass("active");
		}
		$(domEl).click(function(event){
			$("#home .tab").hide();
			var el = $(this).attr("href");
			$(el).show();
			$(this).parents("ul.tabset").find("li").removeAttr("class");
			$(this).parents("li").addClass("active");
			event.preventDefault();
			event.stopPropagation();
			if(jQuery.browser.msie && parseInt(jQuery.browser.version) == 6){
				$(this).parent().data("curr", true)
			}
			
		});
		
		if(jQuery.browser.msie && parseInt(jQuery.browser.version) == 6){
			$(domEl).hover(function(){
				if(!$(this).parent().hasClass("active")){
				  $(this).parent().toggleClass("active", true);
				  $(this).parent().data("curr", false);
				 }
				 else {
				 	$(this).parent().data("curr", true);
				 }
			}, function() {
				if(!$(this).parent().data("curr")){
					$(this).parent().toggleClass("active", false);
				}
			});
		}
	});

	if(location.hash.length > 0) {
		tabs.find("a[href='"+ location.hash+ "']").each(function(){
					tabs.find("li").removeAttr("class");
					$(this).parents("li").addClass("active");
					$("#home .tab").hide();
					$(location.hash).show();
		});
		$(window)[0].scrollTo(0,0);
	}

	
}

function initSlideshow(){
	$('div.gallery').slideShow({
		numElementLink:'div.gallery-nav li a',
		slideEl:'div.gallery-content li',
		autoSlideShow:false,
		duration:500,
		autoSlideShow:true,
		switchTime:12000
	});
}

function initFooterOpenClose() {
    var _holder = $("#footer");
    var _link = _holder.find(".open-close-links");
    var _heightBlock = _holder.find(".footer-content");
    var _activeClass = "footer-open-block";
    var _dur = 700;
    var _height = _heightBlock.innerHeight(true);

    if (!_holder.hasClass(_activeClass)) {
        _heightBlock.css({
            height: "90px"
        });
    };
    _link.click(function() {
        if (!_holder.hasClass(_activeClass)) {
            _heightBlock.animate({ height: _height }, { queue: false, duration: _dur, complete: function() { _holder.addClass(_activeClass); } });
        } else {
            _heightBlock.animate({ height: "90px" }, { queue: false, duration: _dur, complete: function() { _holder.removeClass(_activeClass); } });
        };
        return false;
    });
}
$(function (){
	$("ul.main-nav > li").mouseover(function(){
		//alert("mouseover");
		var dd = $(this).find("div.main-drop-down")
		if(dd.length > 0){
			dd.css("height", "auto").stop(true,false).slideDown("normal");
			//alert("opened dropdown");
		}
	})
	.mouseout(function(event) {
		var dd = $(this).find("div.main-drop-down");
		if($(this).find("div.main-drop-down").length > 0 && !dd.hasClass("active")){
		 // alert("event.target: "+event.target + " this: " +this + " bool: " + (event.target === this));
		  $(this).find("div.main-drop-down").css("height", "auto").stop().slideUp("normal");
		  //alert("li hover: " + event.target.id + " target:" +event.target);
		}
	});
	
	
	$("ul.main-nav select").bind("focus", function(event) {
		$(this).parents("div.main-drop-down").addClass("active");
	}).bind("blur", function(event){
		$(this).parents("div.main-drop-down").removeClass("active");
	});
	
	
	
	$(".overlabel input").bind("focus",function(event){
		if($.trim($(this).val()).length == 0) $(this).prevAll("label").fadeOut("fast");
		//console.debug("e %o", event);
		event.preventDefault();
		event.stopPropagation();
	}).bind("blur",function(event){
		if($.trim($(this).val()).length == 0) $(this).prevAll("label").fadeIn("fast");
		//console.debug("e %o", event);
		event.preventDefault();
		event.stopPropagation();
	}).bind("keypress", function(event){

		//alert("keycode " +event.keyCode +" " + typeof event.keyCode + " " +(event.keyCode == 13));
		if (event.keyCode == 13) {
			//alert("enter key id" + $(this).parent().next().attr("id"));
			event.preventDefault();
			event.stopPropagation();
			$(this).parent().next().click();
		}
	}).each(function(){ 
		//console.debug("this length %d", $.trim($(this).val()).length);
		if($.trim($(this).val()).length > 0) $(this).prevAll("label").fadeOut("fast");
	});
	if(jQuery.browser.msie && parseInt(jQuery.browser.version) == 6){
		$("#tblctrl.itinerary shape").siblings("img").css("visibility", "visible").end().remove();
		$("#header .main-drop-down").bgiframe();
		
	}
	var useragent = new String(navigator.platform);
	if(useragent.indexOf("Mac") > -1) {
		$(".main-nav li").css("padding", "4px 24px");
		$(".main-nav li li").css("padding", "0");
	}

});



