
$(document).ready(function() {
	 
	var config = {
		sensitivity: 7, // number = sensitivity threshold (must be 1 or higher)
		interval: 1, // number = milliseconds for onMouseOver polling interval
		over: dropOpen, // function = onMouseOver callback (REQUIRED)
		timeout: 200, // number = milliseconds delay before onMouseOut
		out: dropClose // function = onMouseOut callback (REQUIRED)
	};
	
	var config2 = {
		sensitivity: 7, // number = sensitivity threshold (must be 1 or higher)
		interval: 1, // number = milliseconds for onMouseOver polling interval
		over: dropOpen, // function = onMouseOver callback (REQUIRED)
		timeout: 200, // number = milliseconds delay before onMouseOut
		out: dropClose // function = onMouseOut callback (REQUIRED)
	};
	
	function emptyFunction() { }
	
	function dropOpen() {
				
		//Calculate width of all ul's
		(function($) { 
			jQuery.fn.calcSubWidth = function() {
				rowWidth = 0;
				//Calculate row
				$(this).find("ul").each(function() {					
					rowWidth += $(this).width()+22; 
				});	
				rowWidth -= 22;
			};
		})(jQuery); 
		
		if ( $(this).find(".row").length > 0 ) { //If row exists...
			var biggestRow = 0;	
			//Calculate each row
			$(this).find(".row").each(function() {							   
				$(this).calcSubWidth();
				//Find biggest row
				if(rowWidth > biggestRow) {
					biggestRow = rowWidth;
				}
			});
			//Set width
			$(this).find(".sub").css({'width' :biggestRow});
			$(this).find(".row:last").css({'margin':'0'});
			
		} else { //If row does not exist...
			
			$(this).calcSubWidth();
			//Set Width
			$(this).find(".sub").css({'width' : rowWidth});
			
		}
		
		$('.sub',this).css({'z-index':1000});	
		$(this).addClass("hover");
		//$('.sub',this).css('visibility', 'visible');
		$('.sub',this).slideDown('fast');	
		
	}
	
	function dropClose() {
		
		//$('.sub',this).css('visibility', 'hidden');
		$('.sub',this).slideUp('fast');
		$(this).removeClass("hover");
	}
	 
 
	//$("ul#topnav li .sub").css({'opacity':'0'});
	$("ul#topnav > li").hover(function() {
			$('.sub').css({'z-index':500});
			$('.sub',this).css({'z-index':700});					
		},
		function() {
			$('.sub',this).css({'z-index':600});
			$('#country-select .sub').css({'z-index':1400});			
		}
	);
	$("ul#topnav > li").hoverIntent(config);
	$("#country-select").hoverIntent(config2);
	
	// to enable dropdown on click
	//$("#country-select").bind('click',dropOpen);
 
 
 	
 
});
 
 
