var isIE = !+"\v1";
var isIE6 = (document.body && typeof(document.body.style.maxHeight) == "undefined");

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 if (document.documentElement && document.documentElement.scrollHeight > document.documentElement.offsetHeight){ // Explorer 6 strict mode
		xScroll = document.documentElement.scrollWidth;
		yScroll = document.documentElement.scrollHeight;
	} else { // Explorer Mac...would also work in 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;
	}

	return [pageWidth,pageHeight,windowWidth,windowHeight];
}

function showBox (width, height, title, description, content) {
	var wrapper = document.getElementById("fsi_wrapper");
	var box = document.getElementById("fsi");
	var boxContent = document.getElementById("fsi_content");
	var boxTitle = document.getElementById("fsi_title");
	var boxDescription = document.getElementById("fsi_description");
	var boxLoading = document.getElementById("fsi_loading");
	
	//box.style.width = width + 20 + "px";
	//box.style.height = height + "px";
	
	var ps = getPageSize();
	
	wrapper.style.width = (isIE) ? ps[0] + "px" : "100%";
	wrapper.style.height = ps[1] + "px";
	
	wrapper.style.display = "block";
	box.style.display = "block";
	boxLoading.style.display = "none";
	
	boxTitle.innerHTML = title;
	if (title !== "") {
		boxTitle.style.display = "block";
	} else {
		boxTitle.style.display = "none";
	}
	
	boxDescription.innerHTML = description;
	if (description !== "") {
		boxDescription.style.display = "block";
	} else {
		boxDescription.style.display = "none";
	}
	
	boxContent.innerHTML = content;
	if (content !== "") {
		boxContent.style.display = "block";
	} else {
		boxContent.style.display = "none";
	}
	if (ps[3] < box.clientHeight) {
		document.getElementById("fsi_content_image").style.height = ps[3] - boxTitle.offsetHeight - boxDescription.offsetHeight - 30 + "px";
	}
	if (!isIE6) {
		box.style.top = Math.ceil((Math.abs(ps[3] - box.clientHeight)) / 2) + 'px';
	}
	box.style.left = Math.ceil((ps[0] - width) / 2) + "px";
}
	
function showFullSizeImage(path, title, description) {
	_fsiImg = {};
	_fsiImg.img = new Image();
	_fsiImg.img.src = path;
	_fsiImg.path = path;
	_fsiImg.title = title;
	_fsiImg.description = description;
	
	_showFullSizeImage();
}

function _showFullSizeImage() {
	if (_fsiImg.img.complete) {
		var content = 
			"<a class=\"link\" onclick=\"document.getElementById('fsi').style.display = 'none'; document.getElementById('fsi_wrapper').style.display = 'none'\">" +
				"<img id=\"fsi_content_image\" src=\"" + _fsiImg.path + "\" alt=\"" + _fsiImg.title + "\" title=\"" + _fsiImg.title + "\" style=\"cursor: pointer;\">" +
			"</a>";
		showBox(_fsiImg.img.width, _fsiImg.img.height, _fsiImg.title, _fsiImg.description, content);
		_fsiImg = null;
	} else {
		setTimeout("_showFullSizeImage();", 100);
	}
}

function showFullSizeVideo(path, preview, width, height, title, description) {
	//var height = height + 20;
	/*var content = 
	"<embed " +
		"src='images/player.swf' " +
		"width='" + width + "' " +
		"height='" + (parseInt(height, 10) + 20) + "' " +
		"allowfullscreen='true' " +
		"flashvars='file=" + path + "&image=" + preview + "&quality=false' " +
	"/>";*/
	
	var content = 
		"<object " +
			"classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' " +
			"codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0' " +
			"width='" + width + "' height='" + (parseInt(height, 10) + 20) + "'>" +
			"<param name='movie' value='images/player.swf' />" +
			"<param name='width' value='" + width + "' />" +
			"<param name='height' value='" + (parseInt(height, 10) + 20) + "' />" +
			"<param name='allowfullscreen' value='true' />" +
			"<param name='flashvars' value='file=" + path + "&image=" + preview + "&quality=false' />" +
			"<embed " +
				"src='images/player.swf' " +
				"width='" + width + "' " +
				"height='" + (parseInt(height, 10) + 20) + "' " +
				"allowfullscreen='true' " +
				"flashvars='file=" + path + "&image=" + preview + "&quality=false' " +
			"/>" +
		"</object>";
	
	showBox(width, height, title, description, content);
}
