/*
24/08/2010         
Behavior jQuery generic live
Reset - Reset input on focusin, focusout
OC - Correction pour :hover
Over - Gestion automatique des changements d'images      
Input et submit - Changement de style automatique pour les inputs          
URL Encode
Hash Change  
Printr - Décrit un objet ou un tableau  
*/


$( document ).ready(
	function () {

		/* RESET INPUT ON FOCUS*/
		$( '.reset' ).live('focusin',
		function () { 
			if($(this).val() == $(this).attr("default"))
			$(this).val('');
		} ); 

		/* RESET INPUT ON BLUR */
		$( '.reset' ).live('focusout',
		function () { 
			if(!$(this).attr("value"))
			$(this).attr("value",$(this).attr("default"));
		} ); 

		/* CHANGEMENT DE CLASS ON MOUSEOVER */
		$( '.oc' ).live("mouseover", function () { 
			$( this ).addClass($( this ).attr("oc"));
		});

		$( '.oc' ).live("mouseout", function () {  
			$( this ).removeClass($( this ).attr("oc"));
		});

		/* ROLLOVER IMAGE - NE FONCTIONNE PAS SI L'ADDRESSE EST ABSOLU */
		$( '.over' ).live("mouseover", function () { 
			$(this).attr("src", $(this).attr("src").split(".").join("_over."));
		});

		$( '.over' ).live("mouseout", function () {  
			$(this).attr("src", $(this).attr("src").split("_over.").join("."));
		});

		/* ACTIVE HREF POUR TOUT ELEMENT */
		$(".href").live("click", 
		function () {    
			window.location.href = $(this).attr("href");
		});

		/* CHANGEMENT DE CLASS POUR LES INPUT - PAS NECESSAIRE UTILISÉ CSS A L'AVENIR */
		$("input[type='text'],input[type='password'],textarea,select").live("mouseover", 
		function () { 

			$( this ).addClass("input_over");
		});

		$("input[type='text'],input[type='password'],textarea,select").live("mouseout", 
		function () {  
			$( this ).removeClass("input_over");
		});

		$(".submit").live("mouseover", 
		function () {  
			$( this ).addClass("submit_over");
		});

		$(".submit").live("mouseout", 
		function () {  
			$( this ).removeClass("submit_over");
		});   

		$(".ajax").live("mouseover", 
		function () {  
			$( this ).addClass("ajax_over");
		});

		$(".ajax").live("mouseout", 
		function () {  
			$( this ).removeClass("ajax_over");
		});   
	   
	}); 


	/* UCFIRST */
	function ucFirst(str) {
		if (str.length > 0) {
			return str[0].toUpperCase() + str.substring(1);
		} else {
			return str;
		}
	}


	/* JUMP MENU */
	function MM_jumpMenu(targ,selObj,restore)
	{  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
	if (restore) selObj.selectedIndex=0;
}


/* UNSET */
function unset(array, valueOrIndex){
	var output=[];
	for(var i in array){
		if (i!=valueOrIndex)
			output[i]=array[i];
	}          
	return output;
}


/* URLENCODE */
$.extend({URLEncode:function(c){var o='';var x=0;c=c.toString();var r=/(^[a-zA-Z0-9_.]*)/;
while(x<c.length){var m=r.exec(c.substr(x));
	if(m!=null && m.length>1 && m[1]!=''){o+=m[1];x+=m[1].length;
		}else{if(c[x]==' ')o+='+';else{var d=c.charCodeAt(x);var h=d.toString(16);
			o+='%'+(h.length<2?'0':'')+h.toUpperCase();}x++;}}return o;},
			URLDecode:function(s){var o=s;var binVal,t;var r=/(%[^%]{2})/;
			while((m=r.exec(o))!=null && m.length>1 && m[1]!=''){b=parseInt(m[1].substr(1),16);
				t=String.fromCharCode(b);o=o.replace(m[1],t);}return o;}
			});

			/* HASH CHANGE */
			(function($,e,b){var c="hashchange",h=document,f,g=$.event.special,i=h.documentMode,d="on"+c in e&&(i===b||i>7);function a(j){j=j||location.href;return"#"+j.replace(/^[^#]*#?(.*)$/,"$1")}$.fn[c]=function(j){return j?this.bind(c,j):this.trigger(c)};$.fn[c].delay=50;g[c]=$.extend(g[c],{setup:function(){if(d){return false}$(f.start)},teardown:function(){if(d){return false}$(f.stop)}});f=(function(){var j={},p,m=a(),k=function(q){return q},l=k,o=k;j.start=function(){p||n()};j.stop=function(){p&&clearTimeout(p);p=b};function n(){var r=a(),q=o(m);if(r!==m){l(m=r,q);$(e).trigger(c)}else{if(q!==m){location.href=location.href.replace(/#.*/,"")+q}}p=setTimeout(n,$.fn[c].delay)}$.browser.msie&&!d&&(function(){var q,r;j.start=function(){if(!q){r=$.fn[c].src;r=r&&r+a();q=$('<iframe tabindex="-1" title="empty"/>').hide().one("load",function(){r||l(a());n()}).attr("src",r||"javascript:0").insertAfter("body")[0].contentWindow;h.onpropertychange=function(){try{if(event.propertyName==="title"){q.document.title=h.title}}catch(s){}}}};j.stop=k;o=function(){return a(q.location.href)};l=function(v,s){var u=q.document,t=$.fn[c].domain;if(v!==s){u.title=h.title;u.open();t&&u.write('<script>document.domain="'+t+'"<\/script>');u.close();q.location.hash=v}}})();return j})()})(jQuery,this);


			/* PRINT_R */
			function printr(theObj)
			{
				if(theObj.constructor == Array ||theObj.constructor == Object)
				{
					document.write("<ul>")
					for(var p in theObj)
					{
						if(theObj[p].constructor == Array||theObj[p].constructor == Object)
						{
							document.write("<li>["+p+"] => "+typeof(theObj)+"</li>");
							document.write("<ul>")
							printr(theObj[p]);
							document.write("</ul>")
						} 
						else 
						{
							document.write("<li>["+p+"] => "+theObj[p]+"</li>");
						}
					}
					document.write("</ul>")
				}
			}