var brand_object = {
    init: function() {
        if($('marques')){
	        Event.observe($('marques'), 'change', function(e){
	            this.goTo($F('marques'));
	        }.bind(this));
        }
        
        var listeSlideshows = $$('.slideshow');
				if(listeSlideshows && listeSlideshows.length > 0){
					listeSlideshows.each(function(element){
						if(typeof(carrousels) != "undefined"){
							if(carrousels[element.id]){	
								if(element.hasClassName('vertical'))
									element.slidehow = new SlideShow(element, carrousels[element.id], 'vertical');
								else
									element.slidehow = new SlideShow(element, carrousels[element.id]);
							}
						}
					}); 
				}
				
				this.rewriteChouchouNights();
    },
    
    goTo: function(url){
        document.location.href=url;
    },
    
    popin : function(div, link){
    	var width = 400;
    	var height = 270;
    	
    	if(div && div != null)
    		DivPopup.openPopup('cgv',width,height,$(div),null);
    	else if(link && link != null)
    		DivPopup.openPopup('cgv',width,height,null,link);
    },
    
    rewriteChouchouNights : function(){			
		if($('arrivee').value == ''){
			var today = new Date();
			$('arrivee').value = today.print(Calendar._TT.DEF_DATE_FORMAT);
		}
	

		
    	if($('booking_min_stay') && $('booking_max_stay') && $('nb_nuit')){
    		if($('booking_min_stay').value != '' && $('booking_max_stay').value != ''){
    			var j=0
    			var min = Number($('booking_min_stay').value);
    			var max = Number($('booking_max_stay').value);

					var selectElement	= $('nb_nuit');
					if (selectElement) {
						selectElement.options.length=0;
						if(min==0 && max==0){
							selectElement[0]=new Option("--", "");
						} else {
							selectElement[0]=new Option("--", "");
							for(var i=0; i<max-min+1; i++){
								selectElement[i+1]=new Option(min+i, min+i);
								if(i==0)selectElement[i+1].selected = true;								
							}
						}
					}
    		}
    	}
    }
}

Event.observe(window, 'load', function(){
    brand_object.init();
});
