$(document).ready(function()
	{
	$(function () {
			
	if($.browser.msie){
		var img = $("a:not(#logo) img");
	}else{
		var img = $("a img");
	}
	img.hover(function(){
		$(this).animate({ 
        opacity: 0.5
      }, 50 );
	},function(){
		$(this).animate({ 
        opacity: 1
      }, 50 );
	});
		
//////////When you look at me ... I completely disappear
		$("#search").find("input").each(function(){
			var defaultVal = $(this).val();
			var input = $(this);
			var test = 'test';
			$(this).focus(function () {
				$(this).val("");
			});
			
			$(this).hover(function(){
				return false;
			},
			function(){
			if (input.val() == '') {
			//alert(test);
			//setTimeout("alert('" + test +"')",1000);
				setTimeout(function(){
					input.val(defaultVal);	
				},5000);
			};
				
			});
		});
		
//////////Cookie monster just around the corner
		function setCookie(name,value,expiredays){
			var exdate=new Date();
			exdate.setDate(exdate.getDate()+expiredays);
			document.cookie=name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
		}
		
		function getCookie(c_name){
			if (document.cookie.length>0){
			  c_start=document.cookie.indexOf(c_name + "=");
				  if (c_start!=-1){ 
				    c_start=c_start + c_name.length+1; 
				    c_end=document.cookie.indexOf(";",c_start);
				    if (c_end==-1) c_end=document.cookie.length;
				    return unescape(document.cookie.substring(c_start,c_end));
			    } 
			}
		return "";
		}
	
	
//////////Make me bigger or smaller, I don't care		
		
		// Original Font Size
		var originalFontSize = $('#content').css('font-size');
		if ($.browser.msie) {
			var originalFontSize = parseInt(originalFontSize, 10);
		}
		$("#normal").click(function(){
			$('#content').css('font-size', originalFontSize);
			setCookie('textSize',""+ originalFontSize + "",365);
			return false;
		});
		
		var getSizeCookie = getCookie("textSize");
		if(getSizeCookie!=null && getSizeCookie!=""){
			var getSizeCookieNum = parseInt(getSizeCookie, 10);
			$('#content').css('font-size', getSizeCookieNum);
		};
		
		// Increase Font Size
		$("#big").click(function(){
			var currentFontSize = $('#content').css('font-size');
			var currentFontSizeNum = parseInt(currentFontSize, 10);
			var newFontSize = currentFontSizeNum*1.2;
			$('#content').css('font-size', newFontSize);
			setCookie('textSize',""+ newFontSize + "",365);
			return false;
		});
		// Decrease Font Size
		$("#small").click(function(){
			var currentFontSize = $('#content').css('font-size');
			var currentFontSizeNum = parseInt(currentFontSize, 10);
			var newFontSize = currentFontSizeNum*0.8;
			$('#content').css('font-size', newFontSize);
			setCookie('textSize',""+ newFontSize + "",365);
			return false;
		});
		
		
//////////Print me me me...
		$("#print").click(function(){
			window.print();
		});
		

/////////She's The Form, you have to do what she say...
		$(":text").each(function(){
			$(this).addClass("text");
		});
		$(":password").each(function(){
			$(this).addClass("password");
		});
		$(":checkbox").each(function(){
			$(this).addClass("checkbox");
		});
		$(":submit").each(function(){
			$(this).addClass("submit");
		});
		$(":button").each(function(){
			$(this).addClass("submit");
		});
			
			
//////////Put some decoration on my links
		$("a[href$=pdf]").addClass("pdf").attr("target","_blank");
		$("a[href$=xls]").addClass("xls").attr("target","_blank");
		
		
//////////Please help me J.J. Abrams i'm lost...
		if($("#siteMap").length !=0) {
			$("#siteMap").treeview({
				collapsed: false,
				animated: "medium",
				control:"#expandCollapse",
				persist: "location"
			});
		};
		
//////////Tell me where i'm going
		$("a[rel='3m4il']").each(function(){
			var spaceShip = $(this).text();
			var spaceStation = $(this).attr('href');
			
			$(this).replaceWith('<a href="mailto:'+ spaceShip +'@'+ spaceStation +'">'+ spaceShip +'@'+ spaceStation +'</a>');
		});
//////////Sorting the table
		if($("#inventaire").length !=0){
			$("#inventaire").tablesorter({
				sortList: [[0,0]]
			}); 
		};
//////////give me a fence I do not want to see my neighbor
		$('#footerMenu').find('li:not(:last-child)').each(function(){
			$(this).after('<li>|</li>');
		});
		
	});	
});
