var Explore_cnt = 0;

function Explore_setCenter(obj) {
	if (obj) {
		var h = (window.innerHeight || self.innerHeight || document.documentElement.clientHeight || document.body.clientHeight);
		var w = (window.innerWidth || self.innerWidth || document.documentElement.clientWidth || document.body.clientWidth);
		var l = ((window.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft) + ((w-(obj.width||parseInt(obj.style.width)||obj.offsetWidth))/2));
		//var t = ((window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop) + ((h-(obj.height||parseInt(obj.style.height)||obj.offsetHeight))/2));
		var t = 100;
		if((obj.width||parseInt(obj.style.width)||obj.offsetWidth) >= w) l = 0;
		if((obj.height||parseInt(obj.style.height)||obj.offsetHeight) >= h) t = 100 + 'px'; //(window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop)
		document.getElementById('Explore_content').style.left = l + "px";
		if(Explore_cnt == 0) {
			document.getElementById('Explore_content').style.top = t + "px";
			if(document.getElementById('Explore_content').offsetHeight >= h - 20) {
				Explore_cnt ++;
			}
			if(obj.nextSibling && (obj.nextSibling.className == 'Explore_close' || obj.nextSibling.className == 'Explore_caption')) {
				obj.nextSibling.style.display = 'block';
				if((t - (window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop))>(obj.nextSibling.offsetHeight/2)) {
					document.getElementById('Explore_content').style.top = parseInt(document.getElementById('Explore_content').style.top) - (obj.nextSibling.offsetHeight/2) + "px";
				}
			}
		}
		obj.style.visibility = 'visible';
		if(!arguments[1]) {
			document.getElementById('Explore_loading').style.display = "none";
		} else {
			obj.style.left = l + "px";
			obj.style.top = t + "px";
		}
	}
}

function hideSelect() {
	var windows = window.frames.length;
	var selects = document.getElementsByTagName("SELECT");
	for (i=0;i < selects.length ;i++ )
	{
		selects[i].style.visibility = "hidden";
	}
	if (windows > 0) {
		for(i=0; i < windows; i++) {
			try {
				var selects = window.frames[i].document.getElementsByTagName("SELECT");
				for (j=0;j<selects.length ;j++ )
				{
					selects[j].style.visibility = "hidden";
				}
			} catch (e) {}
		}
	}
}

function showSelect() {
	var windows = window.frames.length;
	var selects = document.getElementsByTagName("SELECT");
	for (i=0;i < selects.length ;i++ )
	{
		selects[i].style.visibility = "visible";
	}
	if (windows > 0) {
		for(i=0; i < windows; i++) {
			try {
				var selects = window.frames[i].document.getElementsByTagName("SELECT");
				for (j=0;j<selects.length ;j++ )
				{
					selects[j].style.visibility = "visible";
				}
			} catch (e) {}
		}
	}
}

function tryReHeight(sign) {
	var getFFVersion=navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[1];
	var FFextraHeight=parseFloat(getFFVersion)>=0.1? 16 : 0;
	var currentfr=document.getElementById('Explore_iframe');
	var currentDiv=document.getElementById('Explore_content');
	if(sign) {
		try {
			if (currentfr.contentDocument && currentfr.contentDocument.body.offsetHeight) {
				setIframeSize(currentfr.contentDocument.body.offsetHeight+FFextraHeight);
			} else if (currentfr.Document && currentfr.Document.body.scrollHeight) {
				setIframeSize(currentfr.Document.body.scrollHeight);
			}
		}catch(e) { }
		Explore_setCenter(document.getElementById('Explore_content').firstChild);
	} else {
		Explore_setCenter(document.getElementById('Explore_content').firstChild);
	}
}

function setIframeSize(h, w) {
	Explore_cnt = 0;
	var ifr = currentfr=document.getElementById('Explore_iframe');
	if (ifr) {
		if(w) {
			ifr.width = w;
		}
		if(h) {
			ifr.height = h;
		}
		Explore_setCenter(ifr);
	}
}

var prevOnScroll = window.onscroll;
window.onscroll = function () {
	try
	{
		if(prevOnScroll != undefined) prevOnScroll();
		if (document.documentElement.scrollHeight > document.body.scrollHeight) {
			document.getElementById('Explore_film').style.height = document.documentElement.scrollHeight + 'px';
			//document.getElementById('lp_film').style.height = document.documentElement.scrollHeight + 'px';
		} else { 
			document.getElementById('Explore_film').style.height = document.body.scrollHeight + 'px';
			//document.getElementById('lp_film').style.height = document.body.scrollHeight + 'px';
		}
		document.getElementById('Explore_film').style.width = document.body.scrollWidth + 'px';
		//document.getElementById('lp_film').style.width = document.body.scrollWidth + 'px';
		Explore_setCenter(document.getElementById('Explore_content').firstChild);
	}
	catch (e)
	{
	}
}

var prevOnResize = window.onresize;
window.onresize = function () {
	try
	{
		if(prevOnResize != undefined) prevOnResize();
		if (document.documentElement.scrollHeight > document.body.scrollHeight) {
			document.getElementById('Explore_film').style.height = document.documentElement.scrollHeight + 'px';
		} else { 
			document.getElementById('Explore_film').style.height = document.body.scrollHeight + 'px';
		}
		document.getElementById('Explore_film').style.width = document.body.offsetWidth + 'px';
		Explore_setCenter(document.getElementById('Explore_content').firstChild);
	}
	catch (e)
	{
	}
}

//width and height value on window from mootools
var win ={
	getWidth: function(){
		if (document.childNodes && !document.all && !navigator.taintEnabled) return window.innerWidth;
		if (window.opera) return document.body.clientWidth;
		return document.documentElement.clientWidth;
	},

	getHeight: function(){
		if (document.childNodes && !document.all && !navigator.taintEnabled) return window.innerHeight;
		if (window.opera) return document.body.clientHeight;
		return document.documentElement.clientHeight;
	},

	getScrollWidth: function(){
		if (window.ActiveXObject) return Math.max(document.documentElement.offsetWidth, document.documentElement.scrollWidth);
		if (document.childNodes && !document.all && !navigator.taintEnabled) return document.body.scrollWidth;
		return document.documentElement.scrollWidth;
	},

	getScrollHeight: function(){
		if (window.ActiveXObject) return Math.max(document.documentElement.offsetHeight, document.documentElement.scrollHeight);
		if (document.childNodes && !document.all && !navigator.taintEnabled) return document.body.scrollHeight;
		return document.documentElement.scrollHeight;
	},

	getScrollLeft: function(){
		return window.pageXOffset || document.documentElement.scrollLeft;
	},

	getScrollTop: function(){
		return window.pageYOffset || document.documentElement.scrollTop;
	},
	getPosition: function(){return {'x': 0, 'y': 0}}

};


