
$(document).ready(function() {
    $('.enews').attr("href", "http://survey.backroads.com/main/newsletters/ActiveTravelNews.aspx?" +
        "firstVisitSource=" + $.cookie('firstVisitSource') +
        "&mostRecentSource="+ $.cookie("mostRecentSource") +
        "&search_engine="+ $.cookie("search_engine") +
        "&search_term=" + $.cookie("search_term")
    );
})


//This is a simple script for the large drop downs on the main menu

$(document).ready(function() {
    function addMega()
    {
        $(this).addClass("hovering");
        $($(this).find("a")).addClass("hover");
    }
    function removeMega()
    {
        $(this).removeClass("hovering");
        $($(this).find("a")).removeClass("hover");
    }
    var megaConfig =
    {
        interval: 200,
        sensitivity: 10,
        over: addMega,
        timeout: 300,
        out: removeMega
    };
    $("li.mega").hoverIntent(megaConfig);
});


//Closes large map on the trip page and then allows it to be opened by the enlarge anchor
$(document).ready(function(){
    $('#bigmap').hide();
    $('#zoom_map').bind('click',function(){
        $('#bigmap').show();
        return false;
    });
    $('#bigmap').bind('click',function(){
        $('#bigmap').hide();
        return false;
    });
});


//Hides and shows the 'What's this' notes on the trip page
$(document).ready(function(){
    $('.note').hide();
    $('.has_note').toggle(
        function() {
            $(this).parent().next('.note').show();
            $(this).text('Close note!');
        },
        function() {
            $(this).parent().next('.note').hide();
            $(this).text("What's this?");
        });
});


//Tabs for the trip page
$(document).ready(function(){
    $('#lodging , #rating, #quotes, #similar_trips').addClass('off');
    $('#tab_itinerary a').addClass('on');

    $('#lodging_tab, #reviews_tab, #route_rating_tab, #trips_in_region_tab').addClass("unselected")
    $('#trip_overview_tab').addClass("selected")

    $('#tab_itinerary, #trip_overview_tab').click(function(){
        $('#tabs li h4 a').removeClass('on');
        $('#tab_itinerary a').addClass('on');
        $('.tab_content').addClass('off');
        $('#itinerary').removeClass('off');

        $('#lodging_tab, #reviews_tab, #route_rating_tab, #trips_in_region_tab').removeClass('selected').addClass("unselected");
        $('#trip_overview_tab').removeClass('unselected').addClass("selected");
    });

    $('#reviews_tab').click(function(){

        $('.tab_content').addClass('off');
        $('#quote').removeClass('off');

        $('#trip_overview_tab, #lodging_tab, #route_rating_tab, #trips_in_region_tab').removeClass('selected').addClass("unselected");
        $('#reviews_tab').removeClass('unselected').addClass("selected");
    });

    $('#tab_lodging, #other_lodgingTab, #lodging_tab').click(function(){
        $('#tabs li h4 a').removeClass('on');
        $('#tab_lodging a').addClass('on');
        $('.tab_content').addClass('off');
        $('#lodging').removeClass('off');

        $('#trip_overview_tab, #reviews_tab, #route_rating_tab, #trips_in_region_tab').removeClass('selected').addClass("unselected");
        $('#lodging_tab').removeClass('unselected').addClass("selected");
    });

    $('#tab_rating, #other_ratingTab, #route_rating_tab').click(function(){
        $('#tabs li h4 a').removeClass('on');
        $('#tab_rating a').addClass('on');
        $('.tab_content').addClass('off');
        $('#rating').removeClass('off');

        $('#trip_overview_tab, #reviews_tab, #lodging_tab, #trips_in_region_tab').removeClass('selected').addClass("unselected");
        $('#route_rating_tab').removeClass('unselected').addClass("selected");
    })

    $('#reviews_tab').click(function(){

        $('.tab_content').addClass('off');
        $('#quotes').removeClass('off');

        $('#trip_overview_tab, #lodging_tab, #route_rating_tab, #trips_in_region_tab').removeClass('selected').addClass("unselected");
        $('#reviews_tab').removeClass('unselected').addClass("selected");
    });

    $('#trips_in_region_tab').click(function(){

        $('.tab_content').addClass('off');
        $('#similar_trips').removeClass('off');

        $('#trip_overview_tab, #lodging_tab, #route_rating_tab, #reviews_tab').removeClass('selected').addClass("unselected");
        $('#trips_in_region_tab').removeClass('unselected').addClass("selected");
    });

});


//Menu slider
$(document).ready(function(){
    if(!$('#calender_nav')){ return false};
    $('#calender_nav ul').hide();
    $('#calender_nav ul:first').show();
    $('#calender_nav h3').click(
        function() {
            var checkElement = $(this).next();
            if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
                return false;
            }
            if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
                $('#calender_nav ul:visible').slideUp('normal');
                checkElement.slideDown('normal');
                return false;
            }
        }
    );
});


//Table stripe
$(document).ready(function(){
    if(!$('table tr.departures')){ return false};
    $('tr.departures:visible').filter(':nth-child(even)').each(function(index) {
        $(this).addClass('odd');
    });
});

//Removing the dotted border off the top region trip in the search results
$(document).ready(function(){
    if(!$('div.region div:first-child')){ return false};
    $('div.region div:first-child').each(function(){
        $(this).addClass('first');
    });
});

//Removing the solid border off the top location group in the search results
$(document).ready(function(){
    if(!$('div.location:nth-child(3)')){ return false};
    $('div.location:nth-child(3)').each(function(){
        $(this).addClass('first');
    });
});


var profiles =
{
    window600:
    {
        height:600,
        width:500,
        status:1,
        location:0
    }
};


$(function()
{
    if($('.popupwindow').length > 0){
        $(".popupwindow").popupwindow(profiles);
    };
});



function openScript(url, width, height, left, top) {
    var Win = window.open(url,"openScript",'width=' + width + ',height=' + height + ',resizable=0,scrollbars=yes,menubar=no,status=no,left=0,top=10' );
}









