function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

function popUp(url,w,h) {
   newWin = window.open(url,'_blank','width='+w+',height='+h+',menubar=no,scrollbars=1,status=yes,resizable=yes');
   newWin.focus();
}


/* start menu handler */

function setupMenu() {
  /*
	document.getElementById('menu_promo_sub').style.display='none';
	document.getElementById('menu_estilos_sub').style.display='none';
	document.getElementById('menu_mundo_sub').style.display='none';
	document.getElementById('menu_gaudir_sub').style.display='none';
  */
  
	document.getElementById('menu_promo').onmouseout = function() { document.getElementById('menu_promo_sub').style.display='none'; }
	document.getElementById('menu_promo_link').onmouseover = function() { document.getElementById('menu_promo_sub').style.display='block'; }
	document.getElementById('menu_promo_sub').onmouseover = function() { document.getElementById('menu_promo_sub').style.display='block'; }

	document.getElementById('menu_estilos').onmouseout = function() { document.getElementById('menu_estilos_sub').style.display='none'; }
	document.getElementById('menu_estilos_link').onmouseover = function() { document.getElementById('menu_estilos_sub').style.display='block'; }
	document.getElementById('menu_estilos_sub').onmouseover = function() { document.getElementById('menu_estilos_sub').style.display='block'; }

// uncoment if menu contains items
//	document.getElementById('menu_postv').onmouseout = function() { document.getElementById('menu_postv_sub').style.display='none'; }
//	document.getElementById('menu_postv_link').onmouseover = function() { document.getElementById('menu_postv_sub').style.display='block'; }
//	document.getElementById('menu_postv_sub').onmouseover = function() { document.getElementById('menu_postv_sub').style.display='block'; }

	document.getElementById('menu_gaudir').onmouseout = function() { document.getElementById('menu_gaudir_sub').style.display='none'; }
	document.getElementById('menu_gaudir_link').onmouseover = function() { document.getElementById('menu_gaudir_sub').style.display='block'; }
	document.getElementById('menu_gaudir_sub').onmouseover = function() { document.getElementById('menu_gaudir_sub').style.display='block'; }

	document.getElementById('menu_mundo').onmouseout = function() { document.getElementById('menu_mundo_sub').style.display='none'; }
	document.getElementById('menu_mundo_link').onmouseover = function() { document.getElementById('menu_mundo_sub').style.display='block'; }
	document.getElementById('menu_mundo_sub').onmouseover = function() { document.getElementById('menu_mundo_sub').style.display='block'; }

}
// define onload events
addLoadEvent(setupMenu);

/* end menu handler */



/* start external links handler */

function externalLinks() {
   if (!document.getElementsByTagName) return;
   var anchors = document.getElementsByTagName("a");
   for (var i=0; i<anchors.length; i++) {
      var anchor = anchors[i];
      if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external")
         anchor.target = "_blank";
   }
}

// define onload events
addLoadEvent(externalLinks);

/* end external links handler */


/* start carrusel */

var currImgNum;
var numImages;
var iDelay = 2000;
var tSwitch;

function loopImg() {
	// set base values
	calcNumImg();
	if (typeof(currImgNum) == 'undefined') currImgNum = 1;

	// run loop
	switchImg(currImgNum);
	clearTimeout(tSwitch);
	tSwitch = setTimeout("loopImg();", iDelay*5);
}

function calcNumImg() {
	for (i=1; i<100; i++) {
		if (document.getElementById('carrusel' + i)==null) {
			numImages = i-1;
			return;
		}
	}
}

function switchImg(imgNum) {
	$("#carrusel" + imgNum).fadeOut(iDelay, function() {
		$("#carrusel" + nextImg(imgNum)).fadeIn(iDelay);
	});
}

function nextImg(imgNum) {
	imgNum = parseInt(imgNum) + 1;
	if (imgNum > numImages) imgNum = 1;
	currImgNum = imgNum;
	return imgNum;
}

/* end carrusel */
