$(function(){
//  $('ul.sf-navbar').css('display', "none");
  $('ul.sf-navbar').superfish({ 
    pathClass: 'current',
      delay:       1000,                            // one second delay on mouseout 
      animation:   {opacity:'show',height:'show'},  // fade-in and slide-down animation 
      speed:       'fast',                          // faster animation speed 
      autoArrows:  false,                           // disable generation of arrow mark-up 
      dropShadows: false
      //onInit: function(){
       // $('ul.sf-navbar').css('display', "block");
        
      //  var brderwidth = $('ul.sf-navbar').width();
       // alert(brderwidth);
         //$('.border').css('width', brderwidth +'px');
        // $('.border').css('display','block');
      //}
  });
  	if(BrowserDetect.browser == 'Explorer'  && BrowserDetect.version < '8'){
  	   var brderwidth = $('ul.sf-navbar').width();
      // $('.allnav_holder').css('width', brderwidth +'px');
        // $('.border').css('display','block');
  	  
  	}
      //footer quotes animation
      $('.footer_quotes').cycle({ 
    		  fx:  'fade', 
    		  speed:  1000, 
    		  timeout: 0,
    			next: '#refresh_icon',
    			cleartypeNoBg: true
    		});
       $('#refresh_icon, .footer_nav img').hover(function(){
         $(this).fadeTo('normal', 0.5)}, function(){
           $(this).fadeTo('normal', 1);
         });
         $('.members_link div, .submit').hover(function(){
            $(this).fadeTo('normal', 0.8)}, function(){
              $(this).fadeTo('normal', 1);
            } 
       );
  // autolabels for inputs
  labelFields();
});
// ========= home page specific functions
//carousel
home_carousel= {
	init : function(){
	   $('.ulcarousel').jcarousel({
        vertical: true,
        scroll: 1,
        wrap: 'circular',
        visible: 3
      });
  }
}
//home slideshow
home_cycle= {
	init : function(){      
      $('.promos_bg').cycle({ 
    		  fx:  'fade', 
    		  speed:  1000, 
    		  timeout: 3000,
    			pager: '#slide_nav'
    		});
	}
}
//career page headers animation
career_cycle = { 
  init : function(){
    $('.header_career').cycle({ 
  		  fx:  'fade', 
  		  speed:  1000, 
  		  timeout: 6000
  		});
  		
  		$('.job_cta img, p img').hover(function(){
          $(this).fadeTo('normal', 0.5)}, function(){
            $(this).fadeTo('normal', 1);
          });
}
}
// handbook section unused
handbook_cycle={
  init : function(){
    $('.handbook_nav div').css('display', "inline");
    $('.handbook_pages').cycle({ 
  		  fx:  'scrollHorz', 
  		  speed:  1000, 
  		  timeout: 0,
  			prev: '#handbook_prev',
  			next: '#handbook_next'
  		});
  }
}
// handbook section used
handbook={
  init : function(){
    	$('.handbook_holder img').imgpreload(function(){
    	  $('.loader').fadeOut('normal');
    	  $('.handbook_holder img').fadeIn('slow', function(){
    	   
    	 $('.cloud-zoom, .cloud-zoom-gallery').CloudZoom();
    	  });
    });
  }
}

// look page carrousel
look_carousel = {
    init: function(){
      	$('#look_thumbs img').imgpreload(function(){
          $('#look_thumbs').jcarousel({
              scroll: 1,
              visible: '980px'
            });
        });
      $(".prev_thumb_holder, .next_thumb_holder").click(function(){
					window.location = $('a', this).attr('href');
				});
	$('.img_holder img').imgpreload({	
    each: function(){
    // alignement "centre" de l'image principale
    //recupere largeur et hauteur image
		var widthImage = $('.img_holder img').attr('width');
    var heightImage = $('.img_holder img').attr('height');
    
		// appliquer les styles css
		$('.img_holder').css('width', widthImage +'px');
		$('.img_holder').css('padding-top', (500-heightImage)/2 +'px').fadeIn('normal');
	
		//thumbnails centrer verticalement
		var thumb_left_image = ($('.prev_thumb_holder img').attr('height'))/2;
		var thumb_right_image = ($('.next_thumb_holder img').attr('height'))/2;
		// appliquer les styles css
		$('.prev_thumb_holder').css('margin-top', '-'+thumb_left_image +'px').fadeIn('normal');
		$('.next_thumb_holder').css('margin-top', '-'+thumb_right_image +'px').fadeIn('normal');
		
		// afficher l'image
	      //   
	     // $('.prev_thumb_holder').;
	     //      $('.img_holder ');
	     //      $('.next_thumb_holder');

	  }

		
	 });
    }
}
//stylist carrouse
style_carousel = {
    init: function(){
      	$('#look_thumbs img').imgpreload(function(){
          $('#look_thumbs').jcarousel({
              scroll: 1,
              visible: '930px',
              wrap: 'circular'
            });
      });
    }
}

var _start_products_carousel=1;

products_carousel =  {
    init: function(start){
	    if (start) _start_products_carousel=start;
      	$('#products_thumbs img').imgpreload(function(){
        $('#products_thumbs').jcarousel({
          scroll: 1,
          visible: '980px',
          start: _start_products_carousel
        });
      });
     
      $('.product_img img').imgpreload(function(){
        $('.loader').fadeOut('normal');
        $('.product_img img').fadeIn('slow', function(){

        	 $('.cloud-zoom, .cloud-zoom-gallery').CloudZoom();
        	  });
        });
    
    $('.stylist_header a').click(function(){
      $('#stylist_bio').toggle();
      $('.close').toggle();
      $('.open').toggle();
      });
    }
}
// media page functions
media_functions =  {
    init: function(){
      $('.medias_bg a').fancybox(
        {
            'onComplete'    :   function(arg) {
                // Here does the magic starts
                $('#fancybox-img').wrap(
                    $('<a>')
                    .attr('href', $(arg[0]).attr('href'))
                    .addClass('cloud-zoom')
                    .attr('rel', "position: 'inside'")
                );
                // That's it
                $('.cloud-zoom').CloudZoom();
            }
        }
        );

			$('a.thumb').hover(function () { 
			   $(this).find('.strong').stop().css('display', 'block');
			   }, function () {
			   $(this).find('.strong').stop().css('display', 'none');
			 });
			
        $('.medias_bg img').hover(function(){
          $(this).fadeTo('normal', 0.5)}, function(){
            $(this).fadeTo('normal', 1);
          });

          }
}
// rollover effects on collection thumbs
collection_thumbs = {
  init: function(){
    
    (function($){
      $.fn.showdelay = function(){
       var delay = 0;
       return this.each(function(){
       $(this).delay(delay).fadeIn('fast');
        delay += 100;
       });
    };
     })(jQuery);
    
    $('.collection_thumbs li').showdelay();
    		$('.collection_thumbs li').click(function(){
   					window.location = $('a', this).attr('href');
   				});
  }
  
}
store_list =  {
    init: function(){
      $('.hours').click(function(){
        $('.hour_list', this).toggle();
      });
      
}
          }
          

stylistnote = {
  init: function(){
    
    (function($){
      $.fn.showdelay = function(){
       var delay = 0;
       return this.each(function(){
       $(this).delay(delay).fadeIn('normal');
        delay += 500;
       });
    };
     })(jQuery);
 
  $('.img_col img').imgpreload(function(){
   $('div.img_col').fadeIn('normal');
  });
    
    
  }
}
//contest page style hack for ie7
contest = {
  init: function(){
    
    $('.t-a').wrapInner('<table><tr><td></td></tr></table>');
  }
}

// autolabels functino
function labelFields() {
	if (!document.getElementsByTagName){ return; }
	var allfields = $(".valuefield").find('input');	
	for (var i=0; i<allfields.length; i++){ 	// loop through all input tags and add events
		initField(allfields[i]);
	}
	var allfields2 = $(".valuefield").find("textarea");	
	for (var i=0; i<allfields2.length; i++){ 	// loop through all textarea tags and add events
		initField(allfields2[i]);
	}
}
function initField(field) {
	if (field) { //prevent misfire
		var graycolor = "#888";
		if ((field.type == "text" || field.type == "textarea") && (field.value != null)) {	// include text boxes, exclude empty ones
			field.style.color = graycolor;
			field.graytext = field.value;
			field.onfocus = function () {
				if (this.value==this.graytext){
					this.style.color="#000";
					this.value="";
				} else {
					this.select();
				}
			}
			field.onblur = function () {
				if (this.value=="") {
					this.style.color=graycolor;
					this.value=this.graytext;
				}
			}
		}
	}
}
//// browser detection
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			   string: navigator.userAgent,
			   subString: "iPhone",
			   identity: "iPhone/iPod"
	    },
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();
