//if(typeof Effect == 'undefined')
 // throw("lightwindow.js requires including script.aculo.us' effects.js library!");
   
var YoutubeChromeless = Class.create();

YoutubeChromeless.prototype = {
	
  initialize: function(options) {
  	
  	this.ytplayer = null;
  	
  	this.options = Object.extend({
  		divID: options.divID,
  		videoID: options.videoID,
  		apikey: options.apikey,
  		width: options.width,
  		height: options.height,
  		videoName: options.videoName,
	  	youtubeParams: { 
	  		allowScriptAccess: "always", 
	  		bgcolor: "#cccccc", 
	  		wmode: "transparent"
	  	},
	  	atts: { 
	  		id: options.divID + '_video'
	  	},
	  	skin: '<div class="controls">' +
							'<h5>' + options.videoName + '</h5>' +
							'<ul>' +
								'<li><a href="javascript:void(0)" class="play"><img src="ozexperience/images/play.png" alt="Play" /></a></li>' +
								'<li><a href="javascript:void(0)" class="pause"><img src="ozexperience/images/pause.png" alt="Pause" /></a></li>' +
								'<li><a href="javascript:void(0)" class="replay"><img src="ozexperience/images/replay.png" alt="Replay" /></a></li>' +
							'</ul>' +
							'<a href="javascript:void(0)" class="playButton"></a>' +
						'</div>' +
						'<div class="controls-bg"></div>' +
						'<div class="video">' +
							'<div id="ytapiplayer">' +
								'You need Flash player 8+ and JavaScript enabled to view this video.' +
							'</div>' +
						'</div>' +
						'<div class="overlay"></div>'
  	});
  	
  	$(this.options.divID).update(this.options.skin);
  	
  	swfobject.embedSWF("http://www.youtube.com/apiplayer?key=" + this.options.apikey + "&enablejsapi=1&playerapiid=ytplayer", 
                         "ytapiplayer", this.options.width, this.options.height, "8", null, null, this.options.youtubeParams, this.options.atts);
		
    swfobject.addDomLoadEvent(this.SWFObjectReady.bind(this));
    
    $(this.options.divID).down('.play').observe('click', function(event) { 
    	this.ytplayer.playVideo();
    	return false;
    }.bind(this));
    $(this.options.divID).down('.playButton').observe('click', function(event) { 
    	this.ytplayer.playVideo();
    	return false;
    }.bind(this));
    $(this.options.divID).down('.pause').observe('click', function(event) { 
    	this.ytplayer.pauseVideo();
    	return false;
    }.bind(this));
    $(this.options.divID).down('.replay').observe('click', function(event) { 
    	this.ytplayer.seekTo(0);
    	this.ytplayer.playVideo();
    	return false;
    }.bind(this));

  },
  
  SWFObjectReady: function() {
  	this.ytplayer = ytplayer = $(this.options.atts.id);
  	me = this;
  	setTimeout("me.YTPlayerReady()",1000);
  },
  
  // Run this method every second until player is ready to cue
  YTPlayerReady: function() {
  	if (typeof ytplayer.cueVideoById == "function") {
  		ytplayer.cueVideoById(this.options.videoID, 0);
  	} else {
  		me = this;
  		setTimeout("me.YTPlayerReady()",1000);
  	}
  }
}