var LightBox = Class.create();
LightBox.prototype = {

rsid: '',
isOpen: false,
//
// Constructor
initialize: function(rsid)
	{
		this.rsid = rsid;
		
		this.cb = Builder.node("div", {id:'LBclose'});
		this.bg = Builder.node("div", {id:'LBb', style:'display:none'});
		this.lb = Builder.node("div", {id:'LB', style:'display:none'},
							   						[
														Builder.node("div", {id:'LBcont'},
																	 				[
																					 	Builder.node("div", {id:'LBtitle'},
																									 		[
																											 	this.cb,
																												Builder.node("div", {id:'LBtitletext'})
																											]
																									 ),
																					 	Builder.node("div", {id:'LBscont'})																						
																					]
																	 )
													]
							   );

		
		
		
		if ($(rsid))
		{					
			// Append to main surface
			$(rsid).appendChild(this.bg);
			$(rsid).appendChild(this.lb);
			
			$('LBb').style.height = $(rsid).clientHeight + "px";			
			
			$('LB').style.marginTop = (($('LB').clientHeight - $('LBscont').offsetHeight)/2) + "px";
		}
		
		
		mSpaceApplication.Subscribe("LightBox.Show", this);
		
		mSpaceApplication.Subscribe("LightBox.ShowImage", this);
		
		mSpaceApplication.Subscribe("LightBox.Hide", this);
	
		RegisterEvent(this.cb, "click", this, "Close", true);
	
	},
	
Notify: function(eventName, eventParams)
	{
		switch(eventName)
		{
			case 'LightBox.ShowImage' : this.OpenImage(eventParams); break;
			case 'LightBox.Show' : this.Open(eventParams); break;	
			case 'LightBox.Hide' : this.Close(eventParams); break;	
			default: break;
		}
	},		

Open: function(params)
	{
		
		mSpaceApplication.FireEvent("VideoPlayer.Hide");
		
		this.isOpen = true;
		$('LBb').style.height = $(this.rsid).clientHeight + "px";
		$('LBb').style.width = $(this.rsid).clientWidth + "px";
		
		$('LBtitletext').update(params.title);
		
		$('LBscont').update();
		$('LBscont').appendChild(params.childNode);
		$('LBscont').style.height = "";
		
		  var scrOfY = 0;
		  if( typeof( window.pageYOffset ) == 'number' ) {
			//Netscape compliant
			scrOfY = window.pageYOffset;
		  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
			//DOM compliant
			scrOfY = document.body.scrollTop;
		  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
			//IE6 standards compliant mode
			scrOfY = document.documentElement.scrollTop;
		  }			
		  
		  
	  var myWidth = 0, myHeight = 0;
	  if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	  }	
		
		Effect.Appear('LBb', 
					  	{
							duration: 0.6,
							from: 0,
							to: 0.75,
							afterFinish: function()
										{
											$('LB').setStyle({top: "-2000px"});
											$('LB').style.display ="";
											var t = (scrOfY +((myHeight - $('LBcont').offsetHeight)/2));
											var l = (myWidth - $('LBcont').offsetWidth)/2;
											$('LB').style.display ="none";
											$('LB').setStyle({top: t + "px", left: l + "px"});
											new Effect.Unfold('LB');
											//Effect.BlindDown('LB',{scaleFromCenter: true, duration: 1.5, scaleContent:false});										
										}
						}
					  );
		
		
		

		
		
		
	
	},
	
OpenImage: function(params)
	{
		params.childNode = Builder.node('div', {style:'height:400px'} ,'Loading Image');
		this.Open(params);
		
		var imageUrl = params.url;	
		
		var imgElt = new Image();
		var thisObj = this;
		imgElt.onload = function() { thisObj.ImageOnLoad(imgElt); }
		imgElt.src = imageUrl;
		
	},
	
ImageOnLoad: function(imgObj)
	{
		$('LBscont').innerHTML = "";
		$('LBscont').appendChild(imgObj);			
		$('LBscont').setStyle({height:imgObj.height + 'px'});
		$('LB').style.marginTop = (window.scrollY +((window.innerHeight - $('LB').clientHeight - $('LBscont').offsetHeight)/2)) + "px";
		
	},

Close: function()
	 {
		 if (this.isOpen)
		 {
			 
			 mSpaceApplication.FireEvent("VideoPlayer.Show");
			 
			 this.isOpen = false;
		 	Effect.Fade('LBb',{duration: 0.5, from: 0.75, to: 0});
		 	Effect.Fade('LB',{duration: 0.5});
		 }
	 }

}
