/* Jquery Script */

/* Uses Ariel Flesler's ScrollTo plugin
   Link: http://flesler.blogspot.com/2007/10/jqueryscrollto.html
*/

$(document).ready(function() {
	$("#linkbar a").click(function() {
		$("#linkbar a").removeClass("current");
		$(this).addClass("current");
		
		var div_select = $(this).attr('id');
		
		$.scrollTo("div." + div_select + "", 500, {offset: -99});
		
		return false;
	});
	
	// Large Showcase
	
	$("#showcase").easySlider({
		continuous: true,
		auto: true,
		vertical: true,
		speed: 1200,
		pause: 2000,
		prevText: ' ',
		nextText: ' '
	});
	
	// Twitter Box Integration
	
	var twitter_account = $("p#twitter_account").text(); // Pulled from <p> tag in header.php which in turn has a php variable for the account
	
	$("#twitter_content").tweet({
		join_text: "auto",
		username: twitter_account,
		loading_text: "Loading content...",
		count: 1,
		auto_join_text_default: ""
	});
		
	
	// Fancybox Integration
	
	$("#showcase a").fancybox({
		'overlayOpacity' : .5,
		'overlayColor' : '#2a2829'
	});
	
	$("#portfolio_items a").fancybox({
		'overlayOpacity' : .5,
		'overlayColor' : '#2a2829'
	});
	
	// Input Removal and Retrieval of Values (Name, Email, etc)
	
	$("#contact input:eq(0), #contact input:eq(1), #contact input:eq(2) ").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;
	       }
	   });
	});
	
	// Contact Form Error Detection / Submission
	
	$("#submit").click(function() {
		var hasError = false;
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		
		var senderNameVal = $(this).parent().children(".name").val();
		if(senderNameVal == '' || senderNameVal == ' ' || senderNameVal == 'Name...' || senderNameVal == 'Venue Name...') {
			$(this).parent().children(".name").css({ "border" : "1px solid #f00" });
			hasError = true;
		}
		
		var emailFromVal = $(this).parent().children(".emailFrom").val();
		if(emailFromVal == '') {
			$(this).parent().children(".emailFrom").css({ "border" : "1px solid #f00" });
			hasError = true;
		} else if(!emailReg.test(emailFromVal)) {	
			$(this).parent().children(".emailFrom").css({ "border" : "1px solid #f00" });
			hasError = true;
		}
		
		var subjectVal = $(this).parent().children(".subject").val();
		if(subjectVal == '' || subjectVal == ' ' || subjectVal == 'Subject...' || subjectVal == 'Location...') {
			$(this).parent().children(".subject").css({ "border" : "1px solid #f00" });
			hasError = true;
		}
		
		var messageVal = $(this).parent().children(".message").val();
		if(messageVal == '' || messageVal == ' ') {
			$(this).parent().children(".message").css({ "border" : "1px solid #f00" });
			hasError = true;
		}
		
		
		if(hasError == false) {	
			// Next four lines of code reverse the "red outline" error styling if there was any
			$(this).parent().children(".name, .emailFrom, .subject, .message").css({ "border" : "1px solid #ddd" });
			
			$(this).css({ 'opacity' : '.5', 'width' : 'auto' });
   						
			$(this).val('Message Sent!');
			
			emailType = $(this).parent().parent().attr('class'); // If you change the classes, change the values in the next if statement below
			
			template_path_contact = $("#template_path_contact").text(); // Used to get template_path which uses php code
			
			if(emailType == 'userEmail' || emailType == 'venueEmail') {
			
			$.post(template_path_contact + "/emailForm.php",
   				{ subject: subjectVal, message: messageVal, mailFrom: emailFromVal, from: senderNameVal + "<request@yoursite.com>", headers: "From: " + from + "\r\nReply-To: " + mailFrom },
   					function(data) {
   					});
			}
			
			else { // If you add a newsletter php form, put it inbetween here and remove the return false
				return false;
			}
		}
		
		return false;
	});
});

/* Jquery Script */

/* Uses Ariel Flesler's ScrollTo plugin
   Link: http://flesler.blogspot.com/2007/10/jqueryscrollto.html
*/

// Plugin Licensing / Authoring Information:


// EasySlider1.5

/*
 * 	Easy Slider 1.5 - jQuery plugin
 *	written by Alen Grakalic	
 *	http://cssglobe.com/post/4004/easy-slider-15-the-easiest-jquery-plugin-for-sliding
 *
 *	Copyright (c) 2009 Alen Grakalic (http://cssglobe.com)
 *	Dual licensed under the MIT (MIT-LICENSE.txt)
 *	and GPL (GPL-LICENSE.txt) licenses.
 *
 *	Built for jQuery library
 *	http://jquery.com
 *
 */
 
 // FancyBox
 // url: http://fancybox.net/