/**
 * simpleTabs ( http://supercanard.phpnet.org/jquery-test/simpleTabs/ )
 * plugin jQuery pour afficher des bГґites d'onglet.
 * 
 * Version 1.0
 *
 * Auteur : Jonathan Coulet ( j.coulet@gmail.com )
 * 
 **/
(function($){
	$.fn.footerTabs = function(option){
		// Param plugin
		var param = jQuery.extend({
			fadeSpeed: "medium", // @param : low, medium, fast
			//defautContent: 1, // @param : number ( simpleTabs-nav-number)
			autoNav: "false", // @param : true or false
			closeTabs : "true" // @param : true or false;
		}, option);
		$(this).each(function() {
			// Initialisation
			var $this = this;
			var $thisId = "#"+this.id;
			var nbTab = $($thisId+" > div").size();
			autoNav();
			//showCloseTabs();
			hideAll();
			changeLi();

			function hideAll(){
				$($thisId+" .footerTabs-content").hide();
			}
			function changeContent(indice){
				$($thisId+" .footerTabs-nav li").removeClass("actif");
				hideAll();
				$($thisId+" #footerTabs-nav-"+indice).addClass("actif");
				$($thisId+" #footerTabs-content-"+indice).fadeIn(param.fadeSpeed);
			}
			
			function changeLi(indice){
				hideAll();
				$($thisId+" .footerTabs-nav li").removeClass("actif");
				$($thisId+" #footerTabs-nav-"+indice).addClass("actif");
			}	
			
			function autoNav(){
				// GГ©nГЁre les onglets automatiquement
				if(param.autoNav == "true"){
					var listeNav = '';
					for(i=1; i!=nbTab; i++){
						listeNav = listeNav+'<li id="footerTabs-nav-'+i+'">'+i+'</li>';
					}
					$($thisId+" .footerTabs-nav").append('<ul>'+listeNav+'</ul>');
				}
			}
			function showCloseTabs(){
				// GГ©nГ©re un bouton de fermeture gГ©nГ©rale des content
				if(param.closeTabs == "true"){
					if($($thisId+" .footerTabs-content a.close").size() == 0){
						$($thisId+" div.footerTabs-content").append("<a title=\"Close this tab\" class=\"close\">x</a>");
					}
				}
			}
			// Exec
			$($thisId+" .footerTabs-nav li").click(function(){
				if ($(this).hasClass("actif")){
					hideAll();
					$(this).removeClass("actif");						
					$(this).parents().find(".content").css({"margin-bottom": 0, "min-height": $(window).height() - $("#footertabs").outerHeight()-$(".footer").outerHeight()-$(".header").outerHeight()-67});												
				}
				else{
					var numContent = this.id.substr(this.id.length-1,this.id.length);
					changeContent(numContent);
					var mb = $(".footerContent").outerHeight();					
					$(this).parents().find(".content").css({"margin-bottom": mb, "min-height": $(".container-inner").outerHeight() - $("#footertabs").outerHeight()-$(".footer").outerHeight()});					
					$(document).scrollTop($(document).height()+mb);
				}
			});
			
			/*
			$("div").click(function(){
			      if ( $(this).hasClass("protected") )
			        $(this).animate({ left: -10 }, 75)
			               .animate({ left: 10 }, 75)
			               .animate({ left: -10 }, 75)
			               .animate({ left: 10 }, 75)
			               .animate({ left: 0 }, 75);
			    });
						
			*/
			// test function closeTabs
			$($thisId+" .footerTabs a.close").click(function(){
				hideAll();
				$($thisId+" .footerTabs-nav li").removeClass("actif");
			});
		});
	}
})(jQuery);
