$(document).ready(function() {
	
	// AviaSlider
	$('#feature-promo').aviaSlider({		
		slides:'.promo-item',
		betweenBlockDelay:0,
		animationSpeed:0,
		autorotationSpeed:5
	});
	
	// Uniform
	$("form select").uniform();


    $("#featured-videos_carousel").jCarouselLite({
        btnNext: ".next_featured",
        btnPrev: ".prev_featured",
        visible: 4
    });
    
     $("#latest-videos_carousel").jCarouselLite({
        btnNext: ".next_latest",
        btnPrev: ".prev_latest",
        visible: 4
    });
    
    // Form Validation 
	$('form.validate-me').validate();
    
	//Footer tabs
	$(".footertabs a").click(function(){
		var gnutab = "#footerpromo .footer_tabswrap .footertab" + $(this).attr('href');
		$('#footerpromo .footer_tabswrap .footertab').hide();
		// Reset forms here
		$('form#contact').reset();
		$('form#newsletter').reset();
		// Make contact and mailing list forms visible
		$('form#contact').show();
		$('form#newsletter').show();
		// hide all alerts
		$('div#contact .success').hide();
		$('div#contact .error').hide();
		$('div#newsletter .success').hide();
		$('div#newsletter .error').hide();
		$(gnutab).show();
		$(".footertabs a").removeClass('active');
		$($(this)).addClass('active');		
		return false;
	});

     	
});

	
function mailinglist() {
	var temp = $('#mailinglistajax').val();
	if (!temp) {
		temp = none;
	}
	$.get('/?mailinglistajax=' + temp, 
		function(data) {
			if (data == '1') {
				$('form#newsletter').hide();
				$('div#newsletter .success').fadeIn();
			} else {
				$('div#newsletter .error').fadeIn();
			}
			// clean up the one second divs
		}
	
	);
}

function contactform() {
	// you could put a please wait div here
	$.post("/", { 'portal': '1','contactname': $('#contactname').val(), 'contactemail': $('#contactemail').val() , 'contactbody': $('#contactbody').val() },
		function(data) {
			
			$('div#contact .error span').html('');
			$('div#contact .error').hide();
			
			if (data == 'contactname_required') { 
				alert('bad name');
				$('div#contact .error span').html('You must enter your name before sending a message.');
				$('div#contact .error').fadeIn(50);
				return false; 
			}
			if (data == 'contactemail_required') {
				$('div#contact .error span').html('You must enter a valid email before sending a message.');
				$('div#contact .error').fadeIn(50);
				return false; 
			}
			if (data == 'contactemail_invalidemail') { 
				$('div#contact .error span').html('You entered an invalid email address.');
				$('div#contact .error').fadeIn(50);
				return false; 
			}
			if (data == 'contactbody_required') { 
				$('div#contact .error span').html('You must enter a message before sending.');
				$('div#contact .error').fadeIn(50);
				return false; 
			}
			if (data == '1') {
				$('form#contact').hide();
				$('div#contact .success').fadeIn(50);
			} 
			// clean up the one second divs
	}); 
	
}
