﻿$.fn.preload = function() {
    this.each(function(){
        $('<img/>')[0].src = this;
    });
}


$(document).ready(function () {

    $('#slide_image').hide();
    setTimeout("$('#slide_image').slideDown(3000);", 3000);

    $(['/Images/HomeSlider/Indulge.jpg',
    '/Images/HomeSlider/Taste.jpg',
    '/Images/HomeSlider/Stay.jpg',
    '/Images/HomeSlider/Incentives.jpg',
    '/Images/HomeSlider/Experience.jpg']).preload();

    $('.tab').quickFlip({
        vertical: true
    });

    initiateTabs();

    /*
    $(".tab.indulge,.tab.taste,.tab.stay,.tab.incentives,.tab.experience").hover(
    function () {
    $(this).click();
    },
    function () {
    resetTabs();
    }
    );
    */

    $('.tab.indulge').click(function () {
        resetTabs();
        //$(this).quickFlipper({vertical: true, closeSpeed: 1000, openSpeed: 1000}, 1, 1);

        showTab('.' + $(this).attr('class').replace(' ', '.'), true);

        $('img', $('.slide_image')).attr('src', '/Images/HomeSlider/Indulge.jpg');
        $('.slide_image').click(function () {
            window.location.href = '/Explore/Indulge';
        });
        $('.slide_image').css('cursor', 'pointer');
    });

    $('.tab.indulge').click(function () {
        resetTabs();
        //$(this).quickFlipper({vertical: true, closeSpeed: 1000, openSpeed: 1000}, 1, 1);

        showTab('.' + $(this).attr('class').replace(' ', '.'), true);

        $('img', $('.slide_image')).attr('src', '/Images/HomeSlider/Indulge.jpg');
        $('.slide_image').click(function () {
            window.location.href = '/Explore/Indulge';
        });
        $('.slide_image').css('cursor', 'pointer');
    });

    $('.tab.taste').click(function () {
        resetTabs();
        showTab('.' + $(this).attr('class').replace(' ', '.'), true);

        $('img', $('.slide_image')).attr('src', '/Images/HomeSlider/Taste.jpg');
        $('.slide_image').click(function () {
            window.location.href = '/Explore/Taste';
        });
        $('.slide_image').css('cursor', 'pointer');
    });
    $('.tab.stay').click(function () {
        resetTabs();
        showTab('.' + $(this).attr('class').replace(' ', '.'), true);

        $('img', $('.slide_image')).attr('src', '/Images/HomeSlider/Stay.jpg');
        $('.slide_image').click(function () {
            window.location.href = '/Explore/Stay';
        });
        $('.slide_image').css('cursor', 'pointer');
    });
    $('.tab.incentives').click(function () {
        resetTabs();
        showTab('.' + $(this).attr('class').replace(' ', '.'), true);

        $('img', $('.slide_image')).attr('src', '/Images/HomeSlider/Incentives.jpg');
        $('.slide_image').click(function () {
            window.location.href = '/Explore/Incentives';
        });
        $('.slide_image').css('cursor', 'pointer');
    });
    $('.tab.experience').click(function () {
        resetTabs();
        showTab('.' + $(this).attr('class').replace(' ', '.'), true);

        $('img', $('.slide_image')).attr('src', '/Images/HomeSlider/Experience.jpg');
        $('.slide_image').click(function () {
            window.location.href = '/Explore/Experience';
        });
        $('.slide_image').css('cursor', 'pointer');
    });

});

function resetTabs()
{
    $('.tab img:nth-child(2)').hide();
    $('.tab img:nth-child(1)').show();
}

function initiateTabs()
{
    $('.tab').each(function (index) {
        $('a', this).attr('href', '#');
        $('a', this).tooltip();

        $(this).hide();
        $(this).css('height', '0px');
        $(this).css('margin-top', '64px');
        setTimeout('showTab(\'.' + $(this).attr('class').replace(' ', '.') + '\', false);', (index + 3) * 500);
        //setTimeout('$(\'.' + $(this).attr('class').replace(' ', '.') + '\').quickFlipper({vertical: true, closeSpeed: 150, openSpeed: 220}, 0, 1);', (index+7)*500);
    });
}

function showTab(tab, selected)
{
    if (selected)
    {
        //$(tab).animate({'margin-top': '64px', 'height':'0px'}, 'slow', function(){ 
        //    $(this).hide(); 
            $(tab + ' img:nth-child(1)').hide();
            $(tab + ' img:nth-child(2)').show();
        //    $(tab).show();
        //    $(tab).animate({'margin-top': '0px', 'height':'64px'}, 'slow');
        //});
    } else {
        $(tab).show();
        $(tab).animate({'margin-top': '0px', 'height':'64px'}, 'slow');
    }
}

function hideTab(tab)
{
    $(tab).animate({'margin-top': '64px', 'height':'0px'}, 'slow', function(){ $(this).hide(); });
}
