$(document).ready(function(){
    $("table:not(.sponsors, .program) > tbody > tr:nth-child(odd)").addClass("alt");
    $(".program > tbody > tr > td:nth-child(odd)").css({"text-align":"left"});
    $(".program > tbody > tr > td:nth-child(even)").css({"color":"#653F12", "border-left":"1px solid #E9EFDB"});

    $('a[href^="http://"]').attr('target', '_blank');
    $("a[href$='pdf']").attr('target', '_blank');
    $("a[rel^='prettyPhoto'], .rtePhoto").prettyPhoto({theme:'facebook'});

    //When page loads...
    $(".tab_content").hide(); //Hide all content
    $("ul.tabs li:first-child").addClass("active").show(); //Activate first tab
    $(".tab_content:first-child").show(); //Show first tab content

    //On Click Event
    $("ul.tabs li").click(function () {

        $("ul.tabs li").removeClass("active"); //Remove any "active" class
        $(this).addClass("active"); //Add "active" class to selected tab
        $(".tab_content").hide(); //Hide all tab content

        var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
        $("#" + activeTab).fadeIn(); //Fade in the active ID content
        return false;
    });

    // carousel
    // pronadji startni indeks
    var datumRe = /(\d+)\.(\d+)\.$/,
        nd = new Date(),
        d = nd.getDate().toString(),
        m = ( nd.getMonth() + 1 ).toString(),
        startIndex = 11;
    $( "#mycarousel > li" ).each( function( i, v ) {
        var t = $( v ).attr( "title" );
        var dp = datumRe.exec( t );
        if( dp != null && dp.length == 3 && dp[1] == d && dp[2] == m ) {
            startIndex = i + 1;
            return false;
        }
    } );
    // instanciraj carousel
    jQuery('#mycarousel').jcarousel({itemFirstInCallback:function(a,li,c,d){
        var title = $(li).attr("title");
        $("#program-title div.datum").text(title);
        $(".tab_content").hide(); //Hide all content
	$("ul.tabs li:first-child").addClass("active").show(); //Activate first tab
	$(".tab_content:first-child").show(); //Show first tab content
    }, start: startIndex});

    //Show Banner
    $(".main_image .desc").show(); //Show Banner
    /*$(".main_image .block").animate({ opacity: 1 }, 1); //Set Opacity*/

    //Click and Hover events for thumbnail list
    $(".image_thumb ul li:first").addClass('active');
    $(".image_thumb ul li").click(function () {
        //Set Variables
        var imgAlt = $(this).find('img').attr("alt"); //Get Alt Tag of Image
        var imgTitle = $(this).find('a').attr("href"); //Get Main Image URL
        var imgDesc = $(this).find('.block').html(); 	//Get HTML of block
        var imgDescHeight = $(".main_image").find('.block').height(); //Calculate height of block	

        if ($(this).is(".active")) {  //If it's already active, then...
            return false; // Don't click through
        } else {
            //Animate the Teaser				
            $(".main_image .block").animate({ marginBottom: -imgDescHeight }, 250, function () {
                $(".main_image .block").html(imgDesc).animate({ marginBottom: "0" }, 250);
                $(".main_image img").attr({ src: imgTitle, alt: imgAlt });
            });
        }

        $(".image_thumb ul li").removeClass('active'); //Remove class of 'active' on all lists
        $(this).addClass('active');  //add class of 'active' on this list only
        return false;

    }).hover(function () {
        $(this).addClass('hover');
    }, function () {
        $(this).removeClass('hover');
    });

    //Toggle Teaser
    $("a.collapse").click(function () {
        $(".main_image .block").slideToggle();
        $("a.collapse").toggleClass("show");
    });

    $(".inside-text").equalHeights();

});

