/*
    ---------------------------
	SHARED JAVASCRIPT FUNCTIONS
	---------------------------
	KANZO 2009
	---------------------------
*/
window.addEvent('domready', function() {
		
	/*
		-----------------------------------
	
		Add image roll-overs and preloaders
	
		Usage:
		assign class 'goodDog' to image
		default image name must end '-off'
		hover image name must end '-on'
	
		-----------------------------------
	*/
	$$('img.goodDog','input.goodDog').each(function(img) {
			var src = img.getProperty('src');
			var extension = src.substring(src.lastIndexOf('.'),src.length);
			var preloadImg = new Image(100,25); 
			preloadImg.src = src.replace('off' + extension,'on' + extension);
			img.addEvent('mouseenter', function() { img.setProperty('src',preloadImg.src); });
			img.addEvent('mouseleave', function() { img.setProperty('src',src); });
	});
	
	/*
		-----------------------------------
		
		Open links in a new window
		
		Usage:
		Automatically opens links begining http:// or https://
		in a new window. Add a class to the anchor to open other 
		links in a new window. set class name below or leave 
		as default
				
		-----------------------------------
	*/
	// Set class sttribute
	var newWinClass = 'newWindow';
	/*
		Add class to links beginning http:// or https://
	*/
	$(document.body).getElements('a[href^=http://]').addClass(newWinClass);
	$(document.body).getElements('a[href^=https://]').addClass(newWinClass);
	/*
		Open specific links in a new window
	*/
	$$('.'+newWinClass).each(function(el) {
		el.addEvent('click', function(e) {
			e.stop();
			window.open (el.href);
		});
	});
});