/************************************************************
 ** All functions relate to the single-post gallery
 ** By: 	Chmabers Judd (chambersjudd.com)
 ** 
 **	
 ** 
 ** 
 ***********************************************************/

// SET VARS
var currentImage = 1;
var totalImages = 0;
var vimHeight = 0;
var isVimeo = false;
var showSubmit = false;
var start = false;
var pageTitle = "";
$(window).resize(function() {
	positionNav();
});


$(document).ready(function() {
	
	$(function() {
		$.swapImage(".swapImage", true, true, "mouseenter", "mouseleave");
	});
	
	$(this).mousemove(function(e){
		if(start==false){
			start=true;
			positionNav();
			$('.srcBtn_holder').delay(300).fadeIn(200);			
			$('.title-holder').delay(400).html(pageTitle).fadeIn(200);	
			$('.nav-holder').delay(500).fadeIn(200);
			$('#page .description .content').css('display', 'inline').animate({'opacity': 0 }, {duration:0}, "jswing" );
			$('.title-holder').delay(700).html(pageTitle);				
			
		} else if (start=='single'){
			positionNav();
			$('.srcBtn_holder').delay(300).fadeIn(200);			
			$('.title-holder').delay(400).html(pageTitle).fadeIn(200);	
			$('.nav-holder').delay(500).fadeIn(200);			$('#page .description .content').css('display', 'inline');

		}
	});
 
	
	$(this).find('.content').stop(false,true).animate({'opacity': 0 }, {duration:0}, "jswing" );

	$(function() {
	  $("#page .description").hover(function() {
		$(this).find('.content').stop(false,true).animate({'opacity': 1 }, {duration:300}, "jswing" );
	  }, function() {
		$(this).find('.content').stop(false,true).animate({'top': '0px' }, {duration:300}, "jswing" ).animate({'opacity': 0, 'top': '0px' }, {duration:300}, "jswing" );
		
	  });
	});
	
	
	$(".shareBtn ").click(
	  function () {	
				$(this).parent().parent().parent().stop(false,true).animate({'top': '-264px' }, {duration:500}, "jswing" );
		}
	);
	
	$(".hide-share").click(
	  function () {	
				$(this).parent().parent().parent().stop(false,true).animate({'top': '0px' }, {duration:500}, "jswing" );

		}
	);
	
	
	//alert(navW);
	
	// EVENTS
	
	// shink search
	var searchH = '60px';
	$("#searchTop").animate({height: 0}, {duration:0}, "jswing");
		
	$(".srcBtn").click(
	  function () {	
			if($(document).find('#searchTop').css('height') == '0px'){
				$("#searchTop").animate({height: searchH}, {duration:600}, "jswing");
			}else{
				$("#searchTop").animate({height: 0}, {duration: 600}, "jswing");
			}
		}
	);

	// shink about
	var aboutH = '335px';
	$("#aboutTop").animate({height: 0}, {duration:0}, "jswing");
		
	$("#aboutBtn").click(
	  function () {			
			if($(document).find('#aboutTop').css('height') == '0px'){
				$("#aboutTop").animate({height: aboutH}, {duration:600}, "jswing");
			}else{
				$("#aboutTop").animate({height: 0}, {duration: 600}, "jswing");
			}
		}
	);
	
	// shink submit
	var submitH = '240px';
	if(showSubmit == false){
		$("#submitTop").animate({height: 0}, {duration:0}, "jswing");
	}else{
		$("#submitTop").animate({height: submitH}, {duration:0}, "jswing");
	}
		
	$(".submitBtn").click(
	  function () {			
			if($(document).find('#submitTop').css('height') == '0px'){
				$("#submitTop").animate({height: submitH}, {duration:600}, "jswing");
			}else{
				$("#submitTop").animate({height: 0}, {duration: 600}, "jswing");
			}
		}
	);
	
	// hide
	$(".hide-it").click(
	  function () {	
			$(this).parent().parent().parent().animate({height: 0}, {duration: 600}, "jswing");
		}
	);

});


	function positionNav(){
		// move nav holder to the right 
		// doc width
		var docW = $(window).width();
		var logoW = parseFloat($('.logo_holder').css('width'));
		var navW = parseFloat($('.nav-holder').css('width'));
		var srcW = parseFloat($('.srcBtn_holder').css('width'));
		var titW = parseFloat($('.title-holder').css('width'));
		var rightPad = 20;
		var padLeft = docW - logoW - navW - srcW - titW - rightPad;
		$('.nav-holder').css('paddingLeft', padLeft+'px');
	}



	$.fn.delay = function(time, callback){
		// Empty function:
		jQuery.fx.step.delay = function(){};
		// Return meaningless animation, (will be added to queue)
		return this.animate({delay:1}, time, callback);
	}
	
	

	function toTop() {
		$('html, body').animate({scrollTop:0}, 'fast'); 
	}
	
	jQuery.preloadImages = function()
	{
	  for(var i = 0; i<arguments.length; i++)
	  {
	    jQuery("<img>").attr("src", arguments[i]);
	  }
	}
	
	
	$(function() {
	   	$("#about .aboutLink").click(function () {
				
				var t = $('#about .content').css('top');

				if(t == "-85px")
				{
					
					$("#about .content").animate({backgroundColor: '#FDF800', 'top': 0}, 360);
					$("#header").animate({'marginBottom': 80}, 360);
				
				}
				else if(t == "0px") 
				{
					$("#about .content").animate({backgroundColor: '#FDF800', 'top': -85}, 360);
					$("#header").animate({'marginBottom': 30}, 360);
					
				}
		})

	}
	)
	
	// About
	//$(function() {
	//  $("#about").hover(function() {
	//	$(this).find('.content').stop(false,true).animate({'left': 0 }, {duration:200}, "jswing" );
	// }, function() {
	//	$(this).find('.content').stop(false,true).animate({'left': -600 }, {duration:200}, "jswing" );
	// });
	//});


	
	
	// Bottom search bar
	// Back to top 
	$(function() {
	   $(".totop").click(function () { 
	      toTop(); 
	    });
	});
	

	// Flash object resize
	// 
	$(function() {
	   //$(this).find('object').setAttributeNode("width").value = "200";
	});

	$(function() {
    	//$(document).find('.content').corner();
    	//$(this).find('.item .content').corner();
    	//$(this).find('.pagecont').corner();

    	//$(this).find('.catdd .content').corner();
	});

	
	
