/* MONSIEUR ROSE 2008 */
/* COMMON JAVASCRIPT FUNCTIONS */

/* ENABLE ROLLOVER ON TARGETED IMAGES (ALL BROWSERS) */
function imgRollover(elt) {
    jQuery(elt).each( function() {
		jQuery(this).hover(
			function() {
				jQuery(this).attr("src", jQuery(this).attr("src").replace("-off","-on"));
			},
			function () {
				jQuery(this).attr("src", jQuery(this).attr("src").replace("-on","-off"));
			}
		);
	});
}


/* SAME HEIGHT FOR SAME CLASS ELEMENTS */
function sameHeight(elt) {
	var heightBlockMax=0;
	jQuery(elt).each(function(){ if( jQuery(this).height() > heightBlockMax ) heightBlockMax = jQuery(this).height(); }); // get max height
	if (jQuery.browser.msie) {
		if (parseInt(jQuery.browser.version) <= "6") {
			jQuery(elt).each(function(){ jQuery(this).css("height",heightBlockMax); }); // assign max height
		} else {
			jQuery(elt).each(function(){ jQuery(this).css("min-height",heightBlockMax); }); // assign max height
		}
	} else {
		jQuery(elt).each(function(){ jQuery(this).css("min-height",heightBlockMax); }); // assign max height
	}
	heightBlockMax=0;
}

/* FORM VALIDATION */
function formValidation(elt) {
	jQuery(elt).validationAideEnable(null,{summaryMessage: "<h3>Attention, vous devez remplir ou corriger le(s) champs suivant(s) :</h3>"});
}

/* SUCKERFISH DROPDOWN MENUS */
function mySuperfish(elt) {
	jQuery(elt).superfish({
		pathClass : 'current'
	}).find('ul').bgIframe();
}



/* PRODUCT ZOOM */
function refreshZoom(LargeImageId) {

	product_zoom = new Product.Zoom(LargeImageId, 'track', 'handle', 'zoom_in', 'zoom_out', 'track_hint','btn_zoom_up','btn_zoom_left','btn_zoom_right','btn_zoom_down');
};

function preloadImage(img, src,id) {
	var newImg = new Image();
	newImg.onload = function() {	
		newImg.onload = null;
		if (jQuery.browser.mozilla && jQuery.browser.version < 2) {			
			img.onload= null; 			
			img.src = newImg.src;
			refreshZoom(id);
			img.removeClassName('loader');
		}
		else {
		
			img.onload = function() { img.onload= null;refreshZoom(id); img.removeClassName('loader');};
			img.src = newImg.src;
		}
	}
	newImg.src = src;
	 
};

function productZoom(elt,loader) {	
	this.loader=loader;
	// hide zoom box
	jQuery('#productCardImgZoom').addClass('offLeft');
	
	// on click on thumbs, update big picture and big picture in zoom box
	jQuery(elt+' #otherViews a').click( function() {	
    	var newSrc = MoreViewsNormalImages[jQuery(this).children('img').attr('id')];    	
		jQuery('#bigPhoto img').attr('src',newSrc);
		return false;
	});
	
	// on click on thumbs in zoom box, update big picture in zoom box
	jQuery(elt+' #otherViewsZoom a').click( function() {		
		var id = jQuery(this).children('img').attr('id');		
		var newSrc = MoreViewsZoomImages[id];
		var newId = 'large'+id;		
		var srcLoader = jQuery('#loader').attr('src');		
		jQuery('#bigPhotoZoom').html('<img id=\"'+newId+'\" onload=\'preloadImage (this,\"'+newSrc+'\",\"'+newId+'\")\' class=\"loader\"/>');			
		jQuery('#bigPhotoZoom img').attr('src',srcLoader);
		return false;
		
		
	});
	
	// on click on big picture, show zoom box
	jQuery('#bigPhoto a').click( function() {		
    	jQuery('#productCardImgZoom').removeClass('offLeft');
		return false;
	});
	
	// on click on close button in zoom box, hide zoom box
	jQuery('#productCardImgZoom .closeButton').click( function() {
		jQuery('#productCardImgZoom').addClass('offLeft');
	});
	
};

jQuery(document).ready(function() {

    /* ADD hasJS CLASS TO BODY FOR ABS/REL POSITIONNING */
	jQuery("body").addClass("hasJS");

    /* HIDE QUICK LINKS */
	jQuery('#quickAccess').addClass('offLeft');

    /* ENABLE ROLLOVER ON LOGOS IN FOOTER (ALL BROWSERS) */
	if (jQuery('.swapImg').size() > 0) { initImgRollover = imgRollover('.swapImg'); }
	
	/* SAME HEIGHT FOR PRODUCTS LIST */
	if (jQuery('#productList li').size() > 1) { initSameHeight = sameHeight('#productList li'); }

    /* SUCKERFISH DROPDOWN MENUS */
    if (jQuery('#mainNav').size() > 0) { initMainNav = mySuperfish("#mainNav"); }

    /* PRODUCT PICTURE ZOOM ON PRODUCT DETAIL PAGE */
    if (jQuery('#productCardImg').size() > 0) { initProductZoom = productZoom("#productCardImg"); }

});




Varien.inputtext = Class.create();
Varien.inputtext.prototype = {
    initialize : function(form, field, emptyText){
        this.form   = $(form);
        this.field  = $(field);
        this.emptyText = emptyText;		
		this.password = (this.field.type == "password");
		this.newField = this.field;

		
		if (this.password) {
			var strIdNewField = field + "-replace";
			jQuery("<input id='" + strIdNewField + "' type='text' value='(Mot de passe)' />").insertBefore(this.field)							
							.attr("size", this.field.size)
							.attr("title", this.field.title)
							.attr("class", this.field.className);
										
			this.newField = $(strIdNewField);
			
			this.field.hide();
			this.newField.blur();
		}
		
        Event.observe(this.form,  'submit', this.submit.bind(this));
        Event.observe(this.field, 'focus', this.focus.bind(this));
         Event.observe(this.newField, 'focus', this.focus.bind(this));
       Event.observe(this.field, 'blur', this.blur.bind(this));
        this.field.blur();
	 },
	


	
	
	
	

    submit : function(event){	
        if (this.field.value == this.emptyText || this.field.value == ''){
            Event.stop(event);
            return false;
        }
        return true;
    },

    focus : function(event){		
			if (this.password) {
				this.newField.hide();
				this.field.show();
				this.field.focus();
			}
			else {			
				if (this.field.value==this.emptyText){
					this.field.value='';
				}
			}
		

    },

    blur : function(event){	
			
				if (this.password) {
					this.field.hide();
					this.newField.show();
				}
				else {				
			        if(this.field.value==''){
			            this.field.value=this.emptyText;
			        }
				}
			
    }

}















/* END */

