$(document).ready(function () {

	// say whether JS is enabled (add a class to the body tag)
	$("body").addClass("js");

	/* HOMEPAGE */
	// rescale the homepage's bkgd img
	if ($("body#home").length > 0) {
		rescale();
		$(window).resize(function(){
			rescale();
		});
	}

	/* CUFON */
	if ($.browser.msie && $.browser.version.substr(0,1)<7) {
		// do nought if IE6
	} else {

		Cufon.replace('h1');
		Cufon.replace('h2');
		Cufon.replace('#introtext p');

	}

	
	
	/* CONTACT PAGE */
	if ($("body#contact").length > 0) {
		rescaleContact();
		$(window).resize(function(){
			rescaleContact();
		});
	}

	/* PROJECTS/WORK PAGE */
	$("#clientList li .entry").hide();
	$("#clientList li h4 a").click(function () { 
		$(this).toggleClass('on');
		$(this).parent().next(".entry").slideToggle('fast');
		return false;
    });

});


//function rescale() {
//	// alert("Blimey");
//	var max_height = $(window).height();
//	var max_width = $(window).width();
//	var min_width = 960;
//	//alert (max_width);
//
//	var height = $("#bkg img").height();
//	var width = $("#bkg img").width();
//	var ratio = height/width;
//
//	// If height or width are too large, they need to be scaled down
//	// Multiply height and width by the same value to keep ratio constant
//	ratio = max_height / height;
//	height = (height * ratio);
//	width = width * ratio;
//
//	if (width < max_width) {
//		// alert ("image width smaller than window width")
//		ratio = max_width / width;
//		height = height * ratio;
//		width = width * ratio;
//	}
//
//	$("#bkg img").height(height);
//	$("#bkg img").width(width);
//	//$("#bkg").height(height);
//	//$("#content").css("top",height);
//}

function rescale() {
	// alert("Blimey");
	var max_height = $(window).height();
	var max_width = $(window).width();
	var min_width = 960;
	//alert ($(window).width());

	var height = $("#bkg img").height();
	var width = $("#bkg img").width();
	var ratio = height/width;

	// If height or width are too large, they need to be scaled down
	// Multiply height and width by the same value to keep ratio constant
	ratio = max_height / height;
	height = height * ratio;
	width = width * ratio;

	if (width < max_width) {
		// alert ("image width smaller than window width")
		ratio = max_width / width;
		height = height * ratio;
		width = width * ratio;
	}

	$("#bkg img").height(height);
	$("#bkg img").width(width);
	$("#bkg").height(max_height);

	// set top/left
	var top = $("#bkg img").offset().top;
	var left = $("#bkg img").offset().left;
	top = Math.round((max_height - height)/2);
	left = Math.round((max_width - width)/2);
	$("#bkg img").css("margin-top",top);
	$("#bkg img").css("margin-left",left);

}


function rescaleContact() {
	//alert("Blimey");
	var max_height = $(window).height();
	var min_height = 600;

	var height = $("#bkg #map").height();

	if (min_height < max_height) {
		$("#bkg #map").height(max_height);
		$("#bkg").height(max_height);
	}

}