$(document).ready(function(){
	
	// Form Validation
	if ($('.validate').length > 0) {
		$('.validate').validate();
	}

	// Site Navigation Hover Fade Effects
	$('#site.nav li')
        .removeClass('highlight')	
    	.find('a')
		.append('<span class="hover" />').each(function () {
			var $span = $('> span.hover', this).css('opacity', 0);
			$(this).hover(function () {
				// on hover
				$span.stop().fadeTo(500, 1);
			}, function () {
				// off hover
				$span.stop().fadeTo(500, 0);
			});
		});
		
	// Site Navigation Hover Fade Effects
	$('#home.card li')
        .removeClass('highlight')	
    	.find('a')
		.append('<span class="hover" />').each(function () {
			var $span = $('> span.hover', this).css('opacity', 0);
			$(this).hover(function () {
				// on hover
				$span.stop().fadeTo(500, 1);
			}, function () {
				// off hover
				$span.stop().fadeTo(500, 0);
			});
		});

	// Footer Login Slider
	if ($('.account form').length > 0) {
		var login_fields = $('.account form div');
		login_fields.css({ display: 'none' });
		$('.account form h2').wrapInner('<a href="#"></a>');
		$('.account form h2').click(function () {
			login_fields.slideToggle('normal');
			return false;
		});
	}

	// Homepage Featured Effects
	if ($('#featured').length > 0) {

		$(".main_image .desc").show(); //Show Banner
		$(".main_image .block").animate({ opacity: 0.85 }, 250 ); //Set Opacity
	
		//Click and Hover events for thumbnail list
		$(".image_thumbs ul li:first").addClass('active'); 
		$(".image_thumbs ul li").click(function(){ 
			//Set Variables
			var imgAlt = $(this).find('img').attr("alt"); //Get Alt Tag of Image
			var imgTitle = $(this).find('a').attr("href"); //Get Main Image URL
			var imgDesc = $(this).find('.block').html(); 	//Get HTML of block
			var imgDescHeight = $(".main_image").find('.block').height();	//Calculate height of block	
			
			if ($(this).is(".active")) {  //If it's already active, then...
//				return false; // Don't click through
			} else {
				//Animate the Teaser				
				$(".main_image .block").animate({ opacity: 0}, 250 , function() {
					$(".main_image .block").html(imgDesc).animate({ opacity: 0.85,	marginBottom: "0" }, 250 );
					$(".main_image img").attr({ src: imgTitle , alt: imgAlt});
				});
			}
			
			$(".image_thumbs ul li").removeClass('active'); //Remove class of 'active' on all lists
			$(this).addClass('active');  //add class of 'active' on this list only
//			return false;
			
		}) .hover(function(){
			$(this).addClass('hover');
			}, function() {
			$(this).removeClass('hover');
		});
				
		//Toggle Teaser
		$("a.collapse").click(function(){
			$("a.collapse").toggleClass("show");
		});	
		
		//Automated
		function slideSwitch() {
		    var $active = $('.image_thumbs ul li.active');
		    var $next = $active.next();    
		
		    $next.addClass('active');
		
		    $active.removeClass('active');
		}
		
		$(function() {
		    setInterval( "slideSwitch()", 5000 );
		});
	}

});
