var Minox = Class.create({
	initialize: function() {
		this.agentnetwork();

		if(setFooterAbsolute){
			this.footer();
		}else{
			$('footer').setStyle({
				position: 'relative',
				display: 'block',
				marginTop: '30px',
				marginLeft: '-5px',
				clear: 'both'
			});		
		}	
		if($('contentPhotoImg')) this.albumDetailPhotoContent();
	},
	
	footer: function() {	
		var dimPage = $('cpPageC').getDimensions();
		var dimWindow = $('top').getDimensions();
		var dimFooter = $('footer').getDimensions();		

		$('footer').show();
		if(dimPage.height > 700){
			$('footer').setStyle({
				position: 'absolute',
				top: '0',
				marginTop: dimPage.height+10 + 'px'
			});
		}else{
			if (cp.setWorldMap) {
				new Insertion.Top('agnetAreaAfter', $('footer'));	
				$('footer').setStyle({
					paddingTop: '10px'					
				});				
			}else{
				$('footer').setStyle({
					position: 'absolute',
					bottom: '0'
				});
			}
		}

	},	

	registerAGB: function(){
		if($("checkAGB").checked){
			if($("inputAGB_de")) $("inputAGB_de").value = "Nutzungsbedingungen akzeptiert";
			if($("inputAGB_en")) $("inputAGB_en").value = "Terms accepted";
		}else{
			if($("inputAGB_de")) $("inputAGB_de").value = "";
			if($("inputAGB_en")) $("inputAGB_en").value = "";			
		}		

		if($("inputAGB_de").value !="" || $("inputAGB_en").value !=""){		
			$("checkAGB").checked = true;
		}else{				
			$("checkAGB").checked = false;
		}
	},

	uploadAGB: function(){
		if($("checkAGBUP").checked){
			document.uploadFotoForm.submit();
		}else{
			if($("lang").value == "de"){
				$("infoError").innerHTML = "Sie müssen die Nutzungsbedingungen akzeptieren.";
			}else{
				$("infoError").innerHTML = "You must accept the Terms.";
			}
		}		
	},	

	
	albumDetailPhotoContent: function() {
		var dimPhoto = $('contentPhotoImg').getDimensions();
		$('contentPhoto').style.width = dimPhoto.width-20 + "px";
	},
	
	agentnetwork: function() {
		if(cp.setWorldMap){
			$('top').setStyle({backgroundImage: 'none'});

			var clear = document.createElement('img');		
			clear.src = "clear.gif";
			clear.width = "100%";
							
			var _loc1 = document.createElement('div');
			_loc1.appendChild(clear)
			_loc1.setAttribute('id','agnetAreaBefore');		
			new Insertion.Before('flbgID', _loc1);
			//$('agnetAreaBefore').setOpacity(0);
			//$('agnetAreaBefore').fade({ duration: 2.0, from: 0, to:0.9 });

	
			var _loc2 = document.createElement('div');
			_loc2.appendChild(clear);		
			_loc2.setAttribute('id','agnetAreaAfter');
			new Insertion.After('flbgID', _loc2);
			//$('agnetAreaAfter').setOpacity(0);
			//$('agnetAreaAfter').fade({ duration: 2.0, from: 0, to:0.9 });
		}
	},
		
	sortByCountry: function(){
		$('cpUserListSortByCountry').submit();
		
		return false;
	},
	
	getIdCardData: function(id){
		if($('cardOK')) $('idCard').show();
		if (id == "idCard") {
			var fname = $("tx-srfeuserregister-pi1-first_name").value;
			var lname = $("tx-srfeuserregister-pi1-last_name").value;
			var aname = $("tx-srfeuserregister-pi1-username").value;
			var sex = $("tx-srfeuserregister-pi1-gender").value;
			//alert(sex);
			var birthday = $("tx-srfeuserregister-pi1-date_of_birth").value;												
		}
		
		return fname+"#"+lname+"#"+aname+"#"+sex+"#"+birthday;	
	}	
});

var Newsticker = Class.create({
	initialize: function(){
		this.interval           = 6000;
		this.container          = $("ticker");
		this.messages           = $A(this.container.getElementsByTagName("li"));
		this.number_of_messages = this.messages.length;
		if (this.number_of_messages == 0)
		{
			this.showError();
			return false;
		}
		this.current_message = 0;
		this.previous_message = null;

		this.hideMessages();
		this.showMessage();

		this.timer = setInterval(this.showMessage.bind(this), this.interval);
  	},
	
	showMessage: function(){
		Effect.Appear(this.messages[this.current_message]);
		setTimeout(this.fadeMessage.bind(this), this.interval-2000);
		if (this.current_message < this.number_of_messages-1)
		{
			this.previous_message = this.current_message;
			this.current_message  = this.current_message + 1;
		} else {
			this.current_message  = 0;
			this.previous_message = this.number_of_messages - 1;
		}
	},
	
	fadeMessage: function() {
		Effect.Fade(this.messages[this.previous_message]);
	},
	
	hideMessages: function() {
		this.messages.each(function(message) { Element.hide(message); })
	},

	showError: function(){
		if (this.container.getElementsByTagName("ul").length == 0)
		{
			this.list = document.createElement("ul");
			this.container.appendChild(this.list);
		} else {
			this.list = this.container.getElementsByTagName("ul")[0];
		}
		this.errorMessage = document.createElement("li");
		this.errorMessage.className = "error";
		this.errorMessage.innerHTML = "Could not retrieve data";
		this.list.appendChild(this.errorMessage);
	}

});

UClass.minox = Minox;
if($("ticker")){ UClass.ticker = Newsticker; }

