// variables
switch(document.domain) {
	case 'localhost':
		var basedir = '/lesoiseauxrares.com/';
		break;
		
	case 'tix02.be':
		var basedir = '/oiseauxrares/';
		break;
		
	default:
		var basedir = '/';
}



// functions 
function mail(name,domain,tld) {
	var mw = window.open('mailto:'+ name +'@'+ domain +'.'+ tld, 'mail_win','width='+ 1 +', height='+ 1 +',top=0,left=0,menubar=no,scrollbars=no,statusbar=no');
	mw.close();
}

function addslashes(str) {
	str=str.replace(/\'/g,'\\\'');
	str=str.replace(/\"/g,'\\"');
	str=str.replace(/\\/g,'\\\\');
	str=str.replace(/\0/g,'\\0');
	return str;
}

function stripslashes(str) {
	str=str.replace(/\\'/g,'\'');
	str=str.replace(/\\"/g,'"');
	str=str.replace(/\\\\/g,'\\');
	str=str.replace(/\\0/g,'\0');
	return str;
}

var tips;
var Tips = new Class({
	_event: null,	
	
	initialize: function() {
		var _this = this;
		
		// First: check if the tips are needed into this page 
		var els = $(document.body).getElements('*[class=tips]');
		
		els.each(function(e) {		  
			if(e.get('rel'))	{
				
				e.addEvent('mouseover', function(ev) {
					 var content = e.get('rel').split('::');
					_this.set(content[0], content[1]);
				});
				
				e.addEvent('mouseout', function(ev) {
					_this.unset();
				});
			}	
		});
		
		var tipDiv = new Element('div', { 'id': 'tips-wrapper' });
		var tipTitle = new Element('h3');
		var tipText = new Element('p');
		
		this.elTitle = tipTitle;
		this.elText = tipText;
		
		tipTitle.inject(tipDiv);
		tipText.inject(tipDiv);
		
		tipDiv.inject($(document.body));
	},
	
	
	set: function(title, text) {
		var _this = this;
		
		$('tips-wrapper').getElement('h3').innerHTML = stripslashes(title);
		$('tips-wrapper').getElement('p').innerHTML = stripslashes(text);
		$('tips-wrapper').style.display = 'block';
		$('tips-wrapper').get('tween', {
				property: 'opacity', 
				duration: 'short'
			}).start(0,0.8);
		
		
		document.addEvent('mousemove', function(e) {
			_this._event = e;
			var width = 300;
			var height = $('tips-wrapper').getSize().y;
			
			var scrollH = window.getScrollSize().y;
			var winW = window.getSize().x;
			var winH = window.getSize().y;
			var scrollY = window.getScroll().y;
			
			var top = ((e.page.y + 10 + height) > (scrollY + winH - 20)) ? e.page.y - 10 - height : e.page.y + 10;
			var left = ((e.page.x + 10 + width) > (winW - 20)) ? e.page.x - 10 - 300 : e.page.x + 10;
			
			$('tips-wrapper').style.top = top +'px';
			$('tips-wrapper').style.left = left +'px';
		});
	},
	
	unset: function() {
		$('tips-wrapper').get('tween', {
				property: 'opacity', 
				duration: 'short', 
				onComplete: function() { 	
					$('tips-wrapper').style.display = 'none';  
				}
			}).start(0);
	}
	
});



function setSplash() {
	var e = $('splash');
	e.style.top = window.getScroll().y +'px';
	e.style.height = window.getSize().y +'px';
	
	$('navigation').style.visibility = 'visible';
	$('wrapper').style.visibility = 'visible';
	$('footer').style.visibility = 'visible';
	
	e.get('tween', {
			property: 'opacity', 
			duration: 'long', 
			onComplete: function() { 	
				e.style.display = 'none';  
			}
		}).start(0);
}

function setFooter() {
	$('footer').className = window.getScrollSize().y > window.getSize().y ? '' : 'absbottom';
}

function setNavigation() {
	var navigation = new SWFObject(basedir +'swf/navigation.swf?basedir='+ basedir +'&amp;section='+ section,'applet_navigation','500','80','8','#ffffff');
	navigation.addParam('wmode','transparent');
	navigation.write('navigation');
}


function text2SWF(tag) {
	$('wrapper').getElements(tag +'[rel=SWFText]').each(
		function(e) {
			var SWFText = new SWFObject(basedir +'swf/'+ type +'_type.swf?text='+ e.innerHTML,'SWFText-'+ e.id,'325','45','8','#a20707');
			SWFText.addParam('wmode','transparent');
			SWFText.write(e.id);
		}
	);
}



function interactiveForms() {
	$(document.body).getElements('input[rel=focus]').each(
		function(e) {
			var li = e.parentNode;
			e.onfocus = e.onblur = function() {
				li.className = li.className == '' ? 'focus' : ''; 
			}
		}
	);
	
	$(document.body).getElements('select[rel=focus]').each(
		function(e) {
			var li = e.parentNode;
			e.onfocus = e.onblur = function() {
				li.className = li.className == '' ? 'focus' : '';
			}
		}
	);
		
	$(document.body).getElements('textarea[rel=focus]').each(
		function(e) {
			var li = e.parentNode;
			e.onfocus = e.onblur = function() {
				li.className = li.className == '' ? 'focus' : '';
			}
		}
	);	
}


function switchSRC(i, img) {
	var current = i.src;
	var path = current.slice(0, current.lastIndexOf('/') + 1);
	i.src = path + img;
}



// Events
window.onresize = function() {
	$('footer').className = window.getScrollSize().y > window.getSize().y ? '' : 'absbottom';
}

window.addEvent('domready', function() {
	tips = new Tips();
	setNavigation();
	setSplash();
	setFooter();
	text2SWF('h1');
	interactiveForms();
});