$(document).ready(function() {
	
	// Cufon font replacement
	Cufon.replace('h1:not(#content.home h1)', { fontFamily: 'FranklinGothic' });
	
	// PNG fix for IE6
	$.ifixpng.pixel = '/images/pixel.gif';
	$('.enlarge').ifixpng();
	
	/*
	 * imageFrame JS borders for image borders + dropshadows
	 * Modal window for large images in the Image Gallery. Grouped by rel to provide 'back'/'forward' functionality
	 */
	var modal_links = $('a.image-frame:not(.no-modal)')
		.colorbox({
			transition: 'elastic',
			opacity:	0.6
		});
	
	var image_frames = $('a.image-frame')
		.children('img')
		.add('img.image-frame'); // add non-link images with .image-frame
	
	if (isUnderIE8()) { // don't apply imageFrame to hidden elements in IE6/7 or you get wierdness
		image_frames = image_frames.filter(':visible')
	}
	
	image_frames.imageFrame('sharp'); // apply image frame to valid targets
	
	// popup window with options
	$('a[rel~=popup]').click(function(event) {
		var url 	= event.target.href;
		var width 	= getURLParameter('w', url);
		var height 	= getURLParameter('h', url);
		var scroll 	= getURLParameter('s', url);
		
		openPopup(url, url, width, height, scroll);
		
		return false;
	});
	
	// plain new window
	$('a[rel~=new]').click(function(event) {
		window.open($(this).attr('href'));
        
		return false;
	});
	
});

function openPopup(mypage,myname,w,h,scroll)
{
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable';
	
	var realname = myname.substring(1,4);
	
	window.open(mypage, realname, settings);
	return false;
}

function getURLParameter(name, url)
{
	url = (url != null)?url:window.location.href;
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp( regexS );
	var results = regex.exec( url );
	if( results == null )
		return "";
	else
		return results[1];
}

function isUnderIE8()
{
	if (isUnderIE8.is_under_ie8 == true) {
		return true;
	}
	
	if ($.browser.msie && $.browser.version.substr(0, 1) < "8") {
		isUnderIE8.is_under_ie8 = true;
	}
	
	return isUnderIE8.is_under_ie8;
}
isUnderIE8.is_under_ie8 = false;

// helper object method for determining if empty, can't extend prototype as it breaks jQuery
function isObjectEmpty(obj) {
    for(var prop in obj) {
        if(obj.hasOwnProperty(prop))
            return false;
    }
	
    return true;
}