/*
                  Inroads User Interface Dialog JavaScript Functions

                         Written 2011 by James Mussman
                          Copyright 2011 Inroads, LLC
*/

/*
 * options{
 *   video_id: YOUTUBEVIDEOID, [REQUIRED]
 *   ytaddress: http://www.youtube.com/apiplayer?enablejsapi=1&version=3, [DEFAULTED]
 *   player {
 *     height:100, [DEFAULTED]
 *     width:100, [DEFAULTED]
 *     play_button, [DEFAULTED]
 *   }
 *   parent_id: body tag [DEFAULTED]
 *   play_btn: true [DEFAULTED,BOOLEAN]
 *   progress_bar: true [DEFAULTED,BOOLEAN]
 * }
 */
var YT_Inr_Counter = 0;
var flash_player_collection = {'notafish':true};
userPrototypeMethods = false;
if((typeof(Prototype)=="undefined")){
	document.write('<script type="text/javascript" src="/engine/ui.js"></script>');
}else{
	usePrototypeMethods = true;
}
if(typeof(swfobject)=='undefined'){
	document.write('  <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js"></script>');
}
if(typeof(JSON)=='undefined'){
    document.write('  <script type="text/javascript" src="editor-support/develop/json.js"><'+'/script>');
}

function YT_Inr(options){
	this.error = false;
	this.error_message = '';
	this.parentClass = this;
	this.container = null;
	this.swfobject = null;
	this.data = null;
	this.info = null;
	this.oncompletefunc = false;
	this.volume_sliding = false;
	this.time_sliding = false;
	this.time_ratio = 0;
	this.volume_ratio = 0;
	//options is required
	if(!options){
		this.error = true;
		this.error_message = 'No option data given';
		return;
	}
	//we need the video id.
	if(!options.video_id){
		this.error = true;
		this.error_message = 'No Video given';
		return;
	}else{
		this.video_id = options.video_id;
	}
	//init the ytaddress, which is the location of the youtube progam
	//default
	this.ytaddress = 'http://www.youtube.com/apiplayer?enablejsapi=1&version=3';
	//option to change it
	if(options.ytaddress){
		this.ytaddress = options.ytaddress;
	}
	//init player id 
	this.player_id = 'video_id_'+YT_Inr_Counter;
	if(options.id){
		this.player_id = options.id+'_'+YT_Inr_Counter;
	}
	this.flash_id = this.player_id+'_flash';
	flash_player_collection[this.flash_id] = this;
	this.flashvars = 'video_id='+this.video_id+'&player_id='+this.player_id;
	//this is the player controls:
	this.player = {
		height:false,
		width:false,
		play_button: '',
		scale:1
	};
	if(options.player){
		this.player.height = (options.player.height)?options.player.height:this.player.height;
		this.player.width = (options.player.width)?options.player.width:this.player.width;
		this.player.play_button = (options.player.play_button)?options.player.play_button:this.player.play_button;
		if(options.player.ratio)this.player.ratio = options.player.ratio;
		this.player.scale = (options.player.scale)?options.player.scale:this.player.scale;
	}
	this.color = 'white';
	if(options.color){
		this.color = options.color;
	}
	this.center_btn = {
		height:80,
		width:145,
		playImg:'images/ytinr/inr_yt_play_btn.png',
		playAlt:'Play',
		replayImg:'images/ytinr/inr_yt_play_btn.png',
		replayAlt:'Replay'
	};
	if(options.center_btn){
		this.center_btn.height = (options.center_btn.height)?options.center_btn.height:this.center_btn.height;
		this.center_btn.width = (options.center_btn.width)?options.center_btn.width:this.center_btn.width;
		this.center_btn.playImg = (options.center_btn.playImg)?options.center_btn.playImg:this.center_btn.playImg;
		this.center_btn.playAlt = (options.center_btn.playAlt)?options.center_btn.playAlt:this.center_btn.playAlt;
		this.center_btn.replayImg = (options.center_btn.replayImg)?options.center_btn.replayImg:this.center_btn.replayImg;
		this.center_btn.replayAlt = (options.center_btn.replayAlt)?options.center_btn.replayAlt:this.center_btn.replayAlt;
	}
	this.offset_controls = 0;
	if(this.player.scale!=1){
		this.center_btn.height = Math.round(this.center_btn.height * this.player.scale);
		this.center_btn.width = Math.round(this.center_btn.width * this.player.scale);
		this.player.height = this.player.height * this.player.scale;
		this.player.width = this.player.width * this.player.scale;
		//this.offset_controls = 40 * this.player.scale;
	}
	this.parent_id = null;
	if(options.parent_id){
		this.parent_id = options.parent_id;
		this.parent = document.getElementById(this.parent_id);
	}else{
		this.parent = document.body;
	}
	this.progress_bar = true;
	if(typeof(options.progress_bar)!='undefined'){
		this.progress_bar = options.progress_bar;
	}
	this.volume_control = true;
	if(typeof(options.volume_control)!='undefined'){
		this.volume_control = options.volume_control;
	}
	this.play_btn = true;
	if(typeof(options.play_btn)!='undefined'){
		this.play_btn = options.play_btn;
	}
	this.player_cover = true;
	if(typeof(options.player_cover)!='undefined'){
		this.player_cover = options.player_cover;
	}
	this.cover = {active:false};
	if(typeof(options.cover)!='undefined'){
		//alert('setting cover to '+options.cover);
		if(options.cover.active){
			this.cover.active = options.cover.active;
			this.cover.height = (options.cover.height)?options.cover.height:(this.player.height *.1);
			this.cover.classname = (options.cover.classname)?options.cover.classname:'';
			this.cover.topPadding = (typeof(options.cover.topPadding)!='undefined')?options.cover.topPadding:true;
			this.cover.title = (options.cover.title)?options.cover.title:'';
		}
	}
	this.popup = false;
	if(typeof(options.popup)!='undefined'){
		this.popup = options.popup;
	}
	this.playPauseControl = true;
	if(typeof(options.playPauseControl)!='undefined'){
		this.playPauseControl = options.playPauseControl;
	}
	YT_Inr_Counter ++;
}
YT_Inr.prototype.init = function(){
	var youtubeAPI = 'http://gdata.youtube.com/feeds/api/videos?v=2&alt=json&q='+this.video_id;
	var parms = {'cmd':'get_json',url:youtubeAPI};
	var run = 'js/youtube_api.php';
	me = this;
	//alert('start ajax');
	if(usePrototypeMethods){
		new Ajax.Request(run,{
			method:'post',
			parameters:parms,
			onSuccess:function(transport){
			  //alert('ajax finished');
			  me.wrapajax_pro(transport);
    		}
		});
	}else{
		var aj = new Ajax(run,parms,true);
		aj.set_callback_function(function(transport,me){me.wrapajax(transport);},this);
		aj.send();
	}
};
YT_Inr.prototype.wrapajax_pro = function(transport){
	//alert(transport.responseText);
	this.jsonreturn = transport.responseText;
	
	this.data = JSON.parse(transport.responseText);
	
	this.ajax_continue();
};
YT_Inr.prototype.wrapajax = function(transport){
	
	this.data = JSON.parse(transport.responseText, reviver);
	this.ajax_continue();
};
YT_Inr.prototype.set_info = function(){
	//console.log(this.data);
	this.info = {};
	this.info.accessControl = {};
	for(var i = 0; i<this.data.feed.entry[0].yt$accessControl.length;i++){
		this.info.accessControl[this.data.feed.entry[0].yt$accessControl[i].action] = this.data.feed.entry[0].yt$accessControl[i].permission;
	}
	this.info.aspectRatio = this.data.feed.entry[0].media$group.media$content[0].expression;
	this.info.duration = this.data.feed.entry[0].media$group.media$content[0].duration;
	//console.log(this.info);
};
YT_Inr.prototype.ajax_continue = function(){
	this.set_info();
	if(typeof(this.info)=='undefined' || this.info.accessControl.embed!="allowed"){
		alert('Error:\nThe video cannot be displayed.');
		this.error = true;
		this.error_message = 'Error:\nThe video cannot be displayed.';
		return false;
	}

	if(!this.player.ratio){
	  this.player.ratio = 3/4;
	  if(this.info.aspectRatio == 'widescreen'){
	    this.player.ratio = 9/16;
	  }
	  if(this.player.width)this.player.height = Math.round(this.player.width*this.player.ratio);
	  else if(this.player.height) this.player.width = Math.round(this.player.height/this.player.ratio);
	  else{
		 this.player.width = 640;
		 this.player.height = 480;
	  }
	}
	this.cr_container();
	
	this.cr_controls();
	this.onready();
};
//cr_container creates the containing div and the embed object
YT_Inr.prototype.cr_container = function(){
	//create the div
	this.container = document.createElement('div');
	this.container.style.height = this.player.height+'px';
	this.container.style.width = this.player.width+'px';
//	this.contianer.style.position = 'relative';
	this.container.id = this.player_id+'_cont';
	this.parent.appendChild(this.container);
	this.container.className = 'youtube_player_container '+this.color;
	
	this.container.innerHTML = '<a id="'+this.player_id+'_replace" href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player"></a>';
	

	//create flash object
	//*
	swfobject.embedSWF(this.ytaddress, this.player_id+'_replace', this.player.width, this.player.height,
			'8', false,
			{video_id:this.video_id,player_id:this.player_id},
			{bgcolor:'#FFFFFF',wmode:'transparent',allowscriptaccess:'always',allowfullscreen:'true',flashvars:this.flashvars},
	        {id:this.flash_id}
	);//*/	
	//this.flashplayer = this.container.childNodes[0];
    if(this.cover.active){
    	this.coverDiv = document.createElement('div');
    	this.coverDiv.style.height = this.cover.height+'px';
    	this.coverDiv.style.width = '100%';
    	this.coverDiv.className = 'YT_cover_div '+this.cover.classname;
    	this.container.appendChild(this.coverDiv);
    	if(typeof(this.cover.topPadding)=='undefined' || this.cover.topPadding){
    		this.container.style.paddingTop = this.cover.height + 'px';
        	this.offset_controls = this.cover.height;
    	}
    	this.coverDiv.style.position = 'absolute';
    	this.coverDiv.style.bottom = '0';
    	this.coverDiv.style.left = '0';
    	this.coverDiv.innerHTML = '<spa'+'n class="videoTitle">'+this.cover.title+'<'+'/sp'+'an>';
    }
	
	this.controlsCont = document.createElement('div');
	this.controlsCont.className = 'controlsCont';
	this.controlsCont.style.height = this.player.height+'px';
	if(this.cover.active && (typeof(this.cover.topPadding)=='undefined' || this.cover.topPadding)){
		this.controlsCont.style.height = (this.player.height+this.cover.height)+'px';
	}
	this.controlsCont.style.width = this.player.width+'px';
	this.container.appendChild(this.controlsCont);
	this.controlsCont.style.position = 'absolute';
	this.controlsCont.style.top = '0';
	this.controlsCont.style.left = '0';
	this.controlsCont.parentClass = this;
	this.controlsCont.onmouseover = flash_player_collection[this.flash_id].hoveritall;
	this.controlsCont.onmouseout = flash_player_collection[this.flash_id].unhoveritall;
	
	//debug stuff
	this.showdebug = false;
		this.debug = document.createElement('div');
		this.debug.style.position = 'absolute';
		this.debug.style.top = 0;
		this.debug.style.right = 0;
		this.debug.style.width = '300px';
		this.debug.style.backgroundColor = '#ffffff';
		this.debug.style.minHeight = '100px';
		this.debug.style.maxHeight = '600px';
		this.debug.style.overflow = 'scroll';	
		this.debug.style.color = '#999999';
	if(this.showdebug){
		document.body.appendChild(this.debug);
	}
};
//add control interface
YT_Inr.prototype.cr_controls = function(){
	me = this;
	//play button?
	if(this.player_cover){
		this.videoButton = document.createElement('div');
		this.videoButton.className = 'videoButton';
		this.videoButton.onclick = flash_player_collection[this.flash_id].playpause;
		this.videoButton.style.width = (this.player.width)+'px';
		this.videoButton.style.height = (this.player.height-13)+'px';
		this.videoButton.parentClass = this;
		if(this.cover.active){
			this.videoButton.style.height = (this.player.height-13+this.cover.height)+'px';
		}
		this.controlsCont.appendChild(this.videoButton);
	}
	if(this.play_btn){
	  //create play button control.
	  this.play_btn = document.createElement('div');
	  this.play_btn.className = 'controlDiv play';
	  //add the play button to the container
	  this.controlsCont.appendChild(this.play_btn);
	  this.play_btn.onclick= flash_player_collection[this.flash_id].playpause;
	  this.play_btn.parentClass = this;
	  //alert(this.center_btn.height + ' and '+this.offset_controls);
	  //this.play_btn.style.marginTop = ((this.center_btn.height*.5*-1)-(this.offset_controls))+'px';
	  this.play_btn.style.marginTop = ((this.center_btn.height*.5*-1)+(this.offset_controls*.5))+'px';
	  this.play_btn.style.marginLeft = (this.center_btn.width*.5*-1)+'px';
	  this.play_btn.style.width = this.center_btn.width+'px';
	  this.play_btn.style.height = this.center_btn.height+'px';
	  this.play_btn.playImage = document.createElement('img');
	  this.play_btn.playImage.src = this.center_btn.playImg;
	  this.play_btn.playImage.width = this.center_btn.width;
	  this.play_btn.playImage.height = this.center_btn.height;
	  this.play_btn.playImage.alt = this.center_btn.playAlt;
	  this.play_btn.replayImage = document.createElement('img');
	  this.play_btn.replayImage.src = this.center_btn.replayImg;
	  this.play_btn.replayImage.width = this.center_btn.width;
	  this.play_btn.replayImage.height = this.center_btn.height;
	  this.play_btn.replayImage.alt = this.center_btn.replayAlt;
      this.play_btn.appendChild(this.play_btn.replayImage);
	}
	
	//volume slider
	if(this.volume_control){
		this.volume_button = document.createElement('div');
		this.volume_button.className = 'volumeButton';
		this.controlsCont.appendChild(this.volume_button);
		this.volume_button.onclick = flash_player_collection[this.flash_id].toggleVolumeShow;
		this.volume_button.parentClass = this;
		
		this.show_volume_control = false;
		this.volume_controller = document.createElement('div');
		this.volume_controller.className = 'volumeBar';
		this.controlsCont.appendChild(this.volume_controller);
		this.volume_level = document.createElement('div');
		this.volume_level.className = 'volume_level';
		this.volume_level.style.height = '100%';
		this.volume_controller.appendChild(this.volume_level);
		//this.volume_controller['onmousedown'] = flash_player_collection[this.flash_id].slideVolume;
		//this.volume_controller['onmousemove'] = flash_player_collection[this.flash_id].changeVolume;
		this.volume_controller['onclick'] = flash_player_collection[this.flash_id].clickVolume;
		//this.volume_controller['onmouseup'] = flash_player_collection[this.flash_id].stopSlideVolume;
		this.volume_controller.parentClass = this;
		//this.volume_controller.style.display = 'none';
	}
	
	if(this.popup && typeof(this.popup.insert_overlay)!='undefined'){
		this.close = document.createElement('div');
		this.close.className = 'yt_close_btn';
		this.controlsCont.appendChild(this.close);
		this.close['onclick'] = this.popup.hide_element;
	}
	if(this.playPauseControl){
		this.playPauseController = document.createElement('div');
		this.playPauseController.className = 'playPauseControl';
		this.controlsCont.appendChild(this.playPauseController);
		this.playPauseController.parentClass = this;
		this.playPauseController.onclick = flash_player_collection[this.flash_id].playpause;
	}
	
	//progress bar?
	if(this.progress_bar){
	  //create progress bar
	  this.progress_bar = document.createElement('div');
	  this.progress_bar.className = 'progressBar';
	  //add progress bar to the container
	  this.controlsCont.appendChild(this.progress_bar);
	  //create elapsed bar
	  this.elapsed_time = document.createElement('div');
	  this.elapsed_time.className = 'elapsed';
	  this.progress_bar.appendChild(this.elapsed_time);
	  //addEvent(this.progress_bar,'click',flash_player_collection[this.flash_id].changeTime,false);
	  this.progress_bar['onmousedown'] = flash_player_collection[this.flash_id].slideTime;
	  this.progress_bar['onmousemove'] = flash_player_collection[this.flash_id].changeTime;
	  this.progress_bar['onclick'] = flash_player_collection[this.flash_id].clickTime;
	  this.progress_bar['onmouseup'] = flash_player_collection[this.flash_id].stopSlideTime;
	  this.progress_bar.parentClass = this;
	}
};

YT_Inr.prototype.hoveritall = function(e){
	if(this.parentClass.container.className.search('hover')==-1){
		this.parentClass.container.className += ' hover';
		//alert('over');
	}
}
YT_Inr.prototype.unhoveritall = function(e){
	if(this.parentClass.container.className.search('hover')>-1){
		this.parentClass.container.className = this.parentClass.container.className.replace(' hover','');
	}
}

YT_Inr.prototype.toggleVolumeShow = function(e){
	if(this.parentClass.show_volume_control){
		//this.parentClass.hideVolumeController();
		this.parentClass.show_volume_control = false;
		this.parentClass.container.className = this.parentClass.container.className.toString().replace(' adjustVol','');
	}else{
		this.parentClass.show_volume_control = true;
		//this.parentClass.volume_controller.style.display = '';
		this.parentClass.container.className = this.parentClass.container.className.toString() + ' adjustVol';
	}
}

YT_Inr.prototype.hideVolumeController = function(){
	this.volume_controller.style.display = 'none';
	this.show_volume_control = false;
}

YT_Inr.prototype.playpause = function(e){
	//alert(this.parentClass.flash_id);
	//this.parentClass.controlsCont.style.display = 'none';
	var that = this.parentClass;
	if(!this.parentClass.firstPlayed){
	  this.parentClass.swfobject.playVideo();
	  setTimeout(function(){
	    that.container.className += ' playing';
		that.container.className = trim(that.container.className);
		if(that.play_btn.className.toString().search('replay') >= 0){
			that.play_btn.className = that.play_btn.className.toString().replace('replay','pause');
		}else{
			that.play_btn.className = that.play_btn.className.toString().replace('play','pause');
		}
		that.firstPlayed = true;
	  },1000)
      window.clearInterval(that.timer);
	  that.timer = window.setInterval(function(){that.checkTime();},1000);
	}else if(this.parentClass.container.className.search('playing')>=0){
		this.parentClass.swfobject.pauseVideo();
		this.parentClass.container.className = this.parentClass.container.className.toString().replace('playing','paused');
		this.parentClass.container.className = trim(this.parentClass.container.className);
		this.parentClass.play_btn.className = this.parentClass.play_btn.className.toString().replace('pause','play');
		if(typeof(this.timer)!='undefined')
			window.clearInterval(this.timer);
	}else{
		if(this.parentClass.container.className.search('paused')>=0){
			this.parentClass.container.className = this.parentClass.container.className.toString().replace('paused','playing');
		}else{
			this.parentClass.container.className += ' playing';
		}
		this.parentClass.swfobject.playVideo();
		this.parentClass.container.className = trim(this.parentClass.container.className);
		if(this.parentClass.play_btn.className.toString().search('replay') >= 0){
			this.parentClass.play_btn.className = this.parentClass.play_btn.className.toString().replace('replay','pause');
		}else{
			this.parentClass.play_btn.className = this.parentClass.play_btn.className.toString().replace('play','pause');
		}
		me = this.parentClass;
		window.clearInterval(this.timer);
		this.parentClass.timer = window.setInterval(function(){me.checkTime();},1000);
	}
	return false;
};
YT_Inr.prototype.slideTime = function(e){
	  this.parentClass.time_sliding = true;
	  this.blur();
	  this.parentClass.elapsed_time.blur();
	  if(this.parentClass.showdebug)
		  this.parentClass.debug.innerHTML += this.className+"<br>";
};
YT_Inr.prototype.stopSlideTime = function(e){
	this.parentClass.time_sliding = false;
	this.parentClass.seekTime();
};
YT_Inr.prototype.clickTime = function(e){
	this.parentClass.changeTime(e);
	this.parentClass.seekTime();
}
YT_Inr.prototype.seekTime = function(){
	this.swfobject.seekTo(Math.round(this.info.duration*this.time_ratio),true);
	this.parentClass.swfobject.playVideo();
	if(this.container.className.toString().search('playing')<0){
		  if(this.play_btn.className.toString().search('replay') >= 0){
			this.play_btn.className = this.play_btn.className.toString().replace('replay','pause');
		  }else{
			this.play_btn.className = this.play_btn.className.toString().replace('play','pause');
		  }
		  if(this.container.className.toString().search('paused')<0){
			  this.container.className += ' playing';
		  }else{
		    this.container.className = this.container.className.toString().replace('paused','playing');
		  }
		  me = this;
		  window.clearInterval(this.timer);
		  this.timer = window.setInterval(function(){me.checkTime();},1000);
	  }
	  this.elapsed_time.focus();
	  this.elapsed_time.blur();
};
YT_Inr.prototype.changeTime = function(e){
	this.parentClass.elapsed_time.blur();
	//if(!e.pageX && e.clientX)
	if(!e)e = window.event;
	var X = e.clientX;
	//alert('e.pageX: '+e.pageX+' offset(this.parentClass.progress_bar).x: '+offset(this.parentClass.progress_bar).x+' this.parentClass.progress_bar.offsetWidth: '+this.parentClass.progress_bar.offsetWidth);
	//alert('(e.pageX - offset(this.parentClass.progress_bar).x): '+(e.pageX - offset(this.parentClass.progress_bar).x));
	this.parentClass.time_ratio = (X - offset(this.parentClass.progress_bar).x)/(this.parentClass.progress_bar.offsetWidth*1);
	//alert(ratio);
	if(this.parentClass.time_sliding){
	  if(this.parentClass.time_ratio!='Infinity'){
	    this.parentClass.elapsed_time.style.width = (this.parentClass.time_ratio*100)+'%';
	  }
	}
	return false;
};
YT_Inr.prototype.slideVolume = function(e){
	this.parentClass.volume_sliding = true;
	this.blur();
	if(this.parentClass.showdebug)
		  this.parentClass.debug.innerHTML = 'Vol: '+this.className +'<br>' + this.parentClass.debug.innerHTML;
};
YT_Inr.prototype.stopSlideVolume = function(e){
	this.parentClass.volume_sliding = false;
	if(this.parentClass.showdebug){
		this.parentClass.debug.innerHTML = 'sliding off: '+this.parentClass.volume_sliding+'<br>'+this.parentClass.debug.innerHTML;
	}
};
YT_Inr.prototype.clickVolume = function(e){
	this.parentClass.volume_sliding = true;
	this.parentClass.changeVolume(e);
	this.parentClass.volume_sliding = false;
	if(this.parentClass.showdebug){
		this.parentClass.debug.innerHTML = 'sliding off: '+this.parentClass.volume_sliding+'<br>'+this.parentClass.debug.innerHTML;
	}
};
YT_Inr.prototype.changeVolume = function(e){
	if(this.parentClass.showdebug){
	  this.parentClass.debug.innerHTML = 'Enter Slide Volume: '+this.parentClass.volume_sliding+'<br>' + this.parentClass.debug.innerHTML;
	}
	if(this.parentClass.volume_sliding){
	  var ie = (document.all && !window.opera && window.XMLHttpRequest) ? true : false;
	  if(!e)e = window.event;
	  if(ie){
        if(e.clientX){
		  var dbody = document.getElementsByTagName('body')[0]
		  //alert(dbody.scrollTop);
	      e.pageX = e.clientX+(dbody.scrollLeft *1);
	      e.pageY = e.clientY+(dbody.scrollTop *1);
	    }
	  }
	  var Y = e.pageY;
	  //alert('e.pageX: '+e.pageX+' offset(this.parentClass.progress_bar).x: '+offset(this.parentClass.progress_bar).x+' this.parentClass.progress_bar.offsetWidth: '+this.parentClass.progress_bar.offsetWidth);
	  //alert('(Y - offset(this.parentClass.volume_controller).y)/(this.parentClass.volume_controller.offsetHeight*1)-1)*-1: '+'('+Y+' - '+offset(this.parentClass.volume_controller).y+')/('+this.parentClass.volume_controller.offsetHeight+'*1)-1)*-1: '+(Y - offset(this.parentClass.volume_controller).y));
	  this.parentClass.volume_ratio = ((Y - offset(this.parentClass.volume_controller).y)/(this.parentClass.volume_controller.offsetHeight*1)-1)*-1;
	  if(this.parentClass.showdebug)
		  this.parentClass.debug.innerHTML = this.parentClass.volume_ratio+"<br>" + this.parentClass.debug.innerHTML;
	  //alert(this.parentClass.volume_ratio);
	  if(this.parentClass.volume_ratio!='Infinity'){
	    this.parentClass.volume_level.style.height = (this.parentClass.volume_ratio*100)+'%';
	    if(this.parentClass.showdebug)
			  this.parentClass.debug.innerHTML = Math.round(100*this.parentClass.volume_ratio)+"<br>" + this.parentClass.debug.innerHTML;
	    this.parentClass.swfobject.setVolume(Math.round(100*this.parentClass.volume_ratio));
 	  }
	}
	return false;
};
YT_Inr.prototype.onready = function(){
	this.swfobject = document.getElementById(this.flash_id);
	//this.swfobject.addEventListener('onStateChange','currentState');
	//addEvent(this.swfobject,'onStateChange',this.testState,false);
	if(this.oncompletefunc){
	  this.oncompletefunc();
	}
};
YT_Inr.prototype.checkTime = function(){
	if(this){
		if(this.swfobject){
			if(typeof(this.swfobject.getPlayerState)!='function'){
				window.clearInterval(this.timer);
				return false;
			}
			if(this.swfobject.getPlayerState()==0){//stopped
				var current_class = this.play_btn.className+'';
				if(current_class.search('play')>=0 && current_class.search('replay')<0){
					this.play_btn.className = current_class.replace('play','replay');
				}else{
					this.play_btn.className = current_class.replace('pause', 'replay');
				}
				window.clearInterval(this.timer);
				this.container.className = this.container.className.toString().replace('playing',' ');
				this.container.className = trim(this.container.className);
				this.elapsed_time.style.width = '0%';
			}else{
				var current = this.swfobject.getCurrentTime();
				var ratio = current/this.info.duration;
				this.elapsed_time.style.width = (ratio*100)+'%';
			}
		}
    }
	
};

YT_Inr.prototype.setReplay = function (){
	if(this.play_btn.className.toString().search('play')>=0){
		this.play_btn.className = this.play_btn.className.toString().replace('play', 'replay');
	}else{
		this.play_btn.className = this.play_btn.className.toString().replace('pause', 'replay');
	}
};

YT_Inr.prototype.show = function(func){
    if(func)this.oncompletefunc = func
	this.init();
};
function onYouTubePlayerReady(){
}
