$(document).ready(function () {

    $('.rotator').scrollable({
        circular: true,
        auto: null
    });

    $('#content .rotator .items a').fadeTo('slow', 0.5);
    $('#content .rotator .items a').mouseenter(function () { $(this).fadeTo('fast', 1); });
    $('#content .rotator .items a').mouseleave(function () { $(this).fadeTo('fast', 0.5); });

    $('.main-menu ul li, .select, .filter li').mouseenter(function () { $(this).addClass('hover'); });
    $('.main-menu ul li, .select, .filter li').mouseleave(function () { $(this).removeClass('hover'); });

    $('input[title!=""]').focus(function () { if ($(this).val() == $(this).attr('title')) { $(this).val(''); } });
    $('input[title!=""]').blur(function () { if ($(this).val() == '') { $(this).val($(this).attr('title')); } });

    $('.select ul a').click(function () {
        $('.select input').val($(this).text());
        return false;
    });

    $('.cart select').change(function () {
        var sub = ($('.cart input[name="cost"]').val() * $(this).val());
        $('.cart #sub').text(sub);
        $('.cart #total').text(parseFloat(sub) + parseFloat($('.cart input[name="fees"]').val()));
    });

    $('.now-playing .items .item').mouseenter(function () { $(this).addClass('hover'); });
    $('.now-playing .items .item').mouseleave(function () { $(this).removeClass('hover'); });

    /* Gallery */

    $('.gallery .thumbs a').fadeTo('slow', 0.5);

    $('.gallery .thumbs a:first').fadeTo('fast', 1);
    $('.gallery .thumbs a:first').addClass('active');

    $('.gallery .thumbs a:not(.active)').mouseenter(function () { if (!$(this).hasClass('active')) { $(this).fadeTo('fast', 1); } });
    $('.gallery .thumbs a:not(.active)').mouseleave(function () { if (!$(this).hasClass('active')) { $(this).fadeTo('fast', 0.5); } });

    $('.gallery .thumbs a').click(function () {
        $('.gallery .thumbs a').removeClass('active');
        $(this).addClass('active');
        $('.gallery .thumbs a:not(.active)').fadeTo('fast', 0.5);
        $(this).fadeTo('fast', 1);

        $('.gallery .pic img').attr('src', $(this).attr('href'));
        $('.gallery p.title').text($(this).attr('title'));

        if ($('#divCredit #span' + $(this).attr('imid')).html()) {
            $('.gallery p.credit span').html($('#divCredit #span' + $(this).attr('imid')).html());
            $('.gallery p.credit').show();
        }
        else
            $('.gallery p.credit').hide();

        return false;
    });

    $('.gallery .pic img').attr('src', $('.gallery .thumbs li a:first').attr('href'));
    $('.gallery p.title').text($('.gallery .thumbs a:first').attr('title'));
    if ($('#divCredit span:first').html()) {
        $('.gallery p.credit span').html($('#divCredit span:first').html());
        $('.gallery p.credit').show();
    }
    else
        $('.gallery p.credit').hide();

    /* Calendar */

    //$('.calendar table span.half, .calendar table strong.half').hide();

    $('#filter-halfprice').click(function () {
        return;
        if (!$(this).hasClass('active')) {
            $(this).addClass('active');
            $('.calendar table span.half, .calendar table strong.half').fadeTo('slow', 1);
        } else {
            $(this).removeClass('active');
            $('.calendar table span.half, .calendar table strong.half').hide();
        }

        return false;
    });

    $('#filter-fullprice').click(function () {
        return;
        if (!$(this).hasClass('active')) {
            $(this).addClass('active');
            $('.calendar table span:not(.half), .calendar table strong:not(.half)').fadeTo('slow', 1);
        } else {
            $(this).removeClass('active');
            $('.calendar table span:not(.half),.calendar table strong:not(.half)').hide();
        }

        return false;
    });

    /* Main Menu */


    $('.main-menu UL LI').hover(function () {
        $(this).find('ul:first').css({ visibility: "visible", display: "none" }).fadeIn();

    }, function () {
        $(this).find('ul:first').css({ visibility: "hidden" });

    });

    $('#thumbs').jCarouselLite({
        btnNext: ".next",
        btnPrev: ".prev",
        visible: 5,
        circular: false
    });

    var colidx = 0;
    $("#fastageblog-addons table.toc").remove().find("td > a").each(function () {
        colidx++;
        $("#fastageblog-addons").append(
	          '<div class="col ' + ((colidx == 2) ? 'center' : '') + '">' +
                '<a href="' + this.href + '" title="' + this.title + '">' +
                  '<img alt="' + this.title + '" src="' + $(this).find("img").attr("src") + '"/>' +
                '</a>' +
                '<span>' +
                    this.title +
                 '</span>' +
               '</div> ');
    });


}); 

