// accordion.js v2.0
//
// Copyright (c) 2007 stickmanlabs
// Author: Kevin P Miller | http://www.stickmanlabs.com
// 
// Accordion is freely distributable under the terms of an MIT-style license.
//
// I don't care what you think about the file size...
//   Be a pro: 
//	    http://www.thinkvitamin.com/features/webapps/serving-javascript-fast
//      http://rakaz.nl/item/make_your_pages_load_faster_by_combining_and_compressing_javascript_and_css_files
//

/*-----------------------------------------------------------------------------------------------*/

if (typeof Effect == 'undefined') 
	throw("accordion.js requires including script.aculo.us' effects.js library!");

var accordion = Class.create();
accordion.prototype = {

	//
	//  Setup the Variables
	//
	showAccordion : null,
	currentAccordion : null,
	duration : null,
	effects : [],
	animating : false,
	
	//  
	//  Initialize the accordions
	//
	initialize: function(container, options) {
	  if (!$(container)) {
	    throw(container+" doesn't exist!");
	    return false;
	  }
	  
		this.options = Object.extend({
			resizeSpeed : 8,
			classNames : {
				toggle : 'accordion_toggle',
				toggleActive : 'accordion_toggle_active',
				content : 'accordion_content'
			},
			defaultSize : {
				height : null,
				width : null
			},
			direction : 'vertical',
			onEvent : 'click'
		}, options || {});
		
		this.duration = ((11-this.options.resizeSpeed)*0.15);

		var accordions = $$('#'+container+' .'+this.options.classNames.toggle);
		accordions.each(function(accordion) {
			Event.observe(accordion, this.options.onEvent, this.activate.bind(this, accordion), false);
			if (this.options.onEvent == 'click') {
			  accordion.onclick = function() {return false;};
			}
			
			if (this.options.direction == 'horizontal') {
				var options = {width: '0px', display:'none'};
			} else {
				var options = {height: '0px', display:'none'};
			}
//			options.merge({display: 'none'});			
			
			this.currentAccordion = $(accordion.next(0)).setStyle(options);
		}.bind(this));
	},
	
	//
	//  Activate an accordion
	//
	activate : function(accordion) {
		if (this.animating) {
			return false;
		}
		
		this.effects = [];
	
		this.currentAccordion = $(accordion.next(0));
		this.currentAccordion.setStyle({
			display: 'block'
		});		
		
		this.currentAccordion.previous(0).addClassName(this.options.classNames.toggleActive);

		if (this.options.direction == 'horizontal') {
			this.scaling = $H({
				scaleX: true,
				scaleY: false
			});
		} else {
			this.scaling = $H({
				scaleX: false,
				scaleY: true
			});			
		}
			
		if (this.currentAccordion == this.showAccordion) {
		  this.deactivate();
		} else {
		  this._handleAccordion();
		}
	},
	// 
	// Deactivate an active accordion
	//
	deactivate : function() {
		var options = $H({
		  duration: this.duration,
			scaleContent: false,
			transition: Effect.Transitions.sinoidal,
			queue: {
				position: 'end', 
				scope: 'accordionAnimation'
			},
			scaleMode: { 
				originalHeight: this.options.defaultSize.height ? this.options.defaultSize.height : this.currentAccordion.scrollHeight,
				originalWidth: this.options.defaultSize.width ? this.options.defaultSize.width : this.currentAccordion.scrollWidth
			},
			afterFinish: function() {
				this.showAccordion.setStyle({
          height: 'auto',
					display: 'none'
				});				
				this.showAccordion = null;
				this.animating = false;
			}.bind(this)
		});    
//    options.merge(this.scaling);

    this.showAccordion.previous(0).removeClassName(this.options.classNames.toggleActive);
    
		new Effect.Scale(this.showAccordion, 0, options.update(this.scaling).toObject());
	},

  //
  // Handle the open/close actions of the accordion
  //
	_handleAccordion : function() {
		var options = $H({
			sync: true,
			scaleFrom: 0,
			scaleContent: false,
			transition: Effect.Transitions.sinoidal,
			scaleMode: { 
				originalHeight: this.options.defaultSize.height ? this.options.defaultSize.height : this.currentAccordion.scrollHeight,
				originalWidth: this.options.defaultSize.width ? this.options.defaultSize.width : this.currentAccordion.scrollWidth
			}
		});
		options.merge(this.scaling);
		
		this.effects.push(
			new Effect.Scale(this.currentAccordion, 100, options.update(this.scaling).toObject())
		);

		if (this.showAccordion) {
			this.showAccordion.previous(0).removeClassName(this.options.classNames.toggleActive);
			
			options = $H({
				sync: true,
				scaleContent: false,
				transition: Effect.Transitions.sinoidal
			});
			options.merge(this.scaling);
			
			this.effects.push(
				new Effect.Scale(this.showAccordion, 0, options.update(this.scaling).toObject())
			);				
		}
		
    new Effect.Parallel(this.effects, {
			duration: this.duration, 
			queue: {
				position: 'end', 
				scope: 'accordionAnimation'
			},
			beforeStart: function() {
				this.animating = true;
			}.bind(this),
			afterFinish: function() {
				if (this.showAccordion) {
					this.showAccordion.setStyle({
						display: 'none'
					});				
				}
				$(this.currentAccordion).setStyle({
				  height: 'auto'
				});
				this.showAccordion = this.currentAccordion;
				this.animating = false;
			}.bind(this)
		});
	}
}


/**
 * List of premade effect , can be use every where in the website
 * (specially in cms page)
 */


function ParallelSlideFadeEffect(slider, new_x, header_in, header_out, time){
      new Effect.Parallel(
        [
		new Effect.Move(slider, { x: new_x, y: 0, mode: 'absolute',sync: true}),
        new Effect.Appear(header_in, { sync: true }),
		new Effect.Fade(header_out, { sync: true})        
		],
         {duration: 1}
         );
   }



function ParallelFadeEffect(fade_in, fade_out, time){
      new Effect.Parallel(
        [
		new Effect.Appear(fade_in, { sync: true }),
		new Effect.Fade(fade_out, { sync: true})
		],
         {duration: 1}
         );
   }


function PreloadImage(images)
{
	 if (document.images) {
        var i = 0;
        var imageArray = new Array();
        imageArray = images.split(',');
        var imageObj = new Image();
        for(i=0; i<=imageArray.length-1; i++) {
            //document.write('<img src="' + imageArray[i] + '" />');// Write to page (uncomment to check images)
            imageObj.src=images[i];
        }
    }

}


Effect.DropInX = function(element) {
  element = $(element);
  var oldStyle = {
    top: element.getStyle('top'),
    left: element.getStyle('left'),
    opacity: element.getInlineOpacity() };	
	element.style.opacity = "0";
	element.style.display = "block";
  return new Effect.Parallel(
    [ new Effect.Move(element, {x: -100, y: 0, sync: true }),
      new Effect.Opacity(element, { sync: true,from: 0.0, to: 1.0 }) ],
    Object.extend(
      { duration: 0.5,
        beforeSetup: function(effect) {
          effect.effects[0].element.makePositioned();
        },
        afterFinishInternal: function(effect) {
          //effect.effects[0].element.show().undoPositioned().setStyle(oldStyle);
        }
      }, arguments[1] || { }));
};


Effect.DropOutX = function(element) {
  element = $(element);
  var oldStyle = {
    top: element.getStyle('top'),
    left: element.getStyle('left'),
    opacity: element.getInlineOpacity() };
  return new Effect.Parallel(
    [ new Effect.Move(element, {x: 100, y: 0, sync: true }),
      new Effect.Opacity(element, { sync: true, to: 0.0 }) ],
    Object.extend(
      { duration: 0.5,
        beforeSetup: function(effect) {
          effect.effects[0].element.makePositioned();
        },
        afterFinishInternal: function(effect) {
		effect.effects[0].element.hide();
         // effect.effects[0].element.hide().undoPositioned().setStyle(oldStyle);
        }
      }, arguments[1] || { }));
};



/**
 * Function to display generic popup message
 * 
 */



var MyfabPopup = Class.create();
MyfabPopup.prototype = {
    initialize: function(){
    },

    show: function(text){
		$('myfab-popup-display').innerHTML = text;
		$('myfab-popup-display-container').style.display = "block";
    },

    close: function(){
        $('myfab-popup-display-container').style.display = "none";
    }
}

myfab_popup = new MyfabPopup();

/**
 * Magento Enterprise Edition
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Magento Enterprise Edition License
 * that is bundled with this package in the file LICENSE_EE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.magentocommerce.com/license/enterprise-edition
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category    design
 * @package     enterprise_default
 * @copyright   Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
 * @license     http://www.magentocommerce.com/license/enterprise-edition
 */

// Add togglemenu
function toggleMenu(el, over)
{
    if (over) {
        Element.addClassName(el, 'over');
    }
    else {
        Element.removeClassName(el, 'over');
    }
}

/**
 * Myfab
 *
 * @copyright  Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
 * @license    http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 * 
 * display or undisplay the video block
 * 
 */
function displayVideo(){ 
	 Effect.Appear('block-video', { duration:1, from:0.0, to:0.9 });
	 var video = document.getElementById("block-video");
	 video.style.visibility = 'visible';

}

function undisplayVideo(){
	Effect.Fade('block-video', { duration:0.5, from:0.9, to:0.0 });
}


function displayBlock(idName){ 
	     Effect.Appear(idName, { duration:1, from:0.0, to:0.9 });
	     var video = document.getElementById(idName);
	     video.style.visibility = 'visible';

}

function undisplayBlock(idName){
	    Effect.Fade(idName, { duration:0.5, from:0.9, to:0.0 });
}

function myfabClearInputText() {
	    document.getElementById('search-notify-email').value = '';
	    return true;
}

function myfabCheckInputValue() {
	    input_value = document.getElementById('search-notify-email').value;
	    if(!trimAll(input_value)) {
	    	document.getElementById('search-notify-email').value = "E-mail Address";
	    }
}

function trimAll(sString)
{
	  while (sString.substring(0,1) == ' ')
	  {
	  sString = sString.substring(1, sString.length);
	  }
	  while (sString.substring(sString.length-1, sString.length) == ' ')
	  {
	  sString = sString.substring(0,sString.length-1);
	  }
	  return sString;
}

function checkMyfabUkLoginKeyDown(event) {
	    if(event.value == '13') {
	    	  notifyForm.save();
	    }
}

function in_array(string, array)
{
   for (i = 0; i < array.length; i++)
   {
      if(array[i] == string)
      {
	 return true;
      }
   }
return false;
}
Validation.defaultOptions = {
    	    onSubmit : true,
    	    stopOnFirst : true,
    	    immediate : false,
    	    focusOnError : true,
    	    useTitles : false,
    	    addClassNameToContainer: false,
    	    containerClassName: '.input-box',
    	    onFormValidate : function(result, form) {},
    	    onElementValidate : function(result, elm) {}
    	};

testBeforeSave = function(){
	
    if($("isValidCGV").checked == true){
		review.save();
	}else{
		alert($("isValidCGVText").innerHTML);
	}
};

Validation.prototype.initialize = function(form, options){
        this.form = $(form);
        if (!this.form) {
            return;
        }
        this.options = Object.extend({
            onSubmit : Validation.defaultOptions.onSubmit,
            stopOnFirst : Validation.defaultOptions.stopOnFirst,
            immediate : Validation.defaultOptions.immediate,
            focusOnError : Validation.defaultOptions.focusOnError,
            useTitles : Validation.defaultOptions.useTitles,
            onFormValidate : Validation.defaultOptions.onFormValidate,
            onElementValidate : Validation.defaultOptions.onElementValidate
        }, options || {});
        if(this.options.onSubmit) Event.observe(this.form,'submit',this.onSubmit.bind(this),false);
        if(this.options.immediate) {
            Form.getElements(this.form).each(function(input) {
            	Event.observe(input, 'focus', this.onChange.bindAsEventListener(this));
            	Event.observe(input, 'blur', this.onChange.bindAsEventListener(this));
            }, this);
        }
    };
    
Validation.prototype.onChange = function (ev) {
        Validation.isOnChange = true;
    	$$('.validation-advice').each( function(e) {
        	e.hide();
     	})        
        Validation.validate(Event.element(ev),{
                useTitle : this.options.useTitles,
                onElementValidate : this.options.onElementValidate
        });
    	$$('.validation-advice').each( function(e) {
        	e.observe('click',function(ev){
            	Event.element(ev).up(0).hide();
            });
     	})           
        Validation.isOnChange = false;
    };
    
Validation.prototype.validate = function() {
        var result = false;
        var useTitles = this.options.useTitles;
        var callback = this.options.onElementValidate;
        try {
            if(this.options.stopOnFirst) {
                result = Form.getElements(this.form).all(function(elm) {
                    if (elm.hasClassName('local-validation') && !this.isElementInForm(elm, this.form)) {
                        return true;
                    }
                    return Validation.validate(elm,{useTitle : useTitles, onElementValidate : callback});
                }, this);
                Form.getElements(this.form).each(function(input) {
                	Event.observe(input, 'focus', this.onChange.bindAsEventListener(this));
                	Event.observe(input, 'blur', this.onChange.bindAsEventListener(this));
                }, this);
            } else {
                result = Form.getElements(this.form).collect(function(elm) {
                    if (elm.hasClassName('local-validation') && !this.isElementInForm(elm, this.form)) {
                        return true;
                    }
                    return Validation.validate(elm,{useTitle : useTitles, onElementValidate : callback});
                }, this).all();
            }
        } catch (e) {

        }
        if(!result && this.options.focusOnError) {
            try{
                Form.getElements(this.form).findAll(function(elm){return $(elm).hasClassName('validation-failed')}).first().focus()
            }
            catch(e){

            }
        }
        this.options.onFormValidate(result, this.form);
        return result;
    },
    
    	Object.extend(Validation, {
    	    showAdvice : function(elm, advice, adviceName){
    		    if(advice!=null && advice!=" "){
    		    if(!elm.advices){
    		        elm.advices = new Hash();
    		    }
    		    else{
    		        elm.advices.each(function(pair){
    		            this.hideAdvice(elm, pair.value);
    		        }.bind(this));
    		    }
    		    elm.advices.set(adviceName, advice);
    		    advice.style.display = 'inline';
    		    }
    		},
    	   
    	    createAdvice : function(name, elm, useTitle, customError) {
    	        var v = Validation.get(name);
    	        var errorMsg = useTitle ? ((elm && elm.title) ? elm.title : v.error) : v.error;
    	        if (customError) {
    	            errorMsg = customError;
    	        }
    	        try {
    	            if (Translator){
    	                errorMsg = Translator.translate(errorMsg);
    	            }
    	        }
    	        catch(e){}
                if(errorMsg!=null && errorMsg!=" "){
    	        advice = '<div class="validation-advice" id="advice-' + name + '-' + Validation.getElmID(elm) +'" style="display:none"><span>' + errorMsg + '</span></div>'
                }else{advice = null;}
                
    	        Validation.insertAdvice(elm, advice);
    	        advice = Validation.getAdvice(name, elm);
    	        if($(elm).hasClassName('absolute-advice')) {
    	            var dimensions = $(elm).getDimensions();
    	            var originalPosition = Position.cumulativeOffset(elm);

    	            advice._adviceTop = (originalPosition[1] + dimensions.height) + 'px';
    	            advice._adviceLeft = (originalPosition[0])  + 'px';
    	            advice._adviceWidth = (dimensions.width)  + 'px';
    	            advice._adviceAbsolutize = true;
    	        }
    	        return advice;
    	    }
    	});

/**
 * Magento Enterprise Edition
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Magento Enterprise Edition License
 * that is bundled with this package in the file LICENSE_EE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.magentocommerce.com/license/enterprise-edition
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category    design
 * @package     enterprise_default
 * @copyright   Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
 * @license     http://www.magentocommerce.com/license/enterprise-edition
 */
 
if (!window.Enterprise) {
    window.Enterprise = {};
}

if (!Enterprise.CatalogEvent) {
    Enterprise.CatalogEvent = {};
}

Enterprise.CatalogEvent.Ticker = Class.create();

Object.extend(Enterprise.CatalogEvent.Ticker.prototype, {
    initialize: function (container, seconds, displayType) {
        this.container = $(container);
        this.seconds   = seconds;
        this.start     = new Date();
        this.interval = setInterval(this.applyTimer.bind(this), 1000);
        this.displayType = displayType;
		this.applyTimer();
    },
    getEstimate: function () {
        var now = new Date();
        
        var result = this.seconds - (now.getTime() - this.start.getTime())/1000;
        
        if (result <= 0) {
            return 0;
            
        }
        
        return Math.round(result);
    },
    applyTimer: function () {
        var seconds = this.getEstimate();
        var daySec = Math.floor(seconds / (3600*24)) * (3600*24);
        var hourSec = Math.floor(seconds / 3600) * 3600;
        var minuteSec =  Math.floor(seconds / 60) * 60;
        var secondSec = seconds;
        this.container.down('.days').update(this.formatNumber(Math.floor(daySec/(3600*24))));
        this.container.down('.hour').update(this.formatNumber(Math.floor((hourSec - daySec)/3600)));
        this.container.down('.minute').update(this.formatNumber(Math.floor((minuteSec - hourSec)/60)));
        this.container.down('.second').update(this.formatNumber(seconds - minuteSec));
        if( hourSec==0 && minuteSec==0 && secondSec==0){ clearInterval(this.interval); location.reload(true);}
		if(this.displayType == "dynamic")
		{
			if (Math.floor(daySec/(3600*24)) < 2)
			{
				$$('#'+this.container.id+' .countdown-french-plurial').each(function(e){e.hide()});
			}			

			if (daySec > 0) {
				//this.container.down('.second').previous('.delimiter').hide();
				//this.container.down('.countdown-time').hide();

				this.container.down('.countdown-legend-hours').hide();
				this.container.down('.countdown-legend-minutes').hide();
				//this.container.down('.countdown-legend-secondes').hide();
				this.container.down('.countdown-title').show();
				this.container.down('.clock1').show();
				this.container.down('.clock2').hide();
				//this.container.down('.days').next('.delimiter').show();
			} else {
				//this.container.down('.countdown-title').hide();
				//this.container.down('.days').next('.delimiter').hide();
				//this.container.down('.second').previous('.delimiter').show();
				this.container.down('.second').show();
				this.container.down('.countdown-legend-hours').hide();
				this.container.down('.countdown-legend-minutes').hide();
				this.container.down('.countdown-legend-secondes').show();
				this.container.down('.clock1').hide();
				this.container.down('.clock2').show();
			}
		}
    },
    formatNumber: function (number) {
        if (number < 10) {
            return '0' + number.toString();
        }

        return number.toString();
    }
});

/*
$('#xmas-link-fr').load(function() {
	$(this).click(function() {
		$(this).href='http://fr.myfab.com/idee-cadeau-design-noel.html';
	});
});
$('#xmas-link-de').load(function() {
	$('#xmas-link-de').click(function() {
		this.href='http://de.myfab.com/weihnachten-special-design-deko.html';
	});
});
*/
    var __adUrl=document.location.protocol+'//atout.email-match.com/emafunc.js';
    try
    {
     scriptTag=document.createElement("script");
     scriptTag.type="text/javascript";
     scriptTag.src=__adUrl;
     var headTag= document.getElementsByTagName("head")[0];
     headTag.insertBefore(scriptTag,headTag.firstChild);
    } catch(e)
    {  document.write('<sc'+'ript language="javascript" type="text/javascript" src="'+__adUrl+'"></sc'+'ript>'); }
    function w_emasend()
    { if (typeof(emasend)!='undefined'){emasend();} else {setTimeout('w_emasend()',200);} }
    var ema_id_site=227;
    w_emasend();
 

