var MPlog = Class.create({
	initialize: function() {
		//this.plOb = this.startit.bindAsEventListener(this);
		//$$('.ytPrev').invoke('observe','click', this.plOb);
		$$('.ytPrev').invoke('observe','click', (function(event) { this.startit(event); }).bind(this));
		
        var objBody = $$('body')[0];
		objBody.appendChild(new Element('div', {'id': 'mixLogin'}));
		var div1 = new Element('div', { 'id': 'boxShadow' });
		var div2 = new Element('div', { 'id': 'boxContent' });


		var div2one = new Element('div', { 'class': 'srch-tut' });
		var div2title = new Element('span', { 'class': '' }).update("Preview");
		div2title.setStyle({ fontWeight: 'bold'});
		var div2link = new Element('a', { 'id': 'lbclose', 'href': '#' }).update("close [x]");
		div2link.setStyle({ float: 'right'});
		
		var divYT = new Element('div', { 'id': 'boxYT' });
		divYT.setStyle({ clear: 'both'});
		



		
		div2.appendChild(div2one);
		div2one.appendChild(div2link);
		div2one.appendChild(div2title);
		
		div2.appendChild(divYT);

		
		
		div1.appendChild(div2);
		objBody.appendChild(div1);
		
		$('mixLogin').hide();
		$('boxShadow').hide();
		
		//observer
		$('lbclose').observe('click', (function(event) { event.stop(); this.end(); }).bindAsEventListener(this));	
	
	},
	
	startit: function(e) {
		var ts = Event.element(e).identify();
		$$('select', 'object', 'embed').each(function(node){ node.style.visibility = 'hidden' });

	
		var arrayPageSize = this.getPageSize();

        var arrayPageScroll = document.viewport.getScrollOffsets();
        var lightboxTop = arrayPageScroll[1] + (document.viewport.getHeight() / 10);
        var lightboxLeft = arrayPageScroll[0];
		$('mixLogin').setStyle({ width: arrayPageSize[0] + 'px', height: arrayPageSize[1] + 'px', opacity: 0 }).show();
      $('boxShadow').setStyle({ top: lightboxTop + 'px', left: lightboxLeft + 'px' });


	  
	  
	 // $('boxContent').innerHTML = '<div class="srch-tut" style="text-align:left;margin:0px;padding:5px;"><a href="#" onclick="newLogBox.end();" style="float:right">close</a><b>Log In</b></div>';
	 //$('boxContent').innerHTML  += '<div id="noticer" class="noticer" style="display:none;">testing</div>';
	// $('boxContent').innerHTML  += '<div style="padding:10px 0 0 6px;"> Email:<br><input id="lbemail" type="text" size="42" class="login_txtbox" style="width:300px;" /></div><br>';
	// $('boxContent').innerHTML  += '<div style="padding:0 0 0 6px;"> Password:<br><input id="lbpw" type="password" size="42" class="login_txtbox" style="width:300px;" /><br> <br><input id="logformsub" type="submit" class="black-search" value="Log In" alt="search" style="font-weight:bold;" /><br><br>Not a member? <a href="#">Click here</a> to sign up!<br></div>';
	  
	  
	  
		//Event.observe('logformsub', 'click', this.checkForm);

	  
	  // new Effect.Appear('mixLogin', { duration: .5, from: 0.0, to: .5 });
	 
	  
	  
	   new Effect.Appear('boxShadow', { duration: .4, from: 0.0, to: 1, afterFinish: (function(){$('boxYT').innerHTML = ' <object width="420" height="300"><param name="movie" value="http://www.youtube.com/v/'+ts+'&hl=en&fs=1&autoplay=1"></param><param name="allowFullScreen" value="true"></param><embed src="http://www.youtube.com/v/'+ts+'&hl=en&fs=1&autoplay=1" type="application/x-shockwave-flash" allowfullscreen="true" width="420" height="300"></embed></object>';}) });	
	},
	
	end: function () {
		$('boxYT').innerHTML = '';
		$('mixLogin').hide();
        new Effect.Fade('boxShadow', { duration: .4, afterFinish: (function(){ $$('select', 'object', 'embed').each(function(node){ node.style.visibility = 'visible' }); }) });
		
	 },


    getPageSize: function() {
	        
	     var xScroll, yScroll;
		
		if (window.innerHeight && window.scrollMaxY) {	
			xScroll = window.innerWidth + window.scrollMaxX;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
		
		var windowWidth, windowHeight;
		
		if (self.innerHeight) {	// all except Explorer
			if(document.documentElement.clientWidth){
				windowWidth = document.documentElement.clientWidth; 
			} else {
				windowWidth = self.innerWidth;
			}
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { // other Explorers
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}	
		
		// for small pages with total height less then height of the viewport
		if(yScroll < windowHeight){
			pageHeight = windowHeight;
		} else { 
			pageHeight = yScroll;
		}
	
		// for small pages with total width less then width of the viewport
		if(xScroll < windowWidth){	
			pageWidth = xScroll;		
		} else {
			pageWidth = windowWidth;
		}

		return [pageWidth,pageHeight];
	}

});

document.observe("dom:loaded", function() {
	 var newLogBox = new MPlog();
});