/**
 * Using jQuery in Magento requires noConflict() mode
 */

 (function($) { 
	$(document).ready(function(){	
		//Preload any hover images
		$('img.wh-roll').each(function(){
			this.ExtraImage= new Image();
			this.ExtraImage.src = addSuffix(this.src,'_on');
		});
		//Create roll over images on any image with wh-roll as its class
		$('img.wh-roll').hover(
			function(){
				//Over function
				this.src = addSuffix(this.src,'_on');
			},
			function(){
				//Out function
				this.src = remSuffix(this.src,'_on');
			});
		//If the user clicks in the subscribe inputs then clear out the default text
		$('.block-mailing input[type="text"]').one("click", function(){
			$(this).attr("value","");
		});
		//Top link hover code
		//find the <li> element
		$('.header ul.links li').hover(
			function(){
				//On hover over set the:
				//	<li> background position to "background-position:left -104px"
					$(this).addClass('on');			
			},
			function(){
				//On hover out remove the extra css
					$(this).removeClass('on');
			});
					
		//Show Hide the more text on the home page		
		$('div.more').hide();
		$('.intro a.more').toggle(
			function(){
				var arrow = $('.intro a.more img');
				//$(arrow).attr("src",addSuffix($(arrow).attr('src'),'-on'));
				$(this).html("hide <img src='"+addSuffix($(arrow).attr('src'),'-on') + "'/>")
			},
			function(){
				var arrow = $('.intro a.more img');
				//$(arrow).attr("src",remSuffix($(arrow).attr('src'),'-on'));
				$(this).html("more <img src='"+remSuffix($(arrow).attr('src'),'-on') + "'/>")
			}
		);
		$('.intro a.more').click(
			function(){
				$('div.more').slideToggle(500);
			});
	}); 

	/**
	* Helper functions
	*/
	function popupWindow(myurl, myheight, mywidth, mywindowID) {
	 	if(window.open){
			window.open(myurl,mywindowID,'alwaysRaised=yes,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width=' + mywidth
			+ ',height=' + myheight
			+ ',screenX=150,screenY=150,top=150,left=150');
			return false;
	 	}else{
	 		return true;
	 	}
	}
	function remSuffix(a,b){
		//removes suffix b from filename a without removing the file extension
		var lastdot = a.lastIndexOf(b + '.');
		if (lastdot==-1){
			return a;
		} else {
			var ext = a.slice(lastdot+b.length,a.length);
			return a.slice(0,lastdot) + ext;
		}		
	}
	function addSuffix(a,b){
		//adds suffix b to filename a without removing the file extension
		var lastdot = a.lastIndexOf(".");
		if (lastdot==-1){
			return a;
		} else {
			var ext = a.slice(lastdot,a.length);
			return a.slice(0,lastdot) + b + ext;
		}
		
	} 
 
 })(jQuery)
