// Eye of Africa

$(document).ready(function () {
	/* Drop-down menus */							
	function megaHoverOver() {
		$(this).find(".sub").stop().fadeTo('fast', 1).show();
			
		//Calculate width of all uls
		(function ($) { 
			jQuery.fn.calcSubWidth = function () {
				rowWidth = 0;
				//Calculate row
				$(this).find("ul").each(function () {					
					rowWidth += $(this).width(); 
				});	
			};
		})(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});
			
		}
	}
	
	function megaHoverOut() { 
				$(this).find(".sub").stop().fadeTo('fast', 0, function () {
				$(this).hide(); 
			});
		}

	var config = {    
		sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)    
		interval: 100, // number = milliseconds for onMouseOver polling interval    
		over: megaHoverOver, // function = onMouseOver callback (REQUIRED)    
		timeout: 500, // number = milliseconds delay before onMouseOut    
		out: megaHoverOut // function = onMouseOut callback (REQUIRED)    
	};

	$("ul#topnav li .sub").css({'opacity': '0'});
	$("ul#topnav li").hoverIntent(config);


/*	prettyPhoto */

	$("a[rel^='prettyPhoto']").prettyPhoto({
		animation_speed: 'normal', /* fast/slow/normal */
		autoplay_slideshow: false,
		padding: 40, /* padding for each side of the picture */
		opacity: 0.5, /* Value betwee 0 and 1 */
		show_title: false, /* true/false */
		allow_resize: true, /* true/false */
		counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
		theme: 'dark_rounded', /* light_rounded / dark_rounded / light_square / dark_square */
		hideflash: false, /* Hides all the flash objects on a page, set to TRUE if flash appears over prettyPhoto */
		wmode: 'opaque', /* Set the flash wmode attribute */
		modal: false, /* If set to true, only the close button will close the window */
		overlay_gallery: false,
		social_tools: false
	});


/*	
	SWFObject
*/
	var flashvars = {};
	var params = {};
	var attributes = {};
	swfobject.embedSWF("splash.swf", "myAlternativeContent", "960", "395", "9.0.0", false, flashvars, params, attributes);

/*
	Banner slideshow
*/
	$('.slideshow').slideshow({
		timeout: 5000,
		fadetime: 1600,
		type: 'sequence'
	});

/*	A nice effect on the master plan image */
	$("ul#master-plan").hide().fadeIn('2500');

});

/*	Home page advertisement */
	function showAdPopup(inlineElement, Title, Description) {
		var showAd = $.cookie('eoaAds');
		$.cookie('eoaAds', "true", { expires: 7 });
		
		if (showAd !== 'true') {
			$.fn.prettyPhoto ({
				padding: 30,
				show_title: false,
				default_width: 700,
				default_height: 233,
				modal:true,
				social_tools: false
			 });
			$.prettyPhoto.open(inlineElement, Title, Description);
		}
	}


