$(document).ready(function() {
	
// Drawer Drop-down action

	// Expand Panel
	$("#open").click(function(){
		$("ul.screenings").slideDown("slow");	
	});	
	
	// Collapse Panel
	$("#close").click(function(){
		$("ul.screenings").slideUp("slow");	
	});		
	
	// Switch buttons from "Log In | Register" to "Close Panel" on click
	$("#toggle a").click(function () {
		$("#toggle a").toggle();
	});
	
// JQuery Tools Scrollable News Items


	    // initialize scrollable 
	    $(".scrollable").scrollable({size: 3});
		$(".filmmaker_scroll").scrollable({size: 2});

	
// JQuery Tools Tabs


	    // setup ul.htabs to work as tabs for each div directly under div.tabs 
	    $("ul.htabs").tabs("div.tabs > div.tab"); 

	
// Smooth Scrolling
	$.smoothAnchors("slow");
	
// Gallery Setup

// select the thumbnails and make them trigger our overlay 

$(".thumbs a").overlay({ 
 
    // each trigger uses the same overlay with the id "gallery" 
    target: '#gallery', 
 
    // optional exposing effect 
    expose: '#000000' 
 
// let the gallery plugin do its magic! 
}).gallery({ 
 
    // the plugin accepts its own set of configuration options 
    speed: 800 
});

// AJAX-y Mail Processing

$("#submit").click(function(){					   				   
	$(".error").hide();
	var hasError = false;
	var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
	
	var yourNameVal = $("#yourName").val();
	if(yourNameVal == '') {
		$("#yourName").after('<p class="error">You forgot to enter your name.</p>');
		hasError = true;
	}
	
	var yourEmailVal = $("#yourEmail").val();
	if(yourEmailVal == '') {
		$("#yourEmail").after('<p class="error">You forgot to enter the email address to send from.</p>');
		hasError = true;
	} else if(!emailReg.test(yourEmailVal)) {	
		$("#yourEmail").after('<p class="error">Enter a valid email address to send from.</p>');
		hasError = true;
	}
	
	
	if(hasError == false) {
		$(this).hide();
		$("#sendEmail").append('<img src="/wp-content/themes/default/images/template/loading.gif" alt="Loading" id="loading" />');
		
		$.post("sendemail.php",
			{ yourEmail: yourEmailVal, yourName: yourNameVal },
				function(data){
					$("#sendEmail").slideUp("normal", function() {				   
						
						$("#sendEmail").before('<h4>Success</h4><p class="talkbubble">Thanks for your interest. Your request has been sent and we&rsquo;ll keep you informed regarding the release.</p>');											
					});
				}
			 );
	}
	
	return false;
});

$('.default-value').each(function() {
    var default_value = this.value;
    $(this).focus(function() {
        if(this.value == default_value) {
            this.value = '';
        }
    });
    $(this).blur(function() {
        if(this.value == '') {
            this.value = default_value;
        }
    });
});

		
});
