$(document).ready(function() {

    // teaser cycler
    numTabs = $("#teaser .item").length;
    if(numTabs > 1) {
        $('#teaser-menu li a').bind('click', function() {
            openTab($("#teaser .item:eq("+$(this).parent().index()+")"));
            return false;
        });
        autoRotate = setInterval("rotateTabs()", rotateSpeed);
    }

    // reservation date picker
    $('input#q-from, input#q-to, input#from, input#to').datepicker({
        showOn: "both",
        buttonImage: "media/css/i/cho-i-cal.png",
        buttonImageOnly: true,
        showButtonPanel: true,
        minDate: new Date()
    });

    // reservation quick form, blank email field on focus
    $('input#q-email').focus(function() {
        q_input = this.value;
        this.value = '';
    });

    $('input#q-email').blur(function() {
        if(this.value == '') this.value = q_input;
    });

    // colorbox
    $('a[rel^="colorbox"], a.colorbox').colorbox({
        slideshowStart: COLORBOX_MESSAGES.slideshowStart,
        slideshowStop: COLORBOX_MESSAGES.slideshowStop,
        current: COLORBOX_MESSAGES.current,
        previous: COLORBOX_MESSAGES.previous,
        next: COLORBOX_MESSAGES.next,
        close: COLORBOX_MESSAGES.close,
        transition: 'fade',
        transition: 'elastic',
        maxWidth: '90%',
        maxHeight: '90%'
    });

    // inFieldLabels
    $("p.inFieldLabel label").inFieldLabels();

});


// ----------------------------------------------------------------------------
// teaser setting and functions
var currentTab = 0;
var rotateSpeed = 10000;
var numTabs;
var autoRotate;
var toggleSpeed = 1500;
var toggleType = "";

function openTab(clickedTab) {
    var thisTab = $("#teaser .item").index(clickedTab);

    $("#teaser-menu li a").removeClass("active");
    $("#teaser-menu li:eq("+thisTab+") a").addClass("active");

    $("#teaser .item").fadeOut(toggleSpeed);
    $("#teaser .item:eq("+thisTab+")").fadeIn(toggleSpeed);

    currentTab = thisTab;
}

function rotateTabs() {
    var nextTab = (currentTab == (numTabs - 1)) ? 0 : currentTab + 1;
    openTab($("#teaser .item:eq("+nextTab+")"));
}
