Page = {
	init: function(){		
		var FullscreenrOptions = {  width: 2400, height: 1682, bgID: '#bgimg' };
		jQuery.fn.fullscreenr(FullscreenrOptions);		
	  	Cufon.replace("#footer h3");
	  	Cufon.replace("#kontakt_2 h3");
	  	Cufon.replace("#content h1");
		Util.externalLinks();		
		
		if( $("#type_evaluation").length > 0 ){
			var result = 0;
			var item_nmb = $("#type_evaluation .form_select").length;
			var complete = false;
			$("#type_evaluation .form_select").change(function(){
				result = 0;
				item_nmb = $("#type_evaluation .form_select").length;
				complete = true;
				$("#type_evaluation .form_select").each(function(){
					if( parseInt($(this).val()) != 0){
						result += parseInt( $(this).val() );
						complete = complete &&  true;
					}else{
						complete = complete && false;
					}					
				});			
				if( complete ){
					$('#resultHAF').html(result);
				}
			});
		}		
	}
}		

Util= {
	getWindowSize: function(){
		var xScroll, yScroll;

		if (window.innerHeight && window.scrollMaxY) {
			xScroll = window.innerWidth + window.scrollMaxX;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight) {
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else if(document.body) { 
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}

		var windowWidth, windowHeight;
		if (self.innerHeight) {
			if(document.documentElement.clientWidth){
				windowWidth = document.documentElement.clientWidth;
			} else {
				windowWidth = self.innerWidth;
			}
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) {
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) {
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}

		if(yScroll < windowHeight) {
			pageHeight = windowHeight;
		} else {
			pageHeight = yScroll;
		}

		if(xScroll < windowWidth) {
			pageWidth = xScroll;
		} else {
			pageWidth = windowWidth;
		}
		var arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
		return arrayPageSize;
	},
	externalLinks: function(){
		 $("a").each(function(){
		 	if(
			   $(this).attr("href") &&
		 	   $(this).attr("href") != "" &&	
		 	   $(this).attr("href").indexOf(window.location.hostname) < 0 &&
			   $(this).attr("href").indexOf("http://") >= 0 	
			   ||  $(this).attr("rel") == "external"   
		 	 ){
		 		$(this).attr("target", "_blank");
		 	 }
		 });
	},
    validateForm: function(id) {    	
		var result= true;				
		$("#"+id + " input, #"+id + " textarea, #"+id + " input.checkbox, #"+id + " .select").each(function() {
			if($(this).attr("class") && $(this).attr("class").match("required")) {
			    $(this).val($(this).val().replace(/^\s+|\s+$/g, ""));
				var itemresult= Util.validate($(this).attr("id"));
				result= result && itemresult;
			}
		});		
		if(!result){
			$("#error .message").css("visibility", "visible");
		}
		return result;		
	},
	validate: function(id) {
		var result= true;
		var obj= $("#"+id);		
		var commands= $("#"+id).attr("class").split(" ");
		for(var i=0; i<commands.length; i++) {
			var command= commands[i].replace(/[0-9]/g, "");			
			switch(command) {
				case("minlength"):
					var length= parseInt(commands[i].replace(/minlength/g, ""));
					result= result && (obj.val().length>=length);
					break;
				case("maxlength"):
					var length= parseInt(commands[i]);
					result= result && (obj.val().length<=length);
					break;
				case("email"):
					result = result && ( obj.get(0).value.match(/\S@\S.\S{2,}/)!=null );
					break;
				case("checkbox"):
					if( $("#"+id+":checked").length <= 0 ){
						result = result && false;
						$("#"+id).parent().children(".checkbox .info").addClass("error");
					}					
					break;
				case("select"):
					result = result && !( $("#"+id).val() == "---" );					
					break;
				default:
					result= result && (obj.val().length!=0);
					break;
			}
		}						
		if(!result) {
			obj.addClass("error");
		} else {
			obj.removeClass("error");			
		}
		return result;
	}
};


