// JavaScript Document

// ROLLVOERS
//alert("script loaded");


$(document).ready( function()
{
   DEPR.rollover.init();
});

 $(window).load(function () {
      // run code
	  //$('#what-is-depression').attr('src', 'images/depression/btn-what-is-depression_o.gif');
    });

DEPR = {};

DEPR.rollover = 
{

   init: function()
   {
      this.preload();
	  // holds the active button, "#what-is-depression" is default active
 		var activeId="#what-is-depression";
		// holds the last active button
		var inactiveId=activeId;
	  	var inactiveIdSrc;

	  // add to navItems for hover functions
	  $(".navItem").hover(
         
         //alert($(this).attr( 'src', DEPR.rollover.newimage($(this).attr('src')) ));
         function () { $(this).attr( 'src', DEPR.rollover.newimage($(this).attr('src')) ); }, 
         function () { $(this).attr( 'src', DEPR.rollover.oldimage($(this).attr('src')) ); }
      
      );
	 
	 
	 // bind for click functions
	 $(".navItem").click(
         
		/*set last active button back to normal state*/
		function () { 
			if (inactiveId){
				//alert("this is teh inactive ID source" + $(inactiveId).attr('src'));
				inactiveIdSrc = (($(inactiveId).attr('src')).replace(/_o\./, '.'));
				$(activeId).attr('src', inactiveIdSrc);
			}
			// current id set
			activeId = "#" + $(this).attr('id'); 
			$(activeId).attr('src', DEPR.rollover.newimage($(activeId).attr('src'))   );
			// hold current / make it the "old" id
			inactiveId = activeId;
		}
      );
      
      
   },


// PRELOAD FUNCTIONS
   preload: function()
   {
      //$(window).bind('load', function() {
         //$('.navItem').each( function( key, elm ) { $('<img>').attr( 'src', DEPR.rollover.newimage( $(this).attr('src') ) ); });
      //});
   },
   
   newimage: function( src )
   { 
       
            return src.substring( 0, src.search(/(\.[a-z]+)$/) ) + '_o' + src.match(/(\.[a-z]+)$/)[0]; 
       
   },

   oldimage: function( src )
   { 
        
            return src.replace(/_o\./, '.'); 
      
	
   }
};