var patLayer = 'off';
function getScrollY() {
	if(document.body && document.body.scrollTop) return document.body.scrollTop; //DOM compliant
	if(typeof(window.pageYOffset ) == 'number' ) return window.pageYOffset; //Netscape compliant
	if(document.documentElement && document.documentElement.scrollTop) return document.documentElement.scrollTop;
	return 0;
}
function getWindowWidth() {
  var myWidth = 0;
  if(typeof(window.innerWidth)=='number') return window.innerWidth; //Non-IE
  if(document.documentElement&&document.documentElement.clientWidth) return document.documentElement.clientWidth; //IE 6+ in 'standards compliant mode'
  if(document.body&&document.body.clientWidth) return document.body.clientWidth; //IE 4 compatible
  return 800;
}
function getWindowHeight() {
  var myHeight = 0;
  if(typeof(window.innerHeight)=='number') return window.innerHeight; //Non-IE
  if(document.documentElement&&document.documentElement.clientHeight) return document.documentElement.clientHeight; //IE 6+ in 'standards compliant mode'
  if(document.body&&document.body.clientHeight) return document.body.clientHeight; //IE 4 compatible
  return 800;
}
function WriteLayer(ID,txt) {
	if (document.layers) {
		var o;
		o = document.layers[ID].document;
		o.open(); o.write(txt); o.close();
	} else if (parseInt(navigator.appVersion)>=5&&navigator.appName=="Netscape") {
		document.getElementById(ID).innerHTML = txt;
	} else if (document.all) {
		document.all[ID].innerHTML = txt;
	} else {
		document.getElementById(ID).innerHTML = txt;
	}
}

function HideLayer(ID) {
	if (document.getElementById) {
		document.getElementById(ID).style.visibility = "hidden";
	} else if (document.all) {
		document.all[id].style.visibility = "hidden";
	} else if (document.layers) {
		document.layers[ID].visibility = "hidden";
	}
		
}

function ShowLayer(ID) {
	if (document.getElementById) { // this is the way the standards work
		document.getElementById(ID).style.visibility = "visible";
	} else if (document.all) { // this is the way old msie versions work
		document.all[id].style.visibility = "visible";
	} else if (document.layers) { // this is the way nn4 works
		document.layers[ID].visibility = "visible";
	}
}

function patience_on() {
	patLayer = 'on';
	if(document.all) p = document.all.patience.style;
	else p = document.getElementById('patience').style;
	p.top = parseInt(getScrollY())+'px';
	if(document.all) p.width = (parseInt(getWindowWidth())-2)+'px';
	else p.width = (parseInt(getWindowWidth())-17)+'px';
	p.height = (parseInt(getWindowHeight())-1)+'px';
	ShowLayer('patience');
}

function patience_off() {
	patLayer = 'off';
	if(document.all) p = document.all.patience.style;
	else p = document.getElementById('patience').style;
	HideLayer('patience');
	p.top = p.width = p.height = '32px';
}

function hidepic() {
	tbl = document.getElementById("previewtable");
	tbl.style.width = tbl.style.height = '0px';
	HideLayer('preview');
	patience_off();
}

function showpic(name,w,h,desc) {
	var picImg = new Image();
	patience_on();
	i = document.getElementById("previewimage");
	p = document.getElementById('patience');
	pane = document.getElementById("preview");
	picImg.onload = function() {
			i.src = 'http://www.pornotribune.com'+name;
			i.style.width = w+'px';
			i.style.height = h+'px';
			WriteLayer('previewdesc','<span id="caption">'+desc+'</span>');
	}
	picImg.src = 'http://www.pornotribune.com'+name;
	i.style.width = i.style.height = '32px';
	i.src = 'http://images.pornotribune.com/i/lightbox/images/loading.gif';
	pheight = parseInt(getScrollY())+100+h;
	if(parseInt(p.style.height)<pheight) p.style.height = pheight+'px';
	pane.style.top = (parseInt(getScrollY())+20)+'px';
	pane.style.left = Math.round(getWindowWidth()/2-w/2-10)+'px';
	tbl = document.getElementById("previewtable");
	tbl.style.width = (w+12)+'px';
	tbl.style.height = (h+32)+'px';
	WriteLayer('previewdesc','');
	ShowLayer('preview');
	if(document.all) { // For MSIE
		if(picImg.readyState=='complete') picImg.onload();
	}
	return false;
}

function sendRequest(url,callback,postData) {
	var req = createXMLHTTPObject();
	if (!req) return;
	var method = (postData) ? "POST" : "GET";
	req.open(method,url,true);
	req.setRequestHeader('User-Agent','XMLHTTP/1.0');
	if (postData)
		req.setRequestHeader('Content-type','application/x-www-form-urlencoded');
	req.onreadystatechange = function () {
		if (req.readyState != 4) return;
		if (req.status != 200 && req.status != 304) { // HTTP Error
			return;
		}
		callback(req);
	}
	if (req.readyState == 4) return;
	req.send(postData);
}
var XMLHttpFactories = [
	function () {return new XMLHttpRequest()},
	function () {return new ActiveXObject("Msxml2.XMLHTTP")},
	function () {return new ActiveXObject("Msxml3.XMLHTTP")},
	function () {return new ActiveXObject("Microsoft.XMLHTTP")}
];

function createXMLHTTPObject() {
	var xmlhttp = false;
	for (var i=0;i<XMLHttpFactories.length;i++) {
		try { xmlhttp = XMLHttpFactories[i](); }
		catch (e) { continue; }
		break;
	}
	return xmlhttp;
}

window.onscroll = function (e) {
  if(patLayer == 'on') {
		if(document.all) p = document.all.patience.style;
		else p = document.getElementById('patience').style;
			p.top = parseInt(getScrollY())+'px';
			if(document.all) p.width = (parseInt(getWindowWidth())-2)+'px';
			p.width = (parseInt(getWindowWidth())-17)+'px';
			p.height = (parseInt(getWindowHeight())-1)+'px';
  }
}
