// JavaScript Document
var thankpopvar =false;
$(function() {
    // Holiday Package Dropdown starts  
    /*Navigation code*/
    $("#lightboxImg").hide();
    var flag = true;
    $(".ceebox").ceebox({ titles: false});
    bindcontactusevent();
	videolightbox();
    //opencontactusdropdown();

    $("#mainNav a").mouseenter(function() {
        if (flag) {
            flag = false;
            $(".searchdropdown").hide();
            $(this).next(".dropdown").stop(true, true).slideDown(300);
            $(this).parent().addClass("selected");
            Cufon.refresh('.navigation ul li.selected a');
            Cufon.refresh('.navigation ul li a.selected');
        }
    });
    $("#mainNav").mouseleave(function() {
        $(this).children(".dropdown").stop(true, true).slideUp(1, function() {
            flag = true;
            Cufon.refresh('.navigation ul li a');
            Cufon.refresh('.navigation ul li a.selected');
            $(".description").hide();
            $(".description").eq(0).show();
            $(this).parent().removeClass("selected");
            $("#mainNav li a").removeClass("selected");
        });
    });

    // Holiday Package Dropdown Roll over starts
    $("#mainNav .dropdown .dropdown_top ul li a").mouseenter(function() {
        if (!($(this).hasClass("selected"))) {
            indexno = $(this).parent().index();
            $(".description").hide();
            $(".description").eq(indexno).stop(true, true).fadeIn(500);
            $(".dropdown_top ul li a").removeClass("selected");
            Cufon.refresh('.navigation ul li .dropdown .dropdown_top ul li a');
            $(this).addClass("selected");
            Cufon.refresh('.navigation ul li .dropdown .dropdown_top ul li a.selected');

        }
    });
    // Holiday Package Dropdown Roll over ends 

    // Holiday Package Dropdown ends 



    // Contact info Dropdowns starts
    var flag = true;
    $("#entercallback").click(function() {
        //alert($("#ContactInfo1_ithanks").css("display"));
        if ($("#ContactInfo1_ithanks").css("display") == "block") {
            $("#ContactInfo1_ithanks").hide();
            $(this).removeClass("selected");
            thankpopvar = false;
            flag = false;
			
            bindcontactusevent();            
        }
        else {
            $(this).next(".form").stop(true, true).slideToggle(500).siblings(".form").slideUp(500);
            $(this).toggleClass("selected");
        }


        if (flag) {
            flag = false;
            $("#contactinfo").unbind("mouseenter mouseleave");
        }
        else {
            flag = true;
            thankpopvar = false;
            bindcontactusevent();
        }
    });
    $("#entercallback a").click(function(e) {
        e.preventDefault();
    });
    // Contact info Dropdown ends

    // Rate Now starts
    $('.fourstar').hover(function() {
        $(this).find(".ratenow").stop(true, true).show(300);
    }, function() {
        $(this).find(".ratenow").stop(true, true).hide();
    });

    // Rate Now  ends


    // Expand Collapse functionality
    $("#expand_collapse ul li .contentarea").hide();
    $("#expand_collapse ul li:first .contentarea").show();
    $("#expand_collapse ul li h3").click(function() {
        $(this).next(".contentarea").slideToggle(500).siblings(".contentarea").slideUp(500);
        $(this).toggleClass("active");
        return false;
    });

    $(".expandall").click(function() {
        $(".contentarea").slideDown(500, function() {
            $(this).prev().addClass("active");
        });
        return false;
    });

    $(".collapseall").click(function() {
        $(".contentarea").slideUp(500, function() {
            $(this).prev().removeClass("active");
        });

        return false;
    });

    // Expand Collapse functionality

    //homepage bg change functionality
    var listCount = $(".mastheadContainer .packagesdiv").size();
    var listWidth = $(".mastheadContainer .packagesdiv").outerWidth();
    $(".mastheadContainer").css({ "width": (listCount * listWidth) });

    $(".bestDealspackages ul li div.thumb").click(function() {
        _id = this.id;
        indexvalue = $(this).parent().index();

        value = _id.substring(0, _id.length - 1).length;
        value = _id.substring(value);

        if (!($(this).prev().hasClass("whitebgselected"))) {
            $(".whitebgselected").removeClass("whitebgselected");
            $(this).prev().addClass("whitebgselected");
            //$(".packagesdiv").hide();
            $(".bannerbg").stop(true, true).fadeOut(1800);
            $("#bg" + value).stop(true, true).fadeIn(1800);
            $(".mastheadContainer").stop(true, true).animate({ "margin-left": (-1 * listWidth * indexvalue) },
		 {
		     duration: 800,
		     easing: 'easeOutQuad'
		 });
            //$(".package" + value).slideDown(500);	
        }

    });
    //homepage bg change functionality


    // Destination Guide Detail - Image Gallery 
    var imagegallerylistCount = $(".destination_imagegallery .container .largeimage").size();
    var imagegallerylistWidth = $(".destination_imagegallery .container .largeimage").outerWidth();
    $(".destination_imagegallery .container").css({ "width": (imagegallerylistCount * imagegallerylistWidth) });
    $("div.destination_imagegallery div.thumbs ul li").click(function() {
        var imagegalleryindex = $(this).index();
        newxpos = -1 * imagegallerylistWidth * imagegalleryindex;        
        $(".destination_imagegallery .container").stop(true, true).animate({ "margin-left": newxpos });
		
		/*$(".destination_imagegallery .container").stop(true, true).animate({ "margin-left": newxpos }, 500, 'easeInExpo', function() {
            $(this).animate({ "margin-left": ($(this).css("margin-left")) - 10 }, 1000, 'easeOutElastic');
        });*/
        $(this).addClass('selected').siblings().removeClass('selected');
    });
    // \Destination Guide Detail - Image Gallery 

    // Sort by starts

    var flag = true;
    $("#sortby").click(function() {
        if (flag == true) {
            $(this).addClass("active");
            $(this).next(".sortby_dropdown").slideDown();
            flag = false;
        }
        else {
            $(this).next(".sortby_dropdown").slideUp(function() {
                $(this).prev().removeClass("active");
            });
            flag = true;
        }
    });

    $("div.sortby_dropdown ul li a").click(function() {
        var selectedValue = $(this).html();		
		$(this).html($("#sortby").html());
        $("#sortby").html(selectedValue);
        $(".sortby_dropdown").slideUp(function() {
            $(this).prev().removeClass("active");
        });
        flag = true;
    });


    // Sort by ends

    // Choose destination dropdowns starts
    $("div.choosedestination h4").click(function() {
        $(this).next(".destination_dropdown").slideDown();
    });

    $("div.destination_dropdown_top ul li a").click(function() {
        var selectedValue = $(this).html();
        $("div.choosedestination h4").html(selectedValue);
        $(".destination_dropdown").slideUp(500);
    });
		
    $(".destination_dropdown").mouseleave(function() {
        $(".destination_dropdown").slideUp(500);
    });

    // Choose destination dropdowns ends

    // Choose state dropdowns starts
    $("div.choosestate h4").click(function() {
        $(this).next(".state_dropdown").slideDown();
    });

    $("div.state_dropdown_top ul li a").click(function() {
        var selectedValue = $(this).html();
        $("div.choosestate h4").html(selectedValue);
        $(".state_dropdown").slideUp(500);
    });

    $(".state_dropdown").mouseleave(function() {
        $(".state_dropdown").slideUp(500);
    });

    // Choose state dropdowns ends

    /*cufon hover for */
    $(".bookwithus_bottom h4 a").hover(function() {
        $(this).addClass("hoverclass");
        Cufon.refresh('.bookwithus_bottom h4 a.hoverclass');
    }, function() {
        $(this).removeClass("hoverclass");
        Cufon.refresh('.bookwithus_bottom h4 a');
    });

    $(".greenboxinner p a").hover(function() {
        $(this).addClass("hoverclass");
        Cufon.refresh('.greenboxinner p a.hoverclass');
    }, function() {
        $(this).removeClass("hoverclass");
        Cufon.refresh('.greenboxinner p a');
    });

    $(".detailwrapper .packagedetailcont .lhsmenu ul li").hover(function() {
        hasclass = $(this).hasClass("selected");
        if (!hasclass) {
            $(this).addClass("hoverclass");
            Cufon.refresh('.detailwrapper .packagedetailcont .lhsmenu ul li.hoverclass');
            Cufon.refresh('.detailwrapper .packagedetailcont .lhsmenu ul li.selected');
        }
    }, function() {
        if (!hasclass) {
            $(this).removeClass("hoverclass");
            Cufon.refresh('.detailwrapper .packagedetailcont .lhsmenu ul li');
            Cufon.refresh('.detailwrapper .packagedetailcont .lhsmenu ul li.selected');
        }
    });
    /*navigation Hover except First navigation*/
    var hasclassmainnav;
    $(".navigation > ul li > a").not(".dropdown ul li a").hover(function() {
        hasclassmainnav = $(this).parent().attr("id") == "mainNav";
        if (!hasclassmainnav) {
            $(this).addClass("hoverclass");
            Cufon.refresh('.navigation > ul li > a.hoverclass');
            Cufon.refresh('.navigation ul li a.selected');
        }
    }, function() {
        if (!hasclassmainnav) {
            $(this).removeClass("hoverclass");
            Cufon.refresh('.navigation > ul li > a');
            Cufon.refresh('.navigation ul li a.selected');
        }
    });
    /*navigation Hover except First navigation*/

    $(".mastheadCopy p").hover(function() {
        $(this).addClass("hoverclass");
        Cufon.refresh('.mastheadCopy p.hoverclass a');
    }, function() {
        $(this).removeClass("hoverclass");
        Cufon.refresh('.mastheadCopy p a');
    });

    $(".destinationPlace ul li").hover(function() {
        $(this).addClass("hoverclass");
    }, function() {
        $(this).removeClass("hoverclass");
    });

    $("#contactinfo .contactinfo_dropdown_bottom .content a").hover(function() {
        $(this).addClass("selected");
        Cufon.refresh('#contactinfo .contactinfo_dropdown_bottom .content a.selected');
    }, function() {
        $(this).removeClass("selected");
        Cufon.refresh('#contactinfo .contactinfo_dropdown_bottom .content a');
    });

    $(".contactinfo .topnav .titlemargininside a").hover(function() {
        if (!($(this).parent().parent().attr("id") == "contactinfo")) {
            $(this).addClass("selected");
            Cufon.refresh('.contactinfo a.selected');
        }
    }, function() {
        if (!($(this).parent().parent().attr("id") == "contactinfo")) {
            $(this).removeClass("selected");
            Cufon.refresh('.contactinfo a');
        }
    });

    $(".carrierdetailcont .openings li a").click(function() {
        $("#carrierdetail li").removeClass("selected");
        $("#carrierdetail li.tabapplynow").addClass("selected");
        $(".carrierdetailcont").hide();
        $("#carrierdetailcont2").show();
    });

    /*cufon hover for */

    $(".closebox").click(function() {
        $("#overlay").fadeOut();
		$(".overlay1").fadeOut();
		
        $(".displaybox").fadeOut();
		$(".userreviewdisplaybox").fadeOut();
    });
    /*lightbox code for request_booking.htm*/

});

var oldDivId = 1;
var newDivId;

function changeTab(id)
{
	newDivId = id;

	if(oldDivId != newDivId)
	{	
		document.getElementById("destinationtab"+oldDivId).style.display = "none";
		document.getElementById("destinationtab"+newDivId).style.display = "block";
		
		document.getElementById("destinationlitab"+oldDivId).className = "";
		document.getElementById("destinationlitab"+newDivId).className = "selected";
	}
	
	oldDivId = newDivId;
}

function tabchange(pointer,count)
{
	if(!($(pointer).hasClass("selected")))
	{
		_id=$(pointer).parent().attr("id");
		
		$(pointer).siblings().removeClass("selected");
		$(pointer).addClass("selected");
		
		$("." + _id + "cont").hide();
		$("#" + _id + "cont" + count).show();
		
		Cufon.refresh('.detailwrapper .packagedetailcont .lhsmenu ul li');
		Cufon.refresh('.detailwrapper .packagedetailcont .lhsmenu ul li.selected');
		Cufon.refresh('.seasontabs ul li');
		Cufon.refresh('.seasontabs ul li.selected');
		
	}
}


function slideTo(newX, dir)
{
	moose = false;
	if(dir == 'left'){
		halfX = newX - 419;
	}else{
		halfX = newX + 419;
	}
	$('#promo_slider').animate({left:halfX},inSpeed,easeIn,function(){
		$(this).animate({left:newX},outSpeed,easeOut,function(){
			moose = true;
		});
	});
}


function setvalue(value){
	if($(".ui-autocomplete-input").val()=="")
	{
		$(".inputfirst").html(" Choose City, Interest, Theme, etc.");
	}
	else{
		$(".inputfirst").html($(value).html());	
	}
	
}

function thankupopup(){
	var centerDiv = $('.displaybox');
	var height = $(window).height();
	var width = $(window).width();
	var left=width/2 - (centerDiv.width() / 2);
	var top = height/2 - (centerDiv.height() / 2)
	centerDiv.css({'left' : left ,'top' : top});
	$(".overlay1").fadeIn();
	$(".displaybox").fadeIn();
	$("select").hide();	
}
function videolightbox(){
	$(".lightboxVideo").click(function()
   {	
   		var centerDiv = $('#lightboxVideoContainer');
		var height = $(document).height();
		var width = $(document).width();
		var left=width/2 - (centerDiv.width() / 2);		
		$('#lightboxVideoContainer').css({'left' : left});
		$('.videocloseDiv').css({'left' : left});
		$(".videowrapper").fadeIn();
		$(".overlay1").fadeIn();
		var src = $(this).attr("rel");
		$('#lightboxVideoContainer').html("");
		//var iframe = "<iframe src='"+src+"' width='575' height='550'></iframe>";
		var iframe = "<iframe src='"+src+"' width='575' height='525' scrolling='no' border=0></iframe>";
		$('#lightboxVideoContainer').fadeIn().html(iframe);
   });	
	$(".videoclosebtn").click(function(){
		$(".overlay1").hide();		
		$(".videowrapper").hide();
		$('#lightboxVideoContainer').html("");
		$('#lightboxVideoContainer').hide();
	});
}
function packagedetail_tabs()
{
	videolightbox();

	var lightboxIndex=0;
        var lightboxCount;
        $(".openImgageGallery").unbind('click');
		$(".openImgageGallery").bind('click', function() {
			//alert($("#imagegallery").children("a").length);
			$("#lightboxImg").show();
            lightboxCount = $("#imagegallery").children("a").length;
			
			if($("#imagegallery").children("a").length==1)
			{
				$(".lightboxnavigation").hide();
			}
			else{
				$(".lightboxnavigation").show();
			}
            lightboxIndex = 0;
            showLightboxImage(lightboxIndex);

            var centerDiv = $('.imagegallerywrap');
            var height = $(document).height();
            var width = $(document).width();
            var left = width / 2 - (centerDiv.width() / 2);
            //var top =  $("#jquery-lightbox").offset().top + 50;
            centerDiv.css({ 'left': left });

            $(".overlay1").fadeIn();
            $("#jquery-lightbox").fadeIn();
            $("#lightboxPrev").hide();
            $("#lightboxNext").show();
            /*$('html, body').animate({
            scrollTop: $("#jquery-lightbox").offset().top - 80
            }, 500);*/
        });
		$("#lightboxPrev").unbind('click');
        $("#lightboxPrev").bind('click', function() {
            lightboxIndex--;
            if (lightboxIndex == 0) {
                $(this).hide();
            }
            $("#lightboxNext").show();
            showLightboxImage(lightboxIndex);
        });
       
        $("#lightboxNext").unbind('click');
	   $("#lightboxNext").bind('click', function() {
			lightboxIndex++;
			
            if (lightboxIndex == lightboxCount - 1) {
                $(this).hide();
            }
            $("#lightboxPrev").show();
            showLightboxImage(lightboxIndex);
        });

        $("#lightboxClose, #overlay").click(function() {
            $(".overlay1").fadeOut();
            $("#jquery-lightbox").fadeOut();
        });
	
    /*$('#itineraryoptions').jcarousel({
       scroll: 1
    });*/
	
	$(".itinerarysidetab").click(function(){
		Cufon.refresh(".daywiseview h3");
		$('#itineraryoptions').jcarousel({
       		scroll: 1
    	});								  
	});
	
	/*Package Detail Itinerary code*/
	$("#itineraryoptions li").click(function() {
		var itineraryliindex = $(this).index();
		$(this).children().addClass("selected").parent().siblings().children("a").removeClass("selected");
		$(".itinerary").hide();
		$(".itinerary").eq(itineraryliindex).fadeIn();
	});
	/*Package Detail Itinerary code*/

	
	/* User Review */
	$(".postreviewhere h3").click(function() {
		$(this).toggleClass("active");
		$(".reviewform").slideToggle();
	});

	$(".reviewform").hide();
	$(".userreviewtab").click(function() {
		$(".postreviewhere h3").removeClass("active");
		$(".reviewform").slideUp();
	});

	$(".postreviewlink").click(function() {
	    tabchange($("#innerverttab li.userreviewtab"),1)
	    $(".innerverttabcont").hide();
	    $("#innerverttabcont3").show();
	    $(".postreviewhere h3").addClass("active");
	    $(".reviewform").slideDown();
	});
	/* User Review */
}
function showLightboxImage(index) {		
        var src = $("#imagegallery").children("a").eq(index).attr("href");
        var title = $("#imagegallery").children("a").eq(index).attr("title");        
		$("#lightboxImg").attr("src", src);
        $("#lightboxImgName").html(title);
}
function hideoverlay() 
{
    $(".overlay").hide();
    $(".loader").hide();
}
function opencontactusdropdown() {    
    $("#contactinfo").unbind("mouseenter mouseleave");
    thankpopvar = true;
    $(".contactinfo_dropdown").show();
    $("#entercallback").addClass("selected");
    $("#ContactInfo1_iform").hide();
    $("#ContactInfo1_ithanks").show(); 
}

function bindcontactusevent() {
    if (thankpopvar) {
        
    }
    else {
        $("#contactinfo").bind("mouseenter", (function() {
            $(this).children(".titlemargininside").children("a").addClass("selected");
            Cufon.refresh('.contactinfo a.selected');
            $("#entercallback").removeClass("selected");
            $(".content_alt .form").hide();
            $(".searchdropdown").hide(300, function() {
                $(".contactinfo_dropdown").stop(true, true).slideDown(500);
            });
			Cufon.refresh(".contactinfo .contactinfo_dropdown_bottom h3");
			Cufon.refresh("#contactinfo .contactinfo_dropdown_bottom .content a");
			Cufon.refresh("#contactinfo .contactinfo_dropdown_bottom .content a.selected");
			Cufon.refresh(".contactinfo a");
        }));

        $("#contactinfo").bind("mouseleave", (function(handler) {
            $(".contactinfo_dropdown").hide();
            $(this).children(".titlemargininside").children("a").removeClass("selected");
            Cufon.refresh('.contactinfo a');
        }));
    }		
}
function userreviewthankupopup() {	
    var centerDiv = $('.userreviewdisplaybox');
    var height = $(window).height();
    var width = $(window).width();
    var left = width / 2 - (centerDiv.width() / 2);
    var top = height / 2 - (centerDiv.height() / 2)
    centerDiv.css({ 'left': left, 'top': top });
    $(".overlay1").show();
    $(".userreviewdisplaybox").fadeIn();
    $("select").hide();
}
