/*
	Autor: Innovagency - http://www.innovagency.com/
*/
// Function Load Events
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			if(oldonload){oldonload();}
			func();
		}
	}
}

// Star List Menu-itens
function startList() {
	if (document.all&&document.getElementById) {
		if (!document.getElementById("Menu-itens")) return false;
		var navRoot = document.getElementById("Menu-itens");
		for (i=0; i<navRoot.childNodes.length; i++) {
			var node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
					this.className+=" over";
				}
				node.onmouseout=function() {
					this.className=this.className.replace(" over", "");
				}
			}
		}
	}
}
// Prepare Menus
function prepareMenus() {
	if (!document.getElementById("Menu-itens")) return false;
	var navRoot = document.getElementById("Menu-itens");
	var lis = navRoot.getElementsByTagName('li');
	for (var i = 0, li; li = lis[i]; i++) {
		var link = li.getElementsByTagName('a')[0];
		if (link) {
			link.onfocus = function() {
				var ul = this.parentNode.getElementsByTagName('ul')[0];
				if (ul)
				ul.style.display = 'block';
			}
			var ul = link.parentNode.getElementsByTagName('ul')[0];
			if (ul) {
				var ullinks = ul.getElementsByTagName('a');
				var ullinksqty = ullinks.length;
				var lastItem = ullinks[ullinksqty - 1];
				if (lastItem) {
					lastItem.onblur = function() {
						this.parentNode.parentNode.style.display = 'none';
					}
					lastItem.parentNode.onblur = function() {
						this.parentNode.style.display = '';
					}
				}
			}
		}
	}
}


// Abre uma janela centrada
function NewWindow(url, name, width, height, features) {
	var left = 0;
	var top = 0;

	if ( screen.width > width ) {
		left = parseInt( ( screen.width - width ) / 2 );
	} else {
		left = 0;
	}

	if ( screen.height > height ) {
		top = parseInt( ( screen.height - height ) / 2 );
	} else {
		top = 0;
	}

    //alert("url:" + url + "; name:" + name + "; width:" + width + "; height:" + height + "; left:" + left + "; top:" + top + "; features:" + features);

    //if(features != null && features.length != 0) {
	//    window.open(url, name, 'width=' + width + ',height=' + height + ',left=' + left + ',top=' + top + ',' + features);
	//} else {
        window.open(url, name, 'width=' + width + ',height=' + height + ',resizable=yes,scrollbars=yes,left=' + left + ',top=' + top);
	//}
}
// Popup Window
function doPopupWindow() {
	if (!document.getElementsByTagName) return false;
	var links = document.getElementsByTagName("a");
	for (var i=0; i < links.length; i++) {
		var sectionId = links[i].getAttribute("href");
		// Prospectos
		if (links[i].className.match("prospectos")) {
			links[i].destination = sectionId;
			links[i].onclick = function() {
				NewWindow(this.destination, 'prospectos', 540, 371, null);
				return false;
			}
		}
		// Mini-sites
		if (links[i].className.match("minisite")) {
			links[i].destination = sectionId;
			links[i].onclick = function() {
				NewWindow(this.destination, 'minisite', 940, 645, null);
				return false;
			}
		}
		
		// Popups CVs
		if (links[i].className.match("CV_Janelas")) {
			links[i].destination = sectionId;
			links[i].onclick = function() {
				NewWindow(this.destination, 'CV',700, 420, null);
				return false;
			}
		}
		
		// PopUps várias
		if (links[i].className.match("popup")) {
			links[i].destination = sectionId;
			links[i].onclick = function() {
				NewWindow(this.destination, '', 580, 580, null);
				return false;
			}
		}
		
		// Videos REN Premio
		if (links[i].className.match("videos")) {
			links[i].destination = sectionId;
			links[i].onclick = function() {
				NewWindow(this.destination, '', 380, 295, null);
				return false;
			}
		}
	}
}


// Window Print
function doPrint() {
	if (!document.getElementsByTagName) return false;
	var links = document.getElementsByTagName("a");
	for (var i=0; i < links.length; i++) {
		if (links[i].className.match("print")) {
			links[i].onclick = function() {
				window.print();
				return false;
			}
		}
	}
}


// Window Close
function doClose() {
	if (!document.getElementsByTagName) return false;
	var links = document.getElementsByTagName("a");
	for (var i=0; i < links.length; i++) {
		if (links[i].className.match("close")) {
			links[i].onclick = function() {
				window.close();
				return false;
			}
		}
	}
}


/* ---------------------------- */
// Add Load Event
addLoadEvent(prepareMenus);
addLoadEvent(startList);
addLoadEvent(doPopupWindow);
addLoadEvent(doPrint);
addLoadEvent(doClose);
