
/* ALL PAGES */
/* Search field focus swap class */
searchFocus = function() {
	if (jQuery('.formSearch .search').size() < 1) return 0;	
	jQuery(".formSearch .search").focus( function() { if(this.value=="") this.className='focus'; });
	jQuery(".formSearch .search").blur( function() { if(this.value=="") this.className=''; });	
	return jQuery('.formSearch .search').size();
}

/* ALL PAGES */
/* SuckerFish Dropdowns menu */
sfHover = function() {
	if (jQuery('#dropDowns').size() < 1) return 0;

    var menuOffset = 700;
    var menuToTheLeft = function() {
        jQuery('#dropDowns .sfhover2 li').hover(
            function(){
                jQuery(this).children('ul').addClass('toTheLeft');
            },
            function() {
                jQuery(this).children('ul').removeClass('toTheLeft');                
            }
        );
    }
	var sfEls = document.getElementById("dropDowns").getElementsByTagName("li");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
			if (this.offsetLeft > menuOffset) {
                this.className += ' sfhover2';
        		menuToTheLeft();
			}
		}
		sfEls[i].onmouseout=function(	) {
			this.className="";
		}
	}
	return jQuery('#dropDowns').size();
}

/* PAGE FAMILY */
/* Vertical and horizontal align products if there are just a few */
centerProducts = function() {
	if (jQuery('#centerer').size() < 1) return 0;
	var productSize = jQuery('.product').size();
	var productWidth = jQuery('.product').width();
	var productHeight = jQuery('.product').get(0).offsetHeight;		
	var blocContentHeight = jQuery('.blocContent').height();
	if (productSize <= 10) {
		if (productSize <= 5) {
			myPadding = (blocContentHeight - productHeight)/2;
			jQuery('#centerer').width(productSize*productWidth);
		} else {
			myPadding = (blocContentHeight - (productHeight*2) )/2;
			jQuery('#centerer').width(5*productWidth);
		}
		jQuery('#centerer').css({ paddingTop:myPadding });
		jQuery('.product').width(productWidth);
	} else {
		jQuery('#bloc2 .blocContent').jScrollPane({showArrows:true, scrollbarWidth:14});
	}	
	jQuery('.product:last').addClass('last');
	return jQuery('#centerer').size();
}


/* PRODUCT DETAILS PAGE */
/* jQuery accordion on themes */
accordionThemes = function() {
	if (jQuery('#navThemes').size() < 1) return 0;
	jQuery('#navThemes div.hidden p').jScrollPane({showArrows:true, scrollbarWidth : 5});
	jQuery('#navThemes>ul>li>div.hidden').hide();
	//jQuery('#navThemes>ul>li>div.hidden:eq(0)').show();
	jQuery('#navThemes>ul>li>a').click(function() {
		jQuery(this).addClass('on');
		var $nextDiv = jQuery(this).parent().children('div.hidden');
		var $visibleSiblings = $nextDiv.parent().siblings('li').children('div.hidden:visible');
		if ($visibleSiblings.length ) {
			$visibleSiblings.slideUp('slow', function() {
				$nextDiv.slideToggle('slow');
				jQuery(this).parent().children('a').removeClass('on');				
			});
		} else {
			$nextDiv.slideToggle('slow');
		}
	});
	
	return jQuery('#navThemes').size();
}

/* Image zoom function */
zoom = function() {
	if (jQuery('.picZoom').size() < 1) return 0;
	jQuery('.zoomIn, #bigPic a').click(function() {
		jQuery('#fullZoom').removeClass('off').addClass('on').fadeIn('slow');
	});
	jQuery('.zoomOut, .picZoom, .picZoom a').click(function() {
		jQuery('#fullZoom').fadeOut('slow',function(){jQuery(this).removeClass('on').addClass('off')});
	});
	jQuery('#fullZoom').hide();
	return jQuery('.picZoom').size();
}

/* RANGE PAGE */
/* Text over product function */
textOver = function() {
	if (jQuery('.textOver').size() < 1) return 0;
	jQuery(".areaHover").mouseover(function(){
		jQuery(".textOver").hide();
		jQuery(this).children(".textOver").show();
	});
	jQuery(".hoverItems").mouseout(function(){
		jQuery(".textOver").hide();
	});
	jQuery(".textOver").hide();
	return jQuery('.textOver').size();
}

lastProduct = function() {
	if (jQuery('#furtherSkincare').size() < 1) return 0;
	jQuery('#furtherSkincare .product:last').addClass('last');
	return jQuery('#furtherSkincare').size();
}

brevetProducts = function() {
	if (jQuery('#brevet').size() < 1) return 0;
	jQuery('#brevet').hide();
	jQuery('#btBrevet a').click(function(){
		jQuery(this).addClass('on');
		jQuery('#btProducts a').removeClass('on');
		jQuery('#brevet').fadeIn();
		jQuery('#productsType1').fadeOut();
		if (jQuery('.jcarousel-container').size() == 1) {	
			jQuery('.jcarousel-container').hide();
		}
	});
	jQuery('#btProducts a').click(function(){
		jQuery(this).addClass('on');
		jQuery('#btBrevet a').removeClass('on');
		jQuery('#brevet').fadeOut();
		jQuery('#productsType1').fadeIn();
		if (jQuery('.jcarousel-container').size() == 1) {	
				jQuery('.jcarousel-container').show();
		}	
	});
	return jQuery('#brevet').size();
}

carouselProducts = function() {
	if (jQuery('#productsType1').size() < 1) return 0;
		if (jQuery("#productsType1>li").size() > 7) {
    jQuery("#productsType1").jcarousel({
        scroll: 1,
        animation:"slow"
   });
  	}
   return jQuery('#productsType1').size();
}

simpleScrollPane = function() {
	if (jQuery('.scrollPane').size() < 1) return 0;
	jQuery('.scrollPane').jScrollPane({showArrows:true, scrollbarWidth : 14});
	return jQuery('.scrollPane').size();
}


/* input type file skin */
/* please remember to replace by jQuery syntaxe */
fileUploads = function() {
	if (jQuery('#resume').size() < 1) return 0;
	var W3CDOM = (document.createElement && document.getElementsByTagName);
	if (!W3CDOM) return;
	var fakeFileUpload = document.createElement('div');
	fakeFileUpload.className = 'fakefile';
	fakeFileUpload.appendChild(document.createElement('input'));
	var image = document.createElement('div');
	image.className = 'pic';
	fakeFileUpload.appendChild(image);
	var x = document.getElementsByTagName('input');
	for (var i=0;i<x.length;i++) {
		if (x[i].type != 'file') continue;
		if (x[i].parentNode.className != 'relative') continue;
		x[i].className = 'file hidden';
		var clone = fakeFileUpload.cloneNode(true);
		x[i].parentNode.appendChild(clone);
		x[i].relatedElement = clone.getElementsByTagName('input')[0];
		x[i].onchange = x[i].onmouseout = function () {
			this.relatedElement.value = this.value;
		}
	}
	return jQuery('#resume').size();
}

/* LABEL OVER INPUT IN SALE POINTS PAGE */
/* 1. put label over input, 2. empty input on focus (hide label), 3. fill it back on blur if left empty (show label) */
jQuery.fn.labelOver = function(overClass) {
	return this.each(function(){
		var label = jQuery(this);
		var f = label.attr('for');
		if (f) {
			var input = jQuery('#' + f);
			
			this.hide = function() {
			  label.css({ textIndent: -10000 })
			}
			
			this.show = function() {
			  if (input.val() == '') label.css({ textIndent: 0 })
			}

			// handlers
			input.focus(this.hide);
			input.blur(this.show);
		   label.addClass(overClass).click(function(){ input.focus() });
			
			if (input.val() != '') this.hide(); 
		}
	})
}
labelOver = function() {
	if (jQuery('.labelOver').size() < 1) return 0;
	jQuery('.labelOver').labelOver('over-apply');
	return jQuery('.labelOver').size();
}

/* CAROUSEL ON SALE POINTS PAGE */
// sets up jCarousel with buttons for paging
jQuery.fn.pagedCarousel = function (pagingElem, numberofvisible, imgEmpty, imgFull, options) {
	elem = jQuery(this);
	pagingElem = jQuery(pagingElem);
	
	var numberofelements = Math.ceil(jQuery("li", elem).length/numberofvisible);
	
	function drawButtons(on) {
		//pagingElem.html(' ');
		pagingElem.empty();
		if(numberofelements > 1)
			for(i = 0; i < numberofelements; i++) {
				if(i != on)
					pagingElem.append('<a href="#" title="'+(i*numberofvisible+1)+'"><img src="../images/' + imgEmpty + '" alt="" /></a>');
				else
					pagingElem.append('<a href="#" title="'+(i*numberofvisible+1)+'"><img src="../images/' + imgFull + '" alt="" /></a>');
			}
	}
	
	function reDrawButton(whichone) {
		jQuery("a", pagingElem).removeClass('active');
		jQuery("a", pagingElem).eq(whichone).addClass('active').find("img").attr('src','images/' + imgFull);
		jQuery("a", pagingElem).not('.active').find("img").attr('src','images/' + imgEmpty);
	}
	
	drawButtons(0);
	
	function mycarousel_initCallback(carousel) {
		jQuery("a", pagingElem).bind('click', function() {
			carousel.scroll(jQuery.jcarousel.intval(jQuery(this).attr('title')));
			reDrawButton((jQuery(this).attr('title')-1)/numberofvisible);
			return false;
		});
	};	
	
	function mycarousel_itemLastInCallback(carousel, item, idx, state) {
		var currentpage = Math.ceil(idx/numberofvisible)-1;
		
		reDrawButton(currentpage);
	};
	
	options = jQuery.extend(options, {
		visible: numberofvisible,
		itemLastInCallback: mycarousel_itemLastInCallback,
		initCallback: mycarousel_initCallback
	});
	
	elem.jcarousel(options);
}
salePointsCarousel = function() {
	if (jQuery('#carouselPaging').size() < 1) return 0;
	jQuery("#carouselDiv").pagedCarousel("#carouselPaging", 1, "../../../extension/esthederm/design/esthederm/images/icon_status_empty.gif", "../../../extension/esthederm/design/esthederm/images/icon_status_full.gif", { scroll: 1, animation: "slow", wrap:"both" });
	return jQuery('#carouselPaging').size();
}

slideshowCarteSoins = function() {
	if (jQuery('#decoImgs').size() < 1) return 0;
	jQuery('#decoImgs').cycle('fade');
	return jQuery('#decoImgs').size();
}

theBrandTabs = function() {
	if (jQuery('#theBrand .tabs').size() < 1) return 0;
	jQuery('#theBrand .tabs').tabs({fxFade: true});
	return jQuery('#theBrand .tabs').size();
}

googleMapTabs = function() {
	if (jQuery('#searchSalePoints .tabs').size() < 1) return 0;
	jQuery('#searchSalePoints .tabs').tabs({fxFade: true});
	return jQuery('#searchSalePoints .tabs').size();
}

careDetailsTabs = function() {
	if (jQuery('#careDetails .tabs').size() < 1) return 0;
	jQuery('#careDetails .tabs').tabs({fxFade: true});
	return jQuery('#careDetails .tabs').size();
}

/* Defines a black BG for selects dropdowns */
isBlackSelect = function() {
	if (jQuery('.blackBg .niceform select').size() < 1) return 0;
	jQuery('body').addClass('blackBg');	
	return jQuery('.blackBg .niceform select').size();
}

listeCarteAddClass = function() {
	if (jQuery('#listeCarte').size() < 1) return 0;
	jQuery('#listeCarte li:last').addClass('last');
	return jQuery('#listeCarte').size();
}

/* triggered at the end of the animation on the Home page */
hideFlash = function() {
	jQuery('#flashHome').hide();
}

setBgNone = function() {
	jQuery('#flashHome').css({background:'none'});
}

productsType2 = function() {
	if (jQuery('.productsType2').size() < 1) return 0;
	jQuery('.productsType2').jScrollPane({showArrows:true, scrollbarWidth:14});
	return jQuery('.productsType2').size();
}



/* Only initialize functions for all pages if needed */
/* please use alert(initCareDetailsTabs); */
jQuery(document).ready(function() {
	initSearchFocus = searchFocus(); 
	initCenterProducts = centerProducts(); 
	initZoom = zoom(); 
	initSfHover = sfHover(); 
	initAccordionThemes = accordionThemes(); 
	initTextOver = textOver(); 
	initBrevetProducts = brevetProducts(); 
	initCarouselProducts = carouselProducts();
	initSimpleScrollPane = simpleScrollPane(); 
	initFileUploads = fileUploads(); 
	initLabelOver = labelOver(); 
	initSalePointsCarousel = salePointsCarousel(); 
	initSlideshowCarteSoins = slideshowCarteSoins(); 
	initTheBrandTabs = theBrandTabs(); 
	initGoogleMapTabs = googleMapTabs();
	initCareDetailsTabs = careDetailsTabs(); 
	initIsBlackSelect = isBlackSelect();
	initListeCarteAddClass = listeCarteAddClass();
	initLastProduct = lastProduct();
	initProductsType2 = productsType2();
});














//END 
