/*
===== CONTENTS =================================
	module - jQuery plugins
	last-updated: 2008.2.6;
	note:
================================================

    * Compatibility Plugin for jQuery 1.1 (on top of jQuery 1.2)
    * set_rollovers 
    
================================================
*/


/*
 * Compatibility Plugin for jQuery 1.1 (on top of jQuery 1.2)
 * By John Resig
 * Dual licensed under MIT and GPL.
 *
 * For XPath compatibility with 1.1, you should also include the XPath
 * compatability plugin.
 */

(function(jQuery){

	// You should now use .slice() instead of eq/lt/gt
	// And you should use .filter(":contains(text)") instead of .contains()
	jQuery.each( [ "eq", "lt", "gt", "contains" ], function(i,n){
		jQuery.fn[ n ] = function(num,fn) {
			return this.filter( ":" + n + "(" + num + ")", fn );
		};
	});

	// This is no longer necessary in 1.2
	jQuery.fn.evalScripts = function(){};

	// You should now be using $.ajax() instead
	jQuery.fn.loadIfModified = function() {
		var old = jQuery.ajaxSettings.ifModified;
		jQuery.ajaxSettings.ifModified = true;
	
		var ret = jQuery.fn.load.apply( this, arguments );
	
		jQuery.ajaxSettings.ifModified = old;

		return ret;
	};

	// You should now be using $.ajax() instead
	jQuery.getIfModified = function() {
		var old = jQuery.ajaxSettings.ifModified;
		jQuery.ajaxSettings.ifModified = true;
	
		var ret = jQuery.get.apply( jQuery, arguments );
	
		jQuery.ajaxSettings.ifModified = old;

		return ret;
	};

	jQuery.ajaxTimeout = function( timeout ) {
		jQuery.ajaxSettings.timeout = timeout;
	};

})(jQuery);

/***
* 
* $.set_rollovers
*
* Use:
* set_rollovers( @options )
* 
***/

(function($){

jQuery.fn.set_rollovers = function( options ){
   var settings = {
      extension: '_o',
      hover_extension: '_h',
      fade: false,
      menu:{},
      menu_type: 'files'
   };
   if(options){ jQuery.extend(settings, options); };
   
   var path = String(document.location);
   var active = false;
   var longest_match = 0;
   $.each( settings.menu , function( menu_path ){
      if( settings.menu_type == 'files' ){
         if( menu_path.match(/|/) ){
            menu_path_arr = menu_path.split('|');
            for( k=0; k<menu_path_arr.length; k++ ){
               if( path.match( menu_path_arr[k] ) && menu_path_arr[k].length>longest_match ){ active = settings.menu[menu_path_arr[k]]; longest_match = menu_path_arr[k].length; };
            };
         } else {
            if( path.match( menu_path ) && menu_path.length>longest_match ){ active = settings.menu[menu_path]; longest_match = menu_path.length; };
         };
      } else if( settings.menu_type == 'nodes' ){
         if( $(menu_path).length ){ active = settings.menu[menu_path]; };
      };
   });
   
   return this.filter( '[src*='+ settings.extension +'.]' ).each(function(){
      var roll = new Image;
      roll.src = this.src.replace( settings.extension+'.', settings.hover_extension+'.');
      if( this.src.match(/[^\/]+$/)[0] == active){ this.src = this.src.replace( new RegExp(settings.extension+"(\.[a-z]+)$"), settings.hover_extension+"$1"); }
      else{
         this._hsrc = this.src.replace( new RegExp(settings.extension+"(\.[a-z]+)$") , settings.hover_extension+"$1");
         this._src = this.src;
         if( !settings.fade ){
            $(this).mouseover(function(){ this.src = this._hsrc; }).mouseout(function(){ this.src = this._src; });
         } else {
            var img_holder = $(this).wrap('<span style="position:relative; display:block;"></span>').parent();
            img_holder.append('<img src="'+roll.src+'" style="position:absolute; top:0; left:0;" />');
            img_holder.find('> :last-child').hide();
            img_holder.hover(
               function(){ $("> img:last-child", this).fadeIn(settings.fade); },
               function(){ $("> img:last-child", this).fadeOut(settings.fade); }
            );
         };
         if( this.parentNode.nodeName.match(/^a$/i) ){
            $(this).parent().focus(function(){ $(">img", this).trigger("mouseover"); }).blur(function(){ $(">img", this).trigger("mouseout"); });
         }else if( this.parentNode.nodeName.match(/span/i) && this.parentNode.parentNode.nodeName.match(/a/i) ){
            $(this).parents("a").focus(function(){ $("> span > img:last-child", this).fadeIn(settings.fade); }).blur(function(){ $("> span > :last-child", this).fadeOut(settings.fade); });
         };
      };
   });
};

})(jQuery);



