window.addEvent('domready', function() {

/** window.loadFirebugConsole(); **/

//Verlinkung zu Photo ------------------------------------------------------------------

// Neue Verlinkung (Formular) einblenden ----------------------------------------
	var b_newLinking = $('newLinkingShow');
	var newLinking = $('newLinking');
	var b_break2 = $('newLinkingAbbrechen');
	
	if(($type(b_newLinking) != false) && ($type(newLinking) != false))
	{
		b_newLinking.setStyle('cursor','pointer');
		b_newLinking.addEvent('click', function(){
			newLinking.setStyle('display','block');
			b_newLinking.setStyle('display','none');
		});

		var tokens = new Array();
		var help = $$('.friends');
		help.each(function(item, index){
			tokens[index] = item.get('html');
		});
		
	}
	
	if($type(b_break2) != false)
	{
		b_break2.addEvent('click',function(){
			newLinking.setStyle('display','none');
			b_newLinking.setStyle('display','block');
		});
	}
// ------------------------------------------------------------------------------

// Neue Verlinkung in x und y Felder schreiben ----------------------------------
	var body 		= $('body');
	if($type(body) != false)
	{
		var bodyPosition 	= body.getPosition();
	}
	var bild 		= $('bild');
	var inputx		= $('x');
	var inputy		= $('y');
	var temp		= $('temp');
	
	if(($type(body) != false) && ($type(inputx) != false) && ($type(inputy) != false) && ($type(temp) != false))
	{
		bild.addEvent('mousemove', function(event){
			bild.addEvent('mousedown', function(event){
			
				var event = new Event(event);
				inputx.setProperty("value",event.page.x-25-bodyPosition.x);
				inputy.setProperty("value",event.page.y-25-bodyPosition.y);
				temp.set('html',"<div style='border: 1px solid yellow; top: "+(event.page.y-25)+"px; left: "+(event.page.x-25)+"px; position: absolute; width: 50px; height: 50px;'></div>");
			});
		});
	}
// ---------------------------------------------------------------------------------

// Vorhandene Verlinkungen anzeigen ------------------------------------------------
	var maps = $$('.linking');
	var persons = $$('.person');
	
	if(($type(maps) != false) && ($type(persons) != false))
	{
		maps.each(function(item, index){
		
		item.setStyle('top',item.getPosition().y + bodyPosition.y);
		item.setStyle('left',item.getPosition().x + bodyPosition.x);
			item.addEvents({
				'mouseover' : function(){
					showDiv(item.getAttribute('id'), maps,persons);
				},
				'mouseout' : function(){
					hideDiv(item.getAttribute('id'), maps,persons);
				}
			
			});
		});
		
		persons.each(function(item, index){
			item.addEvents({
				'mouseover' : function(){
					showDiv(item.getAttribute('nr'), maps,persons);
				},
				'mouseout' : function(){
					hideDiv(item.getAttribute('nr'), maps,persons);
				}
			
			});
		});
	}
// ------------------------------------------------------------------------------

//--------------------------------------------------------------------------------------


//Kommentar zu Photo anlegen -----------------------------------------------------------
var b_newComment = $('newCommentShow');
var newComment = $('newComment');
var b_break1 = $('newCommentAbbrechen');

if(($type(b_newComment) != false) && ($type(newComment) != false))
{
	b_newComment.setStyle('cursor','pointer');
	b_newComment.addEvent('click', function(){
		newComment.setStyle('display','block');
		b_newComment.setStyle('display','none');
	});
}
if($type(b_break1) != false)
{
	b_break1.addEvent('click',function(){
		newComment.setStyle('display','none');
		b_newComment.setStyle('display','block');
	});
}
//--------------------------------------------------------------------------------------

//Loginfelder -----------------------------------------------------
	var username = $('username');
	var password = $('password');
	if($type(username) != false && $type(password) != false)
	{
		username.addEvent('focus', function(){
			username.set('value',"");
		});
		password.addEvent('focus', function(){
			password.set('value',"");
		});
	}
//------------------------------------------------------------------------------

	
// Multiupload für Photos ---------------------------------------------------------------
	var multi = $( 'main_form' );
	if($type(multi) != false)
	{
		new MultiUpload( $( 'main_form' ).picture );
	}
//--------------------------------------------------------------------------------------

	
// Datumsfeld für Geburtstagsangabe -----------------------------------------------------
	var geb		= $('geb');
	
	if($type(geb) != false)
	{
		myCal1 = new Calendar({ geb: 'd.m.Y' });
	}
//--------------------------------------------------------------------------------------

// Datumsfeld für Mein Bike -----------------------------------------------------
	var construction		= $('construction');
	var registration		= $('registration');
	var from				= $('from');
	var to					= $('to');
	
	if($type(construction) != false)
	{
		myCal1 = new Calendar({ construction: 'd.m.Y' });
	}
	if($type(registration) != false)
	{
		myCal2 = new Calendar({ registration: 'd.m.Y' });
	}
	if($type(from) != false)
	{
		myCal3 = new Calendar({ from: 'd.m.Y' });
	}
	if($type(to) != false)
	{
		myCal4 = new Calendar({ to: 'd.m.Y' });
	}
//--------------------------------------------------------------------------------------
	
	
// Gästebucheintrag (Eingabefeld ausklappen) -------------------------------------------
	var newGbEntry = $('newGbEntry');
	var b_newGbEntry = $('b_newGbEntry');
	var b_newGbEntryClose = $('b_newGbEntryClose');
	
	if($type(newGbEntry) != false && $type(b_newGbEntry) != false)
	{
		b_newGbEntry.addEvent('click',function(){
			newGbEntry.setStyle('display','block');
			b_newGbEntry.setStyle('display','none');
		});
		
		b_newGbEntryClose.addEvent('click',function(){
			newGbEntry.setStyle('display','none');
			b_newGbEntry.setStyle('display','block');
		});
	}
	
//--------------------------------------------------------------------------------------
	
	
	// Gruppeneintrag (Eingabefeld ausklappen) -------------------------------------------
	var newGroupEntry = $('newGroupEntry');
	var b_newGroupEntry = $('b_newGroupEntry');
	var b_newGbEntryClose = $('b_newGroupEntryClose');
	
	if($type(newGroupEntry) != false && $type(b_newGroupEntry) != false)
	{
		b_newGroupEntry.addEvent('click',function(){
			newGroupEntry.setStyle('display','block');
		});
		
		b_newGroupEntryClose.addEvent('click',function(){
			newGroupEntry.setStyle('display','none');
		});
	}
	
//--------------------------------------------------------------------------------------
	
});

function setNumber()
{
	if((document.Linking.userid.value == "") || (document.Linking.top.value == "") || (document.Linking.left.value == ""))
	{
		alert('Diese Person kann so nicht verlinkt werden!');
		return false;
	}
	else
	{
		return true;
	}
}
			

function showDiv(index, maps,persons)
{
	$each(maps,function(item, count){
		if(item.getAttribute('id') == index)
		{
			map_index = count;
		}
	});
	$each(persons,function(item, count){
		if(item.getAttribute('nr') == index)
		{
			person_index = count;
		}
	});
	
	maps[map_index].setStyle('border','2px solid red');
	persons[person_index].setStyle('background','red');
}

function hideDiv(index, maps,persons)
{
	$each(maps,function(item, count){
		if(item.getAttribute('id') == index)
		{
			map_index = count;
		}
	});
	$each(persons,function(item, count){
		if(item.getAttribute('nr') == index)
		{
			person_index = count;
		}
	});
	
	maps[map_index].setStyle('border','0px');
	persons[person_index].setStyle('background','none');
}

function checkPW()
{
	if(document.getElementById("password1").value == document.getElementById("password2").value)
	{
		if(document.getElementById("email1").value == document.getElementById("email2").value)
		{
			return true;
		}
		else
		{
			alert("Die beiden Emailadressen stimmen nicht!");
			return false;
		}
	}
	else
	{
		alert("Die beiden Passworte stimmen nicht!");
		return false;
	}
}

function really()
{
	return confirm("Wirklich?");
}
