/**************************************
*  GUI functions tool kit (non obscruptive js)

*  required jQuery
*      
* author:  erational(http://www.erational.org)
* version: 0.3
* date:    2010.10.10
* licence: GPL 3.0    
***********************************/


//
//  merci b_b
//
jQuery.fn.newsTicker = jQuery.fn.newsticker = function(delay){
	return this.each(
		function(){
			if(this.nodeName.toLowerCase()!= "ul") return;
			delay = delay || 4000;
			var self = this;
			self.items = jQuery("li", self);
			// hide all items (except first one)
			self.items.not(":eq(0)").hide().end();
			// current item
			self.currentitem = 0;
			var doTick = function(){
				jQuery.newsticker(self);
			}
			setInterval(doTick,delay);
		}
	)
	.addClass("newsticker")
	.hover(
		function(){
			// pause if hovered over
			this.pause = true;
		},
		function(){
			// unpause when not hovered over
			this.pause = false;
		}
	);
}
jQuery.newsticker = function(el){
	// return if hovered over
	if(el.pause) return;
	// hide current item
	jQuery(el.items[el.currentitem]).fadeOut("slow",
		function(){
			jQuery(this).fadeOut("slow");
			// move to next item and show
			el.currentitem = ++el.currentitem % (el.items.size());
			jQuery(el.items[el.currentitem]).fadeIn("slow");
		}
	);
}


//
// ARE U READY ?
// 
$(document).ready(function(){

    // slide en fade
   // $("#pub_lie ul").newsTicker();
    
    // une publication au hasard    
   $("#pub_lie ul li").hide();
   lie = $("#pub_lie ul li").size();
   if (lie>0) {  
    lie_rand = Math.floor(Math.random()*lie);   
    $("#pub_lie ul li:eq("+lie_rand+")").show();
   }
      
   // gestion des onglets
   $(".artab").hide();
   //$(".artab1").show();  --> affiche le premier onglet displo
   $(".artab:first").show();
   $(".tabfiche:first").addClass('tabfiche_on');
        
   $(".tabfiche").click(function(){
        $(".tabfiche").removeClass('tabfiche_on');
        $(this).addClass('tabfiche_on');
        var rel = $(this).attr("rel");
        $(".artab").hide();
        $("."+rel).show();
        return false; 
   }); 
   
   // gestion formulaire abonnement
   $("#os0").change(function(){
     update_basket();    
   });
   
   $("#os1").change(function(){
     update_basket();    
   });
   
   // mise a jour a somme pour inclure les frais expediations au moment submit
   $("#paypal_abo_ligne").submit(function(){
         debut_abonnement =  parseInt($("#os2").val());         
         if ((isNaN(debut_abonnement)) || (debut_abonnement < 0)) {
            alert("Veuillez saisir un numéro de  début d'abonnement valide");   
            return false;
         }
         update_basket();
         montant = $("#amount").val();
         // correctif frais port auto paypal
         if (montant<50) montant -= 4;
                    else montant -= 5;
         //alert("->"+montant);                             
         $("#amount").val(montant);                
   });
 
   $("#paypal_abo_vertigo").submit(function(){
         debut_abonnement =  parseInt($("#os1").val());         
         if ((isNaN(debut_abonnement)) || (debut_abonnement < 37)) {
            alert("Veuillez saisir un numéro de  début d'abonnement valide (à partir du numéro 37)");   
            return false;
         }  
         update_basket();
         montant = $("#amount").val();
         // correctif frais port auto paypal
         if (montant<50) montant -= 4;
                    else montant -= 5;           
         $("#amount").val(montant);         
   });
   
   // mise a jour du panier seulement option retenue
   function update_basket() {   
      quoi = $("#tracker-ed").val();
      qui = $("#os0").val();
      pays = $("#os1").val();      
     
      // abonnement lignes ?
      if (quoi == 6) {      
          montant = 54;
          if (qui == "Particulier") {
              if (pays == "Autre pays")   montant = 60;
          } 
          if (qui == "Institution") {
              if (pays == "Autre pays")   montant = 65;
                                    else  montant = 59;
          } 
          $("#amount").val(montant);  
          $("#os_amount").empty().html(montant+ "&euro;");
      }
      
       // abonnement vertigo ?
      if (quoi == 13) {      
          montant = 47;
          if (qui == "France (Etudiant)")  montant = 42;  
          if (qui == "Europe")             montant = 58;
          if (qui == "Monde")              montant = 64;                 
          
          $("#amount").val(montant);  
          $("#os_amount").empty().html(montant+ "&euro;");
      }
      
   }
   
   
   
        
});



