/**
 * 
 * @author Alphastudio - Renaud
 * @copyleft
 */
 
function cl() {
	if(!!(console))
		console.log(arguments);
}
function cd() {
	if(!!(console))
		console.dir(arguments);
}

window.addEvent('domready', function() {
	var ua = navigator.userAgent;
	var isiPad = ua.match(/iPad/i) != null;
	var isiPhone = ua.match(/iPhone/i) || ua.match(/iPod/i);
	var isAndroid = ua.match(/android/i); 
	
	$$('.fb-link').addEvent('click', function(event){
		event.stop();
		$('fb').position({
			relativeTo: event.target,
			position: 'upperRight',
			edge: 'bottomRight',
			offset: {
				x: 0,
				y: -10
			}
		});
		$('fb').fade('hide').show().fade('in');
	});
	
	$('fb').getElement('h4 a').addEvent('click', function(){
		$('fb').fade('out');
	});
	
	var myTips = new Tips('#map area,.domtom a,a.corse', {
		title: function(el){
			return el.get('title');
		},
		text: ''
	});
	
	if ($('main-content').hasClass('contact') && $('message')) {
		$('message').addEvents({
			'focus': function(){
				if (this.get('rel') == this.get('html').trim())
					this.set('html', '');
			},
			'blur': function(){
				if (this.get('html').trim() == '')
					this.set('html', this.get('rel'));
			}
		});
	}
	
	$$('#map area,.domtom a,a.corse').addEvent('click', function(event){
		event.stop();
		var self = this;
		if ($('crt-coord-title')) {
			var toHide = ($('crt-coord-title').getStyle('display') != 'none') ? $('crt-coord-title') : $$('.crt-coord').filter(function(el){
				return el.getStyle('display') == 'block';
			}).pop();
			if (self.id == toHide.id) return;
			var fx = new Fx.Tween(toHide, {property: 'opacity'});
			fx.start(1,0).chain(
				function(){
					toHide.hide();
					$('crt-' + self.get('rel')).fade('hide').show().fade('in'); 
				}
			);
		} else {
			var toHide = ($('presse-title').getStyle('display') != 'none') ? $('presse-title') : $$('.presse-coord').filter(function(el){
				return el.getStyle('display') == 'block';
			}).pop();
			if (self.id == toHide.id) return;
			var fx = new Fx.Tween(toHide, {property: 'opacity'});
			fx.start(1,0).chain(
				function(){
					toHide.hide();
					$('presse-' + self.get('rel')).fade('hide').show().fade('in'); 
				}
			);
		}
	});
	
	function initNewMooScroll() {
		scrollBox1 = null;
		scrollBox1 = new MooScroll({
			selector: '#main-content'
		});
	}
	
	if (isiPad || isiPhone) {
		$('main-content').setStyles({
			overflow: 'scroll',
			paddingRight: '20px',
			width: '670px'
		});
	} else {
		window.addEvent('resize', function() {
			var content = $('main-content').getElement('.paddingEl').get('html');
			$('main-content').empty().set('style', '').set('html', content);
			initNewMooScroll();
		});
		
		if(document.body.addBehavior) initNewMooScroll.delay(400);
		else initNewMooScroll();
	}

});

