//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//

function getPageSize() {
	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;
	}

	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;
	}

	// 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;

	pageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	return pageSize;
}

var slide = {
	pos: 0,

	left: function(obj) {
		if(slide.pos==0) return;
		slide.pos += 151;
		slide.topos(obj);
	},

	right: function(obj,pics) {
		if(pics <= 4) return;
		if(slide.pos==(pics-4)*(-151)) return;
		slide.pos -= 151;
		slide.topos(obj);
	},

	topos: function(obj) {
		document.getElementById(obj).style.marginLeft = slide.pos+"px";
	},

	set: function(id) {
		var img = new Image();
		img.src = 'img.php?id='+id+'&w=592';

		if($('overlay')==null) {
			var objBody = document.getElementsByTagName("body").item(0);

			var objOverlay = document.createElement('div');
			objOverlay.setAttribute('id','overlay');
			objOverlay.style.display = 'none';
			objOverlay.style.position = 'absolute';
			objOverlay.style.top = '0';
			objOverlay.style.left = '0';
			objOverlay.style.zIndex = '90';
			objOverlay.style.width = '100%'

			objBody.insertBefore(objOverlay,objBody.firstChild);

			var objLoading = document.createElement('img');
			objLoading.src = 'img/fnd/loading.gif';
			objLoading.setAttribute('id','loading');
			objLoading.alt = 'loading';
			objLoading.style.position = 'absolute';
			objLoading.style.zIndex = '150';

			objOverlay.appendChild(objLoading);

			this.loadingWidth = objLoading.width;
			this.loadingHeight = objLoading.height;
		}

		var pageSize = getPageSize();
		var scroll = 0;

		if(self.pageYOffset) scroll = self.pageYOffset;
		else if(document.documentElement && document.documentElement.scrollTop) scroll = document.documentElement.scrollTop; // Explorer 6 Strict
		else if(document.body) scroll = document.body.scrollTop; // all other Explorers

		$('overlay').style.height = pageSize[1]+'px';
		$('overlay').style.display = 'block';

		$('loading').style.top = (scroll+((pageSize[3]-35-this.loadingHeight)/2)+'px');
		$('loading').style.left = (((pageSize[0]-20-this.loadingWidth)/2)+'px');

		var selects = document.getElementsByTagName('select');
        for(var i = 0; i < selects.length; i++) selects[i].style.visibility = 'hidden';

		img.onload = function() {
			$('overlay').style.display = 'none';
			$('largePic').src = img.src;

			var selects = document.getElementsByTagName('select');
	        for(var i = 0; i < selects.length; i++) selects[i].style.visibility = 'visible';

			img.onload = function() {};
			return false;
		}
	}
}
