/*
*    Calendar
*    Loads and interfaces with a Flash calendar application
*    
*    Requires jQuery library (http://www.jquery.com),
*    SWFObject (http://blog.deconcept.com/swfobject/)
*    
*    Taylan Pince (taylan@trapeze.com) - July 26, 2007
*/


if (typeof trapeze == 'undefined') trapeze = new Object();


trapeze.Calendar = {

    assets_path : trapeze.RachaelRay.assets_path,

    open_shield : function() {
        if ($("#WeekShowcaseShield").size() == 0) {
            var html = '';
            var h = $("#WeekShowcaseContent").height();
            html += '<div id="WeekShowcaseShield" style="height: ' + h + 'px;">';
            html += '<img src="' + this.assets_path + 'img/ico-loader.gif" alt="Loading..." style="margin-top: ' + (h / 2) + 'px;" /></div>';

            $("#WeekShowcase").append(html);
        }
    },

    close_shield : function() {
        $("#WeekShowcaseShield").remove();
    },

    resetShowcaseContent : function(url) {
        //this.open_shield();
        url = url + "&ajax=1&section=showcase-content";
        if (trapeze.Calendar.content_url != url) {
          $.get(url, {}, function (response) {
              trapeze.Calendar.domHandle.find("#WeekShowcaseContent").html(response);
              epLinks = trapeze.Calendar.domHandle.find(".showcase-content-link");
              if( epLinks.length > 0 )
                  trapeze.RachaelRay.init_showcase(epLinks[0].href + 'player/');
              //trapeze.Calendar.close_shield();
          })
          trapeze.Calendar.content_url = url
        }
    },

    resetShowcaseBrowser : function(url) {
        url = url + "&ajax=1&section=showcase-browser";
        if (trapeze.Calendar.browser_url != url) {
          $.get(url, {}, function (response) {
              trapeze.Calendar.domHandle.find("#WeekShowcaseBrowser").html(response);
              trapeze.Calendar.setMouseOvers();
              //trapeze.Calendar.overrideNavLinks();
          })
          trapeze.Calendar.browser_url = url
        }
    },

    setMouseOvers : function() {
        this.domHandle.find("#WeekShowcaseBrowser .showcaseDate").hover(
            function() {
                $('#WeekShowcaseBrowser .showcaseDate img').each(function(){
                  this.src = this.src.replace(/hover|active/, 'normal');
                });

                image = $(this).find("img")[0]
                image.src = image.src.replace(/normal/, 'active');
                trapeze.Calendar.resetShowcaseContent(this.href);
                return false;
            },
            function() {});
        this.domHandle.find("#WeekShowcaseBrowser .showcaseDate").unbind('click');
    },

    init : function() {
        this.domHandle = $("#WeekShowcase");
        this.setMouseOvers();
    }

};

$(function() {
    trapeze.Calendar.init();
})

