﻿$(document).ready(function() {

    $('.rollover').hover(function() {
        var src;
        src = $(this).find('img').attr('src');
        src = src.replace('_off', '_over');
        $(this).find('img').attr('src', src);
        document.body.style.cursor = "hand";
    },
    function() {
        var src;
        src = $(this).find('img').attr('src');
        src = src.replace('_over', '_off');
        $(this).find('img').attr('src', src);
        document.body.style.cursor = "auto";
    });

    //Setup function

    //Setup itinerary tabs
    Shadowbox.init();
    $('.pane').hide();
    $('#pane-itinerary').show();
    $('.tabLink').click(function() {
        var id;
        var idRoot;
        idRoot = this.id.split("-")[1];
        id = "#pane-" + idRoot;
        $('.pane').hide();
        $(id).show();

        id = "#img-" + idRoot;
        $(id).attr('src', "/images/itinerarytabs/" + idRoot + "_active.gif");
        return false;
    });

    $('#tab-travelplanner').click(function() {
        window.open('TravelPlanner.htm', 'Window1', 'menubar=no,width=430,height=360,toolbar=no');
    });

    $('.popup').click(function() {
        var urlTarget;
        urlTarget = this.href;
        var tl;
        tl = this.title;
        Shadowbox.open({
            player: 'iframe',
            content: urlTarget,
            title: tl,
            width: 650
        });

        return false;
    });


    $('.tabImage').hover(
                function() {
                    var id;
                    var paneId;
                    var idRoot;
                    idRoot = this.id.split("-")[1];
                    id = "#img-" + idRoot;

                    paneId = "#pane-" + idRoot;
                    if ($(paneId).is(':visible')) {
                        $(id).attr('src', "/images/itinerarytabs/" + idRoot + "_active.gif");
                    }
                    else {
                        $(id).attr('src', "/images/itinerarytabs/" + idRoot + "_over.gif");
                    }


                },
                function() {
                    var id;
                    var idRoot;
                    idRoot = this.id.split("-")[1];
                    id = "#img-" + idRoot;

                    paneId = "#pane-" + idRoot;
                    if ($(paneId).is(':visible')) {
                        $(id).attr('src', "/images/itinerarytabs/" + idRoot + "_active.gif");
                    }
                    else {
                        $(id).attr('src', "/images/itinerarytabs/" + idRoot + "_off.gif");
                    }


                });

    $('.bookmarkImage').hover(
                function() {
                    var id;
                    var paneId;
                    var idRoot;
                    idRoot = this.id.split("-")[1];
                    id = "#img-" + idRoot;

                    $(id).attr('src', "/images/Bookmarks/" + idRoot + "_over.gif");



                },
                function() {
                    var id;
                    var paneId;
                    var idRoot;
                    idRoot = this.id.split("-")[1];
                    id = "#img-" + idRoot;

                    $(id).attr('src', "/images/Bookmarks/" + idRoot + "_off.gif");



                });

    //Setting up right hand nav

    $('.rightImage').hover(
        function() {
            var id;
            var idRoot;
            idRoot = this.id.split("-")[1];
            id = "#img-" + idRoot;
            $(id).attr('src', "/images/rightsidebar/" + idRoot + "_over.jpg");
        },
        function() {
            var id;
            var idRoot;
            idRoot = this.id.split("-")[1];
            id = "#img-" + idRoot;
            $(id).attr('src', "/images/rightsidebar/" + idRoot + "_off.jpg");

        });

    $('.brochurePopup').click(function() {
        Shadowbox.open({
            player: 'iframe',
            title: 'Order a Brochure',
            content: 'http://tools.tauck.com/Brochure/',
            width: 645
        });
        return false;

    });

    $('.rightHandPopup').click(function() {
        var urlTarget;
        urlTarget = this.href;
        var tl;
        tl = this.title;
        Shadowbox.open({
            player: 'iframe',
            content: urlTarget,
            title: tl,
            width: 645
        });
        return false;
    });


    $('.rightHandPopup').hover(function() {
        var src;
        src = $(this).find('img').attr('src');
        src = src.replace('_off', '_over');
        $(this).find('img').attr('src', src);
    },
    function() {
        var src;
        src = $(this).find('img').attr('src');
        src = src.replace('_over', '_off');
        $(this).find('img').attr('src', src);
    });

    $('.availabilityPopup').click(function() {
        var urlTarget;
        urlTarget = this.href;
        Shadowbox.open({
            player: 'iframe',
            title: 'Check availabile dates',
            content: urlTarget,
            width: 645
        });
        return false;

    });

    $('#rightChat').click(function() {
        window.open('http://server.iad.liveperson.net/hc/56579838/?cmd=file&file=visitorWantsToChat&site=56579838&imageUrl=http://www.tauck.com/images/rightsidebar/livepersonicon.gif&referrer=' + escape(document.location), 'chat56579838', 'width=472,height=320');
        return false;
    });
});




function checkemail(str) {
    var filter = /^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i
    if (filter.test(str)) {
        return true;
    } else {
        return false;
    }
}

function getCookie(check_name) {
    // first we'll split this cookie up into name/value pairs
    // note: document.cookie only returns name=value, not the other components
    var a_all_cookies = document.cookie.split(';');
    var a_temp_cookie = '';
    var cookie_name = '';
    var cookie_value = '';
    var b_cookie_found = false; // set boolean t/f default f

    for (i = 0; i < a_all_cookies.length; i++) {
        // now we'll split apart each name=value pair
        a_temp_cookie = a_all_cookies[i].split('=');


        // and trim left/right whitespace while we're at it
        cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

        // if the extracted name matches passed check_name
        if (cookie_name == check_name) {
            b_cookie_found = true;
            // we need to handle case where cookie has no value but exists (no = sign, that is):
            if (a_temp_cookie.length > 1) {
                cookie_value = unescape(a_temp_cookie[1].replace(/^\s+|\s+$/g, ''));
            }
            // note that in cases where cookie is initialized but no value, null is returned
            return cookie_value;
            break;
        }
        a_temp_cookie = null;
        cookie_name = '';
    }
    if (!b_cookie_found) {
        return null;
    }
}