/*****************************************************************************************************/
/*                                                                                                   */
/*                                           'NOW PLAYING'                                        	 */          
/*                                                                                                   */
/*****************************************************************************************************/

function ONAIRNOW(){
	var JSObject = this;
	this.type = "onairnow"; 
	
	this.DOMDoc; //document object from thickbox window
	
	this.container;
	
	this.seconds = 60;
	this.autoplay = true;
	
	
	/*****************************************************************************************************/
	/*                                                                                                   */
	/*                                      FUNCTION INIT                                                */          
	/*                                                                                                   */
	/*****************************************************************************************************/
	this.init = function(){
		
		this.container = $('#'+ this.type+'_container',this.DOMDoc).get(0);
		// alert(this.container);
		
		this.initCounter();
	}
	
	/*****************************************************************************************************/
	/*                                                                                                   */
	/*                                      FUNCTION LOAD BOX                                            */
	/*                                                                                                   */
	/*****************************************************************************************************/
	
	this.loadBox = function(){
		
		$.ajax({
				type: "POST",
				url: JSInterface.localpath+"showsschedules/showschedule/box",
				cache: false,
				async: true,
				success: function(responseJSON){
					
					if ((typeof(responseJSON) != "object" && typeof(responseJSON) != "string") || responseJSON == "") return;
							
		 			var JSON = eval ("("+responseJSON+")");
		 			
		 			$('#'+JSObject.type+'_container',JSObject.DOMDoc).html(unescape(JSON.html));
		 
				},
				error: function(){					
				}
			})
	}
		
	/*****************************************************************************************************/
	/*                                                                                                   */
	/*                                      FUNCTION COUNTER                                             */          
	/*                                                                                                   */
	/*****************************************************************************************************/
	this.initCounter = function(){

		$(this.container).unbind("countTimerOnAirNow");
		$(this.container).bind("countTimerOnAirNow", function(){
																var seconds = $(this).data("seconds");
																
																if (seconds - 1 >= 0){
																	$(this).data("seconds",seconds-1)
																}
																else{
																	$(this).data("seconds",JSObject.seconds);
																																		
																	JSObject.loadBox();
																}
															 })

		$(this.container).data("timerIntervalOnAirNow", setInterval(function(){if (JSObject.autoplay == true) $(JSObject.container).trigger("countTimerOnAirNow")},1000));
		$(this.container).data("seconds",this.seconds);	
	}
	
}
