jQuery.extend({
	
	isHDireccion:undefined,
	isHCallback: undefined,
	
	isHInit:function(callback){
		// Asignamos los valores a las variables globales
		jQuery.isHDireccion = location.hash;
		jQuery.isHCallback	= callback;
		// Hacemos que cargue por primera vez la url
		if(location.hash != ''){
			if(jQuery.isHCallback != undefined) jQuery.isHCallback(location.hash);
		}
		
		//Añadimos el iframe para IE
		if (jQuery.browser.msie) {
			$('body').prepend('<iframe id="isHIframe" style="display:none;" ></iframe>');
			$("#isHIframe").attr('src', "php/isHIframe.php?random=" + Math.random() + location.hash);
			
		}
		
		// Comprobamos cada cierto tiempo si varia la direccion
		setInterval(jQuery.isHCheck, 100) // Tiempo de llamada del check
	},
	
	isHCheck:function(){
		if(!jQuery.browser.msie){
			var jash = location.hash;
			jash = jash.replace(/%23/g,'#');
			if(jQuery.isHDireccion != jash){
				var jashOld = jQuery.isHDireccion;
				jQuery.isHDireccion = jash;
				
				// Realizamos el callback pasandole el parametro jash
				if(jQuery.isHCallback != undefined) jQuery.isHCallback(jash,jashOld);
			}
		}else{
			var isHIframe = $('#isHIframe')[0];
			//var iframe = isHIframe.contentWindow.document;
			var direcc	= location.href;
			var jash 	=direcc.replace(/^[^#]+/,'');
			
			if(jQuery.isHDireccion !=jash){
				var jashOld = jQuery.isHDireccion;
				jQuery.isHDireccion = jash;

				// Realizamos el callback pasandole el parametro jash
				if(jQuery.isHCallback != undefined) jQuery.isHCallback(jash,jashOld);
			}
			
		}
		
	},
	
	isHLoad: function(jash){
		
		if(jQuery.browser.msie){
			$("#isHIframe").attr('src',"php/isHIframe.php?random="+Math.random()+'#'+ jash);
		}
		var direccion = location.href;
		//direccion = direccion.replace(location.hash,'');
		direccion	= direccion.replace(/#.+$/,'');
		//alert(direccion);
		location.href = direccion + '#' + jash;
		
	}
	
	
});
