
var platform = new PLATFORM();

function PLATFORM(url) {
		
	// object uebergeben doku http://colorpowered.com/colorbox/
	this.layer = function(obj) {
		$.fn.colorbox(obj);
	}
	
	this.clearText = function(field){
		if (field.defaultValue == field.value) field.value = '';
	    else if (field.value == '') field.value = field.defaultValue;
	}
	
	this.showBox = function (obj, box) {
		$('#'+box).slideDown();
	}

	this.closeBox = function(obj, box) { 
		$('#'+box).slideUp();
	}

}

var newsletter = new NEWSLETTER();
function NEWSLETTER() {
	var activObj;
	this.checkValueInField = function (obj, start_value) {
		var field = $(obj).val();
		
		if(field == start_value) {
			$(obj).val('');
			newsletter.activObj=obj;
		}
		else {
			return
		}
	}

	this.checkEmail = function (email) 	{
		if(newsletter.activObj) {
			var a = false;
		 	var res = false;
		 	if(typeof(RegExp) == 'function') {
			  	var b = new RegExp('abc');
			  	if(b.test('abc') == true){a = true;}
		  	}

			if(a == true) {
				reg = new RegExp('^([a-zA-Z0-9\-\.\_]+)'+
			                   '(\@)([a-zA-Z0-9\-\.]+)'+
			                   '(\.)([a-zA-Z]{2,4})$');
				res = (reg.test(email));
			}
			else {
				res = (email.search('@') >= 1 &&
			         email.lastIndexOf('.') > email.search('@') &&
			         email.lastIndexOf('.') >= email.length-5)
			}
			if(!res) {
				newsletter.showMessage();
				return false;
			}
			else {
				newsletter.hideMessage();
			 }
		}
	}
	
	this.showMessage = function() {
		var id =$(newsletter.activObj).attr('id');
		$("#"+id+"_error_message").show('slow');
	}

	this.hideMessage = function() {
		var id =$(newsletter.activObj).attr('id');
		$("#"+id+"_error_message").hide('slow');
		$("#newsletter_box_form").submit();
	}
}


/* magic */

$(document).ready(
		function() {		
			
			var bodyWidth = $('body').width();
			 
			 $('.magicLoginBtn').click(function(e) {
				 e.preventDefault();
				 $('#'+f3func.currentOpenContainer).fadeOut('fast');
				 f3func.currentOpenContainer="loginForm";
				 $('#animated').css({'z-index': 9999}).show().animate({
					'left' : '350px',
					'top' : '200px'
				  }, 2000, function() {
					  $('#loginForm').slideDown('slow');
				  });

				 showAbdunkler();
				  $('#loginForm').css({'z-index': 8888});
				  $('#loginForm').animate({'left': '400px', 'top': '350px'}, 2000);
			  });
			 
			$('#abdunkler').click(function() {
				whichCloseAnimation();
			});
		}
	);

	function debug(val) {
		if(window.console && window.console.firebug) {
			console.log(val);
		}
	}
	
	// bestimmen welche close animation verwendet werden soll
	function whichCloseAnimation() {
		if (f3func.currentOpenContainer == "loginForm") {
			$('#loginForm').slideUp('slow', function() {
				$('#animated').css({'z-index': 9999}).show().animate({
				'left' : '1000px',
				'top' : '-350px'
			  }, 2000, function(){
				hideAbdunkler();
			  });
			});
		}
		else {
			$('#'+f3func.currentOpenContainer).fadeOut('fast', function() {
				hideAbdunkler();
			}); 
		}
	}
	
	function showAbdunkler(){
		$('#abdunkler').fadeIn("slow").css('height', '4000px');
	}

	function hideAbdunkler(){
		$('#abdunkler').fadeOut("fast");
	}
	
	function hideLoginForm(){
		if (f3func.currentOpenContainer !="loginForm") return;
		$('#animated').css({'z-index': 9999}).show().animate({
		left: '1100px',
		top: '-300px'}, 1000);
		$('#loginForm').slideUp('slow');
	}
