window.addEvent('domready', function() {
	$$('.email').each(function(el) {
		var link = el.get('rel').replace('|','@');
		var anchor = new Element('a', {href: 'mailto:' + link, 'class': el.get('class'), 'text': link}).replaces(el);
	});
});


/* Author: luistar15, <leo020588 [at] gmail.com> | License: MIT License | Requires: mootools 1.2 core */
var viewer = new Class({
	mode: 'rand',
	modes: ['top','right','bottom','left','alpha'],
	sizes: {w:480,h:240},
	fxOptions: {duration:500},
	interval: 5000,
	initialize: function(items,options){
		if(options) for(var o in options) this[o]=options[o];
		if(this.buttons){this.buttons.previous.addEvent('click',this.previous.bind(this,[true]));this.buttons.next.addEvent('click',this.next.bind(this,[true]));}
		this._current = 0;
		this._previous = null;
		this.items = items.setStyle('display','none');
		this.items[this._current].setStyle('display','block');
		this.disabled = false;
		this.attrs = {left: ['left',-this.sizes.w,0,'px'],top: ['top',-this.sizes.h,0,'px'],right: ['left',this.sizes.w,0,'px'],bottom: ['top',this.sizes.h,0,'px'],alpha: ['opacity',0,1,'']};
		this.rand = this.mode=='rand';
		this.sequence = typeof(this.mode)=='object' ? this.mode : false;
		this.curseq = 0;
		this.timer = null;
	},
	walk: function(n,manual){
		if(this._current!==n && !this.disabled){
			this.disabled = true;
			if(manual){ this.stop(); }
			if(this.rand){ this.mode = this.modes.getRandom(); }
			else if(this.sequence){this.mode = this.sequence[this.curseq];this.curseq += this.curseq+1<this.sequence.length ? 1 : -this.curseq;}
			this._previous = this._current; 
			this._current = n;
			var a = this.attrs[this.mode].associate(['p','f','t','u']);
			for(var i=0;i<this.items.length;i++){
				if(this._current===i){ this.items[i].setStyles($extend({'display':'block','z-index':'2'},JSON.decode('{"'+a.p+'":"'+a.f+a.u+'"}'))); }
				else if(this._previous===i){ this.items[i].setStyles({'z-index':'1'}); }
				else{ this.items[i].setStyles({'display':'none','z-index':'0'}); }
			}
			this.items[n].set('tween',{onComplete:this.onComplete.bind(this)}).tween(a.p,a.f,a.t);
		}
	},
	play: function(wait){ this.stop(); if(!wait){ this.next(); } this.timer = this.next.periodical(this.interval,this,[false]); },
	stop: function(){ $clear(this.timer); },
	next: function(manual){ this.walk(this._current+1<this.items.length ? this._current+1 : 0,manual); },
	previous: function(manual){ this.walk(this._current>0 ? this._current-1 : this.items.length-1,manual); },
	onComplete: function(){
		this.disabled = false;
		this.items[this._previous].setStyle('display','none');
		if(this.onWalk) this.onWalk(this._current);
	}
});
var jswin = new Class({
	Implements: Options,
	options: {data:'.jswin',overlay:false,width:320,height:240,htmlWidth:600,htmlHeight:350},
	initialize: function(options){
		this.setOptions(options);
		this.timer = 0;
		this.index = 0;
		this.opened = false;
		this.contentToLoad = {};
		this.contentObj = {};
		this.openClosePos = {};
		switch($type(this.options.data)){
			case 'string': 
				this.content = $$(this.options.data); 
				this.content.each(function(el,i){el.addEvent('click', function(e){ e.stop(); this.open(el); }.bind(this));}, this);
			break;
			case 'element': 
				var el = this.options.data;
				this.content = [el]; 
				el.addEvent('click', function(e){ e.stop(); this.open(el); }.bind(this));
			break;
		}
		var closeButton = new Element('div',{'class':'jsbox-close'}).addEvent('click', this.close.bind(this));
		var clearControls = new Element('div',{'class':'clear'});
		this.previousButton = new Element('div',{'class':'jsbox-previous'}).addEvent('click', this.previous.bind(this));
		this.nextButton = new Element('div',{'class':'jsbox-next'}).addEvent('click', this.next.bind(this));
		this.number = new Element('div',{'class':'jsbox-number'});
		this.title = new Element('div',{'class':'jsbox-title'});
		this.controls = new Element('div',{'class':'jsbox-controls'}).adopt(this.previousButton,this.nextButton,this.number,this.title,clearControls);
		this.controlsContainer = new Element('div',{'class':'jsbox-controls-container'}).adopt(this.controls);
		this.box = new Element('div', {'styles': {'width':'100%','opacity':0}});
		this.boxContainer = new Element('div', {'class': 'jsbox-content'}).adopt(this.box);
		var b1 = new Element('div', {'class': 'jsbox-top'}).adopt(new Element('div'));
		var b2 = new Element('div', {'class': 'jsbox-left'}).adopt(new Element('div', {'class': 'jsbox-right'}).adopt(this.boxContainer,this.controlsContainer));
		var b3 = new Element('div', {'class': 'jsbox-bottom'}).adopt(new Element('div'));
		this.container = new Element('div',{'class':'jsbox','styles': {'opacity':0}}).adopt(closeButton,b1,b2,b3).inject(document.body,'top');
		this.containerEffects = new Fx.Elements([this.container,this.box],{duration: 400, transition: Fx.Transitions.Sine.easeInOut});
		this.controlEffects = new Fx.Morph(this.controlsContainer, {duration: 300, transition: Fx.Transitions.Sine.easeInOut});
		new Drag(this.container,{handle:b1});
		this.reset();
	},
	getOpenClosePos: function(el){
		if(el.getFirst()){
			var w = el.getFirst().getCoordinates().width; if(w < 0){w = 0}
			var h = el.getFirst().getCoordinates().height; if(h < 0){h = 0}
			this.openClosePos = { 'width': w, 'height': h, 'top': el.getFirst().getCoordinates().top, 'left': el.getFirst().getCoordinates().left };
		}
		else{
			var w = el.getCoordinates().width; if(w < 0){w = 0}
			var h = el.getCoordinates().height; if(h < 0){h = 0}
			this.openClosePos = { 'width': w, 'height': h, 'top': el.getCoordinates().top, 'left': el.getCoordinates().left };
		}
		return this.openClosePos;
	},
	open: function(el){
		if(this.options.overlay){ this.overlay = new Overlay({onClick:this.close.bind(this)}); }
		ieFixOverlay(true);
		this.index = this.content.indexOf(el);
		if(!this.opened){
			this.opened = true;
			if(this.options.overlay){ this.overlay.show(); }
			this.container.setStyles(this.getOpenClosePos(el));
			this.container.setStyle('display', 'block');
			this.containerEffects.start({
				0: {'width': this.options.width,'height': this.options.height,'top': (window.getHeight()/2)+(window.getScrollTop())-(this.options.height/2),'left': (window.getWidth()/2)-(this.options.width/2),'opacity': 1},
				1: {'height': this.options.height}
			});
			this.load(this.index);
		}
		else{
			this.hideControls();
			this.getOpenClosePos(this.content[this.index]);
			this.timer = this.hideContent.delay(500,this);
			this.timer = this.load.delay(1100,this,this.index);
		}
		return false;
	},
	load: function(index){
		this.boxContainer.addClass('jsbox-loading');
		var link = this.content[index];
		var contentOptions = {};
		this.contentToLoad = { title: link.title ? link.title : null, number: index+1 };
		if($chk(link.rel)){var optArr = link.rel.split(',');optArr.each(function(el){ var ta = el.split(':'); contentOptions[ta[0]] = ta[1]; });}
		var str = link.href.substr(link.href.lastIndexOf('.')+1).toLowerCase();
		if($defined(contentOptions.type)){ str = contentOptions.type; }
		switch(str){
			case 'jpg': case 'gif': case 'png': this.type = 'image'; break;
			case 'youtube': this.type = 'youtube'; break;
			default: this.type = 'html'; break;
		}
		if(this.type == 'image'){ this.contentObj = new Asset.image(link.href, {onload: this.resize.bind(this)}); }
		else if(this.type == 'youtube'){
			this.contentObj = new Element('div', {
				'html':'<p style="padding:20px;">Hello, you either have JavaScript turned off or an old version of Adobes Flash Player. <a href="http://www.macromedia.com/go/getflashplayer/" title="Get the latest Flash player">Get the latest Flash player</a></p>',
				'styles': {'overflow':'auto'} 
			});
			this.contentObj.width = contentOptions.width ? contentOptions.width : this.options.width;
			this.contentObj.height = contentOptions.height ? contentOptions.height : this.options.height;
			if (Browser.Plugins.Flash.version > 7){
				new Swiff('/media/player.swf', {
					id: 'mplayer',
					container: this.contentObj,
					width: this.contentObj.width,
					height: this.contentObj.height,
					params: {wmode: 'opaque',bgcolor: '#ffffff',allowfullscreen: 'true'},
					vars: {stretching: 'exactfit',file: 'http://www.youtube.com/watch?v='+contentOptions.video,image: 'http://img.youtube.com/vi/'+contentOptions.video+'/2.jpg'}
				});
			}
			this.resize.delay(500,this);
		}
		else{ 
			var html_height = contentOptions.height ? contentOptions.height.toInt() : this.options.htmlHeight;
			var html_width = contentOptions.width ? contentOptions.width.toInt() : this.options.htmlWidth;
			var div = new Element('div', {'styles': {'padding':'20px'} }).load(link.href);
			this.contentObj = new Element('div', {'styles': {'overflow':'auto', 'height': html_height } }).adopt(div);
			this.contentObj.width = html_width;
			this.contentObj.height = html_height;
			this.resize();
		}
	},
	resize: function(){
		var top = (window.getHeight()/2)-((this.contentObj.height.toInt()/2)+46)+window.getScrollTop();
		var left = (window.getWidth()/2)-(this.contentObj.width/2);
		if(top < 0){top = 0;}
		if(left < 0){left = 0;}
		this.containerEffects.cancel();
		this.containerEffects.start({
			0: {'width': this.contentObj.width.toInt()+40,'height': this.contentObj.height,'top': top,'left': left,'opacity': 1},
			1: {'height': this.contentObj.height}
		});
		this.timer = this.showContent.delay(500,this);
	},
	showContent: function(){
		this.boxContainer.removeClass('jsbox-loading');
		this.removeContent();
		this.box.adopt(this.contentObj).fade('in');
		this.title.set('html',this.contentToLoad.title);
		this.number.set('html',this.contentToLoad.number+' of '+this.content.length);
		this.timer = this.showControls.delay(800,this);
	},
	showControls: function(){
		if(this.type == 'youtube' || this.content.length > 1){
			this.contentToLoad.number == 1 ? this.previousButton.addClass('jsbox-previous-disabled') : this.previousButton.removeClass('jsbox-previous-disabled');
			this.contentToLoad.number == this.content.length ? this.nextButton.addClass('jsbox-next-disabled') : this.nextButton.removeClass('jsbox-next-disabled');
			this.controlEffects.start({'height': this.controls.getStyle('height')});
		}
	},
	hideContent: function(){
		this.boxContainer.addClass('jsbox-loading');
		this.box.fade('out');
		this.hideControls();
		this.removeContent.delay(500,this);
	},
	removeContent: function(){ this.box.empty(); },
	hideControls: function(){this.controlEffects.start({'height': 0});},
	zoomOut: function(){
		this.containerEffects.start({
			0:{'width': this.openClosePos.width,'height': this.openClosePos.height,'top': this.openClosePos.top,'left': this.openClosePos.left,'opacity': 0},
			1: {'height': this.openClosePos.height}
		});
		this.reset.delay(500,this);
	},
	next: function(){if(this.index < this.content.length-1){this.index++;this.hideControls();this.getOpenClosePos(this.content[this.index]);this.timer = this.hideContent.delay(500,this);this.timer = this.load.delay(1100,this,this.index);}},
	previous: function(){if(this.index > 0){this.index--;this.hideControls();this.getOpenClosePos(this.content[this.index]);this.timer = this.hideContent.delay(500,this);this.timer = this.load.delay(1100,this,this.index);}},
	reset: function(){this.container.setStyles({'opacity':0,'display': 'none'});this.controlsContainer.setStyle('height', 0);this.removeContent();this.opened = false;},
	close: function(){if(this.options.overlay){ this.overlay.hide(); }this.hideContent();this.containerEffects.cancel();this.zoomOut.delay(500,this);ieFixOverlay.delay(1000);}
});
var Overlay = new Class({
	Implements: Options,
	options: { colour: '#515151', opacity: 0.8, zIndex: 98, onClick: $empty },
	initialize: function(options){
		this.setOptions(options);
		this.overlay = new Element('div', {
			'id': 'overlay',
			'styles': { 'position': 'absolute', 'left': '0px', 'top': '0px', 'width': '100%', 'zIndex': this.options.zIndex, 'background-color': this.options.colour }
		}).inject(document.body);
		this.overlay.addEvent('click', function(){ this.options.onClick(); }.bind(this));
		this.overlay.fade('hide');
		this.position.delay(10,this);
		window.addEvent('resize', this.position.bind(this));
	},
	position: function(){ 
		var h = window.getScrollSize().y; 
		this.overlay.setStyles({'top': 0, 'height': h}); 
	},
	show: function(){ this.overlay.fade(this.options.opacity); },
	hide: function(){ this.overlay.fade('out'); }
});
Native.implement([Element,Document,Window,String,Number],{
	fromQueryString: function(){
		switch($type(this)){
			case 'window':
			case 'document': var url = location.href; break;
			case 'element':
				switch(this.get('tag')){
					case 'a': var url = this.get('href'); break;
					case 'form': var url = this.get('action'); break;
					default: return false;
				}
				break;
			case 'string': var url = this; break;
			default: return false;
		}
		var parameters = false;
		if(url.contains('?')){
			if(url.contains('#')){ url = url.split('#')[0]; }
			var query = url.split('?')[1];
			if(query != ""){
				var parameters = new Hash();
				params = query.split('&');
				params.each(function(param){ param = param.split('='); parameters.set(param[0],param[1]); });
			}
		}
		return parameters;
	},
	numberFormat: function(decimals, dec_point, thousands_sep) {
		decimals = Math.abs(decimals) + 1 ? decimals : 2;
		dec_point = dec_point || '.';
		thousands_sep = thousands_sep || ',';
		var matches = /(-)?(\d+)(\.\d+)?/.exec((isNaN(this) ? 0 : this) + '');
		var remainder = matches[2].length > 3 ? matches[2].length % 3 : 0;
		return (matches[1] ? matches[1] : '') + (remainder ? matches[2].substr(0, remainder) + thousands_sep : '') + matches[2].substr(remainder).replace(/(\d{3})(?=\d)/g, "$1" + thousands_sep) + (decimals ? dec_point + (+matches[3] || 0).toFixed(decimals).substr(2) : '');
	}
}); 
function ieFixOverlay(open){
	if (Browser.Engine.trident4){
		var elements = $$(document.getElementsByTagName('object'));
		elements.extend(document.getElementsByTagName(Browser.Engine.trident4 ? 'select' : 'embed'));
		elements.each(function(el){ el.style.visibility = open ? 'hidden' : ''; });
	}
}
function onSelect(what){ var destination = what.options[what.selectedIndex].value; if (destination) location.href = destination; }
function isEmpty(val){ if(val == null){return true;} for(var i=0; i < val.length; i++) { if ((val.charAt(i)!=' ')&&(val.charAt(i)!="\t")&&(val.charAt(i)!="\n")&&(val.charAt(i)!="\r")){ return false; } } return true; }
function isPhone(val){ pattern = new RegExp(/^[0-9-\s+]{5,16}$/); if (!pattern.test(val)) { return false; } return true; }
function isAccess(val){ var pattern = /^([a-zA-Z0-9_]{6,16})$/; if (!pattern.test(val)) { return false; } return true; }
function isEmail(val){
	if (isEmpty(val)){ return false; }
	var i = 1,length = val.length;
	while ((i < length) && (val.charAt(i) != "@")){i++;}
	if ((i >= length) || (val.charAt(i) != "@")){ return false; }else{ i += 2; }
	while ((i < length) && (val.charAt(i) != ".")){i++;}
	if ((i >= length - 1) || (val.charAt(i) != ".")){ return false; }else{ return true; }
}