/* SET THE FLOWER INSIDE THE BODY WITH RANDOM POSITION */

var setFlowerWindows = function(){


    this.windowWidth = null;
    this.windowHeight = null;

    this.numberFlower = 3;
    this.boucle = 4;
    this.init();
}

setFlowerWindows.prototype = {
    init : function(){
       
        this.windowWidth = jQuery('body').outerWidth();
        this.windowHeight = jQuery('body').outerHeight();

        this.setFlower();

    },

    setFlower : function(){


        for( var i = 0; i <  this.boucle ; i++ ){


            for( var a = 0; a <  this.numberFlower ; a++ ){

                 var top= Math.random() * Math.floor((this.windowHeight) + 1 );
                 var left= Math.random() * Math.floor((this.windowWidth) + 1 );

                 var fl = jQuery('<img src="/images/flowers/flower' + a +'.png" />');

                 var sizeW = jQuery(fl).width();

                 jQuery(fl).css({
                     'position' : 'fixed',
                     'top' : top,
                     'left' : left - sizeW,
                     'z-index' : 1
                 });

                 

                 jQuery('body').prepend(fl);

            }

        }


    }


}






var _tab = function( o, options){

  this.options = options ? options : {};

  //nb of tab
  this.tab = 0;
  this.panelTab = o;

  this.error = 0;
  this.heightTab = null;
  this.widthTab = null;
  this.baseTab = 0;
  this.firstErrorTab = null;
  this.colorTab = null ;
  this.active = null ;
  this.activeId = null;
  this.nbError = new Array();

  if(this.options.form){

     this.displayFormError()

  }

  this.init();
}


_tab.prototype = {

init : function(){

var t = this;

    //active the tab view
    jQuery(this.panelTab).children("dd").each( function(){

              jQuery( this ).css('display' , 'none');

        if( t.tab == 0 && t.firstErrorTab == null ){

            t.activeTab(jQuery( this ).attr('id'));

        }

        t.tab++;
    });


    if( this.firstErrorTab != null ){

            t.activeTab( this.firstErrorTab + '_dd' );

     }


     //bind the event for all tab
      jQuery(this.panelTab).children("dt").click(function(){

            t.activeTab( jQuery( this ).attr('id') + '_dd' );

      });


},
//active tab form view
activeTab : function( e ){

        //not bug
        var e = e.replace('#', '')

        if( this.colorTab == null ){
                  this.colorTab = jQuery(e).css('background-color');
              }

        //get the id of the dt
        var str= '#' + e;
        var dt = str.replace('_dd', '');
        //dt
        jQuery(dt).addClass('c_active_dt');
        //dd
        jQuery( dt + '_dd').fadeIn('1000');
        //unactive the old tab
        if( this.active != null ){
           this.unactiveTab();
        }

        this.active = e;

    },
//active tab form view
unactiveTab : function(){

        //not bug
        this.active = this.active.replace('#', '')

        var dt = this.active.replace('_dd', '');
        //dt
        jQuery('#' + dt).removeClass('c_active_dt');
        //dd
        jQuery('#' + this.active).hide();

    },
//add the pin error on the dt
displayFormError : function(){
var t = this;

    jQuery('#c_form .form_row ul.error_list').each( function(){

         var parent = jQuery(this).prevAll( '.form_field' );
         jQuery( parent).children('input').css('border-color' , 'red' );
         jQuery( parent).children('textarea').css('border-color' , 'red' );
         jQuery( parent).children('select').css('border-color' , 'red' );

    });


    //error pin's over the tab form for informed the user
    jQuery( 'ul.error_list' ).each( function(){

             var str = jQuery( this ).parents('dd').attr('id');
             var dt = str.replace('_dd', '')
             t.nbError.push(dt);


    });


    jQuery(this.panelTab).children("dt").each(function(){

     //calcul error for all tab
        for(var i = 0; i < t.nbError.length; i++ ){


             if( t.nbError[i] === jQuery( this ).attr('id') ){

                 t.error ++;

                 if( t.firstErrorTab == null ){
                     t.firstErrorTab = jQuery( this ).attr('id');

                 }
             }


        }

        if( t.error > 0 ){
           var pins = jQuery( '<span class="c_pins">' + t.error + '</span>' );
           jQuery( this ).append( pins );
        }

        t.error = 0;

        });

}


}


