
jQuery(document).ready(function($) {
	// Load 'supersleight' plugin for PNG transparancy
	//$('body').supersleight({shim: 'wp-content/themes/tpc-gray/custom/images/x.gif'});
	// Set body.ie6 if appropriate
	if (jQuery.browser.msie && parseInt(jQuery.browser.version) < 7 && parseInt(jQuery.browser.version) > 4) {
		$('body').addClass('ie6');
	}
});

jQuery(window).load(function() {
	jQuery('.split3pages .format_text').equalHeight();
});



/* ---[	Functions Follow ]--- */

// From: http://exscale.se/archives/2007/11/11/jquery-equal-height-elements-plugin/
jQuery.fn.equalHeight = function() {
    var height = 0, 
        maxHeight = 0;

    // Store the tallest element's height
    this.each(function() {
        var t = jQuery(this);
        //height = t.height() + parseInt(t.css('paddingTop'), 10) + parseInt(t.css('paddingBottom'), 10) + parseInt(t.css('borderTopWidth'), 10) + parseInt(t.css('borderBottomWidth'), 10);
        
        var border_top = ( isNaN(parseInt(t.css('borderTopWidth'),10)) ? 0 : parseInt(t.css('borderTopWidth'),10) );
        var border_bottom = ( isNaN(parseInt(t.css('borderBottomWidth'),10)) ? 0 : parseInt(t.css('borderBottomWidth'),10) );
        height = t.height() + parseInt(t.css('paddingTop'), 10) + parseInt(t.css('paddingBottom'), 10) + border_top + border_bottom;
        maxHeight = (height > maxHeight) ? height : maxHeight;
    });

    // Set element's min-height to tallest element's height
    return this.each(function() {
        var t = jQuery(this);
            var border_top = ( isNaN(parseInt(t.css('borderTopWidth'),10)) ? 0 : parseInt(t.css('borderTopWidth'),10) );
            var border_bottom = ( isNaN(parseInt(t.css('borderBottomWidth'),10)) ? 0 : parseInt(t.css('borderBottomWidth'),10) );
        
            mh = maxHeight - (parseInt(t.css('paddingTop'), 10) + parseInt(t.css('paddingBottom'), 10) + border_top + border_bottom );
            //mh = maxHeight - (parseInt(t.css('padding-top'), 10) + parseInt(t.css('padding-bottom'), 10) + parseInt(t.css('border-top-width'), 10) + parseInt(t.css('border-bottom-width'), 10));
            t.height(mh);
            //t.css({minHeight: mh +'px'});
    });
};



jQuery.fn.supersleight = function(settings) {
	settings = jQuery.extend({
		imgs: true,
		backgrounds: true,
		shim: 'x.gif',
		apply_positioning: true
	}, settings);
	
	return this.each(function(){
		if (jQuery.browser.msie && parseInt(jQuery.browser.version) < 7 && parseInt(jQuery.browser.version) > 4) {
			jQuery(this).find('*').each(function(i,obj) {
				var self = jQuery(obj);
				// background pngs
				if (settings.backgrounds && self.css('background-image').match(/\.png/i) !== null) {
					var bg = self.css('background-image');
					var src = bg.substring(5,bg.length-2);
					var mode = (self.css('background-repeat') == 'no-repeat' ? 'crop' : 'scale');
					var styles = {
						'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='" + mode + "')",
						'background-image': 'url('+settings.shim+')'
					};
					self.css(styles);
				};
				// image elements
				if (settings.imgs && self.is('img[src$=png]')){
					var styles = {
						'width': self.width() + 'px',
						'height': self.height() + 'px',
						'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + self.attr('src') + "', sizingMethod='scale')"
					};
					self.css(styles).attr('src', settings.shim);
				};
				// apply position to 'active' elements
				if (settings.applyPositioning && self.is('a, input') && self.css('position') === ''){
					self.css('position', 'relative');
				};
			});
		};
	});
};