/*
 * Common Utility function
 */

/* Jquery plugin to preload image:
	use as:
		$.preloadImages("image1.gif", "/path/to/image2.png","some/image3.jpg");
*/

jQuery.preloadImages = function()
{
  for(var i = 0; i<arguments.length; i++)
  {
    jQuery("<img>").attr("src", arguments[i]);
  }
}

//The name of window could be passed dinamically
var popup='';
function openPopUp(pUrl,wdth,hght) {
	if (popup && popup.open && !popup.closed) {
		popup.focus();
		popup.location.href = pUrl;
	} else {
		popup = window.open(pUrl,'popup','width='+wdth+', height='+hght+',left=0px,top=0px,scrollbars=yes,toolbar=no');
		popup.focus();
	}
	return true;
}

var currentPage = '';

$(document).ready(function()
{
	// Fix Menu
	$('li.mainMenu').each(function() {
		$(this).addClass('appear');
		$('#'+this.id+'SubMenu').hide();
		// Bring all of them on top, the "current" will be bringed down
		// in page js
		$('#'+this.id+'SubMenu').css('z-index', 1000);
	});
	
	$('li.mainMenu').hover(
			function() 
			{ //over
					$('#'+this.id+'SubMenu').show();
					$('#'+this.id+'Link').addClass('bgColor');
			},
			function()
			{ //out
				if (currentPage != this.id) 
				{
					$('#'+this.id+'SubMenu').hide();
					$('#'+this.id+'Link').removeClass('bgColor');
				}
			}
	);
	
	//	set the _blank target to all links marked external
	$("A[rel='external']").attr('target', '_blank');
	
});
