var isIE = '\v' == 'v';

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();
	
	var tmpHeight = height;
	var commonTop = (Math.ceil((Math.abs(ps[3] - height)) / 2) - 20);
	
	box.style.top = commonTop + 'px';
	box.style.left = Math.round((ps[0] - width)/2) + "px";
	
	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";
	
	if (title != "") {
		boxTitle.innerHTML = title;
		boxTitle.style.display = "block";
	}
	if (description != "") {
		boxDescription.innerHTML = description;
		boxDescription.style.display = "block";
	}
	if (content != "") {
		boxContent.innerHTML = content;
		boxContent.style.display = "block";
	}
}
	
function showFullSizeImage(path, width, height, title, description) {
	var content = 
		"<a class=\"link\" onclick=\"document.getElementById('fsi').style.display = 'none'; document.getElementById('fsi_wrapper').style.display = 'none'\">" +
			"<img src=\""+path+"\">" +
		"</a>";
	showBox(width, height, title, description, content);
}

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);
}

