var arrImg = [];
arrImg[0] = [1,"images/featured_destination1.jpg", "111text"];
arrImg[1] = [2,"images/featured_destination2.jpg", "222text"];
arrImg[2] = [3,"images/featured_destination3.jpg", "333text"];
arrImg[3] = [4,"images/featured_destination4.jpg", "444text"];
arrImg[4] = [5,"images/featured_destination5.jpg", "555text"];


$(function() {

    var sub_menu_divId = '#myholidays_popup';
    var my_holiday_a_tag_id = '#popup_menu_holiday';
    var my_holiday_div_html = 'menu_html_my_holiday.html';

    $('#popup_menu_holiday').click(function() {

        if ($(sub_menu_divId).css('display') == 'block') {
            hideMenu($(sub_menu_divId));
        }

        else {
            jQuery.get(my_holiday_div_html, null,
                        function(d, s) {
                            $('#linkscontainer').after(d);

                            $('.popup_holiday_menu').click(function(event) {
                                event.preventDefault();
                                $(sub_menu_divId).fadeOut('slow', function() { 
                                    window.location.href = event.target.href;
                                });
                            });

                            showMenu($(my_holiday_a_tag_id), $(sub_menu_divId));
                        },
                        'html');
        }
    });



    $('#slide_show_back').click(function(event) {
    showPrevSlide(event);
    });

    $('#slide_show_next').click(function(event) {
    showNextSlide(event);
    });

});


var showMenu = function(a, sub_menu_div) {
    var left = (a.offset().left - (sub_menu_div.outerWidth() / 2 * .76)) + "px";
    var top = (65) + "px";
    sub_menu_div.css({
        position: 'absolute',
        zIndex: 5000,
        left: left,
        top: top,
        visibility: 'visible'
    });
    sub_menu_div.hide().slideDown('slow');
    //sub_menu_div.mouseout(function() { hideMenu(sub_menu); });
};

var hideMenu = function(sub_menu_div) {
    sub_menu_div.fadeOut('slow');
};


var posTooltip = function(event) {
    var tPosX = event.pageX - 5;
    var tPosY = event.pageY + 10;
    $('#TooltipContainer').css({ top: tPosY, left: tPosX });
};



var showNextSlide = function(event) {

    iCurrent = -1;
    jQuery.each(arrImg, function() {
        if (this[1] == $("#imgSlideShow").attr("src")) {
            iCurrent = this[0];
        }
    });

    if (iCurrent >= arrImg.length || iCurrent == -1) {
        iCurrent = 1;
    }
    else {
        iCurrent += 1;
    }

    $("#imgSlideShow").attr("src",arrImg[iCurrent-1][1]);
    $("#txtSlideShow").html(arrImg[iCurrent - 1][2]);
    event.preventDefault();

    return false;
};

var showPrevSlide = function(event) {

    iCurrent = -1;
    jQuery.each(arrImg, function() {
        if (this[1] == $("#imgSlideShow").attr("src")) {
            iCurrent = this[0];
        }
    });

    if (iCurrent == 1 || iCurrent == -1) {
        iCurrent = arrImg.length;
    }
    else {
        iCurrent -= 1;
    }

    $("#imgSlideShow").attr("src", arrImg[iCurrent - 1][1]);
    $("#txtSlideShow").html(arrImg[iCurrent - 1][2]);
    event.preventDefault();

    return false;
};

