/* Scripts for Balance of Fitness */

var bof = {};

$(document).ready(function() {
	bof.ui.slideshow();
	if ( /MSIE ((5\.5)|[6])/.test(navigator.userAgent) && navigator.platform == 'Win32' ) {
		bof.iehelper.fixPngs(); // help ie6 render transparent pngs correctly
	}
});

bof.config = {
	blankSrc: '/wp-content/themes/bof/images/spacer.gif'
};

bof.ui = {
	slideshow: function() {
		if ( $('body#home').length > 0 ){
			$('#slideshow').crossSlide({
				speed: 30,
				fade: 1
				}, [
					{ src: '/wp-content/themes/bof/images/photo4.jpg',  dir: 'up'   },
					{ src: '/wp-content/themes/bof/images/photo2.jpg',   dir: 'down' },
					{ src: '/wp-content/themes/bof/images/photo5.jpg', dir: 'down' }
			]);
		}
	}
};

bof.iehelper = {
	fixPngs: function() {
		var type, background_image, background_repeat;
		$('.pngfix').each(function() {
			type = this.tagName.toLowerCase();

			if ( type == 'input' || type == 'img' ) {
				if ( (type == 'input' && this.getAttribute('type') == 'image') || this.src.toLowerCase().search(/\.png$/) ) {
					bof.iehelper.fixPng(this);
					$(this).bind('propertychange', function() {
						bof.iehelper.fixPng(this);
					});
				}
			}

			background_image = $(this).css('background-image');

			if ( background_image.toLowerCase().search(/\.png"\)$/) < 0 ) return;

			background_image = background_image.substring(5, background_image.length-2);
			background_repeat = $(this).css('background-repeat');
			this.style.background = 'none';

			if ( background_repeat == 'no-repeat' ) {
				this.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + background_image + "', sizingMethod='crop')";
			} else {
				this.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + background_image + "', sizingMethod='scale')";
			}
		});
	},

	fixing: false,
	fixPng: function(obj) {
		if ( bof.iehelper.fixing ) return;

		bof.iehelper.fixing = true;

		var src = obj.src;

		if ( new RegExp(bof.config.blankSrc).test(src) ) {
			bof.iehelper.fixing = false;
			return;
		}

		obj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src  + "', sizingMethod='image')";

		$(obj).bind('beforeprint', function(imgObjSrc) {
			return function() {
				this.src = imgObjSrc;
			}
		}(obj.src));

		$(obj).bind('afterprint', function() {
			this.src = bof.config.blankSrc;
		});

		obj.src = bof.config.blankSrc;
		bof.iehelper.fixing = false;
	}
};
