 $(document).ready(function(){
  

 
 	
	
	//$('#contact_form #cheque').blur(
		//function(){
			//var cVal = $(this, 'input').val();
				//if (cVal == 'yep') {
					//$('#contact_form form').attr('action', 'email.php');			
				//}
			//}
						
	
	// );
	
	
	//$("div.sb-ct").html('<button class="submit" type="submit">Send Message</button>');
	//$('#contact_form').prepend('<form method="post" id="ajax_form" action="email.php">');
 
  
  $(".tweet").tweet({
            username: "jakewoneal",
            count: 1,
            auto_join_text_default: "I said:",
            auto_join_text_ed: "I",
            auto_join_text_ing: "I was",
            auto_join_text_reply: "I replied to",
            auto_join_text_url: "I was checking out",
            loading_text: "loading tweets..."
        });
  
  
  var bodyMinWidthCss = $("body").css("min-width");
  var bodyMinWidth = parseInt(bodyMinWidthCss.substring(0,bodyMinWidthCss.indexOf("px")))
  
  var headerOpenHeight = $('#header-wrap').height();
  
  //set closed dimensions
 
  var sectionClosed = 90;
  var cardClosed = 60;
  var headerClosed = 165;
  
  // set ease types
  var cardEaseType = 'easeOutBack'
  var sectionEaseType = 'easeOutExpo'
  
 
  //set hover colors
  var cardInactive = '#ededed';
  var cardInactiveBorder = '#d4d4d4'
  var cardActive = '#fff';
  


  $("#header-wrap").height(headerClosed);
  $(".section").height(sectionClosed);
  $(".section").width('500%')
  $(".card-xpand").width(cardClosed);
  $(".card").css("margin-left"," -300px");
  $(".card").css("background-color",cardInactive);
  $(".card").css("border-color", cardInactiveBorder );
  $(".nav-arrow").css({display:"none"});
  //$(".full-size").css("display", "none");



  //nav  
  
 
	var scrollZone = 60;
	var winTop = $(window).scrollTop();
	var winHeight = $(window).height();
	var winLeft = $(window).scrollLeft();
	var winWidth = $(window).width();
	var docWidth = $(document).width();
	var wrBorder = winLeft + winWidth;	
	var isInScrollZone = false;
	
  	setInterval(constVars,1);
	
	
 	function constVars () {
		winLeft = $(window).scrollLeft();
		winWidth = $(window).width();
		winTop = $(window).scrollTop();
	}
	

	
	$(document).mousemove(function(e){
		if (winWidth < bodyMinWidth) {//if the window is small enough to need scroll arrows
		if ((winLeft > 0 && e.pageX < (winLeft+scrollZone)) || e.pageX > ((winLeft+winWidth)-scrollZone)) {
				isInScrollZone = true;
				//$(".nav-arrow").css({display:"block"}); // display both
			} else {
				isInScrollZone = false;
				$(".nav-arrow").css({display:"none"});
			};
			
			if (e.pageX > ((winLeft+winWidth)-scrollZone) && (winLeft != (docWidth-winWidth))){ // if the mouse is in the right side scroll zone
					$(".nav-arrow-right").css({display:"block"}); // display right arrow
				};
				
			if((winLeft > 0 && e.pageX < (winLeft+scrollZone))){//if the mouse is in the left side scroll zone and page isn't at left scroll zero
						$(".nav-arrow-left").css({display:"block"}); // display left arrow
			};
			
			if (winLeft != 0) {// when you scroll away from zero, the "back" (left) arrow is constantly visible
				//$(".nav-arrow-left").css({display:"block"});				
			}
			
			//$(".nav-arrow-arrow").css({top:(e.pageY-winTop)}); //the nav arrow follows the mouse's Y position
			
			
		};
		});
	
	
	var hasScrolled = false;
	var scrollEaseTime = 500;
	var scrollEaseType = 'easeInOutQuad';
	
	$('.nav-arrow-right').click(function() {
		
  		$('html, body').animate({
			scrollLeft: winLeft+(winWidth/2)}, {
					duration:scrollEaseTime,
					easing:scrollEaseType,
					complete: function(){
							hasScrolled = true;
							//closeCard();	
						}
					});
	});

	$('.nav-arrow-left').click(function() {
		
  		$('html, body').animate({
			scrollLeft: winLeft-(winWidth/2)}, {
					duration:scrollEaseTime,
					easing:scrollEaseType,
					complete: function(){
							hasScrolled = true;
							//closeCard();	
						}
					});
	});

	

  
	$(".title").toggle(
	  function () {
        $("#header-wrap").animate( {height:headerOpenHeight}, {queue:false, duration:300, easing: sectionEaseType});
      }, 
      function () {
         $("#header-wrap").animate( {height:headerClosed}, {queue:false, duration:300, easing: sectionEaseType});	
      }
	);
	

	
	
	function preventDefault(e) {
    	e.preventDefault();
	}
	$(".section").bind("click", preventDefault);

	$(".section").hover(
		function(){
			isVisitingLink = false;
			$(this).css({borderLeft: "5px solid #fcdf00"});// Yellow left border
		},
		function (){
			if (isInScrollZone == false){
				$(this).css({borderLeft: "none"});
			};
		}
	);

	
	
	$(".section").click(
		function () {
			if ($(this).height() == sectionClosed) {
				$(this).animate( {height:"465"}, {
								queue:false,
								duration:300,
								easing: sectionEaseType,
								complete: function (){
										$(this).unbind("click", preventDefault);
									}
								});
				
				$(this).siblings().animate( {height:sectionClosed}, {queue:false, duration:300, easing: sectionEaseType});
				$(this).siblings().bind("click", preventDefault);
			}
			else {
				if (isVisitingLink == false) {
				$(this).animate( {height:sectionClosed}, {queue:false, duration:300, easing: sectionEaseType});
				$(this).bind("click", preventDefault);
				closeCard();
				}
			}
			
		}
	);
	
	var isVisitingLink = false;
	
	
	

	function deactivateCat(){
		$(".category-titles").css({backgroundColor: "#1b1b1b", color: "#fcdf00"});
	};
  
 
  
  $(".category").hover(
		function(){
			
			//$(this).children(".category-titles").addClass("active-cat");
			deactivateCat();
			$(this).children(".category-titles").css({backgroundColor: "#fcdf00", color: "#333"});	
		},
		function(){
			deactivateCat();
		}
	);
  
  function closeCard(){
  	$(".openCard").children().css("border-color", cardInactiveBorder);
    $(".openCard").animate( {width:cardClosed}, {queue:false, duration:400, easing: 'easeOutQuad' });
	$(".openCard").children().animate( { backgroundColor: cardInactive }, {queue:true, duration:400});
	$(".openCard").removeClass("openCard");
  }
  
  	$(".card").prepend('<a href="#"><img src="images/full-size.png" width="139" height="141" class="full-size" alt="" /></a>');// add 'fullsize.png' images
  
  	$('.card').each(function() {//give 'fullsize' images the same href as the thumnail preview
		var cardLink = $(this).children("a:nth-child(2)").attr('href');
		$(this).children("a:nth-child(1)").attr('href', cardLink);
	});
  

	var thisSectionHeight = sectionClosed;
  
	$(".card-xpand").hover(
      function () {
		  isVisitingLink=false;
		  var thisSectionHeight = $(this).parent().parent().parent('.section').height();
	  if ((isInScrollZone == false) && (thisSectionHeight > sectionClosed)) {
		$(this).children().css("border-color", "#fff");
        $(this).animate( { width:"338"}, {
			queue:false,
			duration:400,
			easing: cardEaseType,
			complete: function(){
					
					if (hasScrolled == true) {
						hasScrolled = false;
						closeCard();
					}
					closeCard();
					$(this).addClass("openCard");
				}
			});
		$(this).children().animate( { backgroundColor: cardActive }, {queue:true, duration:200});
		}
		}, 
      function () {
	  	if (isInScrollZone == false && isVisitingLink == false) {
		 $(this).parent().children(".category-titles").removeClass("active-cat"); 
		 $(this).removeClass("openCard");
		 $(this).children().css("border-color", cardInactiveBorder);
         $(this).animate( {width:cardClosed}, {queue:false, duration:400, easing: 'easeOutQuad' });
		 $(this).children().animate( { backgroundColor: cardInactive }, {queue:true, duration:400});
		}
	  }
    );
	
	
		$(".card a").click(
		function() {
			isVisitingLink = true;
		}		  
	);

});//document ready end