var speed_timeout=5000;
var speed_transition=1000;
var arrow_wait=2000;
var this_carousel=0;


var stateDropDownIsVisible = false;
jQuery(function() {

    //Add target="_blank" to any rel="external"
    jQuery('a[rel=external]').attr('target', '_blank');

});



jQuery(document).ready(function()
{
		//make HTML5 placeholders work in non supportive browsers
		  jQuery("input[placeholder]").each(function(){
		    if(jQuery(this).val()==""){
		      jQuery(this).addClass('hasplaceholder');
		      jQuery(this).val(jQuery(this).attr("placeholder"));
		      jQuery(this).focus(function(){
		        if(jQuery(this).val()==jQuery(this).attr("placeholder")) jQuery(this).val("");
		        jQuery(this).removeClass('hasplaceholder');
		      });
		      jQuery(this).blur(function(){
		        if(jQuery(this).val()==""){
						   jQuery(this).addClass('hasplaceholder');
		           jQuery(this).val(jQuery(this).attr("placeholder"));
		        }
		       });		
		    }
		  });

		jQuery('form').submit(function(evt){
			jQuery('input[placeholder]').each(function(){
				if(jQuery(this).attr("placeholder") == jQuery(this).val()) {jQuery(this).val('');}
			});
		});
		
		if (jQuery('.panel-content table.calendar.long').length) {
			jQuery('.home-panel.calendar-panel .panel-content').addClass('long');
			if (jQuery('.home-panel-wrapper'.length))
			jQuery('.home-panel-wrapper').addClass('long');
		};

		// Catch users from submitting the search form whilst empty
		jQuery('#search-form').submit(function() {
			if (jQuery('input#sitesearch').val() == '' || jQuery('input#sitesearch').val() == 'SEARCH') {
			  alert('Please enter a search term.');
			  return false;
			}
		});
		
    jQuery('div#state-select-clicker').click( function(event){
        showHideForm();
    });
    
    function showHideForm()
    {
        if (stateDropDownIsVisible) {
            hideForm();
        }
        else {
            showForm();
        }
    }
    
    function showForm()
    {
        // jQuery('#state-select-options').css('display','block');
        jQuery('#state-select-options').show();
        
        if(jQuery('#state-select-options').is(':visible'))
        {
            jQuery('#state-select-clicker').addClass('closeme');
        }
        stateDropDownIsVisible = true;
    }

    function hideForm()
    {
        jQuery('#state-select-options').hide();
        jQuery('#state-select-clicker').removeClass('closeme');
        stateDropDownIsVisible = false;
    }

		// Detect all other clicks and if necessary close the State select dropdown
		jQuery(document).bind('click', function(e) {
		    var clicked = jQuery(e.target);
		    if (!clicked.parents().hasClass("closeme"))
				{
		        hideForm();
				}
		});

});



jQuery(window).load(function(){
    
    if(jQuery('#hero').length){                
        var carousels=jQuery('#hero > .carousel').length;                

        jQuery('.carousel').each(function(count){
            var carousel = jQuery(this);
            
            carousel.css('z-index',carousels-count);
            if(count!=0) carousel.hide();            
        });
        
        jQuery('.carousel .item span').each(function(){
            
            jQuery(this).css('cursor','pointer');
            
            jQuery(this).click(function(){
                
                var rel=jQuery(this).parent().attr('rel');
                redirect('exhibition/'+rel+'/');
            })
        });

        jQuery('#hero').css('visibility','visible');

        jQuery('#hero0').cycle({timeout: speed_timeout});
        
    }
});

