
$(window).load(function() {
	//$("#loader").css("visibility", "hidden");
	$("#loader").delay(0).fadeOut("fast", function() {
    // Animation complete.
	});
	positionMain();
	//console.log("window load");
	//$(".home #content").delay(2300).css("visibility", "visible");
	//$(".home #content").css("display", "none");
	//$("#mainWrap").css("display", "none");
	//$("#mainWrap").hide();
	
	//$("#mainWrap").delay(1500).slideDown(800, "easeInOutExpo");
	
	
    $("#mainWrap").delay(1000).animate({width: "100%"}, 1000, "easeInOutExpo", checkScroller);
		
})

$(function() {	
	//console.log("jQuery load");
	$("#loader").css("visibility", "visible");
	
	//$('.home #content').fadeIn('slow');
	
	//$(".home #content").css("display", "none");
	
	// load the modal window
	$('a.modal').click(function(){
		
		// scroll to top
		$('html, body').animate({scrollTop:0}, 'fast');

		// before showing the modal window, reset the form incase of previous use.
		$('.success, .error').hide();
		$('form#contactForm').show();
		
		//show the mask and contact divs
		$('#mask').show().fadeTo('', 0.8);
		$('div#request').fadeIn();

		// stop the modal link from doing its default action
		return false;
	});

	// close the modal window is close div or mask div are clicked.
	$('div#close, div#mask').click(function() {
		$('div#request, div#mask').stop().fadeOut('fast');

	});


	$(window).resize(function() {
	  positionMain();
	  checkScroller();
	});
	
	
	// Check the max height of the venue list elements
	var highest = 0;
	$('#venuesList li').each(function(){
		if ($(this).height() > highest) { highest = $(this).height(); }
	});
	$('#venuesList li').css('height',highest+'px');
	
	
	// Scroll to bottom of the page
	var $elem = $('body');
	var $elemHeight = $elem.height();
	// clicking the "down" button will make the page scroll to the $elem's height
	$('#pageScroll').click(
		function (e) {
			//console.log($('body').height());
			$('html, body').animate({scrollTop: ($(document).height()-$(window).height())}, 1000, "easeInOutExpo");
		}
	);


});

function positionMain()
{
	var vMarg = ($(window).height() - $("#header").height() - $("#footer").height() - $("#mainWrap").height())/2  ;
	var mainOffset = $("#mainWrap").offset();
	if (vMarg<=30)
	{
		vMarg=30;
	}
	$("#mainWrap").css("margin-top", vMarg);
	
	
	//checkScroller();
}

function checkScroller()
{
	/*var mainOffset = $("#mainWrap").offset();	
	$("#pageScroll").css("top", mainOffset.top - $("#pageScroll").height());*/
	
	var wrapOffset = $("#mainWrap").offset();
	//console.log($("#mainWrap").height())
	if((wrapOffset.top + $("#mainWrap").height()) > ($(window).height() - ($("#footer").height()+24)))
	{
		$("#pageScroll").fadeIn('slow');
	}
	else{
		$("#pageScroll").hide();
	}
	$("#pageScroll").css("top", -35);
	$("#pageScroll").delay(200).animate({top: 32}, 500, "easeOutBack");
}

// Paul Irish @font-face FOUT work around for Firefox 3.5
(function(){
  // if firefox 3.5+, hide content till load (or 3 seconds) to prevent FOUC
  var d = document, e = d.documentElement, s = d.createElement('style');
  if (e.style.MozTransform === ''){ // gecko 1.9.1 inference
    s.textContent = 'body{visibility:hidden}';
    e.firstChild.appendChild(s);
    function f(){ s.parentNode && s.parentNode.removeChild(s); }
    addEventListener('load',f,false);
    setTimeout(f,3000); 
  }
})();

		

