$(document).ready(function() {
	
	
	/* Full screen background image */
	$(window).bind('resize', function() {
		resizeApp($('div#container'));
		resizeBg($('div.bg img'));
	});
	$(window).bind('load', function() {
		resizeApp($('div#container'));
		resizeBg($('div.bg img'));
	});
	
	function resizeApp(element) {
		element.height($(window).height()-36);
	}
	var photoRatio = 0.75;
	function resizeBg(element) {
		if ($(window).height()/$(window).width() <= photoRatio) {
		 	element.width($(window).width());
		 	element.height($(window).width()*photoRatio);
			//alert('picture width 100%');
		} else {
		 	element.height($(window).height());
		 	element.width($(window).height()/photoRatio);
			//alert('picture height 100%');
		}
		
	}
	
	
	/* Pricing Buttons */
	$('a#show-gbp').addClass('selected');
	$('a#show-aud').click(function() {
		$(this).parent().find('a').removeClass();
		$(this).addClass('selected');
		$('.price-gbp').hide();
		$('.price-aud').show();
	});
	$('a#show-gbp').click(function() {
		$(this).parent().find('a').removeClass();
		$(this).addClass('selected');
		$('.price-aud').hide();
		$('.price-gbp').show();
	});
	
	/* Set Subject Field */
	$('.enquiry').click(function(){
		var subject = $(this).attr("title");
		$('input#subject').val(subject);
	});
	
	
	
	/* Smooth Scroll for inline links */
	$('body a[href*=#]').click(function() {
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
		&& location.hostname == this.hostname) {
			var $target = $(this.hash);
			if ($target.length>0) {
				var targetOffset = $target.offset().top - 72;

                var currentOffset = $('#container').scrollTop();

                $('#container').animate({scrollTop: targetOffset+currentOffset}, 500);
			}
		}
		return false;
	});
	
	
	/* Setup Margin Bottom Offset for each Section */
	$('.section-panel').each(function(){
		var section = $(this);
		var thisOffset = $(window).height()-$(this).height()-36;
		if (thisOffset < 0) {
			section.css("marginBottom", "90px");
		} else {
			section.css("marginBottom", thisOffset);
		}
	});
	
	
	/* Back to Top Button */
	$('#container').scroll(magic);
	$('#container').each(magic);
		
});


function magic() {
	var topPos = $('#home').offset().top;
	//alert(scroll);
    if (topPos < -150) {
		$('#gnav-top, #small-branding').fadeIn(250);
		//$('#bottom').fadeIn(250);
    } else {
  		$('#gnav-top').fadeOut(250);
  		//$('#bottom').fadeOut(250);
  		$('#small-branding').hide();
    }
}