(function($){
    //global vars
    var myIntervall;
    var global_counter=0;
    //end of global vars
    $.fn.extend({
        //name des Plugins
        fadeInMessage: function(options,args){
            var settings = {
                color: "white",
                width: "300px",
				height:"150px",
				background: "black",
				position: "absolute",
                iv:1000,//Intervall voreinstellen
				timeout:5000,//in n/1000 Sekunden ausblenden
				display:"none"
            };
            //counter
            var count=0;
            
            // console.log(options.constructor);
            // console.log( args );
            
            //hier die Stringoptionen auswerten und entspr. reagieren
            //Private Funktionen siehe weiter unten führen entspr. Befehle aus
            if( options.constructor == String ){
            
              switch(options){
                case "show":
                    show( $(this), args );
                    return;
                case "hide":
                    stopit( args );
                    return;
                default:
                    return "No such commmand!";//kein solches Kommando implementiert
                //wir könnten hier auch zwar das start Kommando aufrufen, aber das nicht erwünscht an dieser Stelle
              }
            
            }else{
                //falls kein Objekt übergeben wird, nimm an,
                //dass es der Wert für width ist.
                if( typeof(options) !="object" && options !=undefined )
                    options = {width: parseInt( options ) };
                
            }
            
            
            var conf = $.extend({}, settings, options);
            
            //hier mach was mit dem HTML Element
            return $(this).each(function(){
			
			   $(this).stop();
               $(this).css( "background",conf.background );
               $(this).css( "color",conf.color );
			   $(this).css( "position", conf.position );
			   $(this).css( "display", conf.display );
               $(this).width( parseInt( conf.width ) );
			   $(this).height( parseInt( conf.height ) );
			   $.fn.extend({timeout: parseInt( conf.timeout )});
               
            });
            
            
            //private functions/////////////////////////////////////////////////
            function show( element ){
              
			    
				var fadein_message = $( element );
				
				
				// fadein_message.show();
				
				$("body").css("overflow","hidden");
				
				var sheight = $(window).height();
				
				var scrheight = $(window).scrollTop();// - fadein_message.height();
				
				var fiw = parseInt( fadein_message.width() );
				var fih = parseInt( fadein_message.height() );
// debugger;
//console.log(sheight+scrheight);
				//an den unteren Bildschirmrand positionieren
				fadein_message.css({"left": ($(window).width()-fiw-10),"top":sheight+scrheight});

				//callback function nach einblenden
				var cb_fadeout = function( ){
					
					//callback ausblender
					var cb_hide = function(){
					  $(this).hide();
					  $("body").css("overflow","auto");
					};
					
					fadein_message.bind('click',function(){
						$(this).animate({"top":sheight+scrheight}, cb_hide);
					});

					var timer =	setTimeout(function(){
							fadein_message.trigger('click');//animate({"top":sheight},cb_hide);
							//console.log($(this).timeout);
						},$(this).timeout);
					
					
				};//end of cb_fadeout
				
				//nach oben einrollen , ausrollen (cb_fadeout)
				fadein_message.show().animate({"top":sheight+scrheight-fih-15},cb_fadeout);
				
			  
              
            };//end of show()
            //end of private functions//////////////////////////////////////////
            
        }
    });

})(jQuery);
