
/*
---

script: More.js

description: MooTools More

license: MIT-style license

authors:
	- Guillermo Rauch
	- Thomas Aylott
	- Scott Kyle

requires:
	- core:1.2.4/MooTools

provides: [MooTools.More]

...
*/

MooTools.More = {
	'version': '1.2.4.2',
	'build': 'bd5a93c0913cce25917c48cbdacde568e15e02ef'
};


/*
---

script: Tips.js

description: Class for creating nice tips that follow the mouse cursor when hovering an element.

license: MIT-style license

authors:
- Valerio Proietti
- Christoph Pojer

requires:
- core:1.2.4/Options
- core:1.2.4/Events
- core:1.2.4/Element.Event
- core:1.2.4/Element.Style
- core:1.2.4/Element.Dimensions
- /MooTools.More

provides: [Tips]

...
*/

(function(){

var read = function(option, element){
	return (option) ? ($type(option) == 'function' ? option(element) : element.get(option)) : '';
};

this.Tips = new Class({

	Implements: [Events, Options],

	options: {
		/*
		onAttach: $empty(element),
		onDetach: $empty(element),
		*/
		onShow: function(){
			this.tip.setStyle('display', 'block');
		},
		onHide: function(){
			this.tip.setStyle('display', 'none');
		},
		title: 'title',
		text: function(element){
			return element.get('rel') || element.get('href');
		},
		showDelay: 100,
		hideDelay: 100,
		className: 'tip-wrap',
		offset: {x: 16, y: 16},
		fixed: false
	},

	initialize: function(){
		var params = Array.link(arguments, {options: Object.type, elements: $defined});
		this.setOptions(params.options);
		document.id(this);
		
		if (params.elements) this.attach(params.elements);
	},

	toElement: function(){
		if (this.tip) return this.tip;
		
		this.container = new Element('div', {'class': 'tip'});
		return this.tip = new Element('div', {
			'class': this.options.className,
			styles: {
				position: 'absolute',
				top: 0,
				left: 0
			}
		}).adopt(
			new Element('div', {'class': 'tip-top'}),
			this.container,
			new Element('div', {'class': 'tip-bottom'})
		).inject(document.body);
	},

	attach: function(elements){
		$$(elements).each(function(element){
			var title = read(this.options.title, element),
				text = read(this.options.text, element);
			
			element.erase('title').store('tip:native', title).retrieve('tip:title', title);
			element.retrieve('tip:text', text);
			this.fireEvent('attach', [element]);
			
			var events = ['enter', 'leave'];
			if (!this.options.fixed) events.push('move');
			
			events.each(function(value){
				var event = element.retrieve('tip:' + value);
				if (!event) event = this['element' + value.capitalize()].bindWithEvent(this, element);
				
				element.store('tip:' + value, event).addEvent('mouse' + value, event);
			}, this);
		}, this);
		
		return this;
	},

	detach: function(elements){
		$$(elements).each(function(element){
			['enter', 'leave', 'move'].each(function(value){
				element.removeEvent('mouse' + value, element.retrieve('tip:' + value)).eliminate('tip:' + value);
			});
			
			this.fireEvent('detach', [element]);
			
			if (this.options.title == 'title'){ // This is necessary to check if we can revert the title
				var original = element.retrieve('tip:native');
				if (original) element.set('title', original);
			}
		}, this);
		
		return this;
	},

	elementEnter: function(event, element){
		this.container.empty();
		
		['title', 'text'].each(function(value){
			var content = element.retrieve('tip:' + value);
			if (content) this.fill(new Element('div', {'class': 'tip-' + value}).inject(this.container), content);
		}, this);
		
		$clear(this.timer);
		this.timer = this.show.delay(this.options.showDelay, this, element);
		this.position((this.options.fixed) ? {page: element.getPosition()} : event);
	},

	elementLeave: function(event, element){
		$clear(this.timer);
		this.timer = this.hide.delay(this.options.hideDelay, this, element);
		this.fireForParent(event, element);
	},

	fireForParent: function(event, element){
			if( element && typeof element.getParent() == 'function' )
			{
					parentNode = element.getParent();
					if (parentNode == document.body) return;
					if (parentNode.retrieve('tip:enter')) parentNode.fireEvent
('mouseenter', event);
					else this.fireForParent(parentNode, event);
			}
			else return;
	},

	elementMove: function(event, element){
		this.position(event);
	},

	position: function(event){
		var size = window.getSize(), scroll = window.getScroll(),
			tip = {x: this.tip.offsetWidth, y: this.tip.offsetHeight},
			props = {x: 'left', y: 'top'},
			obj = {};
		
		for (var z in props){
			obj[props[z]] = event.page[z] + this.options.offset[z];
			if ((obj[props[z]] + tip[z] - scroll[z]) > size[z]) obj[props[z]] = event.page[z] - this.options.offset[z] - tip[z];
		}
		
		this.tip.setStyles(obj);
	},

	fill: function(element, contents){
		if(typeof contents == 'string') element.set('html', contents);
		else element.adopt(contents);
	},

	show: function(element){
		this.fireEvent('show', [this.tip, element]);
	},

	hide: function(element){
		this.fireEvent('hide', [this.tip, element]);
	}

});

})();

/*
---

script: Assets.js

description: Provides methods to dynamically load JavaScript, CSS, and Image files into the document.

license: MIT-style license

authors:
- Valerio Proietti

requires:
- core:1.2.4/Element.Event
- /MooTools.More

provides: [Assets]

...
*/

var Asset = {

	javascript: function(source, properties){
		properties = $extend({
			onload: $empty,
			document: document,
			check: $lambda(true)
		}, properties);

		var script = new Element('script', {src: source, type: 'text/javascript'});

		var load = properties.onload.bind(script), 
			check = properties.check, 
			doc = properties.document;
		delete properties.onload;
		delete properties.check;
		delete properties.document;

		script.addEvents({
			load: load,
			readystatechange: function(){
				if (['loaded', 'complete'].contains(this.readyState)) load();
			}
		}).set(properties);

		if (Browser.Engine.webkit419) var checker = (function(){
			if (!$try(check)) return;
			$clear(checker);
			load();
		}).periodical(50);

		return script.inject(doc.head);
	},

	css: function(source, properties){
		return new Element('link', $merge({
			rel: 'stylesheet',
			media: 'screen',
			type: 'text/css',
			href: source
		}, properties)).inject(document.head);
	},

	image: function(source, properties){
		properties = $merge({
			onload: $empty,
			onabort: $empty,
			onerror: $empty
		}, properties);
		var image = new Image();
		var element = document.id(image) || new Element('img');
		['load', 'abort', 'error'].each(function(name){
			var type = 'on' + name;
			var event = properties[type];
			delete properties[type];
			image[type] = function(){
				if (!image) return;
				if (!element.parentNode){
					element.width = image.width;
					element.height = image.height;
				}
				image = image.onload = image.onabort = image.onerror = null;
				event.delay(1, element, element);
				element.fireEvent(name, element, 1);
			};
		});
		image.src = element.src = source;
		if (image && image.complete) image.onload.delay(1);
		return element.set(properties);
	},

	images: function(sources, options){
		options = $merge({
			onComplete: $empty,
			onProgress: $empty,
			onError: $empty,
			properties: {}
		}, options);
		sources = $splat(sources);
		var images = [];
		var counter = 0;
		return new Elements(sources.map(function(source){
			return Asset.image(source, $extend(options.properties, {
				onload: function(){
					options.onProgress.call(this, counter, sources.indexOf(source));
					counter++;
					if (counter == sources.length) options.onComplete();
				},
				onerror: function(){
					options.onError.call(this, counter, sources.indexOf(source));
					counter++;
					if (counter == sources.length) options.onComplete();
				}
			}));
		}));
	}

};

/*
---

script: Hash.Cookie.js

description: Class for creating, reading, and deleting Cookies in JSON format.

license: MIT-style license

authors:
- Valerio Proietti
- Aaron Newton

requires:
- core:1.2.4/Cookie
- core:1.2.4/JSON
- /MooTools.More

provides: [Hash.Cookie]

...
*/

Hash.Cookie = new Class({

	Extends: Cookie,

	options: {
		autoSave: true
	},

	initialize: function(name, options){
		this.parent(name, options);
		this.load();
	},

	save: function(){
		var value = JSON.encode(this.hash);
		if (!value || value.length > 4096) return false; //cookie would be truncated!
		if (value == '{}') this.dispose();
		else this.write(value);
		return true;
	},

	load: function(){
		this.hash = new Hash(JSON.decode(this.read(), true));
		return this;
	}

});

Hash.each(Hash.prototype, function(method, name){
	if (typeof method == 'function') Hash.Cookie.implement(name, function(){
		var value = method.apply(this.hash, arguments);
		if (this.options.autoSave) this.save();
		return value;
	});
});



var ChooseCss = new Class({
						 
				
	initialize: function(){
		
		this.classlist = ['color1.css','color2.css','color3.css','template.css'];
		this.HashCookie = new Hash.Cookie('HashCookieCss',{path : '/'});
		this.settings = new Hash();
		this.cssnumber = 0;
		
	}, //end constructor	
	
	
	
	setCss : function(){
		
			if (window.ie6==true){	
				return
			};
	
			modifyCss = function(classlist, cssnumber){
				
				var nextnum = cssnumber + 1;			
				if (nextnum >3){nextnum = 0};
					
				var newsettings = {
					//randomcss: classlist[Math.round(Math.random()*3.4)]
					newcss: classlist[nextnum],
					cssnum: nextnum
				};
				return newsettings;
			};
			
			var readcss = this.HashCookie.get('cssnum');
			
			if (readcss) {
				var newsettings = modifyCss(this.classlist, readcss);
				
			}else{
				var newsettings = modifyCss(this.classlist, 0);	
			}
			
			this.HashCookie.extend(newsettings);
			this.HashCookie.save();
			
			var thecss = newsettings['newcss'];
			
			new Asset.css('/stylesheet/'+thecss, {id: thecss, title: thecss});
	
	},
	
	
	
	getCss : function(){
		
		
		if (this.HashCookie.get('newcss')) {
						
			var selected = this.HashCookie.get('newcss');
			new Asset.css('/stylesheet/'+selected, {id: selected, title:selected});
			
		} 
	}
	
						 
}); // end Class




//////////////////////////////////////////////////////////////////////////////////////////////////





var Menu = new Class({
	
	openmarginright : 6,
	initialize: function(handle) {
		
		this.handle = $(handle);
		this.lis = $(document.body).getElements(".mymenu"); 

		this.lis.each(function(el) {
							   				   
							   
			el.submenu = el.getElement('.wrap');
			
			var childs = el.submenu.getFirst().getChildren();
			el.openwidth = 2;
			for (var i=0;i<childs.length;i++){
				el.openwidth += childs[i].getStyle('width').toInt();
			}
							   			   
							   
			
			
			this.selectedmenu =  el.getElements(".s");
			
			if(this.selectedmenu!=""){
				el.submenu.setStyle('width', el.openwidth);	
				el.submenu.getFirst().setStyle('width', el.openwidth+10);	
				el.submenu.setStyle('display', '');
			}else{
				el.submenu.setStyle('display', 'none');
			}
			
			el.getFirst().addEvent('click', function(){this.openMe(el.submenu,el.openwidth) }.bind(this));   
			
			el.as =  el.getElements('a');
			
			el.as.addEvent('click', function(){
					var imgnavigator = new ImgNavigator();
					imgnavigator.setMenuPos(0);
			});

			
		}, this);
	
	
		
	//methods:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

	
	
	},openMe: function(el,totalwidth) {
		

		if (el.hasClass('s')==false){
			
			el.addClass('s');
			el.setStyle('display', '');
			
			
			el.getFirst().setStyle('width', totalwidth+10);
			
			
			var myEffects = new Fx.Tween(el, {duration: 600});
			myEffects.start('width',1, totalwidth );

			this.lis.each (function(other){
		   
				if (other != el.getParent()){

					other.submenu.removeClass('s');
					var w = other.submenu.getStyle('width').toInt(); // doesn't work with safari! -> w is fixed to 200
					
					var myEffects = new Fx.Tween(other.submenu, {
						duration: 300, 
						onComplete: function(){other.submenu.setStyle('display', 'none')} // corrects a bug with safari				  
					});
			
					myEffects.start('width',300, 1 );

				}
			});
		
		}//end if

	}//end methods
	
	
}); // end class Menu




//////////////////////////////////////////////////////////////////////////////////////////




var ImgNavigator = new Class({
							 
	distance : -138, // The distance to animate
	moving : false,
	position : 0,
	duration: 300,
	transition: Fx.Transitions.quadOut,

	
	initialize: function() {
		
		this.HashCookie = new Hash.Cookie('HashCookieMenuPos',{path : '/'});
		
	}, // end constructor
	

	begin : function(handle, nvisibleimages) {
		
		this.handle = $(handle);
		
		if (!this.handle) return;
		
		this.handle.setStyle('height',72);
		this.imgcontainer = this.handle.getFirst();
		this.imgs = $$(this.imgcontainer.childNodes);
		this.nimages =this.imgs.length;
		this.nvisibleimages =  nvisibleimages;

		if(window.ie==true){
			this.imgs.getFirst().setProperty('alt',''); // avoids the yellow tip to appear
		}

		this.initialposition(this.nimages);

		if (this.nimages>7){

			// creating prev and next buttons after the imgcontainer div////
			
			this.btncontainer = new Element('div').addClass('btncontainer').injectInside(this.handle);
			
			this.prev_btn = new Element('div').setStyle('display','none').addClass('prev').adopt(
					new Element('a').setProperty('href','javascript:void(0)').addEvent('click', this.animate.pass('left',this))	
			).injectInside(this.btncontainer);
			
			this.next_btn = new Element('div').setStyle('opacity',0).addClass('next').adopt(
					new Element('a').setProperty('href','javascript:void(0)').addEvent('click', this.animate.pass('right',this))	
				).injectInside(this.btncontainer);

			this.handle.addEvent('mouseenter', this.showbtns.pass([this.prev_btn,this.next_btn],this));
			this.handle.addEvent('mouseleave',  this.hidebtns.pass([this.prev_btn,this.next_btn],this));
			
		}	
		
	},
	
	
	//methods:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
	
	
	setMenuPos : function(num){
			
			var newsettings = {menupos: num};
			this.HashCookie.extend(newsettings);
			this.HashCookie.save();
			
			
	},
	
	
	getMenuPos : function(){
		
		var actualpos = this.HashCookie.get('menupos');
		return actualpos;
	},  
	

	
	initialposition : function(n){
		
		this.position = this.getMenuPos();	
		var newmargin =  -138 * this.position ;
		this.imgcontainer.setStyle('margin-left', newmargin);
		
		
		if (window.ie6==true){
			var mywidth = 138*n + 12;
		}else{
			var mywidth = 138*n ;
		}
			
		this.imgcontainer.setStyle('width',mywidth);
	},
	
	
	
	
	animate : function(direction){
		
		if( this.moving ) return;			
		
		if( direction == 'right' ) this.position++;
		else this.position--;
		
		var newMargin =  this.distance * this.position ;
		
		new Fx.Tween(this.imgcontainer, {duration: this.duration, transition: this.transition, 
			onStart :  function(){this.moving = true;  }.bind(this), 
			onComplete : function(){ this.moving = false; }.bind(this)
			}).start('margin-left', newMargin);
		
		if(!this.position) this.prev_btn.setStyle('display','none');
		else this.prev_btn.setStyle('display','');
		if(this.position == this.nimages - this.nvisibleimages ) this.next_btn.setStyle('display','none');
		else this.next_btn.setStyle('display','');
		
		this.setMenuPos(this.position);
		
	},	// end animate

	showbtns : function(div1, div2){

		new Fx.Tween(div1,{duration:200
			}).start('opacity',0.9);
		new Fx.Tween(div2, {duration: 200
			}).start('opacity',0.9);

		if(!this.position) this.prev_btn.setStyle('display','none');
		else this.prev_btn.setStyle('display','');
		if(this.position == this.nimages - this.nvisibleimages ) this.next_btn.setStyle('display','none');
		else this.next_btn.setStyle('display','');
	},
	
	hidebtns : function(div1, div2){
		
		new Fx.Tween(div1, {duration: 200
			}).start('opacity', 0.01);
		new Fx.Tween(div2, {duration: 200
			}).start('opacity', 0.01);
	}
}); // end class




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



	var StartTips = new Class({
							 

			initialize: function() {	
				var mytips = new Tips($$('.tips'), {
					
					
					onShow: function(tip,el) {
						tip.fade('in');
						//this.setStyle('cursor','pointer');
					},
					onHide: function(tip,el) {
						tip.fade('out');
					}
				});
			}
	});




////////////////////////////////////////////////////////////////////




var NextBigImage = new Class({
							 
	distance : -600, //-612, // The distance to animate
	position: 0,		
	moving : false,
	duration: 800,
	transition: Fx.Transitions.quadOut,

	
	initialize: function(handle, nvisibleimages) {

		this.handle = $(handle);
		if (this.handle==null) return;
		this.imgcontainer = this.handle.getFirst();
		this.imgs = $$(this.imgcontainer.childNodes);

		if(window.ie==true){ 
			this.imgs.getFirst().setProperty('alt',''); // avoids the yellow tip to appear
		}
		
		this.nimages = 0;

		this.imgs.each(function(e){
				
				if(e.getFirst().getProperty('src').test(".jpg") | e.getFirst().getProperty('src').test(".gif")){
						  this.nimages++ ;
				}else{e.destroy();}	
													  
		}.bind(this));
		
		if (this.nimages<2) return;
		
		this.nvisibleimages =  nvisibleimages;
		
	
		this.btncontainer = new Element('div').addClass('btncontainer').injectInside(this.handle);
		
		this.prev_btn = new Element('div').setStyle('display','none').setStyle('opacity',0.01).addClass('prev tips').setProperty('title', 'précédente').adopt(
				new Element('a').setProperty('href','javascript:void(0)').addEvent('click', this.animate.pass('left',this))	
		).injectInside(this.btncontainer);
		
		this.next_btn = new Element('div').setStyle('opacity',0.01).addClass('next tips').setProperty('title', 'suivante').adopt(
				new Element('a').setProperty('href','javascript:void(0)').addEvent('click', this.animate.pass('right',this))	
		).injectInside(this.btncontainer);
	

		
		this.modifyopacity2 = new Fx.Tween(this.prev_btn, {
			duration: 2000, 
			transition: Fx.Transitions.quartInOut,
			onStart :  function(){this.showing = true;  }.bind(this), 
			onComplete : function(){ this.showing = false; }.bind(this)
		});
		
		this.modifyopacity = new Fx.Tween(this.next_btn, {
			duration: 2000, 
			transition: Fx.Transitions.quartInOut,
			onStart :  function(){this.showing = true;  }.bind(this), 
			onComplete : function(){ this.showing = false; }.bind(this)
		});

		this.showbtnnext();

	
	}, // end constructor
	
	
	//methods:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
	
	
	// move the imgcontainer div
	animate : function(direction){
		
		if( this.moving ) return;			
		
		if( direction == 'right' ) this.position++;
		else this.position--;
		
		var newMargin = this.distance * this.position;
		
		new Fx.Tween(this.imgcontainer, {duration: this.duration, transition: this.transition, 
			onStart :  function(){ this.moving = true;  }.bind(this), 
			onComplete : function(){ this.moving = false; }.bind(this)
		}).start('margin-left',newMargin);
		
		if(!this.position){
			this.prev_btn.setStyle('display','none');
			this.showbtnnext();
		}
		else this.prev_btn.setStyle('display','');
		
		if(this.position == this.nimages - this.nvisibleimages ){
			this.next_btn.setStyle('display','none');
			this.showbtnprev();	
		}
		else this.next_btn.setStyle('display','');
		
	},	// end animate
	
	
	
	
	showbtnprev : function(){
		
		if( this.showing ) return;

		this.modifyopacity.set('opacity', 0.01);
		
		this.modifyopacity2.start('opacity',0.01,0.9).chain(
			this.modifyopacity2.start.pass(['opacity',0.9,0.01], this.modifyopacity2)
		);
		
	},
	
	showbtnnext : function(){

		if( this.showing ) return;
		
		this.modifyopacity2.set('opacity',0.01);
		
		this.modifyopacity.start('opacity',0.01,0.9).chain(
			this.modifyopacity.start.pass(['opacity',0.9,0.01], this.modifyopacity)
		);
		//this.modifyopacity.start('opacity',0.01,0.9);

		
	}
}); // end class


