$(document).ready(function() {
	
	//$("body.single div.textbody img").parent("a").attr("rel", "facebox");
	
	$('a[rel*=facebox]').facebox();
	$("div.trunc p").truncate( 60 );
	
	
	var adCheck = $("div#leader").attr("class");
	if(adCheck == "board") { 
		$("div#content").css("padding-top", "5px");
		$("div#hotness").css("padding-bottom", "5px");
		}
	
// Contact Form
$("form#sendEmail #submit").click(function(){					   				   
		$(".error").hide();
		$(this).attr("disabled", false);
		var hasError = false;
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		
		
		var senderName = $("#name").val();
		
		var emailFromVal = $("#emailFrom").val();
		if(emailFromVal === '') {
			$("#emailFrom").after('<div class="error">You forgot to enter the email address to send from.</div>');
			hasError = true;
		} else if(!emailReg.test(emailFromVal)) {	
			$("#emailFrom").after('<div class="error">Enter a valid email address to send from.</div>');
			hasError = true;
		}
		
		var subjectVal = $("#subject").val();
		//if(subjectVal == '') {
		//	$("#subject").after('<div class="error">You forgot to enter the subject.</div>');
		//	hasError = true;
		//}
		
		var messageVal = $("#message").val();
		if(messageVal === '') {
			$("#message").after('<div class="error">You forgot to enter the message.</div>');
			hasError = true;
		}
		
		
		if(hasError === false) {
			$(this).attr("disabled", true);
			$("#sendEmail li.buttons").append('<img src="wp-content/themes/las_subdomain/images/ajax-loader.gif" alt="Loading" id="loading" />');
			
			$.post("wp-content/themes/las_subdomain/contact/inc/sendEmail.php",
   				{ emailTo: "kyle@lacrosseallstars.com", name: senderName,  emailFrom: emailFromVal, subject: subjectVal, message: messageVal },
   					function(data){
						$("#sendEmail").slideUp("slow", function() {				   
							
							$("#sendEmail").before('<h3>Sweet!</h3><p>Your email was sent, and we do our best to get back to everybody.</p>');											
						});
   					}
				 );
		}
		
		return false;
	});
	
	$("#answer").click(function(){$(this).val("");});
	$("form#question #submit").click(function(){					   				   
			$(".error").hide();	
			var hasError = false;
				
			var questionVal = $("h5#quest").text();
			var answerVal = $("#answer").val();
			if(answerVal === 'Leave a Response') {
				$("#answer").after('<div class="error">Please fill in response.</div>');
				hasError = true;
			}

			if(hasError === false) {
				//$(this).attr("disabled", true);

				$.post("wp-content/themes/las_subdomain/scripts/sendQuest.php",
	   				{ emailTo: "kyle@lacrosseallstars.com", answer: answerVal, quest: questionVal},
	   					function(data){
							$("#question").slideUp("slow", function() {				   

								$("#question").before('<small>You answered: '+answerVal+'</small>');											
							});
	   					}
					 );
			}

			return false;
		});
	
	
	
	
	$("a.br_close").click(function (){
		$("div.announcement").slideUp("slow");
		return false;
	});
	$("ul.idTabs").idTabs();
	
	$.twitterGraph('lacrosse', $(".twitterUsage")); 
	
	$('.collapse').click(function() {
	        $(this).hide();
	        $('.openit').show();
	        $('#featured').slideUp("slow");
	        $.cookie('panel', 'collapsed');
	    });
	    // When the expand button is clicked:
	    $('.openit').click(function() {
	        $(this).hide();
	        $('.collapse').show();
	        $('#featured').slideDown("slow");
	        $.cookie('panel', 'expanded');
	    });

	// COOKIES
	    // Left column state
	    var panel = $.cookie('panel');
	    // Set the user's selection for the left column
	    if (panel == 'collapsed') {
	        $('.collapse').hide();
	        $('.openit').show();
	        $('#featured').hide();
	    }

		$("#randomPost").load("/random");
		$("#another").click(function(){
		   $("#randomPost")
		            .html('<img src="/wp-content/themes/las_subdomain/images/ajax-loader.gif" alt="Loading" /> Loading')
		            .load("/random");
		   return false;
		});
	
	

	
	$("li.beer a").hover(
	  function () {
	    $(this).text("or some Whiskey");
	$(this).parent().addClass("whiskey");
	  },
	  function () {
	    $(this).text("Buy us a Beer");
	$(this).parent().removeClass("whiskey");
	  }
	);
		
	$("#featured li").click(function(){
		  window.location=$(this).find("a").attr("href");
	});
	
	$("div#hotness div.right a").click(function(){
		$("body").toggleClass("mediabuy");
	});
	
	// $("div#tweets").hover(function () {
	//         $("div.buttons").fadeIn();
	// 	// Fill in the proper links
	//       }, 
	// function () {
	//   $("div.buttons").fadeOut();
	//   // Reset Links
	// });
	

	
	
	$('ul#nav').superfish({ 
		delay:       500,                            // one second delay on mouseout 
		animation:   {opacity:'show',height:'show'},  // fade-in and slide-down animation 
		speed:       'medium',                          // faster animation speed 
		autoArrows:  false,                           // disable generation of arrow mark-up 
		dropShadows: false                            // disable drop shadows 
	});
	
		
	
	$("#featured li").hover(
		function () {
		  $(this).addClass("hover");
		}, 
		function () {
		  $(this).removeClass("hover");
	});
	


	$.fn.clickUrl = function() {  
		var exp = /(\b(https?|ftp|file):\/\/[\-A\-Z0\-9+&@#\/%?=~_|!:,.;]*[\-A\-Z0\-\9+&@#\/%=~_|])/i;  
		this.each(function() {  
		    $(this).html(  
		        $(this).text().replace(exp,"<a href='$1'>$1</a>"));  
		});  
		return $(this);  
  	};

	$(".twitter_list").jCarouselLite({
	    btnNext: "a.right",
	    btnPrev: "a.left",
		speed: "slow"
	
	});

	
	
	// Load More
	$(function() {
	$(".more").click(function() {
	var element = $(this);
	var msg = element.attr("id");
	$("#morebutton").html('<img src="ajax-loader.gif" />');

	$.ajax({
	type: "POST",
	url: "more_ajax.php",
	data: "lastmsg="+ msg,
	cache: false,
	success: function(html){

	$("#more_updates").append(html);
	$(".more").remove();

	}
	});
	return false;
	});
	});
});

