/* 
 *Date: 25 June, 2008
 *Created by: Mohammed Arif
 *Description: global landing page - navigation for continent, country.
 *Last modified date: 30 June, 2008
 */
	var imageNames= new Array();
//Declaring namespace object to bind all methods related to navigation hover
var navigationObj = {
	//findPosY function which can get the position of any element
	findPosY: function( obj ) {
		var curtop = 0;
		if( obj.offsetParent )
			while( 1 )
			{
			  curtop += obj.offsetTop;
			  if( !obj.offsetParent )
				break;
			  obj = obj.offsetParent;
			}
		else if( obj.y )
			curtop += obj.y;
		return curtop;			
	},
	//navigationHover function which set the global landing page navigation functionality unobtrusively
	navigationHover: function( params ) {
		//params = continentName, continentData, imgPath, prefixName, localeName;
			params.continentName = params.continentName || "continent_name";
			params.continentData = params.continentData || "continent_data_";
			params.imgPath = params.imgPath || "../../common/media_asset/";
				//params.imgPath = params.imgPath || "../../common/media_asset/";
			params.prefixName = params.prefixName || "vw_glp_reg_";
			params.localeName = params.localeName || "_en_US.gif";
			/*params.width = params.width || "100px";
			params.height = params.height || "200px";
			alert("width: " + params.width + "  height: " + params.height);*/
		
		var oCountryName = document.getElementById( params.continentName );
		var oAnchor = oCountryName.getElementsByTagName( "a" );
		var oImg = oCountryName.getElementsByTagName( "img" );
		for ( var i = 0; oAnchor.length > i; i++ ) {
			oAnchor[i].onmouseover = function(e) {
				this.firstChild.src = params.imgPath + params.prefixName + this.id +"_on"+ params.localeName; //black color image [Hover state]

				for ( var k = 0; oAnchor.length > k; k++ ) {
					oAnchor[k].firstChild.src = params.imgPath + params.prefixName+ oAnchor[k].id +"_inactive"+ params.localeName; //disbaled image [Disabled state]
					oCountryNameData = document.getElementById( params.continentData + oAnchor[k].id );
					//alert("Clicked on anchor : " + oCountryNameData);
					oCountryNameData.style.display = "none";
					}
					
				oCountryNameData = document.getElementById( params.continentData + this.id );
				//alert("oCountryNameData: " + this.id);
				oCountryNameData.style.display = "block";
					/*oCountryNameData.onmouseout = function(e) {
						//this.style.display = "none";
						console.log("onmouseout");
						//this.style.border = "2px solid red";
						stopBubble(e);
					}*/
					var config = {     
						 out: function() {
							 oCountryNameData.style.display = 'none';
							 } // function = onMouseOut callback (REQUIRED)    
					};
					
					$(oCountryNameData).hoverIntent(config)
					
					var config1 = {     
						 out: function() {
							 oCountryNameData.style.display = 'none';
							 //console.log("Fire");
							 } // function = onMouseOut callback (REQUIRED)    
					};
					$('#continent_name').hoverIntent(config1);

				//alert("jQuery: " + $(oCountryNameData).attr('id'));
				
				this.firstChild.src = params.imgPath + params.prefixName+ this.id +"_on"+ params.localeName; //black color image
				var oStorePos = navigationObj.findPosY( this );
				//oCountryNameData.style.top = ( oStorePos-90 )+"px";
				oCountryNameData.style.top = ( oStorePos-90 )+"px"; /*New value*/
				stopBubble(e);
				
			}
			oAnchor[i].onmouseout = function(e) {
				this.firstChild.src = params.imgPath + params.prefixName+ this.id +"_on"+ params.localeName; //red color image [Default state]
				//console.log("onmouseout");
				//oCountryNameData.style.display = "none";
				stopBubble(e);
			}
			oAnchor[i].onclick = function() {
				return false; //to remove # from the address bar
			}
		}
	
		var j=0;
		for ( var i = 0; oImg.length > i; i++ ) {
		imageNames[j++]=params.imgPath + params.prefixName + oImg[i].id +"_on"+ params.localeName;
		imageNames[j++]=params.imgPath + params.prefixName + oImg[i].id +"_off"+ params.localeName;
		imageNames[j++]=params.imgPath + params.prefixName + oImg[i].id +"_inactive"+ params.localeName;
		}
	}
}

//Common method for stopping bubble/propogation in diff browsers
function stopBubble(e) {
	// If an event object is provided, then this is a non-IE browser
	if ( e && e.stopPropagation )
	{
	// and therefore it supports the W3C stopPropagation() method
	e.stopPropagation();
	}
	else
	// Otherwise, we need to use the Internet Explorer
	// way of cancelling event bubbling
	window.event.cancelBubble = true;
}



//preloader images
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

// delay download navigation
function startNavigationDisplay() {
	document.getElementById('navigation').style.visibility="visible";
}