// JavaScript Document

$(document).ready(function() {
	
	/**DropDown Menu**/	
				
  $('#nav li.dropdown').hover(function()
	{
		$('li.dropdown > ul').slideToggle();
		
		if($('#nav li.dropdown').hover())
		{
			$('li.dropdown > ul').css('display','block');
		}
		else
		{
			$('li.dropdown > ul').hide();
		}
	});
	
	
	
	/**HomePage Slider**/	

	function slideSwitch() {
		var $active = $('div#slider li.active');
		var $next =  $active.next().length ? $active.next(): $('div#slider li:first');
	//check to see if there is another image after the current $active element, if not then set the $next variable to the first image in the slideshow
	
		$active.addClass('last-active');
	
		$next.css({opacity: 0.0})
			.addClass('active')
			.animate({opacity: 1.0}, 1000, function() {
				$active.removeClass('active last-active');
			});
	}
	
	var timer = 3000;
	setInterval( slideSwitch, timer );
	
	//Don't show images until they are full loaded
	var sliderLength = $('#slider ul li').length;
	var sliderImgs = $('#slider ul li img').toArray();
	
	for(var i=0; i<sliderLength; i++)
	{
		$(sliderImgs[i]).load(function()
		{
			$(this).fadeIn(1000);
			if($('div#slider li').index() == i)
			{
				$(this).addClass('active').delay(3000);
			}
		});
	}
	
});
