// -----------------------------------------------------------------------------------

//
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.org
//
function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}

// -----------------------------------------------------------------------------------

//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		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
		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 = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

// -----------------------------------------------------------------------------------

	function endyt() {

		
		//new Effect.Fade('overlayPlayBox', { duration: 0.1});
		//new Effect.Fade('overlay', { duration: 0.2});
		$('mp3player').style.visibility = 'visible';
		Element.remove('overlayPlayBox');
		Element.remove('overlay');
		

	}



function showytp(tid, title, time){
	
		title = decodeURIComponent(title);
		title = title.replace(/\+/g,' ');
	
		var objBody = document.getElementsByTagName("body").item(0);
		
		var objOverlay = document.createElement("div");
		objOverlay.setAttribute('id','overlay');
		objOverlay.style.display = 'none';


		var playBox = document.createElement("div");
		playBox.setAttribute('id','overlayPlayBox');
		playBox.style.display = 'none';
		
		var playBoxTop = document.createElement("div");
		playBoxTop.className = 'topz';
		var playBoxTopTxt = document.createTextNode(decodeURIComponent(title));
		
		var playBoxTitle = document.createElement("div");
		playBoxTitle.className = 'playtitle';

		var playBoxClose = document.createElement("div");
		playBoxClose.className = 'playclose';
		
		var playBoxLink = document.createElement("a");
		playBoxLink.setAttribute('href', '#' );
		playBoxLink.onclick = function(){
			endyt();return false;
		}
		
	
		var playBoxCloseTxt = document.createTextNode("close");
		
		playBoxLink.appendChild(playBoxCloseTxt);
		
		var playBoxHolder = document.createElement("div");
		playBoxHolder.setAttribute('id','playBoxHolder');
		playBoxHolder.style.margin = '5px';
		playBoxHolder.style.clear = 'left';
		playBoxHolder.style.zIndex = '20';
		
		var playButtonHolder = document.createElement("div");
		playButtonHolder.setAttribute('id','playButtonHolder');

		var br = document.createElement("br");
		br.style.clear = 'left';
		var br2 = document.createElement("br");


		
		playBox.appendChild(playBoxTop);
		playBoxTop.appendChild(playBoxTitle);
		playBoxTitle.appendChild(playBoxTopTxt);
		playBoxTop.appendChild(playBoxClose);
		playBoxClose.appendChild(playBoxLink);
		playBoxTop.appendChild(br);
		playBox.appendChild(playBoxHolder);


/*
			var viewpllink = document.createElement("a");
			viewpllink.className = 'pllink';
			viewpllink.style.backgroundColor = '#F0723A';
			viewpllink.style.color = '#FFFFFF';
			viewpllink.setAttribute('href', '#');	
			viewpllink.onclick = function(){
				//endyt();
				//addV(tid, tid, title, time);
				
				//return false;
			}
			var viewpllinkTxt = document.createTextNode("Add To Playlist");
			
			viewpllink.appendChild(viewpllinkTxt);
			//playBox.appendChild(br);
			playBox.appendChild(viewpllink);
*/

		// calculate top offset for the lightbox and display 
		var arrayPageSize = getPageSize();

		objOverlay.style.height = arrayPageSize[1]+"px";
		objOverlay.onclick = function() { end(); return false; }
		objBody.appendChild(objOverlay);
		objBody.appendChild(playBox);


		
		new Effect.Appear('overlay', { duration: 0.2, from: 0.0, to: 0.3, afterFinish: function(){	apPlayer(tid, title);/*alert("done");*/ } });
}



function apPlayer(tid, title) {

		$('mp3player').style.visibility = 'hidden';
		
		//var height2 = parseInt(height)+60;
		$('overlayPlayBox').style.height = '340px';
		//var width2 = parseInt(width)+70;
		//$('overlayPlayBox').style.width = width2+'px';
		
					var so = new SWFObject("http://assets.myflashfetish.com/swf/video/mff-cntrls.swf?singleYT="+tid+"&singleYTitle="+title, "sotester", "390", "270", "8", "#FFFFFF");
					//so.addVariable("myid", myid);
					//so.addParam("wmode", "transparent");
					so.write("playBoxHolder");
					
					

		// calculate top and left offset for the lightbox 
		var arrayPageSize = getPageSize();
		var arrayPageScroll = getPageScroll();
		var lightboxTop = arrayPageScroll[1] + (arrayPageSize[3] / 10);
		var lightboxLeft = arrayPageScroll[0];
		$('overlayPlayBox').style.top = lightboxTop+'px';
		//$('overlayPlayBox').style.left = lightboxLeft+'px';
		


	new Effect.Appear('overlayPlayBox', { duration: 0.2, from: 0, to: 100 });
}