﻿// Onload
$(function() {

    // Homepage carousel
    if ($('#homepage_carousel').length) {
        $("#homepage_carousel ul.tabs").tabs("#homepage_carousel div.panes > div", {
            initialIndex: 0,
            effect: 'fade',
            fadeOutSpeed: "slow",
            rotate: true
        }).slideshow({ clickable: false, interval: 5000 });

        $("#homepage_carousel ul.tabs").click(function() {
            $("#homepage_carousel ul.tabs").data("slideshow").stop();
        });

        $("#homepage_carousel ul.tabs").data("slideshow").play();
    }

    // Comments tabs
    if ($('#comments_tabs').length) {
        $("#comments_tabs ul.tabs").tabs("#comments_tabs div.panes > div", {
            effect: 'default'
        });
        $("#comments_container").show();
    }

    //Top menu tooltips/dropdowns (don't worry, will comment/remove the ones we don't end up using...)
    if ($("#menu a[rel=menu_trigger_260]").length) {
        $("#menu a[rel=menu_trigger_260]").tooltip({
            position: "bottom left",
            offset: [0, 264],
            delay: 100,
            //opacity: 0.95,
            tipClass: "menu_tooltip_260"
        });
    }
    
    //Tooltips for the tagline editions
    if ($("#tagline-edition a[rel=edition_trigger]").length) {
        $("#tagline-edition a[rel=edition_trigger]").tooltip({
            position: "bottom left",
            offset: [-4, 155],
            delay: 100,
            tipClass: "edition_tooltip"
        });
    }
    
    //Apply highlight to Dropdown's parent menu item link
    if ($("div.all_tooltips").length) {
        $("div.all_tooltips").hover(function() {
            $(this).prev("#menu a").addClass("highlight");
        }, function() {
            $(this).prev("#menu a").removeClass("highlight");
        });
    }

    // Event calendar - search
    if ($("#searchEventDates :date").length) {
        $(":date").dateinput({ trigger: true, format: 'dd/mm/yyyy' });

        // use the same callback for two different events. possible with bind
        $(":date").bind("onShow onHide", function() {
            $(this).parent().toggleClass("active");
        });
        // when first date input is changed
        $(":date:first").data("dateinput").change(function() {
            // we use it's value for the seconds input min option
            $(":date:last").data("dateinput").setMin(this.getValue(), true);
        });
    }

    //Article image zoom overlay
    if ($("img.article-image-zoomable").length) {
        $("img.article-image-zoomable").overlay({
            mask: {
                color: '#000000',
                loadSpeed: 200,
                opacity: 0.75
            }
        });
    }
    
    
    
});

