
// NetVision JS - Browser Utils
// (c) 2006-2010 unix-world.org
// v.8.1
// r.20100204


// DEPENDS: MooTools
// Images: closex.png, loading_ifrm.gif

// TODO: fix custom Window WIDTH and HEIGHT

//===========================================

var NetVision_RefreshBy_iFrmBox_State = 0; // if=1, will refresh parent
var NetVision_RefreshBy_iFrmBox_URL = ''; // ^=1 -> if != '' will redirect parent

// [PUBLIC]
var NetVision_RefreshBy_SET = function(yURL) {
	NetVision_RefreshBy_iFrmBox_State = 1;
	if(typeof yURL != 'undefined') {
		NetVision_RefreshBy_iFrmBox_URL = ''+yURL;
	} //end if
} //END FUNCTION

// [PUBLIC]
var NetVision_RefreshBy_EXEC = function() {
	if(NetVision_RefreshBy_iFrmBox_State) {
		if((typeof NetVision_RefreshBy_iFrmBox_URL == 'undefined') || (NetVision_RefreshBy_iFrmBox_URL == '')) {
			parent.location.reload(true);
		} else {
			parent.location = ''+NetVision_RefreshBy_iFrmBox_URL;
		} //end if else
		NetVision_RefreshBy_iFrmBox_State = 0;
		NetVision_RefreshBy_iFrmBox_URL = '';
	} //end if
} //END FUNCTION

//===========================================

var NetVision_iFrmBox = new function() { // START CLASS

// [PUBLIC]
this.is_Loaded = function() {
	//--
	var ifrmoverlay = document.getElementById('netVision__iFrmBox__Bg');
	var ifrmcontainer = document.getElementById('netVision__iFrmBox__Div');
	var ifrmldbar = document.getElementById('netVision__iFrmBox__Ldr');
	var ifrmclose = document.getElementById('netVision__iFrmBox__X');
	var ifrmloader = document.getElementById('netVision__iFrmBox__iFrame');
	//--
	ifrmldbar.innerHTML = '&nbsp;';
	ifrmloader.style.backgroundColor = '#FFFFFF';
	ifrmloader.style.visibility = 'visible';
	//--
	return false;
	//--
} //END FUNCTION

// [PUBLIC]
this.go_Load = function(yURL, yProtect, windowWidth, windowHeight) {
	//--
	do_load(yURL, yProtect, windowWidth, windowHeight);
	//--
	return false;
	//--
} //END FUNCTION

// [PUBLIC]
this.go_UnLoad = function() {
	//--
	do_unload();
	//--
	setTimeout("NetVision_iFrmBox.fx_Unload();", 500); // reset after 1 second
	//--
	return false;
	//--
} //END FUNCTION

// [PUBLIC]
this.fx_Unload = function() {
	//--
	var ifrmoverlay = document.getElementById('netVision__iFrmBox__Bg');
	//--
	fx_out(ifrmoverlay);
	//--
	return false;
	//--
} //END FUNCTION

//================================== # [PRIVATES]

var do_load = function(yURL, yProtect, windowWidth, windowHeight) {
	//--
	var ImgPath = 'lib/js/jsutil/img/';
	//--
	var ifrmoverlay = document.getElementById('netVision__iFrmBox__Bg');
	var ifrmcontainer = document.getElementById('netVision__iFrmBox__Div');
	var ifrmldbar = document.getElementById('netVision__iFrmBox__Ldr');
	var ifrmclose = document.getElementById('netVision__iFrmBox__X');
	var ifrmloader = document.getElementById('netVision__iFrmBox__iFrame');
	//--
	ifrmldbar.innerHTML = '<br><br><img src="' + ImgPath + 'loading_ifrm.gif">';
	//--
	if((typeof windowWidth == 'undefined') || (windowWidth == 0)) {
		windowWidth = window.getWidth() * 0.9; // MOO
	} else {
		windowWidth = parseInt(windowWidth);
	} //end if
	if((typeof windowHeight == 'undefined') || (windowHeight == 0)) {
		windowHeight = window.getHeight() * 0.9; // MOO
	} else {
		windowHeight = parseInt(windowHeight);
	} //end if
	//--
	fx_in(ifrmoverlay, yProtect);
	//--
	ifrmcontainer.style.position = 'absolute';
	ifrmcontainer.style.zIndex = 9999998;
	ifrmcontainer.style.textAlign = 'center';
	ifrmcontainer.style.left = ((window.getWidth() - windowWidth) / 2); // MOO
	ifrmcontainer.style.top = (window.getScrollTop() + 10); // MOO
	ifrmcontainer.style.width = windowWidth;
	ifrmcontainer.style.height = windowHeight;
	ifrmcontainer.style.visibility = 'visible';
	//--
	ifrmloader.style.visibility = 'hidden';
	ifrmloader.width = '100%';
	ifrmloader.height = '100%';
	//--
	var UrlTime = new Date().getTime();
	//--
	if(yURL.contains('?')) { // fix bug if same URL as parent
		yURL += '&netVision__iFrmBox__iFrame=' + escape(UrlTime);
	} else {
		yURL += '?netVision__iFrmBox__iFrame=' + escape(UrlTime);
	} //end if else
	//--
	ifrmloader.src = '' + yURL;
	//--
	ifrmclose.innerHTML = '<img src="' + ImgPath + 'closex.png">';
	ifrmclose.style.position = 'absolute';
	ifrmclose.style.zIndex = 9999999;
	ifrmclose.style.cursor = 'pointer';
	ifrmclose.style.top = 5;
	ifrmclose.style.left = -40;
	ifrmclose.style.width = 50;
	ifrmclose.style.height = 50;
	ifrmclose.style.visibility = 'visible';
	//--
	ifrmclose.onclick = function() {
		NetVision_iFrmBox.go_UnLoad();
	} //end function
	//--
	ifrmoverlay.onclick = function() {
		if(yProtect != 1) {
			NetVision_iFrmBox.go_UnLoad();
		} //end function
	} //end if
	//--
	if(yProtect != 1) {
		document["addEvent"]("keydown", NetVision_iFrmBox.go_UnLoad);
	} //end if
	//--
	setTimeout("NetVision_iFrmBox.is_Loaded();", 1000); // show after 1 second
	//--
	return false;
	//--
} //END FUNCTION

var do_unload = function() {
	//--
	var ifrmoverlay = document.getElementById('netVision__iFrmBox__Bg');
	var ifrmcontainer = document.getElementById('netVision__iFrmBox__Div');
	var ifrmldbar = document.getElementById('netVision__iFrmBox__Ldr');
	var ifrmclose = document.getElementById('netVision__iFrmBox__X');
	var ifrmloader = document.getElementById('netVision__iFrmBox__iFrame');
	//--
	document["removeEvent"]("keydown", NetVision_iFrmBox.go_UnLoad);
	//--
	ifrmoverlay.onclick = function() {
	} //end function
	//--
	ifrmclose.onclick = function() {
	} //end function
	//--
	ifrmclose.style.position = 'absolute';
	ifrmclose.innerHTML = '&nbsp;';
	ifrmclose.style.width = 1;
	ifrmclose.style.height = 1;
	ifrmclose.style.left = 0;
	ifrmclose.style.top = 0;
	ifrmclose.style.visibility = 'hidden';
	//--
	ifrmldbar.innerHTML = '&nbsp;';
	//--
	ifrmloader.src = 'lib/js/jsutil/blank.html'
	ifrmloader.width = 1;
	ifrmloader.height = 1;
	ifrmloader.style.visibility = 'hidden';
	//--
	ifrmcontainer.style.position = 'absolute';
	ifrmcontainer.style.width = 1;
	ifrmcontainer.style.height = 1;
	ifrmcontainer.style.left = 0;
	ifrmcontainer.style.top = 0;
	ifrmcontainer.style.visibility = 'hidden';
	//--
	return false;
	//--
} //END FUNCTION

var fx_in = function(y_ifrmoverlay, yProtect) {
	//--
	window.onscroll = function () { // called when the window is scrolled
		y_ifrmoverlay.style.left = window.getScrollLeft(); // MOO
		y_ifrmoverlay.style.top = window.getScrollTop(); // MOO
		y_ifrmoverlay.style.width = window.getWidth();
		y_ifrmoverlay.style.height = window.getHeight();
	} //end function
	//--
	y_ifrmoverlay.style.position = 'absolute';
	y_ifrmoverlay.style.zIndex = 9999997;
	if(yProtect != 1) {
		y_ifrmoverlay.style.cursor = 'pointer';
	} //end if
	y_ifrmoverlay.style.textAlign = 'center';
	y_ifrmoverlay.style.left = window.getScrollLeft(); // MOO
	y_ifrmoverlay.style.top = window.getScrollTop(); // MOO
	y_ifrmoverlay.style.width = window.getWidth();
	y_ifrmoverlay.style.height = window.getHeight();
	y_ifrmoverlay.style.visibility = 'visible';
	//--
	var fx = new Fx.Tween(y_ifrmoverlay, {property: "opacity", duration: 500}).set(0); // MOO
	fx.start(0.8); // MOO
	//--
	return false;
	//--
} //END FUNCTION

var fx_out = function(y_ifrmoverlay) {
	//--
	window.onscroll = function () {
	} //end function
	//--
	y_ifrmoverlay.style.position = 'absolute';
	y_ifrmoverlay.style.width = 1;
	y_ifrmoverlay.style.height = 1;
	y_ifrmoverlay.style.left = 0;
	y_ifrmoverlay.style.top = 0;
	y_ifrmoverlay.style.visibility = 'hidden';
	//--
	var fx = new Fx.Tween(y_ifrmoverlay, {property: "opacity", duration: 500}).set(0); // MOO
	fx.start(0.1); // MOO
	//--
	NetVision_RefreshBy_EXEC();
	//--
	return false;
	//--
} //END FUNCTION


} //END CLASS


//===========================================

//-- AUTOLOAD CODE BLOCK (CAN BE CHANGED)
var NetVision_Scan_iFrmBox = function() {
	var links = $$("a").filter(function(el) {
		if(el.rel && el.rel.test(/^slim_ifrmbox/i)) {
			el.onclick = function() {
				//--
				var aDim = this.rel.match(/[0-9]+/g);
				var w = (aDim && (aDim[0] > 0)) ? aDim[0] : 640;
				var h = (aDim && (aDim[1] > 0)) ? aDim[1] : 480;
				//--
				NetVision_JSUtil.PopUpLink(this.href, this.target, w, h, 0, 1);
				return false;
			} //end function
			return false;
		} //end if else
	});
} //END FUNCTION
//--
window.addEvent("domready", NetVision_Scan_iFrmBox);
//--

//===========================================

// #END
