(function ($) {
    if (!$) return;
    $.fn.extend({
        fixPNG: function(sizingMethod, forceBG) {
                if (!($.browser.msie)) return this;
                var emptyimg = "/images/blank.gif"; //Path to empty 1x1px GIF goes here
                sizingMethod = sizingMethod || "scale"; //sizingMethod, defaults to scale (matches image dimensions)
                this.each(function() {
                        var isImg = (forceBG) ? false : jQuery.nodeName(this, "img"),
                                imgname = (isImg) ? this.src : this.currentStyle.backgroundImage,
                                src = (isImg) ? imgname : imgname.substring(5,imgname.length-2);
                        this.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='" + sizingMethod + "')";
                        if (isImg) this.src = emptyimg;
                        else this.style.backgroundImage = "url(" + emptyimg + ")";
                });
                return this;
        }
    });
})(jQuery);

function fixcolheight() {
	var str = '#subpage';
	if($('#homepage').length) str = '#homepage';
	var max=0;
	for(var x=1; x<=4;x++) {
	  $('#homepage .col'+x).css('height','auto');
	}
	
	for(var x=1; x<=4;x++) {
		if(max < $(str +' .col'+x).outerHeight()) max = $(str +' .col'+x).outerHeight();
	}
	for(var x=1; x<=4;x++) {
		var h = parseInt($(str +' .col'+x).css('padding-bottom'));
		$(str +' .col'+x).css('height', (max - h));
	}
	$(str + ' .col2').css('height: auto');
}

function zhoverin() {
	$(this).find('span').addClass('photohover');
}
function zhoverout() {
	$(this).find('span').removeClass('photohover');
}

$(function() { 
	/* Subnav rollover */
   $('#nav li').hover(
        function () {
            //show its submenu
            $('ul', this).fadeIn(75);
 
        }, 
        function () {
            //hide its submenu
            $('ul', this).fadeOut(250);         
        }
    );
 	if(window.isCmsPageEditorPreview) { 
		$('#headerimg').html('<br /><br /><br /><br /><a href="/headerimages.php">Click here to edit the rotating header images.</a>').css('height','338px').css('text-align','center').css('font-size','32px');
/*
		$('#headerimages').fader({
				  'speed': 1200,
			    'timeout':8000,
			    'containerHeight':338,
			    'animationType':'none',
			    'play':false
	
		});
		$('#dots').css('top','345px');
*/
 	} else {
	/* Fading images */	
		if($('#headerimages li').size() > 1) {
			$('#headerimages').fader({
					  'speed': 1200,
				    'timeout':8000,
				    'containerHeight':338
		
			});
		}
	}
	// fix for IE's 24big PNG problem
	$('.item img').fixPNG('scale', true);

	$('.photozoom-right, .photozoom-left').yoxview({
		backgroundColor: '#FFFFFF',
		onSelect: function(imageIndex, image){
			if(!image.media.title.match(/photocredit/)) 
		  		image.media.title += "<div class='photocredit'>"+image.media.alt+"</div>";
		  }
    });
	$('.photozoom-right, .photozoom-left').find('span').remove();
	$('.photozoom-right, .photozoom-left').each(function() { $(this).append('<span />'); });
	$('.photozoom-right, .photozoom-left').hover(zhoverin, zhoverout);
	/* Extend content column height so they all match the max height */
	fixcolheight();
});

