$(document).ready(function(){	

// Add class last to last child in all lists, columns and figures
$("ul li:last-child").addClass('last');
$(".colgroup .col:last-child").addClass('last');
$(".applications figure:last-child").addClass('last');
	
// Call those functions
scrolltop();
}); 

// Top to magazine scroll
function scrolltop() {
	$('a.self').click(
	function(){
	$.scrollTo( '#page', 500 );
	return false;
});
}

// Form validation
$(document).ready(function(){
	// validate signup form on keyup and submit
	$("#feedbackForm").validate({	   
		rules: {
			message:		"required",
			email:			{ email: true }
			
		},
		messages: {
			message:		"Required"
		},
				errorElement: "div",
				wrapper: "div",  // a wrapper around the error message
				errorPlacement: function(error, element) {
					$("#messageLabel").addClass("error");
			}
	})
});

// Clear zip code form value
$(document).ready(function(){

var clearMePrevious = '';

// clear input on focus
$('.clearMeFocus').focus(function()
	{
	if($(this).val()=='zip code' || $(this).val()=='site search')
		{
			clearMePrevious = $(this).val();
			$(this).val('');
			//$(this).css('color', '#000')
		}
	});
	
	// if field is empty afterward, add text again
	$('.clearMeFocus').blur(function()
		{
			if($(this).val()=='')
		{
			$(this).val(clearMePrevious);
			//$(this).css('color', '#999')
		}
	});
});

// Subscribe popout
jQuery(document).ready(function () {

 var login_box = jQuery('#login-popout');
 var login_button = jQuery('.login-button');
 var login_button_text = login_button.html();



 jQuery('.login-button').bind('click', function (e) {
	 e.preventDefault();
	 if (login_box.css('display') == 'none') {
	
		 login_box.show(1, function () {
		 login_button.addClass('login-button-alternative');
	
	 });

 }

 else {
		 login_box.hide(1, function () {
		 login_button.removeClass('login-button-alternative');
		 });
	 }
 });

});

//Equal height columsn
function setEqualHeight(columns)
 {
 var tallestcolumn = 0;
 columns.each(
 function()
 {
 currentHeight = $(this).height();
 if(currentHeight > tallestcolumn)
 {
 tallestcolumn  = currentHeight;
 }
 }
 );
 columns.height(tallestcolumn);
 }
$(document).ready(function() {
 setEqualHeight($(".feature-sub > .feature-box"));
 setEqualHeight($(".footer-sitemap > ul"));
});

//feature image slider
	$(document).ready(function(){		
		$('#photos').galleryView({
				panel_width: 615,
				panel_height: 340,
				frame_width: 17,
				frame_height: 17,
				overlay_color: 'black',
				overlay_opacity: 0,
				overlay_text_color: 'white',
				caption_text_color: '#222',
				background_color: 'black',
				border: 'none',
				nav_theme: 'light',
				easing: 'easeInOutQuad',
				pause_on_hover: true,
				overlay_height: 100,
				transition_interval: 6000,
				slide_method: 'strip',
				overlay_position: 'bottom'
		});
	});

