function stateify (stateID) {
 $('#instruction_panel').hide();
 $('.state').hide();
 $('#'+stateID).show()
}

function populateElement(selector, defvalue) {
   $(selector).each(function() {
       if($.trim(this.value) == "") {
           this.value = defvalue;
       }
   });
 
   $(selector).focus(function() {
       if(this.value == defvalue) {
           this.value = "";
       }
   });
   
   $(selector).blur(function() {
       if($.trim(this.value) == "") {
           this.value = defvalue;
       }
   });
}


$(document).ready(function() {
  	$('#body .intro').fancyletter({commonClass: 'drop'});
  	$("div#state_scroller").smoothDivScroll({scrollingSpeed: 6, mouseDownSpeedBooster: 5, autoScroll: "", autoScrollDirection: "right", autoScrollSpeed: 1, pauseAutoScroll: "mouseover", visibleHotSpots: "always", hotSpotsVisibleTime: 9});
	
	$('#feature_wrap').cycle({ 
    fx:      'fade',
    speed:    500, 
    timeout:  8000,
	pause: 1,
 	pager: '#feature_nav',
    pagerAnchorBuilder: function(idx, slide) { 
        return '#feature_nav li:eq(' + idx + ') a'; 
    	} 
	});
	
	$('#free_slide_wrap').cycle({ 
    fx:      'scrollHorz',
    speed:    500, 
    timeout:  0,
	pause: 1,
	
	next: '#next',
	prev: '#prev'
	
 	//pager: '#free_nav',
	//pagerAnchorBuilder: function(idx, slide) { 
    //    return '<li><a href="#">Slide</a></li>'; 
    //}
    
	});
	
	$("#feature_nav").hover(
		function () {
			$('#feature_wrap').cycle('pause');
		},
		function () {

		}
	);
	
	$(function(){
   		var path = location.pathname.substring(1);
   		if ( path )
     	$('#subnav a[href$="' + path + '"]').parent().attr('class', 'active');
 	});
	
	var content_height = $('#content').height() - 120;

	$('.sub_page #container').css('background-position', "center "+content_height+"px");
	
	populateElement('#email1', 'Your email address');
	
	$('#email1').focus(function() {
		$(this).css('color', "#333");
    });
    
    populateElement('#email2', 'Your email address');
    
    $('#email2').focus(function() {
    	$(this).css('color', "#333");
    });
    
    $('#closebox').click(function() {
    	$.colorbox.close();
    });

	$("#subscribeForm").validate({
			rules: {
				'Email Address': {
					required: true,
					email: true
				}
			},
			messages: {
				'Email Address': "Please enter a valid email address"
			},
		  errorPlacement: function(error, element) {
		     error.appendTo(element.parent("form"));
		   }  
		    
		});

	$('.webinar_show').click(function() {
		  $(this).parent().next(".webinar").toggle();
		  return false;
	});

	
});

