/**
 * jQuery.fullBg
 * Copyright (c) 2010 c.bavota - http://bavotasan.com
 * Dual licensed under MIT and GPL.
 * Date: 02/23/2010
**/

//Modified substantially from original by JM

;(function($) {
  $.fn.fullBg = function(){
    var bgImg = $(this);
 
    function resizeImg() {
		//var imgwidth = bgImg.width();
		//var imgheight = bgImg.height();
		
		var menuwidth = 280;
		
		var winwidth = $(window).width() - menuwidth;
		var winheight = $(window).height();
		
		var widthratio = winwidth / imgwidth;
		var heightratio = winheight / imgheight;
		
		var widthdiff = Math.ceil(heightratio * imgwidth);
		var heightdiff = Math.ceil(widthratio * imgheight);
		
		if(heightdiff>winheight) {
			bgImg.css({
				width: winwidth+'px',
				//height: heightdiff+'px',
				height: winwidth/HeroImageRatio+'px',
				right: 0
			});
		} else {
			bgImg.css({
				width: winheight*HeroImageRatio+'px',
				//width: widthdiff+'px',
				height: winheight+'px',
				right: (winwidth-widthdiff)/2
			});		
		}
	}
	 
	resizeImg();
	
	$(window).resize(function() {
		resizeImg();
	}); 
  };
})(jQuery);

;(function($) {
  $.fn.shiftLogo = function(){
    var Logo = $(this);
 
    function positionLogo() {
		
		var offset = $('#Navigation').height() + 160 + 35;
		
		var ypos = Math.ceil(($('#Header').height() - offset)/2);
		
		Logo.css({
			top: ypos+ 'px'
		});
	}
	 
	positionLogo();
	
	$(window).resize(function() {
		positionLogo();
	}); 
  };
})(jQuery);

;(function($) {
	$(document).ready(function() {
		
		//Set min height on nav
		
		var BodyMinHeight = $('#Navigation').height() + 215 + 'px';
		
		$('body').css('min-height', BodyMinHeight);
		$('#Header').css('min-height', BodyMinHeight);
		
		//--
		
		$("#background").fullBg();
		
		$("#Header h1").shiftLogo();
    
	    //Hide background image and fade in when ready
		//$("#background").hide();
	
		$(window).load(function(){
			//$("#background").fullBg();
			//$("#background").fadeIn();
		});
		
		//Set up FancyBoxes
		$("#facebooklink").fancybox({
			'width': 460,
			'height': 330
		});
		$("#CMLink").attr("href", "#CMForm").fancybox();//Patch href as is messed up by base tag
		
/*
		if ($('#Layout').length != 0){
			$.fancybox(
				$("#Layout").html()
			);
		}
*/
		
	})
})(jQuery);
