// Poop-up DIV for IRCPics.com, Copyright IRCPics.com ++S 2007/10/02

//const td_flashWindowMode = "transparent";
var databox;

function showbox(id) {
	loaded = 0;
//	obj = document.getElementById('advert');
//	obj.style.visibility = 'hidden';
	obj = document.getElementById('PIC');
	obj.style.overflow = "hidden";
	databox = obj;
	loadXMLDoc('/show.php?id='+id);
	obj.style.visibility = 'visible';
}

function rate(id,rate) {
	databox = document.getElementById('rating');
	loadXMLDoc('/rate.php?id='+id+'&rate='+rate);
}

function closebox() {
	obj = document.getElementById('PIC');
	obj.style.overflow = 'hidden';
	obj.style.visibility = 'hidden';
	obj = document.getElementById('ipic');
	obj.style.visibility = 'hidden';
	obj.width = 1;
	obj.height = 1;
	obj = document.getElementById('picsize');
	//obj.style.display = 'none';
	obj.style.visibility = 'hidden';
	obj.style.backgroundColor = '';
	obj.innerHTML = '';
	loaded = 0;
//	obj = document.getElementById('advert');
//	obj.style.visibility = 'visible';
}

var xmlhttp;

function loadXMLDoc(url) {
	xmlhttp=null;
	// code for Mozilla, etc.
	if (window.XMLHttpRequest) {
		xmlhttp=new XMLHttpRequest();
	}
	// code for IE
	else if (window.ActiveXObject) {
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (xmlhttp!=null) {
		xmlhttp.onreadystatechange=state_Change;
		xmlhttp.open("GET",url,true);
		xmlhttp.send(null);
	}
	else {
		alert("Your browser does not support XMLHTTP.");
	}
}

function state_Change() {
	// if xmlhttp shows "loaded"
	if (xmlhttp.readyState==4) {
		// if "OK"
		if (xmlhttp.status==200) {
			databox.innerHTML=xmlhttp.responseText;
			databox='';
		}
		else {
			alert("Problem retrieving data:" + xmlhttp.statusText);
		}
	}
}

var origw;
var origh;

var loaded;

function resize(img) {
	origw = img.width;
	origh = img.height;
	orig = 0;
	w = 800;
	h = 600;
	if(img.width > w || img.height > h) {
		xscale = img.width / img.height;
		yscale = img.height / img.width;
		wscale = w / img.width;
		hscale = h / img.height;
		
		if (wscale <= hscale) {
			nw = w;
			nh = w * yscale;
		}
		if (wscale > hscale) {
			nw = h * xscale;
			nh = h;
		}
		img.width = nw;
		img.height = nh;
		orig = 1;
	}
	setloc();
	img.style.visibility = "visible";
	pics = document.getElementById('picsize');
	sizebox = document.getElementById('sizedata');
	if(!loaded) {
		if(orig) {
			idata = 'Size: ' + origw + 'x' + origh + ' / <a href="javascript:origSize();"> Show image in its original size</a>';
		} else idata = 'Size: ' + origw + 'x' + origh;
		sizebox.innerHTML=idata;
	}
	pics.style.backgroundColor = "#666666";
	pics.style.visibility = "visible";
	loaded = 1;
}

function origSize() {
	img = document.getElementById('ipic');
	img.style.visibility = "hidden";
	img.width = origw;
	img.height = origh;
	setloc();
	img.style.visibility = "visible";
	picdiv = document.getElementById('PIC');
	//picdiv.style.top = "160px";
	picdiv.style.overflow = "visible";
}

function setloc() {
	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;
	}
	div = document.getElementById('PIC');
//	divw = div.offsetWidth;
//	divh = div.offsetHeight;
	pic = document.getElementById('ipic');
	divw = pic.width;
	divh = pic.height;
	if(divw > myWidth) {
		locw = 0;
	} else {
		locw = parseInt((myWidth / 2) - (divw / 2));
//		loch = parseInt((myHeight / 2) - (divh / 2));
	}
	div.style.left = locw + 'px';
	//div.style.top = loch + 'px';
	//div.style.top = 100 + 'px';
	div.style.top = 200 + 'px';
//	alert("Width: " + divw + " Height: " + divh + " Location left: " + locw);
}
