$(document).ready(function() {
	var old_src;
	
	$(".edit").live("click", function(){
		element_id = $(this).attr('id');

		// Hide other
		$(".inneredit").each (function (i) {
			if ($(this).css('height') != 'auto' && $(this).attr('id') != 'inneredit_'+element_id) {
				$(this).slideUp('slow');
			};
		});
		
		// Show inneredit container
		$('#inneredit_'+element_id).slideToggle('slow');
	});
	
	$(".verkaufspferde").live("click", function(){
		element_id = $(this).attr('id');
		
		if ($('#inneredit_'+element_id).hasClass('shown') == false) {
			// Add fake class
			$('#inneredit_'+element_id).addClass('shown')

			$.ajax({
				type: "POST",
				url: "./ajax/getVerkaufspferd.php",
				data: "id="+element_id,
				async: false,
				cache: false,
				success: function(data) {
					//settings = '';
			        $('#inneredit_'+element_id).html(data);
			    },
				error: function(XMLHttpRequest, textStatus, errorThrown) {}
			});
			
		}
	});
	
	$(".pferdegesuche").live("click", function(){
		element_id = $(this).attr('id');
		
		if ($('#inneredit_'+element_id).hasClass('shown') == false) {
			// Add fake class
			$('#inneredit_'+element_id).addClass('shown')

			$.ajax({
				type: "POST",
				url: "./ajax/getPferdegesuch.php",
				data: "id="+element_id,
				async: false,
				cache: false,
				success: function(data) {
					//settings = '';
			        $('#inneredit_'+element_id).html(data);
			    },
				error: function(XMLHttpRequest, textStatus, errorThrown) {}
			});
			
		}
	});
	
	$(".marktplatz").live("click", function(){
		element_id = $(this).attr('id');
		
		if ($('#inneredit_'+element_id).hasClass('shown') == false) {
			// Add fake class
			$('#inneredit_'+element_id).addClass('shown')

			$.ajax({
				type: "POST",
				url: "./ajax/getMarktplatz.php",
				data: "id="+element_id,
				async: false,
				cache: false,
				success: function(data) {
					//settings = '';
			        $('#inneredit_'+element_id).html(data);
			    },
				error: function(XMLHttpRequest, textStatus, errorThrown) {}
			});
			
		}
	});
	
	$(".padr").live("click", function(){
			element_id = $(this).attr('id');

			if ($('#inneredit_'+element_id).hasClass('shown') == false) {
				// Add fake class
				$('#inneredit_'+element_id).addClass('shown')

				$.ajax({
					type: "POST",
					url: "./ajax/getPadr.php",
					data: "id="+element_id,
					async: false,
					cache: false,
					success: function(data) {
						//settings = '';
				        $('#inneredit_'+element_id).html(data);
				    },
					error: function(XMLHttpRequest, textStatus, errorThrown) {}
				});

			}
		});
	
	$('.fake').click(function() {
		bild_id = $(this).attr('id');
		old_src = $('#big_image').attr('src');
		new_src = $(this).attr('name');
		$('#big_image').attr('src', new_src);
		small_src = old_src.replace(/detail/, "thumb");
		group_link_src = old_src.replace(/detail/, "");
		link_src = new_src.replace(/detail/, "");
		$('#big_image_link').attr('href', link_src);
		$(this).attr('src', small_src);
		$(this).attr('name', old_src);
		$('#group_image_link_'+bild_id).attr('href', group_link_src);
	});
	
	$("a.big_image_link").fancybox({
		'overlayOpacity'	:	0.7,
		'overlayColor'		:	'#000000'
	});


	/*$('.fake').mouseleave(function() {
		$('#big_image').attr('src', old_src);
	});*/
});
