﻿/* decrypt spam-protected emails */
var _mEncrypt = {
	dcString:function(e,o){ var d="", l=e.length; for(var i=0;i<l;i++){ var n=e.charCodeAt(i); if(n>=0x2B&&n<=0x3A) d+=this.dcChar(n,0x2B,0x3A,o); else if(n>=0x40&&n<=0x5A) d+=this.dcChar(n,0x40,0x5A,o); else if(n>=0x61&&n<=0x7A) d+=this.dcChar(n,0x61,0x7A,o); else d+=e.charAt(i); } return d; },
	dcChar:function(n,s,e,o){ n=n+o; if(o>0&&n>e) n=s+(n-e-1); else if(o<0&&n<s) n=e-(s-n-1); return String.fromCharCode(n);},
	dcMail:function(s,p){var link='mailto:'+this.dcString(s,-2)+(p?'?'+p:''); location.href=link;}
};


var api = {
	thisScriptName: "api.esn",
	reqMootoolsVer: 1.3,
	anchorScroll: null,
	requirePlugs: function() { if((typeof MooTools=='undefined') || (parseFloat(MooTools.version) < api.reqMootoolsVer)){ throw("this api requires the MooTools JavaScript framework >= " + api.reqMootoolsVer); } eval("var js = /"+ api.thisScriptName +"\\.js(\\?.*)?$/;"); $(document.head).getElements('script[src]').each(function(s){ if(!s.src.match(js)) return; var path = s.src.replace(js, '', s.src)+'plugins/';var includes = s.src.match(/\?.*plug=([A-Za-z0-9,]*)/); (includes ? includes[1] : '').split(',').each(function(include){ if(include!='') api.includePlugs(path+include+'.js'); }); }); },
	includePlugs: function(library) { try{ document.write('<script type="text/javascript" src="'+library+'"><\/script>'); } catch(e) { var script = new Elemen('script', {type:'text/javascript', src:library}); $$('head').grab(script);}},
	activAnchor: null,


	mooSlideShow:		function(e,o){ if(typeof mooSlideShow	    != 'undefined') new mooSlideShow(e,o); },
	mooAccordion:		function(e,o){ if(typeof mooAccordion	    != 'undefined') new mooAccordion(e,o);},
	mooGallerieScroll:	function(e,o){ if(typeof mooGallerieScroll	!= 'undefined') new mooGallerieScroll(e,o);},

	mooSlimboxScanPage: function() {
		$$("a").filter(function(el) {
			return el.rel && el.rel.test(/^lightbox/i);
		}).mooSlimbox({counterText:"{x} / {y}"}, null, function(el) {
			return (this == el) || ((this.rel.length > 8) && (this.rel == el.rel));
		});
	},
	
	subFormGroup: function(e, o) {
		e.switcher = e.getElement('.switcher input[type="checkbox"]');
		e.content  = e.getElement('.content');
		if(!e.switcher || !e.content) return;
		e.effectfx = new Fx.Slide(e.content, { link:'cancel', duration: 500});
		if(!e.switcher.checked) e.effectfx.hide();
		e.switcher.addEvent('click', function(event) {
			if(e.switcher.checked) e.effectfx.slideIn('vertical');
			else e.effectfx.slideOut('vertical');
		});
	},
	 
	 
	setRating: function(e,o) {
		var starDef = [{min:-4, max:4},{min:4, max:15},{min:16, max:28},{min:29, max:41},{min:42, max:54},{min:55, max:66}], ratLayer = e.getElement('.ratingStars img'), ratValue = e.getElement('input.fact'), currRat = ratValue.value;
		if(!ratLayer) return;
		ratLayer.removeClass(ratLayer.className).addClass('rating0'+currRat);
		var getPos = function(mouse, layer) { return {x: mouse.x - layer.left, y: mouse.y - layer.top}; };
		var getSum = function(){ var nodes = $$("#setRatings input.fact"); var summ = 0; nodes.each(function(node){ summ += parseFloat(node.value); }); var count = nodes.length; var total = summ / count; return {num: total, str:total.toFixed(1).toString().replace(".", ",")}; };
		ratLayer.addEvents({
			'mousemove': function(event) { var myPos = getPos(event.page, ratLayer.getCoordinates()); for(var i=0; i < 6; i++){if(myPos.x > starDef[i].min && myPos.x < starDef[i].max && !ratLayer.hasClass('rating0'+i) ) {currRat = i; ratLayer.removeClass(ratLayer.className).addClass('rating0'+i);}}},
			'mouseout': function() { ratLayer.removeClass(ratLayer.className).addClass('rating0'+ ratValue.value); },
			'click': function() { ratValue.value = currRat; var total = getSum(); $('totalNodeStr').set('html', total.str); $('totalNodeVal').set('value', total.num);}
		});
		var total = getSum();
		$('totalNodeStr').set('html', total.str);
		$('totalNodeVal').set('value', total.num);
	},
	
	initFunct: function(e) {
		//api.anchorScroll = new Fx.Scroll(window);
		var fnt = e.get('data-funct'), opt = e.get('data-opt');
		if(opt && (opt != '' && opt != null)) eval("opt = {"+ opt +"};"); else opt = {};
		if (api[fnt]) api[fnt](e,opt);
	}
}

$$('html').addClass("js");

window.addEvent('domready', function(){
	$$("[data-funct]").each(function(e){api.initFunct(e);});
	//if (!/android|iphone|ipod|series60|symbian|windows ce|blackberry/i.test(navigator.userAgent)) api.mooSlimboxScanPage();
});

