$(document).ready(function() {
	
	
	//IE 6 png fix
	$.ifixpng('/img/clearpixel.gif');
	$('img[@src$=.png]').ifixpng();
	$(function(){
    	$('#login input').keydown(function(e){
	        if (e.keyCode == 13) {
	            $(this).parents('form').submit();
	            return false;
	        }
	    });
	});
	
	$('.lack-of-points').click(function(){
		$.prompt($('.lack-of-points-message').html(),{
		buttons:{'Ok':true},
		prefix:'jqi',
		callback: function(){
            return false;			
		}
		});

	});
		
	$('.tooltip').hover(
        function(event) {
            var el = this;
            
            var show = function()
            {
            	$('#__tooltip').remove();
            	var text = $(el).attr('title');

            	if (!text) {
            		text = $(el).attr('alt');
            	}

            	if (!text) {
            		return;
            	}

            	var position = $(el).position();
            
            	if (event) {
					position.left = event.pageX + 10;
					position.top = event.pageY + 10;
				}
            
            	console.log(position);
            
            	$('<div id="__tooltip" class="description description_show"></div>')
            	.text(text)
            	.css('position', 'absolute')
            	.css('left', position.left)
            	.css('top', position.top)
            	.appendTo('body')
            	.fadeIn('fast');
            }
            
            if (t != undefined)
            	clearTimeout(t);
            
            var t = setTimeout(show, 200);
            
        },
        function() {
            $('#__tooltip').fadeOut('fast', function() { $(this).remove() });
        }
    );
	//Registrierung Infoboxen
	$('.button_description').hover(
		function() {
	    	var desc = $('#' + $(this).attr('description_for'));
	    	var position = $(this).position();
	    	desc.toggleClass('description_show');
	    	desc.css('left', position.left + 30);
	    	desc.css('top', position.top - 40);
	    	desc.fadeIn('fast');
	    	
	    },
	    function() {
	    	var desc = $('#' + $(this).attr('description_for'));
	    	desc.fadeOut('fast');
	    }
	);
	//Registrierung nicht public
    $('.not_public').hover(
        function() {
            var public = $('.description_public');
            var position = $(this).position();
            public.css('left', position.left + 30);
            public.css('top', position.top - 40);
            public.fadeIn('fast');
            
        },
        function() {
            var public = $('.description_public');
            public.fadeOut('fast');
        }
    );
	//Registrierung Fachgebiet Unterbereich
	$('#upload #specialist_area_id, #registration #specialist_area_id').change(function(){
        
		var loader = $('#loader');
        var position = $('#specialist_area_id_input').position();
        loader.css('left', position.left + 90);
        loader.css('top', position.top);
        loader.show();
		$('#specialist_subarea_id').load('/registrierung/subarea/id/' + $(this).val(), function()
		{
			$('#specialist_subarea_id_container').remove();
			$('#specialist_subarea_id_input').remove();
			if(!$.browser.safari)
			{
			    $('#specialist_subarea_id').selectbox();
			}
		    
		    $('#loader').fadeOut('fast');	
		}
		);
		
		
	});
	//Erweterte Suche Fachgebiet Unterbereich
    $('#search_advanced #specialist_area_id').change(function(){
        
        var loader = $('#loader');
        var position = $('#specialist_area_id_input').position();
        loader.css('left', position.left + 90);
        loader.css('top', position.top);
        loader.show();
        $('#specialist_subarea_id').load('/registrierung/subarea/id/' + $(this).val() + '/suche/1/', function()
        {
            $('#specialist_subarea_id_container').remove();
            $('#specialist_subarea_id_input').remove();
            if(!$.browser.safari)
            {
                $('#specialist_subarea_id').selectbox();
            }
            $('#loader').fadeOut('fast');   
        }
        );
        
        
    });
	//Ajax Loader
	
	//Preview for Empfehlen
	$('#empfehlenPreview').click(function(){
		$('#empfehlungMwName').text($('#empfehlenFormMwName').val());
		$('#empfehlungText').html($('#empfehlenFormText').val().replace(/\n/g,"<br />").replace(/\r/g,""));
		$('#empfehlungPreview').css('display', 'block');
		$('#empfehlen').css('display', 'none');
//		alert($('#empfehlenFormText').html());
		return false;
	});
	
	//Comboboxen mit Web 2.0 Layout
	if(!$.browser.safari)
    {
		$('#upload select, #registration select, #search_advanced select, #serie select').selectbox(
		{
		   
		});
	}

	// check on ready also, to show custom field if selected
	if($('#comeFrom').val() == 'sonstiges'){
		$('#sonstiges').css('display', 'block');
	}

	$('#comeFrom').change(function(){
		var sonstiges = $('#sonstiges');
		if($('#comeFrom').val() == 'sonstiges'){
			sonstiges.css('display', 'block');
		} else {
			sonstiges.css('display', 'none');
			sonstiges.val('');
		}
	});
	
	//Admin Bereich Dialog-Boxen
	$('#admin_table .delete').click(function(){
		var theme_text = '<h3>Datensatz l&ouml;schen</h3>' + '<p>Diesen Datensatz l&ouml;schen?</p>';
		var linkDelete = $(this).attr('id');
		$.prompt(theme_text,{
		buttons:{Ja:true,Nein:false},
		prefix:'jqi',
		callback: function(v,m){
			if(v)
			{
				document.location.href = linkDelete;
			}
			else
			{
				return false;
			}
			
		}
		});
	});
	//Punkte aufbuchen
    $('#punkte_hinzu').click(function(){
		var loader = $('#loader');
		var position = $(this).position();
		loader.css('left', position.left + 90);
		loader.css('top', position.top);
        loader.css('z-index', 2000);
		loader.show();
        $.post('/admin/user/points/point_action/add/id/' + $(this).attr('userId'), 
        		{points: $('#punkte_hinzu_value').val(), desc: $('#punkte_hinzu_desc').val()}, 
        		function(){
					loader.fadeOut('fast');
        			$('#punkte_container').load('/admin/user/listpoints/id/' + $('#punkte_hinzu').attr('userId'))
        		}
        	);
        return false;
    });
    //Punkte abziehen
    $('#punkte_abziehen').click(function(){
		var loader = $('#loader');
		var position = $(this).position();
		loader.css('left', position.left + 90);
		loader.css('top', position.top);
        loader.css('z-index', 2000);
		loader.show();
        $.post('/admin/user/points/point_action/remove/id/' + $(this).attr('userId'), 
        		{points: $('#punkte_abziehen_value').val(), desc: $('#punkte_abziehen_desc').val()}, 
        		function(){
					loader.fadeOut('fast');
        			$('#punkte_container').load('/admin/user/listpoints/id/' + $('#punkte_abziehen').attr('userId'))
        		}
        	);
        return false;
    });
    //Tabs
    $('#container-1 > ul').tabs();
    //Star-Rating
    var clicked = false;
    $('#bewerten :radio.star').rating(
    {required:true,
	  callback: function(value, link){
	   // 'this' is the hidden form element holding the current value
	   // 'value' is the value selected
	   // 'element' points to the link element that received the click.
	   if(clicked)
	   {
		 return;  
		}
		clicked = true;
		   $.get('/bilder/bewerten/' + $('#image_id').val() + '/' + value + '/',
	      	function(data){
		        if(data != '0')
		        {
					var voted = parseInt($('#total_votes').html())+1;
					$('#total_votes').html(voted);
		        	$('#bewertung_message').show();
		        	$('.star_group_score2').removeClass('star_on');
		        	for(i=0; i<6; i++){
		        		if(i<data) $('.star_group_score2:eq('+i+')').addClass('star_on');
		        		$('.star_group_score2:eq('+i+') > a').attr('title', data + ' von 6 Sternen');
		        	}
		        }
		        $('#bewerten').removeClass('star_form');
		        $('#bewerten div').removeClass('star_group_score');
				$('#bewerten').attr('id', 'bereits_bewertet');
				$('#bereits_bewertet :radio.star').rating({readOnly:true});
				$('div.star').addClass('star_readonly');
				$('div.star').unbind('click');
	      });
	 	}
    });
    $('#aktuelle_bewertung :radio.star').rating({readOnly:true});
    $('.aktuelle_bewertung :radio.star').rating({readOnly:true});
    $('#bereits_bewertet :radio.star').rating({readOnly:true});
    //Bild-Detail Serien-Vorschau
    $('.serie_preview').hover(
        function() {
            var preview = $('#' + $(this).attr('rel'));
            var position = $(this).position();
            preview.css('left', position.left + 100);
            preview.css('top', position.top -15);
            preview.fadeIn('fast');
            
        },
        function() {
            var preview = $('#' + $(this).attr('rel'));
            preview.fadeOut('fast');
        }
    );
    
    //Bild loeschen
	$('#delete_image').click(function(){
		var theme_text = '<h3>Bild l&ouml;schen</h3>' + '<p>Dieses Bild wirklich l&ouml;schen?</p>';
		$.prompt(theme_text,{
        buttons:{Ja:true,Nein:false},
        prefix:'jqi',
        callback: function(v,m){
            if(v)
            {
                document.location.href = $('#delete_image').attr('href');
            }
            else
            {
                return false;
            }
            
        }
        });
        return false;
	});
	//meine Auswahl
	$('#mycarousel').jcarousel({
        // Configuration goes here
    });
    //Drag and Drop Serien
    var positions = new Array();
    //Sonderfall Auswahlliste
    $(".drag-image").draggable(
        {
            helper: function(){
                return $(this).clone().appendTo("body")[0];
            },
            start: function(e, ui){
                sourcePath = $(this).attr('src');
                sourceId = $(this).attr('id');
                sourceAlt = $(this).attr('alt'); 
                sourceTitle = $(this).attr('title');
                newImage = true;
                
            },
            stop: function(){
                $('#placeholder-cursor').hide();
            },
            snap:'#landing-zone .zone-image'
        }
    );
    //Bildfelder initialiseren
    init();
    function init()
    {
        $.each(
            $('#landing-zone .zone-item'),
            function(i){
                positions[$(this).attr('id')] = {position: $(this).attr('id'), id: $(this).find('img').attr('id'), path: $(this).find('img').attr('src')};
//                console.log(positions[$(this).attr('id')].position, positions[$(this).attr('id')].id, positions[$(this).attr('id')].path);
            }
        );
        makeDraggable();
        makeDroppable();
        
        $('#landing-zone .zone-item img[id!=0]').draggable('enable');
        $('#landing-zone img[src="/img/no_picture-mini.gif"]').draggable('disable');
//        disableDraggable();//Bilder, die schon in der Serie sind
        $('#landing-zone .zone-item img').unbind('click');
        $('#mycarousel .drag-item img').unbind('click');
        $('#landing-zone.auswahl-special .zone-item img[id!=0]').click(function()
        {
            //console.log($(this).attr('id'));
            document.location.href = '/bilder/detail/' + $(this).attr('id') + '/?back=auswahl&serie_id='+ $('#serieId').val() + '&offset=' + $(this).parent().attr('rel');
        });
        $('#landing-zone.serie-bearbeiten .zone-item img[id!=0]').click(function()
        {
            //console.log($(this).attr('id'));
            document.location.href = '/bilder/detail/' + $(this).attr('id') + '/?back=serie-bearbeiten&serie_id='+ $('#serieId').val() + '&offset=' + $(this).parent().attr('rel');
        });
        $('#mycarousel .drag-item img').click(function()
        {
            //console.log($(this).attr('id'));
            document.location.href = '/bilder/detail/' + $(this).attr('id') + '/?back=auswahl&serie_id='+ $('#serieId').val() + '&offset=' + $(this).parent().attr('rel');
        });
    }
    
    function disableDraggable()
    {
        $(".drag-image").each(function(i){
            if(inSerie($(this).attr('id')))
            {
                $(this).draggable('disable');
            }
        }
        );
    }
    
    function makeDraggable(){
	    $("#landing-zone .zone-image").draggable(
	        {
	            helper: function(){
	                return $(this).clone().appendTo("body")[0];
	            },
	            start: function(e, ui){
	                sourcePosition = $(this).parent().attr('id');
	                //console.log(sourcePosition);
	                sourcePath = $(this).attr('src');
	                sourceId = $(this).attr('id');
	                sourceAlt = $(this).attr('alt'); 
    	            sourceTitle = $(this).attr('title');
	                newImage = false;
	            },
	            stop: function(){
	                $('#placeholder-cursor').hide();
	            },
	            snap:'#landing-zone .zone-image'
	        }
	    );
    };

	function moveImagesLeft(current)
	{
		next = current.next();
		current.find('img').attr('src', next.find('img').attr('src'));
		current.find('img').attr('id', next.find('img').attr('id'));
		current.find('img').attr('alt', next.find('img').attr('alt'));
		current.find('img').attr('title', next.find('img').attr('title'));
		if(next.attr('id') != current.attr('id') && next.find('img').attr('src') != '/img/no_picture-mini.gif')
		{
			next.find('img').attr('id', 0);
			next.find('img').attr('src', '/img/no_picture-mini.gif');
			next.find('img').attr('alt', '');
			next.find('img').attr('title', '');
			moveImagesLeft(next);
		} else {
			current.find('img').attr('id', 0);
			current.find('img').attr('src', '/img/no_picture-mini.gif');
			current.find('img').attr('alt', '');
			current.find('img').attr('title', '');
		}
		
	}


	function moveImagesRight(current, last)
	{
		prev = last.prev();
		last.find('img').attr('src', prev.find('img').attr('src'));
		last.find('img').attr('id', prev.find('img').attr('id'));
		last.find('img').attr('alt', prev.find('img').attr('alt'));
		last.find('img').attr('title', prev.find('img').attr('title'));
		if(last.attr('id') != current.attr('id')) {
			moveImagesRight(current, prev);
		}
	}



	function findFirstEmptyZone(){
		for(i=positions.length-1; i>0; i--){
			last = $("#landing-zone .zone-row .zone-item[id='"+i+"']");
			src = last.prev().find('img').attr('src');
			if(src != "/img/no_picture-mini.gif") return last;
		}
	}

	function createEmptyImagesRow(){
		empties = countEmptyRows();
		if(empties < 2)
			for(i = positions.length; i < positions.length+5; i++){
				$("#landing-zone .zone-row").append('<div id="'+i+'" class="zone-item ui-droppable"><img src="/img/no_picture-mini.gif" class="zone-image ui-draggable" title="" alt="" id=0 /></div>');
			}
		init();
	}

	function countEmptyRows(){
		z = 0;
		for(i=positions.length-1; i>0; i--){
			if($("#landing-zone .zone-row .zone-item[id='"+i+"']").find('img').attr('src') == "/img/no_picture-mini.gif"){
				z++;
			} else {
				return z;
			}
		}
		
	}

// hm... what if i really want to remove node, even from jquery object?

	function deleteMultipleEmptyRows(){
		empties = countEmptyRows();
		if(empties-5 > 0){
			survive = 5 - (empties % 5);
			console.log("SURVIVE: " + survive);
			for(i=positions.length-1; i>positions.length-survive-2; i--){
				$(".zone-item[id='"+i+"']").remove();
			}
			init();
		}
	}

    function makeDroppable(){
	    $("#papierkorb").droppable(
	       {
	           accept: ".zone-image",
	           tolerance: 'pointer',
	           drop: function() {
	               //Bild entfernen
					moveImagesLeft($('.zone-item[id=' + sourcePosition + ']'));
					modifySerie('delete', sourceId, sourcePosition);
					init();
//					deleteMultipleEmptyRows();
	           }
	       }
	    );
	    $("#landing-zone .zone-item").droppable(
	        {
	            accept: ".drag-image, .zone-image",
	            tolerance: 'pointer',
	            over: function() {
	                var position = $(this).position();
	                $('#placeholder-cursor').css('top', position.top - 3).css('left', position.left + 3).show();
	            },
	            drop: function() {
					if(newImage){
						if($(this).find('img').attr('src') == '/img/no_picture-mini.gif'){
							zone = findFirstEmptyZone();
						} else {
							zone = $(this);
			            	moveImagesRight(zone, findFirstEmptyZone());
						}
						if(findFirstEmptyZone().attr('id') == positions.length-1) createEmptyImagesRow();
						zone.find('img').attr('src', sourcePath);
						zone.find('img').attr('id', sourceId);
						zone.find('img').attr('alt', sourceAlt);
						zone.find('img').attr('title', sourceTitle);
                        modifySerie('new', sourceId, zone.attr('id'));
                        init();
					} else {
						if($(this).find('img').attr('src') == '/img/no_picture-mini.gif'){
							zone = findFirstEmptyZone();
							zone.find('img').attr('src', sourcePath);
							zone.find('img').attr('id', sourceId);
							zone.find('img').attr('alt', sourceAlt);
							zone.find('img').attr('title', sourceTitle);
							moveImagesLeft($('.zone-item[id=' + sourcePosition + ']'));
						} else {
							zone = $(this);
							moveImagesLeft($('.zone-item[id=' + sourcePosition + ']'));
			            	moveImagesRight(zone, findFirstEmptyZone());
							zone.find('img').attr('src', sourcePath);
							zone.find('img').attr('id', sourceId);
							zone.find('img').attr('alt', sourceAlt);
							zone.find('img').attr('title', sourceTitle);
						}
                        modifySerie('update', sourceId, zone.attr('id'), sourcePosition);
                        init();					
					}
	            }
	        }
	    );
    };
    
    function inSerie(imageId)
    {
        for(var i = 1; i <= positions.length - 1; i++)
        {
            if(positions[i].id == imageId)
            {
                return true;
            }
        }
        return false;
    }
    
    function modifySerie(action, imageId, position, sourcePosition)
    {
        query = '?aktion=' + action + '&imageId=' + imageId + '&position=' + position + '&src_pos=' + sourcePosition;
        $.get('/serien/bearbeiten/' + $('#serieId').val() + '/' + query, function(data){
                //console.log(data);
                //if(action == 'delete')
                {
                   //document.location.href = document.location.href;
                   //console.log(document.location.href);
                }
            }
        );
    }
    
    //Web 2.0 Menue
    var imageId;
    $('.auswahl_hinzu').click(function()
	    {
	        imageId = $(this).attr('id');
	        var position = $(this).position();
	        
	        $('#menu-desktop').css('top', position.top + 20).css('left', position.left).slideDown('normal');
	        return false;
	    }
    );
    $('.meine_auswahl_hinzu').click(function()
        {
            imageId = $(this).attr('id');
            var loader = $('#loader');
            var position = $(this).offset();
            loader.css('left', position.left + 30);
            loader.css('top', position.top - 80);
            loader.show();
            query = '?aktion=new&imageId=' + imageId + '&position=1&meine=1';
            $.get('/serien/bearbeiten/' + $(this).attr('rel') + '/' + query,
                function(data){
                    loader.fadeOut('fast');
                    if(data == 0)
                    {
                        message = $('#bereits_vorhanden').fadeIn('fast');
                        message.css('left', position.left - 30);
                        message.css('top', position.top - 80);
                        setTimeout(function() {$('#bereits_vorhanden').fadeOut('fast')}, 2000);
                    }
                    else
                    {
                        message = $('#bild_hinzu').fadeIn('fast');
                        message.css('left', position.left - 30);
                        message.css('top', position.top - 80);
                        setTimeout(function() {$('#bild_hinzu').fadeOut('fast')}, 2000);
                    }
                }
                
            );
            return false;
        }
    );
    $('#menu-desktop').hover(
        function(){},
        function()
        {
            $(this).slideUp('normal');
        }
    );
// declare links for image/detail view links for serien
    function initSeriesMenuLink(){
		$('.meine-serie').click(function()
			{
				var loader = $('#loader');
				var position = $(this).offset();
				loader.css('left', position.left + 30);
				loader.css('top', position.top - 80);
				loader.show();
				query = '?aktion=new&imageId=' + imageId + '&position=1';
				$.get('/serien/bearbeiten/' + $(this).attr('id') + '/' + query,
					function(data){
						loader.fadeOut('fast');
						if(data == 0)
						{
							message = $('#bereits_vorhanden').fadeIn('fast');
							message.css('left', position.left - 30);
							message.css('top', position.top - 80);
							setTimeout(function() {$('#bereits_vorhanden').fadeOut('fast')}, 2000);
						}
						else
						{
							message = $('#bild_hinzu').fadeIn('fast');
							message.css('left', position.left - 30);
							message.css('top', position.top - 80);
							setTimeout(function() {$('#bild_hinzu').fadeOut('fast')}, 2000);
						}
					}
					
				);
				return false;
			}
		);
    }
// ini them
    initSeriesMenuLink();
    
    $('.neue-serie').click(function()
        {
            var seriePrompt = $.prompt($('#serie_neu').html(),{
	        buttons:{},
	        prefix:'jqiSerie',
	        callback: function(v,m){
	            if(v)
	            {
	                document.location.href = linkDelete;
	            }
	            else
	            {
	                return false;
	            }
	            
	        }
	        });
            if(!$.browser.safari)
            {
                $('.jqiSeriemessage select').selectbox();
            }
            $('.button_description').hover(
		        function() {
		            var desc = $('#' + $(this).attr('description_for'));
		            var position = $(this).position();
		            desc.toggleClass('description_show');
		            desc.css('left', position.left + 30);
		            desc.css('top', position.top - 40 + $(window).scrollTop());
		            desc.css('z-index', 10000);
		            desc.fadeIn('fast');
		            
		        },
		        function() {
		            var desc = $('#' + $(this).attr('description_for'));
		            desc.fadeOut('fast');
		        }
		    );
            var position = $('#jqiSerie').offset();
            $('#jqiSerie #serie_title').val('');
            $('#jqiSerie #serie_erstellen').click(function()
	            {
	               if($('#jqiSerie #serie_title').val() != '')
	               {
	                   var loader = $('#loader');
		               loader.css('left', position.left + 150);
	                   loader.css('top', position.top + 80);
	                   loader.css('z-index', 2000);
		               loader.show();
		               $.post('/serien/',
		                   { serie_title: $('#jqiSerie #serie_title').val(), serie_description: $('#jqiSerie #serie_description').val(), private: $('#jqiSerie #private').val(), public: 1, ajax_request: 1 },
		                   function(data){
						        query = '?aktion=new&imageId=' + imageId + '&position=1';
					            $.get('/serien/bearbeiten/' + data + '/' + query,
					                function(data2){
					                    loader.fadeOut('fast');
					                    $("#menu-desktop ul").append("<li><a href='#' id='"+data+"' class='meine-serie'>"+$('#jqiSerie #serie_title').val()+"</a></li>");
					                    initSeriesMenuLink();
					                    $('#jqiSerie #serie_erstellen').unbind('click');
					                    $('#serie_erstellt').css('left', position.left + 150);
				                        $('#serie_erstellt').css('top', position.top + 80);
				                        $('#serie_erstellt').css('z-index',2000);
					                    $('#serie_erstellt').show('slow');
					                    
					                    seriePrompt.remove();
					                    setTimeout(function() {$('#serie_erstellt').fadeOut('slow')}, 2000);
					                    return false;
					                }
					            )
						   }
		               );
		           }
		           else
		           {
		              $('#jqiSerie #serie_title').css('border', '1px solid red');
		           }
	               return false;
	            }
            );
            return false;
        }
    );
    //Flash-Game
    $('.flashgame a').click(function()
	    {
	       var seriePrompt = $.prompt($('#flashgame').html(),{
            buttons:{},
            prefix:'jqiFlashgame'
            });
	    }
    );
    //Flash-Film
    $('.flashfilm').click(function()
        {
           var seriePrompt = $.prompt($('#flashfilm').html(),{
            buttons:{},
            prefix:'jqiFlashgame'
            });
        }
    );
    //Newsletter
    //MarkItUp
    $("#markItUp").markItUp(mySettings);
    //Testmail
    $('.testmail').click(function()
        {
            $('#newsletter').attr('action', '/admin/newsletter/sendmail/id/' + $(this).attr('id'));
            $('#newsletter').submit();
            return false;
        }
    );
    //Newsletter senden
    $('.send-newsletter').click(function()
        {
			var theme_text = '<h3>Newsletter senden</h3>' + '<p>Wollen Sie den Newsletter wirklich versenen?</p>';
			var linkDelete = $(this).attr('id');
			$.prompt(theme_text,{
				buttons:{Ja:true,Nein:false},
				prefix:'jqi',
				callback: function(v,m){
					if(v)
					{
						$('#newsletter').attr('action', '/admin/newsletter/sendnewsletter/id/' + $('.send-newsletter').attr('id'));
						$('#newsletter').submit();
						return false;
					}
					else
					{
						return false;
					}
				}        	
	        });
      	}
    );
    $('input[name=keywords]').click(function()
        {
            $(this).val('');
        }
    
    );
    
    $('#submitFreigabe').click(function()
        {
            var type = $('#upload #public').val();
            //console.log(type);
            if(type == 1)
            {
                action = $('#mail').attr('action') + '&ajax=1';
                userId = $('#userId').val();
                email = $('#email').val();
                subject = $('#subject').val();
                body = $('#body').val();
            }
            else
            {
                action = $('#mail-abgelehnt').attr('action') + '&ajax=1';
                userId = $('#userId-abgelehnt').val();
                email = $('#email-abgelehnt').val();
                subject = $('#subject-abgelehnt').val();
                body = $('#body-abgelehnt').val();
            }
            //console.log(action);
            var loader = $('#loader');
	        var position = $(this).position();
	        loader.css('left', position.left + 90);
	        loader.css('top', position.top);
	        loader.show();
            $.post(action,
            { userId: userId, email: email, subject: subject, body: body },
	            function(data){
	                loader.fadeOut('fast');
	                $('#mail-gesendet').css('left', position.left);
                    $('#mail-gesendet').css('top', position.top + 30);
                    $('#mail-gesendet').css('z-index',2000);
                    $('#mail-gesendet').show('fast');
	                setTimeout(function() {$('#upload').submit()}, 1000);
	            }
            );
            //console.log(userId, email, subject, body);
            return false;
        }
    );
    //Serie loeschen
    $('.serie-loeschen').click(function(){
        var theme_text = '<h3>Serie l&ouml;schen</h3>' + '<p>Diesen Serie wirklich l&ouml;schen?</p>';
        var linkDelete = $(this).attr('id');
        $.prompt(theme_text,{
        buttons:{Ja:true,Nein:false},
        prefix:'jqi',
        callback: function(v,m){
            if(v)
            {
                document.location.href = linkDelete;
            }
            else
            {
                return false;
            }
        }
        });
    });
});//Ende ready function
