var showSchedule = {
    timeStart: 0,
    timeEnd: 0,
    timer: null,
    clickUrl: null,
    
    init: function() {
        showSchedule.timer = setInterval(showSchedule.tickDown,1000);
        showSchedule.tickDown();
        
        if(showSchedule.clickUrl) 
        {        
            jQuery("#ShowIndicator").click(function() {    
                window.open(showSchedule.clickUrl);
            }).css("cursor","pointer");
        }
    },
    
    formatCount: function(time) {
    	var formattedTime;
    	
        var days = Math.floor(time / 86400);
        var hours = Math.floor((time % 86400) / 3600);
        var minutes = Math.floor(((time % 86400) % 3600) / 60);
        var seconds = ((time % 86400) % 3600) % 60;
        
        if(days < 0)
            days = 0;
    	
    	if(hours < 0)
    		hours = 0;
    	
    	if(minutes < 0)
    		minutes = 0;
    		
    	if(seconds < 0)
    		seconds = 0;
    	
    	return new Array(days,hours,minutes,seconds);        
    },
    
    tickDown: function() {
        var indicator = jQuery("#ShowIndicator");
        
        if(indicator.length > 0) 
        {
        	showSchedule.timeStart--;
        	showSchedule.timeEnd--;
    
        	if(showSchedule.timeStart > 0) {
        		timeToShow = showSchedule.timeStart;
        	} else {
                jQuery("div:first", indicator).removeClass("Scheduled").addClass("Running");
        		timeToShow = showSchedule.timeEnd;
        	}
        	
        	if(showSchedule.timeEnd >= 0) {
        		var timeParts = showSchedule.formatCount(timeToShow);
                
                jQuery(".Countdown .CountdownDays").html(timeParts[0]);
                jQuery(".Countdown .CountdownHours").html(timeParts[1]);
                jQuery(".Countdown .CountdownMinutes").html(timeParts[2]);
                jQuery(".Countdown .CountdownSeconds").html(timeParts[3]);
        	} else {
        		clearInterval(showSchedule.timer);
                jQuery(indicator).parent().remove(indicator);
        	}
        } else
            clearInterval(showSchedule.timer);
    }
}
