/*Anchor*/
$(document).ready(function() {
	anchor.init()
});
anchor = {
	init : function()  {
	$("a.anchorLink").click(function () {	
	elementClick = $(this).attr("href")
	destination = $(elementClick).offset().top;
	$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, 1100 );
	return false;
	})
	}
}

/*Carousel 1*/
$(document).ready(function() {
	var speed = 10000;
	var run = setInterval('rotate()', speed);	
	var item_width = $('#slides li').outerWidth(); 
	var left_value = item_width * (0); 
	$('#slides li:first').before($('#slides li:last'));
	$('#slides ul').css({'left' : left_value});
	$('#prev').click(function() {
		var left_indent = parseInt($('#slides ul').css('left')) + item_width;
		$('#slides ul').animate({'left' : left_indent}, 200,function(){    
			$('#slides li:first').before($('#slides li:last'));           
			$('#slides ul').css({'left' : left_value});
		});
		return false;    
	});
	$('#next').click(function() {
		var left_indent = parseInt($('#slides ul').css('left')) - item_width;
		$('#slides ul').animate({'left' : left_indent}, 200, function () {
			$('#slides li:last').after($('#slides li:first'));                 	
			$('#slides ul').css({'left' : left_value});
		});
		return false;
	});        
	$('#slides').hover(
		function() {
			clearInterval(run);
		}, 
		function() {
			run = setInterval('rotate()', speed);	
		}
	); 
});
function rotate() {
	$('#next').click();
}

/*Fading Slideshow*/
function slideSwitch() {
    var $active = $('#hero-slider div.active');
    if ( $active.length == 0 ) $active = $('#hero-slider div:last');
    // use this to pull the divs in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#hero-slider div:first');
    // uncomment below to pull the divs randomly
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );
    $active.addClass('last-active');
    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}
$(function() {
    setInterval( "slideSwitch()", 5000 );
});

/*Thumbnail Fade*/
$(document).ready(function(){
$(".thumb img").fadeTo("fast", 1); // This sets the opacity of the thumbs to fade down to 60% when the page loads
$(".thumb img").hover(function(){
$(this).fadeTo("slow", 0); // This should set the opacity to 100% on hover
},function(){
$(this).fadeTo("slow", 1); // This should set the opacity back to 60% on mouseout
});
});

/*Carousel Fade*/
$(document).ready(function(){
$(".slide img").fadeTo("fast", 1); // This sets the opacity of the thumbs to fade down to 60% when the page loads
$(".slide img").hover(function(){
$(this).fadeTo("slow", 0); // This should set the opacity to 100% on hover
},function(){
$(this).fadeTo("slow", 1); // This should set the opacity back to 60% on mouseout
});
});