/* JavaScripts for NdP9.com */

var ndp9 = {};

$(document).ready(function(){
	//ndp9.ui.scrollbars();
	$('#gallery .gallery a').attr('rel', 'lightbox');
	 if(/MSIE ((5\.5)|[6])/.test(navigator.userAgent)&&navigator.platform=="Win32"){
		ndp9.ie.fixPngs();
	}
});

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

ndp9.ui = {
	scrollbars: function() {
		$('#scroll-wrap').jScrollPane({showArrows:true, scrollbarWidth:16});
	}
};

ndp9.ie = {
	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$/) ) {
					ndp9.ie.fixPng(this);
					$(this).bind('propertychange', function() {
						ndp9.ie.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 ( ndp9.ie.fixing ) {return;}

		ndp9.ie.fixing = true;

		var src = obj.src;

		if ( new RegExp(ndp9.config.blankSrc).test(src) ) {
			ndp9.ie.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 = ndp9.config.blankSrc;
		});

		obj.src = ndp9.config.blankSrc;
		ndp9.ie.fixing = false;
	}
};