// JavaScript Document

$(document).ready( function(){ 
/*---------------------------------------------------------------------------------------
   Side Nav
---------------------------------------------------------------------------------------*/					
	/* Set defaults for JS enabled users */
	$('#sideNav ul').hide(); // hide subnavs
	$('#sideNav ul').parents('li').addClass('expandable'); //add hook to subnavs

	/* Nav open/close functionality + cookie */
	$('#sideNav li.expandable > a').click(function(e){
		e.preventDefault();
		if ($(this).hasClass('expanded')) { // if open
			$(this).removeClass('expanded').next('ul').slideUp(); // remove class and close
			$.cookie('navIndex', null); // delete any set cookies
		}
		else { // if closed
			$('.expanded').removeClass('expanded').next('ul').slideUp(); // close any open
			$(this).addClass('expanded').next('ul').slideDown(); // open the selected one
			var getindex = $(this).parents('li').index(); // find index
			$.cookie('navIndex', getindex); // set index into cookie
		}		
	});
	
	/* Retrieve Cookie and use */
	var openindex = $.cookie('navIndex'); // fetch cookie
	$('#sideNav > li:eq('+openindex+') > a').addClass('expanded').next('ul').show(); // open ul based on index and add selected class
	

/*---------------------------------------------------------------------------------------
News Scroller
---------------------------------------------------------------------------------------*/
	$('#latestNews').scrollable({ vertical: true, circular: true }).autoscroll({ interval: 6000 });
	$('#productDisplay').scrollable({ vertical: true, circular: true }).autoscroll({ interval: 8000 });


});
