var ypwidth = 435;
var ypheight = 360;

function youpreview(movie,tid) {
    var youpreview = document.getElementById("youpreview");
    if(tid!=0) var youdescr = document.getElementById("yp_descr_"+movie+"_"+tid).innerHTML;
    else var youdescr = '&nbsp;';
    var pageSize = getPageSize();
    var pageScroll = getPageScroll();
    
    var ypOverlay = document.getElementById("youpreview_overlay"); 
    ypOverlay.style.height = (pageSize[1] + 'px');
	ypOverlay.style.display = 'block';
    if(document.all) ypOverlay.style.top = pageScroll[1]+'px';
    
    var yptop = Math.floor((pageSize[3]/2)-(ypheight/2))+pageScroll[1];
    var ypleft = Math.floor((pageSize[2]/2)-(ypwidth/2));
    
    youpreview.style.top      =  yptop+"px";
    youpreview.style.left     =  ypleft+"px";
    youpreview.style.width     =  ypwidth+"px";
    youpreview.style.height     =  ypheight+"px";
    
    document.getElementById("youpreview_box").innerHTML = '<object width="425" height="350"><param name="movie" value="http://www.youtube.com/v/'+movie+'"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/'+movie+'" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed></object>';
    document.getElementById("youpreview_descr").innerHTML = youdescr;
    youpreview.style.display  =  "block";
    
    return false;
}

function yp_close() {
    var youpreview = document.getElementById("youpreview");
    var ypOverlay = document.getElementById("youpreview_overlay");
    
    youpreview.style.display='none';
    ypOverlay.style.display='none';
}

//
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
// Originaly from Lightbox Wordpress Plugin - http://huddletogether.com/projects/lightbox/
//
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;
}

// 
// Returns array with x,y page scroll values.
// Core code from - quirksmode.org
// Originaly from Lightbox Wordpress Plugin - http://huddletogether.com/projects/lightbox/
//
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;
}


function ypcheckscroll() {
    var youpreview = document.getElementById("youpreview");
    var ypOverlay = document.getElementById("youpreview_overlay");
    if(youpreview.style.display=='block') {
        var pageSize = getPageSize();
        var pageScroll = getPageScroll();

        var yptop = Math.floor((pageSize[3]/2)-(ypheight/2))+pageScroll[1];
        youpreview.style.top = yptop+'px';
        if(document.all) ypOverlay.style.top = pageScroll[1]+'px';
    }
}

var oldscroll = window.onscroll;
if (typeof window.onscroll != 'function'){
	window.onscroll = ypcheckscroll;
} else {
    window.onscroll = function(){
        oldscroll();
        ypcheckscroll();
    }
}
