/*

Written by Mitch Ellems | NBM 2010
www.nbm.com.au

*/

$(function(){
	// Rollover Image Script (use .fadeHover for fading rollover or .imgHover for straight swap)
	
	// Setup Background				   
	$("a.fadeHover, a.imgHover").each(function(){
											
		var bgURL = $(this).find('img').attr('src').replace('_off', '_on');	
		
		$(this).css('background-image', 'url(' + bgURL + ')');
		
	});
	
	// Hover Fade Image		
	$(".fadeHover img").mouseover(function(){
		
		$(this).stop().fadeTo('medium', 0);
		
	});
	
	$(".fadeHover img").mouseout(function(){
		
		$(this).stop().fadeTo('medium', 1);
		
	});

	// Hover Swap Image				 
	$(".imgHover img").mouseover(function(){
		
		$(this).stop().css('opacity', 0);
		
	});
	
	$(".imgHover img").mouseout(function(){
		
		$(this).stop().css('opacity', 1);
		
	});
	
	
	// PNG Swap Scipt - Swaps image with png and sets original image to background (used for curved corner images coming from a system)
	
	// Check browser
	var badBrowser = (/MSIE ((5\.5)|6)/.test(navigator.userAgent) && navigator.platform == "Win32");
	
	// Do not do if IE6 or lower
	if (!badBrowser) {
		$("div.pngSwap").each(function(){	
			
			$(this).css('background-image', 'url(' + $(this).find('img').attr('src') + ')');
			
			if ($(this).attr('id') == '') {
				pngimage = 'default_png';
			} else {
				pngimage = $(this).attr('id');
			}
			
			$(this).find('img').attr('src','/images/backgrounds/' + pngimage + '.png')
				.removeAttr("width").removeAttr("height");
			
		});
	}

});
