// I'm no jQuery expert, so if you have a more efficient way to do any of these, let me know > matt@drxlr.com

jQuery(document).ready(function(){  
   			
   			//Document's ready. Let's Do This.
   			
   			//Homepage Slider Animation
	    		var curr = 1;
	    		var numThumbs = $(".post-thumbnail").size(); // How many thumbs?
	    		var tL = numThumbs +1 // Add one for "go back" panel

				function slideLeft() {
				      // slide back left
				      	if (curr > 1) {
				     	$("#work-det li.panel, #home .post").animate({
			      			left: "+=990"
			      		}, 220, 'easeOutQuad');
			      		curr --;
				    	}
				}
		
				function slideRight() {
				      // slide right 1 panel
				      	$("#useyerarrows").fadeOut();		      	
				     	if (curr < tP || curr < tL) {
				     	$("#work-det li.panel, #home .post").animate({
			      			left: "-=990"
			      		}, 220, 'easeOutQuad');
			      		curr ++;
			      		return false;
				    	}		
				}
	    		
	    		function scrollRight() {
		    		$("a .next").click(function () {
		      			slideRight();
		      			return false;
		   			})
	   			}
	   			
	   			// If there's more than 1 panel, let's run the function
	   			if (tL > 1 ) {
	   				scrollRight();
	   			}
	   			
   			//Homepage Arrow Fade
	    		$(".post-thumbnail a .next").fadeTo(200, .35);
	    		$("#footer .back-up").fadeTo(200, .2);
	    		$("#home .post").hover(
	    		function () {
	      		$(this).find("img.next").fadeTo(200, 1);
	      		},
	      		function () {
	      			$(this).find("img.next").fadeTo(200, .35);
	   			});
   			
   			//Homepage Slide Startover
	   			$(".start-over").click(function () {
	   			$("img.next").fadeIn();
	   			curr = 1;
	      		$("#home .post").animate({
	      			left: "0"
	      		}, 300, 'easeInOutCirc')
	      		return false;
	   			});	   			
   			//Go Back Up
	   			$("#footer .back-up").hover(
	    		function () {
	      		$(this).fadeTo(150, 1);
	      		},
	      		function () {
	      			$(this).fadeTo(250, .2);
	   			});
	   			//The Click, Nice & Smooth
	   			$(".back-up a").click(function () {
				var anchor = $(this).attr("href");
				$("html, body").animate({scrollTop: $("#wrapper").offset().top }, 200, "swing")
				return false;
				});
   			
   			//External Page Fader
	    		$(".external").hide();
	    		$("#twitter-box a").hover(
	    		function () {
	      		$(".external").fadeIn(200);
	      		},
	      		function () {
	      			$(".external").fadeOut(200);
	   			});
   			
   			//Open That Contact Form - Talk to Us!
	   			$("#contact").hide();
	   			$(".contact-button, a.con-tog").click(function () {
	   			$("#contact").slideToggle()
				return false;
	   			});
	   			$("a.contact-close").click(function () {
	   			$("#contact").slideUp()
	   			return false;
	   			});
   			
   			//Contact Close Button
   			$("a.contact-close span").hide();
   			$("a.contact-close").hover(function () {
   			$("a.contact-close span").fadeIn(200);
   			});
   			$("p.allowed-tags").hide();

   			//The Sharing Bar - (Sharing is Caring)
	    		$("li.share, .close-sb").click(
	    		function () {
	   				$("li.share-bar").slideToggle("fast")
	   				return false;
	      		},
	      		function () {
	   				$("li.share-bar").slideToggle("fast")
	   				return false;
	   			});
	   			
   			//Comment Form
   				$("#commentform").hide();
	    		$("a.add").click(
	    		function () {
	   				$("#commentform").slideToggle("fast")
	   				return false;
	      		},
	      		function () {
	   				$("#commentform").slideToggle("fast")
	   				return false;
	   			});	   			
   			
   			//Work Thumb Hover
   			$(".fav-thumb h3").hide();
   			$("div.fav-thumb").hover(function () {
	      		$(this).find("img").animate({
	      			left: "-150px",
	      			opacity: .2
	      		}, 200);
	      		$(this).find("h3").fadeIn(150);
	      		},function(){
	      		$(this).find("img").animate({
	      			left: "0px",
	      			opacity: 1	      			
	      		}, 200);
	      		$(this).find("h3").fadeOut(150);
      		}); 			
   		
   		//Work Filtering
   		
   		$(function() {

			var newSelection = "";
			
				$("#work-filter a").click(function(){		
				    $(".fav-thumb").fadeTo(100, 0.5);
					$("#work-filter a").removeClass("current");
					$(this).addClass("current");
					newSelection = $(this).attr("rel");
					$(".fav-thumb").not("."+newSelection).hide();
					$("."+newSelection).show();
				//Let em know something happened			
				    $(".fav-thumb").fadeTo(200, 1)
				    return false;
				});
			});

   		//Single Project Arrow Fade
		$("li.panel a .next").fadeTo(0, .2);
		$("li.panel").hover(
		function () {
  		$(this).find("img.next").fadeTo(200, 1);
  		},
  		function () {
  			$(this).find("img.next").fadeTo(200, .2);
			});
	

		//Project Slider Animation
				var curr = 1;
	    		var numPanels = $("li.panel").size(); //Total Panels
	    		var tP = numPanels -1; // -1 to compensate
	    		
	    		function slidePanel() {
		    		$("li.panel a .next").click(function () {
		      		
		      		// if the total panels is less than the current, then do your thing.
		      		if (curr < tP ) {	
		      		curr ++;
		      		$("li.panel").animate({
		      			left: "-=990"
		      		}, 300)
		   			return false;
		      		}		      		
						// Fade next arrows upon reaching the end  
			      		if (curr == tP) {
			      		$("img.next").fadeOut();
		   				} 
		   			})
	   			}
	   			
	   			// If there's more than 1 panel, let's run the function
	   			if (tP > 1 ) {
	   				slidePanel();
	   			}
		
		//Project Slide Startover
	   			$(".start-over").click(function () {
	      		$("#work-det li.panel").animate({
	      			left: "0"
	      		}, 300)
	      		return false;
	   			});
		
		//Hide all imgs with title of thumb
		$("img.attachment-full[title*='thumb']").parent("li").hide();
	
		//Search box text clear
	  	$('#s').one("focus", function() {
		  $(this).val("");
			});
		
		//Somewhat of a Keyboard Nav - Thanks, @rem
		$(document.documentElement).keyup(function (event) {
		    var direction = null;
			
		    if (event.keyCode == 37) {
		    	slideLeft();
		    } 
		    if (event.keyCode == 39) {
				slideRight();
		    }		  
		  });
		  
		  
	  	   	// Multitouch Gesture Support (Just a test)
			//	$('#wrapper').swipe({
			//     swipeLeft: function() {
			//			slideRight();
			//      },
			//     swipeRight: function() {
			// 		    slideLeft();
			//      },
			// });


			$('#home .thumb img').attr('title', '');

		  //Equalize Archive Sidebar Height			
			// get height of the post section
			var getHeight = $(".all-posts").height();
			//compensate for offset
			var newHeight = getHeight + 149;
			//set the new height
			$('#sidebar').css('height', newHeight);


			//SHOP
			
			//Even Class for offset
			$('.product-list li:odd').addClass('even');

			//Call Carousel
			$(function() {
			    $(".prod-main-imgs").jCarouselLite({
			        btnNext: ".next",
			        btnPrev: ".prev",
			        visible: 1
			    });
			});

			//Key Nav for Products
			$(document.documentElement).keyup(function (event) {
			    var direction = null;				
				//Left
			    if (event.keyCode == 37) {
					$('.prod-main-imgs .prev').click(); }
			    //Right 
			    if (event.keyCode == 39) {
			      	$('.prod-main-imgs .next').click(); }
			  });
			
			//var el = $('.eshopwidget');
			//el.html(el.html().replace(/\s+product in cart./gi, 'Item'));

			//var el = $('.eshopwidget');
			//el.html(el.html().replace(/\s+products in cart./gi, 'Items'));
			
			$USofA = $('.eshop #country option[name="US"]');
			$($USofA).before('.eshop #country option[name="AL"]');
			
		// All done, shawty.
			
});
