/**********************

   Stan Wilson Jr
   for: stanwilsonjr.com


***********************/




 (function($) {
 $.fn.randomize = function(childElem) {
  return this.each(function() {
      var $this = $(this);
      var elems = $this.children(childElem);
       elems.sort(function() { return (Math.round(Math.random())-0.5); });  
       $this.remove(childElem);  
       for(var i=0; i < elems.length; i++)
        $this.append(elems[i]);      
   });    
}
})(jQuery);


/* Create SWJR or Add to SWJR  */
var SWJR =  SWJR || {};

(function(){
	this.init = function(){		
		var page = $('body').attr('id');
		switch(page){
			case 'home':
				slideshow(); 
 			break;
 			case 'contact':
 				$("#contact_form").validate({
					rules: {
							name: "required",
 							email: { required: true, email: true },
							message: { required: true }
 					},
					messages: {
							name: "Please enter your firstname",
							email: "Please enter a valid email address",
							message: "Please Enter Your Message"
					},
					submitHandler: function(form) {
						$(form).ajaxSubmit({ type:"post", success: showResponse });
					}
				}); 
 			break;
			default:
		}
	};	
	var slideshow = function(){
		var $slides = $('#slideshow li');
		
		$('#slideshow').randomize('li');	
		$slides.filter(':lt(3)').each(function(index){ 
			$(this).addClass('active_'+(index + 1)) 
		});
		$slides.filter(':gt(2)').hide();
		$slides.filter(':even').hover(function(){
			$slides.filter(':even').stop().animate({ top: 10 }).css('z-index',1);
			$slides.filter(':odd').stop().animate({ top: 40, opacity: 0.7  }).css('z-index',0 );
  		},function(){
			$slides.filter(':even').stop().animate({ top: 40 }).css('z-index',0);
			$slides.filter(':odd').stop().animate({ top: 0, opacity: 1   }).css('z-index',1);
  		});
 	};
  	var showResponse = function(){
  		$("#contact_form").remove();
 		$("<p>Thanks for contacting me. I will get back to you as soon as I can</p>").appendTo("#page_content");
 	} 
  }).apply(SWJR);


$(document).ready(function(){  	SWJR.init();  	});



