/* -------------------------------------------------------------------------------- */
/*  Americarna 2010 - In Page JS Code  								                */
/*  Ver     : 1                                                                     */
/*  Created : 1 November 2010                                                       */
/* -------------------------------------------------------------------------------- */

/*--------------------------*/		
/* Document Ready Functions */
/*--------------------------*/

$(document).ready(function () {
	/*------------------*/
	/* Top Visual Slide */
    /*------------------*/
	
	slideShow("div.top-visual-container");
						
	/*---------------------*/
	/* Topa Main Navigation */
	/*---------------------*/
			
	// drop down
	var $loginDropDown = $("#login").parent();
			
    
	$loginDropDown.hover(
	function()
	{
		$(this).addClass("selected").removeClass("default").find("div.sub-menu").show(); //Drop down the subnav on hover on
	},
	function()
	{						
		$(this).addClass("default").removeClass("selected").find("div.sub-menu").hide(); //When the mouse hovers out of the subnav, move it back up  									
	});
    
	
	// position adjustment
	if($.browser.mozilla)
	{
		$("div.main-navigation ul").addClass("firefox-nav-adjustment");
	}
						
	/*-----------------*/
	/* Home Slide Show */
	/*-----------------*/
			
	if ($("body.home").length) 
	{				
		// anything Slider
		$('#featured-item-slider').anythingSlider({
			//startStopped        : true,  // If autoPlay is on, this can force it to start stopped
			autoPlay            : true,
			pauseOnHover        : true,  // If true & the slideshow is active, the slideshow will pause on hover
			resumeOnVideoEnd    : true
			//width           : 530,   // Override the default CSS width			
			//height          : 300
		});
												
		$('div.featured-item ul.thumbNav li a').text("");
						
		$('.gallery-area-slider').anythingSlider({
			startStopped    : true,  // If autoPlay is on, this can force it to start stopped
			width           : 254,   // Override the default CSS width
			height          : 144
		});
		
		// class adjustment for JS active display
		$("div.featured-item").removeClass("hide-overflow border-white");
}

//weird scrolling bug on homepage.
if ($('body.home').length) { scrollTo(0, 0); }
});

/*-----------------------*/		
/* Window Load Functions */
/*-----------------------*/

$(window).load(function () {
    
    // empty on click
    $('.emptyonclick').emptyonclick();
    
});

/*-----------*/		
/* Functions */
/*-----------*/

function slideShow(slideContainer) 
{   	
	var $slider = $(slideContainer),
		$activeSlide = "",
		$nextToActive = "";
	
	setInterval(
		function() 
		{			
			$activeSlide = $slider.find(".active-slide");
			
			if ($activeSlide.hasClass("last")) {				
				$nextToActive = $slider.find(".first");				
			}
			else {				
				$nextToActive = $activeSlide.next();
			}
												
			$activeSlide.fadeOut(2000, function() {
				$(this).removeClass("active-slide");	
			});	
			
			$nextToActive.fadeIn(2000).addClass("active-slide");			
		}
		, 5000);			
}
