// jQuery menu structure for Monax Mining Limited by stretchcreative.com.au

$(window).load(function () {
						 
	// Home page image slideshow area fade-in
	// Uses the $(window).load() function to ensure all 
	// the images have loaded before the div fades in
	$('#slideshow').fadeIn(1000);
	
});


$(document).ready(function(){
						   
	// Firstly, set all the submenus not to display
	var topLevel = $(".menu ul:not(.menu ul li ul)").children("li"); 
	var secondLevel = $(".menu ul li ul");
	$(secondLevel).hide();
	// If the page is active, show its child menu
	var activeLevel = $(".menu ul li.active ul");
	$(activeLevel).show();
	// When you roll over a top level <li> element, we need the following to happen:
	// • If it's the active parent, nothing, and nothing on roll out
	// • If it's another parent, hide the active parent's submenu and show the rolled over parent's submenu;
	//   then, on roll out, hide the rolled over paren't submenu and show the active parent's submenu again.
	$(topLevel).hover(
		function()
		{
			if($(this).attr("class").indexOf("parent") != -1)
			{
				//alert($(this).attr("class"));
				$(this).children("a").addClass("over"); //Retain active top level parent hover state	
				if($(this).attr("class").indexOf("active") == -1)
				{
					$(this).children("ul").fadeIn(500);
					$(activeLevel).hide();
				}
			}
		},
		function()
		{
			if($(this).attr("class").indexOf("parent") != -1)
			{
				$(this).children("a").removeClass("over");
				if($(this).attr("class").indexOf("active") == -1)
				{
					//alert($(this).attr("class"));
					$(this).children("ul").fadeOut(0);
					$(activeLevel).fadeIn(500);
				}
			}
		}
	);
});


// Slideshow for home page
function slideSwitch() {
	var $active = $('#slideshow img.active');

	if ( $active.length == 0 ) $active = $('#slideshow img:last');

	var $next =  $active.next().length ? $active.next()
		: $('#slideshow img:first');

	$active.addClass('last-active');

	$next.css({opacity: 0.0})
		.addClass('active')
		.animate({opacity: 1.0}, 750, function() {
			$active.removeClass('active last-active');
		});
}

$(function() {
	setInterval( "slideSwitch()", 5000 );
});

