var _tBox = null;

var _boxes = [];



function initTeasers() {

	_tBox = $("teasers");

	if (_tBox)

	{

		_boxes = _tBox.getElements("div.item");

		

		_boxes.each(function(box){

			var _front = box.getElements("div.front")[0];

			var _back = box.getElements("div.back")[0];

			var _link = box.getElements("div.front")[0];//box.getElements("a.more")[0];

			_link._box = box;

			

			box._front = _front;

			box._back = _back;

			

			_front.fx = new Fx.Style(_front, "opacity", {duration: 100, wait: false}).set(0.4);

			_back.fx = new Fx.Style(_back, "opacity", {duration: 100, wait: false}).set(0);

			

			_back.style.display="block";

			

			box.addEvent("mouseenter", function() {

				this._front.fx.start(1);

			});

			box.addEvent("mouseleave", function() {

				this._front.fx.start(0.4);

				this._back.fx.start(0);

			});

			_link.onclick = function () { 

				this._box._front.fx.start(00);

				this._box._back.fx.start(1);

				return false;

			};

		});

	}

}



var _fader = null;

var _faderhide = false;



function initCForm() {

	_fader = $("fader");

	if (_fader)

	{

		_fader._fx = new Fx.Style(_fader, "opacity",{

			duration:100,

			wait:true,

			onComplete: function() {

				if (_faderhide) {

					//_fader.style.display = "none";

				}

			}

		}).set(0);

		

		var _cshow = $("cform-show");

		if (_cshow) {

			_cshow.onclick = function() {

				showFader();

				enlarge("contact-form");

				return false;

			};

		}

		var _chide = $("cform-hide");

		if (_chide) {

			_chide.onclick = function() {

				hideFader();

				hide("contact-form");

				return false;

			};

		}

	}

}



function showFader() {

	_fader.style.width = document.documentElement.scrollWidth+"px";

	_fader.style.height = document.documentElement.scrollHeight+"px";

	_fader.style.display = "block";

	_fader._fx.start(0.7);

}



function hideFader() {

	_faderhide = true;

	_fader._fx.start(0);

}



function enlarge(_obj)

{

	var popup = document.getElementById(_obj);

	if (popup)

	{

		var scrollTop = 0;

		var scrollLeft = 0;

		var h = 0;

		var w = 0;

		if (window.innerHeight)

		{

			h = window.innerHeight;

		}

		else

		{

			h = document.documentElement.clientHeight;

		}

		if (window.innerWidth) {w = window.innerWidth;}

		else{w = document.documentElement.clientWidth;}

		

		

		if (window.pageYOffset){  

 			scrollTop = window.pageYOffset;

		} else if(document.documentElement && document.documentElement.scrollTop){ 

 			scrollTop = document.documentElement.scrollTop; 

		} else if(document.body){ 

 			scrollTop = document.body.scrollTop; 

		} 



		if(window.pageXOffset){ 

 			scrollLeft=window.pageXOffset;

		} else if(document.documentElement && document.documentElement.scrollLeft){ 

 			scrollLeft=document.documentElement.scrollLeft; 

		} else if(document.body){ 

 			scrollLeft=document.body.scrollLeft; 

		}

		

		popup.style.top = ((h/2 - 180) + scrollTop) + 'px';

		popup.style.left = ((w/2 - 225)) + 'px';

		

		popup.style.display = 'block';

	}

	return false;

}



function hide(_obj)

{

	

	var popup = document.getElementById(_obj);

	if (popup)

	{

		popup.style.display = 'none';

	}

	return false;

}





if (window.addEventListener) {

	window.addEventListener("load", initTeasers, false);

	window.addEventListener("load", initCForm, false);

}

else if (window.attachEvent) {

	window.attachEvent("onload", initTeasers);

	window.attachEvent("onload", initCForm);

}


function checkContact(){

	var $check = 0;

	if( $('name').getValue().replace(/^\s+|\s+$/g, '') == ""){
		$('name').setStyle('background-color', '#ff8b8b');
		$check = 1;
	}
	if( $('email').getValue().replace(/^\s+|\s+$/g, '') == "" ||  echeck($('email').getValue()) == false ){
		$('email').setStyle('background-color', '#ff8b8b');
		$check = 1;
	}
	if( $('message').getValue().replace(/^\s+|\s+$/g, '') == ""){
		$('message').setStyle('background-color', '#ff8b8b');
		$check = 1;
	}

	if($check == 1)
		return false;

	else
		return true;


}

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1)
		   return false

		 if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
		   return false

  		 if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
		    return false

		 if (str.indexOf(at,(lat+1))!=-1)
		    return false

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
		    return false

		 if (str.indexOf(dot,(lat+2))==-1)
		    return false
		
		 if (str.indexOf(" ")!=-1)
		    return false


 		 return true					
	}










