var Spirit_rules = {

	'a' : function(el) {
		el.onfocus = function() {
			this.blur();
			if (el.getAttribute('rel') == 'external') {
				el.setAttribute('target', '_blank');
		   }
		}
	}, 

	'a#mail' : function(el) {
		el.onclick = function() {
			safeEmail('info', 'ellaonrust');
			return false;
		}
	},

	'a#t_omschrijving' : function(el) {
		el.onclick = function() {
			switchTabs(this.id);
			setHeight();
			return false;
		}
	},

	'a#t_kenmerken' : function(el) {
		el.onclick = function() {
			switchTabs(this.id);
			setHeight();
			return false;
		}
	},

	'a#t_fotos' : function(el) {
		el.onclick = function() {
			switchTabs(this.id);
			setHeight();
			return false;
		}
	},

    'a#t_kaart' : function(el) {
		el.onclick = function() {
			switchTabs(this.id);
			setHeight();
			return false;
		}
	},

	'.aanbod' : function(el) {
		el.onmouseover = function() {
			this.className=this.className.replace("aanbod", "aanbodover");
		}
		el.onmouseout = function() {
			this.className=this.className.replace("aanbodover", "aanbod");
		}
		el.onclick = function() {
			if (this.id.indexOf('aanbod') != -1){
				id = this.id;
				el = 'link_' + id.replace('aanbod_', '');
				linkje = $(el).href;
				location.href = linkje;
			}
		}
	},

	'input' : function(el) {
		el.onblur = function() {
			SchoonInputOp();	
		}
		el.onfocus = function() {
			id = this.id;
			temp = 'regel_' + id.replace('input_', '');
			Element.addClassName(temp, ' regelover');
		}
	},

	'textarea' : function(el) {
		el.onblur = function() {
			SchoonInputOp();	
		}
		el.onfocus = function() {
			id = this.id;
			temp = 'regel_' + id.replace('input_', '');
			Element.addClassName(temp, ' regelover');
		}
	},

	'img' : function(el) {
			el.setAttribute('galleryimg', 'no');
		}
	}

Behaviour.register(Spirit_rules);

function init() {
	setHeight();
	sIFR();
	initTabs();
}

Behaviour.addLoadEvent(init);

//<![CDATA[
/* Replacement calls. Please see documentation for more information. */

if(typeof sIFR == "function"){

sIFR.replaceElement(named({sSelector:"h3", sFlashSrc:"/_files/sifr_Ella.swf", sColor:"#EC038D", sWmode: "transparent"}));
sIFR.replaceElement(named({sSelector:"h4", sFlashSrc:"/_files/sifr_Ella.swf", sColor:"#404040", sWmode: "transparent"}));
sIFR.replaceElement(named({sSelector:".prijs", sFlashSrc:"/_files/sifr_Ella.swf", sColor:"#404040", sWmode: "transparent"}));
};

//]]>

function safeEmail(user, domain) { 
	var e = user + unescape("%40") + domain + '.nl'; 
	var s='Mail vanaf www.ellaonrust.nl'
	location = 'mailto:' + e + '?subject=' + s;
}

function getWindowHeight() {
	var windowHeight = 0;
	if (typeof(window.innerHeight) == 'number') {
		windowHeight = window.innerHeight;
	}
	else {
		if (document.documentElement && document.documentElement.clientHeight) {
			windowHeight = document.documentElement.clientHeight;
		}
		else {
			if (document.body && document.body.clientHeight) {
				windowHeight = document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}

function setHeight() {
	viewport = getWindowHeight();
	maincontent = $('main').getHeight();
	if (maincontent < 400) {
		Element.setStyle('main', {height: '400px'});		
	}
}

function initTabs() {
	Element.addClassName('c_kenmerken', 'c_hidden');
	Element.addClassName('c_fotos', 'c_hidden');
	Element.addClassName('c_kaart', 'c_hidden');
}
function switchTabs(current) {
	Element.removeClassName('t_omschrijving', 'tab_active');
	Element.removeClassName('t_kenmerken', 'tab_active');
	Element.removeClassName('t_fotos', 'tab_active');
	Element.removeClassName('t_kaart', 'tab_active');
	Element.removeClassName('c_omschrijving', 'c_hidden');
	Element.removeClassName('c_kenmerken', 'c_hidden');
	Element.removeClassName('c_fotos', 'c_hidden');
	Element.removeClassName('c_kaart', 'c_hidden');
    
	current = current.substring(2,current.length)
    var tabs = new Array("omschrijving","kenmerken","fotos","kaart");
	for (var loop = 0; loop <tabs.length; loop++){
		if (tabs[loop] != current ) {
			el = 'c_' + tabs[loop];
			Element.addClassName(el, 'c_hidden');
		} else {
			el = 't_' + tabs[loop];
			Element.addClassName(el, 'tab_active');
			el = 'c_' + tabs[loop];
			hoogte_inhoud = $(el).getHeight();
			maincontent = $('main').getHeight();
			if (hoogte_inhoud > maincontent){
				stijlen = '{height: ' + hoogte_inhoud + 'px}';
				Element.setStyle('main', {height: 'auto'});		
			}
		}
	}
}

function SchoonInputOp(){
	$('regel_1').className = 'regel';
	$('regel_2').className = 'regel';
	$('regel_3').className = 'regel';
	$('regel_4').className = 'regel';
	$('regel_5').className = 'regel';
	$('regel_6').className = 'regel';
	$('regel_7').className = 'regel';
	$('regel_8').className = 'regel';
}