window.addEvent('domready', function() {	
	
	var supertips  = new SuperTips($$('.itembg'));
	
	new openCloseForm();

	new adaptContainerHeight();

	if (!$('gallery')){
		if(!$('videobtn')) return;
		$('videobtn').setStyle('display' , 'none');
	}
	
	// set main container height:
	
});


window.addEvent('load', function() {	
	
	if (!$('gallery')){
		var videoplayer = $('mpl');
		if (videoplayer == null) return;
		//videoplayer.sendEvent('PLAY');
		$('videobtn').setStyle('display' , 'none');
		return;
	}
		
	var h = $('gallery').getElement('img').getStyle('height');
	$('mask').setStyle('height',h);
	
});



var adaptContainerHeight = new Class(
{
	initialize: function(target){

		if (!$('content')) return;
		var content_y = $('bgimages').getSize().y - $('content').getStyle('padding-top').toInt() - $('content').getStyle('padding-bottom').toInt()-2;
		$('content').setStyle( 'height', content_y+'px');
		
	 }
});// end class




var openCloseForm = new Class(
{
	initialize: function(target){

		if (!$('productContactForm')) return;
		
		var myVerticalSlide = new Fx.Slide('productContactForm');
		myVerticalSlide.hide();
		
		$('reservationBtn').addEvent('click', function(e){
				e.stop();
				myVerticalSlide.toggle();
				//new Fx.Scroll(window).toElement('productContactForm').toLeft();
				
				//var scroll_height = this.getPosition().x;
				//if (myVerticalSlide.open == false) new Fx.Scroll(window).start(0,scroll_height);
				
			});
			
			
	 }
});// end class

var ShowVideoPlayer = new Class({
	
	initialize: function(obj){
        
        if (!$('video')) return;
        
        if (!$('gallery')){
        	 this.playVideo($('mpl'));
        	 return; 
        }
        
        this.video = $('player');
        
        var mynewspan = new Element('span');
        this.video.inject(mynewspan);
        mynewspan.inject($('imgwrapper'));

        this.obj = obj;
		//var videoSlide = new Fx.Slide('player');
		//videoSlide.hide();
		
		//this.grabNoob = new noobSlide({box: $('imgwrapper'), interval: 3000, size: 600});
		
		this.videoisopen = false;
		this.mask = $('mask');
		this.mask.h0 = this.mask.getStyle('height');
		this.mask.fx = new Fx.Tween(this.mask);

		
		$('videobtn').addEvent('click', function(e){
   			if (this.videoisopen==false){
   				//this.playVideo($('mpl'));
   				this.obj.walk(this.obj.items.length-1,true);
   				this.setMaskHeight(450);
   				this.videoisopen = true;
   			}else{
   				this.obj.walk(0,true);
   				this.videoisopen = false;
   				this.setMaskHeight('h0');

   			}
		}.bind(this));			
			
	 }, //end constructor
	 
	 
	 
	 playVideo : function(target){
		
		target.sendEvent('PLAY');
		
	},
	
	setMaskHeight : function(h){
		
		if (h == 'h0'){
			this.mask.fx.start('height', this.mask.h0);
			this.videoisopen = false;
			$('videobtn').set('html','vidéo');
		}else {
			this.mask.fx.start('height', h);
			this.videoisopen = true;
			$('videobtn').set('html','fermer');
		}
		
	}	// end methods	// end methods
	 
	 
	 
	 
});// end class


/*
var openCloseVideo = new Class(
{
	initialize: function(target){
        
        if (!$('video')) return;
        
		var videoSlide = new Fx.Slide('player');
		videoSlide.hide();
		
		$('videobtn').addEvent('click', function(e){
				e.stop();
				videoSlide.toggle().chain(function(){
		   			 $('mpl').sendEvent('PLAY');
				});

				
				//console.log("playER: "+$('mpl'));
				
				
		});			
			
	 }
});// end class
*/




/***********************************************************************/



var SuperTips = new Class(
{
		
	moving : false,
	duration: 300,
	//transition: Fx.Transitions.quadOut,
	
	initialize: function(target)
	 {		
	 	
		this.superbtns = target;
		
		if (this.superbtns == null) return;
		

		// this.supertip = $('supertip');
		this.supertip = new Element('div', {'id':'supertip'}).inject(document.body, 'top');
		
		
		this.tipeffects = new Fx.Morph(this.supertip,{duration: 300, transition: Fx.Transitions.Sine.easeInOut});
		
		
		this.actualpos = {x:0, y:0};
		this.actualopacity = 0;
		this.actualcontent=null;
		
		
		this.supertip.addEvent('mouseenter', function(){
			this.tipeffects.cancel(); 
			this.tipeffects.set({'opacity' : 1});
			this.movetip(this.actualpos, this.actualcontent);
			
		}.bind(this));
		
		
		this.supertip.addEvent('mouseleave', function(){
			this.tipeffects.cancel();
			this.tipeffects.start({'opacity' : 0});  
		}.bind(this));
		
		
		
		
		
		
		
		this.superbtns.each(function(btn){	
				
				btn.tipcontent = btn.getElement('.descr');
				//console.log("btn.tipcontent: "+btn.tipcontent);
				//btn.tipcontent.setStyle('display', 'none');
				btn.position = btn.getPosition();
				
				
				
				btn.addEvent('mouseenter', function(){							
					this.tipeffects.cancel();
					this.movetip(btn.position, btn.tipcontent);
				}.bind(this));
				
				
				btn.addEvent('mouseleave',  function(){
					this.tipeffects.cancel();
					this.tipeffects.start({'opacity' : 0});
				}.bind(this));
				
		
		}.bind(this));  // end each
		
	}, 
			
	//methods::::::::::::::::::::::::::::::::::
	
	movetip : function(position, content){
		
		// this.tipeffects.cancel();
		
		//console.log('content: '+content);
		
		this.tipeffects.start({
				'left': position.x+185, 
				'top' :  position.y+90,
				'opacity' : 1
		});
		this.actualpos.x = position.x;
		this.actualpos.y = position.y;
		this.actualcontent = content;
		
		
		this.supertip.set('html', content.get('html'));

		
	}	// end movetip
	
	
	
	
	
});// end class




//////////////////////// tips //////////////////////////////////


/*
	var StartTips = new Class({
							 

			initialize: function() {	
				var mytips = new Tips($$('.tips'), {
					
					initialize:function(){
						this.fx = new Fx.Style(this.toolTip, 'opacity', {duration: 500, wait: false}).set(0);
					},
					onShow: function(toolTip) {
						this.fx.start(0.9);
						//this.setStyle('cursor','pointer');
					},
					onHide: function(toolTip) {
						this.fx.start(0);
					}
				});
			}
	});

*/



