// <!-- BEGIN: Perfect Pop-up Embedded -->
// Reference: http://www.accessify.com/features/tutorials/the-perfect-popup/
var newWindow = null;
function closeWin(){
	if(newWindow != null) {
		if(!newWindow.closed) {newWindow.close();}
	}
}
function popUpWin(url, type, strWidth, strHeight) {
	closeWin();
	type = type.toLowerCase();
	var centerLeft = 0;var centerTop = 0;
	if(type == 'fullscreen') {
		strWidth = screen.availWidth;
		strHeight = screen.availHeight;
	} else {
		centerLeft = (screen.width)?(screen.width - strWidth) / 2:100;
		centerTop = (screen.height)?(screen.height - strHeight) / 2:100;
	}
	var tools = '';
	if(type == 'standard') tools = 'resizable,toolbar=yes,location=yes,scrollbars=yes,menubar=yes,width='+strWidth+',height='+strHeight+',top='+centerTop+',left='+centerLeft;
	if(type == 'console' || type == "fullscreen") tools = 'resizable,toolbar=no,location=no,scrollbars=yes,width='+strWidth+',height='+strHeight+',top='+centerTop+',left='+centerLeft;
	newWindow = window.open(url, 'newWin', tools);
	newWindow.focus();
}
function doPopUp(e) {
	// Set defaults - if nothing in rel attrib, these will be used.
	var t = 'standard';
	var w = '780';
	var h = '580';
	// Look for parameters.
	attribs = this.rel.split(' ');
	if(attribs[1]!=null) {t = attribs[1];}
	if(attribs[2]!=null) {w = attribs[2];}
	if(attribs[3]!=null) {h = attribs[3];}
	// Call the popup script.
	popUpWin(this.href,t,w,h);
	// Cancel the default link action if pop-up activated.
	if(window.event) {
		window.event.returnValue = false;
		window.event.cancelBubble = true;
	}
	else if(e) {
		e.stopPropagation();
		e.preventDefault();
	}
}
function findPopUps() {
	var popups = document.getElementsByTagName('a');
	for(i=0;i<popups.length;i++) {
		if(popups[i].rel.indexOf('popup') != -1) {
			// Attach popup behaviour.
			popups[i].onclick = doPopUp;
			// Add popup indicator.
			if(popups[i].rel.indexOf('noicon') == -1) {
				popups[i].style.backgroundImage = 'url(pop-up.gif)';
				popups[i].style.backgroundPosition = '0 center';
				popups[i].style.backgroundRepeat = 'no-repeat';
				popups[i].style.paddingLeft = '15px';
			}
			// Add info to title attribute to alert fact that it's a pop-up window.
			popups[i].title = popups[i].title + ' [Opens in pop-up window]';
		}
	}
}
// <!-- END: YUI Perfect Pop-up Embedded -->

// <!-- BEGIN: Remove Border Collapse Embedded -->
function removeBorderCollapse(e) {
	for(i=0;(element = document.getElementsByTagName('table')[i]);i++) {
		if(element.getAttribute('style')) {
			element.style.borderCollapse = 'separate';
			element.style.borderSpacing = '0';
		}
	}
}
// <!-- END: Remove Border Collapse Embedded -->

// <!-- BEGIN: YUI JavaScript Embedded -->
function classLayout(idRegion, idBuffer) {
	this.initialize = initialize
	this.print = print;
	this.idRegion = idRegion;
	this.idBuffer = idBuffer;
	var eRegion;var eBuffer;var width;var height;
	function _apply() {
		YAHOO.util.Dom.setStyle(eRegion, 'width', width + 'px');
		YAHOO.util.Dom.setStyle(eRegion, 'height', (height - 28) + 'px');
		YAHOO.util.Dom.setStyle(eBuffer, 'width', (width - 16) + 'px');
	}
	function print() {
		YAHOO.util.Dom.setStyle(eRegion, 'position', 'static');
		YAHOO.util.Dom.setStyle(eRegion, 'overflow', 'visible');
		YAHOO.util.Dom.setStyle(eRegion, 'top', 'auto');
		YAHOO.util.Dom.setStyle(eRegion, 'left', 'auto');
		YAHOO.util.Dom.setStyle(eRegion, 'width', 'auto');
		YAHOO.util.Dom.setStyle(eRegion, 'height', 'auto');
		YAHOO.util.Dom.setStyle(eBuffer, 'width', 'auto');
	}
	function _resize(e) {
		width = YAHOO.util.Dom.getViewportWidth();
		height = YAHOO.util.Dom.getViewportHeight();
		_apply();
	}
	function initialize(e){
		// No scroll bar. References:
		// http://www.htmlhelpcentral.com/messageboard/showthread.php?t=11789
		// http://www.webdevelopersnotes.com/tips/html/transparent_hidden_scrollbar_code.php3
		document.all[1].style.overflow = 'hidden';
		eRegion = document.getElementById(idRegion);
		eBuffer = document.getElementById(idBuffer);
		width = YAHOO.util.Dom.getViewportWidth();
		height = YAHOO.util.Dom.getViewportHeight();
		YAHOO.util.Dom.setStyle(eRegion, 'overflow', 'auto');
		_apply();
		YAHOO.widget.Overlay.windowResizeEvent.subscribe(_resize);
	}
}
function classMenuBar(idMenu) {
	this.initialize = _initialize
	this.idMenu = idMenu;
	var Dom = YAHOO.util.Dom, oAnim;
	function onAnimationComplete(p_sType, p_aArgs, p_oShadow) {
		var oBody = this.body, oUL = oBody.getElementsByTagName('ul')[0];
		if(p_oShadow) {p_oShadow.style.height = this.element.offsetHeight + 'px';}
		Dom.setStyle(oUL, 'marginTop', '');
		Dom.setStyle(oBody, 'overflow', '');
		if(this.parent && !(this.parent instanceof YAHOO.widget.MenuBarItem) && YAHOO.env.ua.gecko) {
			Dom.setStyle(oBody, 'width', '');
		}
	}
	function onMenuBeforeShow(p_sType, p_sArgs) { // 'beforeshow' event handler for each submenu of the MenuBar instance.
		var oBody, oShadow, oUL;
		if(this.parent) {
			oShadow = this.element.lastChild;
			oShadow.style.height = '0px';
			if(oAnim && oAnim.isAnimated()) {
				oAnim.stop();
				oAnim = null;
			}
			oBody = this.body;
			if(this.parent && !(this.parent instanceof YAHOO.widget.MenuBarItem) && YAHOO.env.ua.gecko) {
				Dom.setStyle(oBody, "width", (oBody.clientWidth + "px"));
			}
			Dom.setStyle(oBody, 'overflow', 'hidden');
			oUL = oBody.getElementsByTagName('ul')[0];
			Dom.setStyle(oUL, 'marginTop', ('-' + oUL.offsetHeight + 'px'));
		}
	}
	function onMenuShow(p_sType, p_sArgs) { // 'show' event handler for each submenu of the MenuBar instance.
		var oElement, oShadow, oUL;
		if(this.parent) {
			oElement = this.element;
			oShadow = oElement.lastChild;
			oUL = this.body.getElementsByTagName('ul')[0];
			oAnim = new YAHOO.util.Anim(oUL, {marginTop:{to:0}}, .1, YAHOO.util.Easing.easeOut);
			oAnim.onStart.subscribe(function() {oShadow.style.height = '100%';});
			oAnim.animate();
			if(YAHOO.env.ua.ie) {
				oShadow.style.height = oElement.offsetHeight + 'px';
				oAnim.onTween.subscribe(onTween, oShadow, this);
			}
			oAnim.onComplete.subscribe(onAnimationComplete, oShadow, this);
		}
	}
	function onTween(p_sType, p_aArgs, p_oShadow) {
		if(this.cfg.getProperty('iframe')) {this.syncIframe();}
		if(p_oShadow) {p_oShadow.style.height = this.element.offsetHeight + 'px';}
	}
	function _initialize(e) {
		var oMenuBar = new YAHOO.widget.MenuBar(idMenu, {autosubmenudisplay:true, hidedelay:750, lazyload:true});
		oMenuBar.subscribe('beforeShow', onMenuBeforeShow);
		oMenuBar.subscribe('show', onMenuShow);
		oMenuBar.render();
	}
}
function classMinHeight(id) {
	this.initialize = initialize
	this.id = id;
	var element;var height;
	function _apply() {
		if(YAHOO.env.ua.ie && YAHOO.env.ua.ie <= 6) {
			YAHOO.util.Dom.setStyle(element, 'height', (height - 192) + 'px');
			element.style.overflow = 'visible';
		} else {
			YAHOO.util.Dom.setStyle(element, 'min-height', (height - 192) + 'px');
		}
	}
	function _resize(e) {
		height = YAHOO.util.Dom.getViewportHeight();
		_apply();
	}
	function initialize(e) {
		element = document.getElementById(id);
		height = YAHOO.util.Dom.getViewportHeight();
		_apply();
		YAHOO.widget.Overlay.windowResizeEvent.subscribe(_resize);
	}
}
function classDashboard(idRegion, idMin, idMax, idDrawers) {
	this.initialize = initialize;
	this.idRegion = idRegion
	this.idMin = idMin;
	this.idMax = idMax;
	this.idDrawers = idDrawers;
	
	var idMaxToggle;
	var maxHeightHideShow;
	
	var idsDrawersToggle = [];
	var esDrawers = [];
	var drawersHeightHideShow = [];
	
	var previousElement = null;
	
	function _toggleDashboardMax(e) {
		YAHOO.util.Event.removeListener(idMaxToggle, 'click');
		var vista = (parseInt(YAHOO.util.Dom.getStyle(idMax, 'height')) == '0')? maxHeightHideShow : '0';
		var anim = new YAHOO.util.Anim(idMax, {height:{to:vista}}, 0.3, YAHOO.util.Easing.easeOut);
		anim.animate();
		YAHOO.util.Event.addListener(idMaxToggle, 'click', _toggleDashboardMax);
	}
	function _toggleDashboardDrawer(e) {
		if(previousElement != null) { closeElement(); }
		YAHOO.util.Event.removeListener(this, 'click');
		for(var i in esDrawers) {
			if(esDrawers[i].id == this.id.substring(0, this.id.length - 7)) {
				var vista = (parseInt(YAHOO.util.Dom.getStyle(esDrawers[i], 'height')) == '0')? drawersHeightHideShow[i] : '0';
				var anim = new YAHOO.util.Anim(esDrawers[i], {height:{to:vista}}, 0.3, YAHOO.util.Easing.easeOut);
				anim.animate();
				if(vista > 0) {previousElement = esDrawers[i];}
				//alert(previousElement);
				break;
			}
		}
		YAHOO.util.Event.addListener(this, 'click', _toggleDashboardDrawer);
	}
	function closeElement() {
		var anim = new YAHOO.util.Anim(previousElement, {height:{to:0}}, 0.3, YAHOO.util.Easing.easeOut);
		anim.onComplete.subscribe(_toggleDashboardDrawer);
		anim.animate();
		previousElement = null;
	}
	function initialize(e){
		// Dashboard Drawers.
		var cssClassDrawer = idDrawers.substring(0, idDrawers.length - 1);
		esDrawers = YAHOO.util.Dom.getElementsByClassName(cssClassDrawer, 'div', idDrawers);
		for(var i=0;i<esDrawers.length;i++) {
			idsDrawersToggle[i] = esDrawers[i].id + '-toggle';
			drawersHeightHideShow[i] = parseInt(esDrawers[i].childNodes[0].offsetHeight);
		}
		YAHOO.util.Event.addListener(idsDrawersToggle, 'click', _toggleDashboardDrawer);
		YAHOO.util.Dom.setStyle(idsDrawersToggle, 'cursor', 'pointer');
		// Dashboard Max.
		idMaxToggle = idMax + '-toggle';
		maxHeightHideShow = parseInt(document.getElementById(idMax).childNodes[0].offsetHeight);
		YAHOO.util.Event.addListener(idMaxToggle, 'click', _toggleDashboardMax);
		YAHOO.util.Dom.setStyle(idMaxToggle, 'cursor', 'pointer');
	}
}
// YUI Event Utility - http://www.dustindiaz.com/yahoo-event-utility/
// Check Brower Legacy:
// http://developer.yahoo.com/yui/docs/YAHOO.env.ua.html
// http://ajaxian.com/archives/detecting-ie7-in-javascript
if(YAHOO.env.ua.ie && YAHOO.env.ua.ie <= 6) {
	var globalLayout = new classLayout('region-container', 'region-container-buffer');
	YAHOO.util.Event.onDOMReady(globalLayout.initialize);
	// IE Proprietary, Print Event - http://www.javascriptkit.com/javatutors/ie5print.shtml
	window.onbeforeprint = globalLayout.print;
	window.onafterprint = globalLayout.initialize;
}
//YAHOO.util.Event.onDOMReady(removeBorderCollapse);
var globalMenuBar = new classMenuBar('navigation-top');
YAHOO.util.Event.onContentReady('navigation-top', globalMenuBar.initialize);
var globalMinHeight = new classMinHeight('region-middle');
var globalDashboard = new classDashboard('dashboard', 'dashboard-min', 'dashboard-max', 'dashboard-drawers');
YAHOO.util.Event.onContentReady('region-dashboard', globalDashboard.initialize);
YAHOO.util.Event.onContentReady('region-middle', findPopUps);
YAHOO.util.Event.onContentReady('region-middle', globalMinHeight.initialize);
// <!-- END: YUI JavaScript Embedded -->
