var sitefunctions = 
{
  /* Function to load the JQUERY Plugin to resize fonts */
	textresize : function(){
		// show text resizing links
		var $cookie_name = "sitename-FontSize";
		var originalFontSize = $("html").css("font-size");
		// if exists load saved value, otherwise store it
		if($.cookie($cookie_name)) {
				var $getSize = $.cookie($cookie_name);
				$("html").css({fontSize : $getSize + ($getSize.indexOf("px")!=-1 ? "" : "px")}); // IE fix for double "pxpx" error
		} else {
			$.cookie($cookie_name, originalFontSize);
		}
		// reset link
		$("#FontSizeReset").bind("click", function() {
			$("html").css("font-size", originalFontSize);
			$.cookie($cookie_name, originalFontSize);
			return false;
		});
		
		// text “+" link
		$("#FontSizeInc").bind("click", function() {
  	var currentFontSize = $("html").css("font-size");
  	var currentFontSizeNum = parseFloat(currentFontSize, 10);
  	var newFontSize = currentFontSizeNum*1.2;
  	if (newFontSize, 11) {
    	$("html").css("font-size", newFontSize);
    	$.cookie($cookie_name, newFontSize);
  	}
  	return false;
		});
		
	$("#FontSizeDec").bind("click", function() {
  	var currentFontSize = $("html").css("font-size");
  	var currentFontSizeNum = parseFloat(currentFontSize, 10);
  	var newFontSize = currentFontSizeNum*0.8;
  	if (newFontSize, 11) {
    	$("html").css("font-size", newFontSize);
    	$.cookie($cookie_name, newFontSize);
  		}
  	return false;
		});
	}
	
	,
	
	/* Function to load the JQUERY Plugin "bookmark" */
	share : function () {

    $.bookmark.addSite('fuzz', 'Fuzz', 15, 
        'http://www.fuzz.fr');
    
    $.bookmark.addSite('blogasty', 'Blogasty', 20, 
        'http://blogasty.com/publications');  
        
    $.bookmark.addSite('diggons', 'Diggons', 9, 
        'www.diggons.com'); 
        
    $.bookmark.addSite('paperblog', 'Paperblog', 13, 
        'http://www.paperblog.fr');          
        
    $('#popupBookmark').bookmark(
    {
        sites: ['blogmarks','delicious','digg','facebook','google','myspace','technorati','yahoobuzz','wikio','scoopeo','fuzz','blogasty','diggons','paperblog'],
        icons: 'js/jquery/plugins/bookmark/bookmarks.png',
        compact: true,
        popup: true,
        popupText: '<img src="images/local/skin/plugins/document/picto-share.png" alt="Partager" height="15" width="15">',
        addEmail: false
    });
    
    $('#popupBookmark2').bookmark(
    {
        sites: ['blogmarks','delicious','digg','facebook','google','myspace','technorati','yahoobuzz','wikio','scoopeo','fuzz','blogasty','diggons','paperblog'],
        icons: 'js/jquery/plugins/bookmark/bookmarks.png',
        compact: true,
        popup: true,
        popupText: '<img src="images/local/skin/plugins/document/picto-share.png" alt="Partager" height="15" width="15">',
        addEmail: false
    });
	}
	
	,
	
	/* Function to load a random banner at every loading of pages */
	banner : function () {
	   var randomImages = ['0','1','2','3'];
     var rndNum = Math.ceil(Math.random()*randomImages.length);
     if (rndNum == 1)
     {
        $('#header').css({ background: "#f8ccde url('document?id=1&id_attribute=52') no-repeat 50% 0"});
     }
     else if (rndNum == 2)
     {
        $('#header').css({ background: "#f8ccde url('document?id=2&id_attribute=52') no-repeat 50% 0"});
     }
     else if (rndNum == 3)
     {
        $('#header').css({ background: "#f8ccde url('document?id=3&id_attribute=52') no-repeat 50% 0"});
     }
     else if (rndNum == 4)
     {
        $('#header').css({ background: "#f8ccde url('document?id=4&id_attribute=52') no-repeat 50% 0"});
     }
	}
}

function displayId( baliseId ) 
{
  if (document.getElementById && document.getElementById(baliseId) != null) 
  {
      document.getElementById( baliseId ).style.visibility='visible';
		  document.getElementById( baliseId ).style.display='block';
	}
}

function hideId( baliseId ) 
{
  if (document.getElementById && document.getElementById(baliseId) != null) 
  {
	    document.getElementById( baliseId ).style.visibility='hidden';
		  document.getElementById( baliseId ).style.display='none';
	}
}
							
function minimize( pageId )
{
  hideId('moins_' + pageId);
	displayId('plus_' + pageId);
	hideId('sub-menu-verti_' + pageId);
}

function maximize( pageId ) 
{
  hideId('plus_' + pageId);
	displayId('moins_' + pageId);
	displayId('sub-menu-verti_' +pageId);
}

/* Function to toggle input field value on blur */
function toggleLabel(inputID){ 

$(inputID).val($(inputID).attr('title'));

$(inputID).focus(function(){

if($(this).val() == $(this).attr('title'))

            { $(this).val(''); }

});

$(inputID).blur(function(){

 if($(this).val() == '')

 {  $(this).val($(this).attr('title')); }

 });

}

$(document).ready( function(){
	sitefunctions.banner();
	sitefunctions.textresize();
	sitefunctions.share();
    toggleLabel('#email'); 
    toggleLabel('#searchinput');
	$(".form-element-conditionnel").css( "visibility","hidden");
	$(".form-element-conditionnel").css( "display","none");
	if ($('#message').length > 0){$('#message').limit('1000','#charsLeft');}
});