var J = jQuery.noConflict();
var draginfo_stoerer_wobbel = false;
J(document).ready(function($){
	/*
	if ($.cookie('showDragInfoInFuture') != 'false' ) {
	*/
		var x = 0;
		var y = 0;
		if ($.cookie('DragInfoPosX') != null && $.cookie('DragInfoPosY') != null) {
			x = $.cookie('DragInfoPosX');
			y = $.cookie('DragInfoPosY');
			
		} else {
			var screen_center_x = 0;
			var screen_center_y = 0;

			var max_offset_x = 150;
			var max_offset_y = 250;

			/** Berechne Position der DragInfo **/
			if (parseInt(navigator.appVersion)>3) {
			 if (navigator.appName=="Netscape") {
				screen_center_x = window.innerWidth / 2;
				screen_center_y = window.innerHeight / 2;
			 }
			 if (navigator.appName.indexOf("Microsoft")!=-1) {
				screen_center_x = document.body.offsetWidth / 2;
				screen_center_y = document.body.offsetHeight / 2;
			 }
			}

			x = screen_center_x + ((Math.random() * (2*max_offset_x)) - max_offset_x);
			y = screen_center_y + ((Math.random() * (2*max_offset_y)) - max_offset_y);
		}
		
		$("div#draginfo").css("top", y + "px");
		$("div#draginfo").css("left", x + "px");

		$("div#draginfo").draggable({
			stop: function(event, ui) {
				x = $("div#draginfo").css("left").substr(0,($("div#draginfo").css("left").length) - 2);
				y = $("div#draginfo").css("top").substr(0,($("div#draginfo").css("top").length) - 2);
				
				$.cookie('DragInfoPosX',x);
				$.cookie('DragInfoPosY',y);
			}
		});
		
		
		$("div#draginfo").show();

		$("div#draginfo").mouseover(function(){
			if (draginfo_stoerer_wobbel == true) {
				if (stoerer_move_count > 4) {
					stoerer_move_count = 0;				
					start_shake_stoerer(2500);
				} else {
					random_move_stoerer();
				}
			} else {
				$(this).css('cursor','move');
			}
		});

		$("div#draginfo").mouseout(function(){
			$(this).css('cursor','default');
		});

		$("div#draginfo_close a").click(function(e){
			$("div#draginfo").draggable("disable");
			$("div#draginfo").hide();

			/* Per Cookie speichern, dass Draginfo nicht mehr gezeigt werden soll */
			$.cookie('showDragInfoInFuture', 'false');

			e.preventDefault();
		});
	/* } */
});

var stoerer_move_count = 0;

function random_move_stoerer() {
		var x = 0;
		var y = 0;
		
		var screen_center_x = 0;
		var screen_center_y = 0;

		var max_offset_x = 400;
		var max_offset_y = 250;

		/** Berechne Position der DragInfo **/
		if (parseInt(navigator.appVersion)>3) {
		 if (navigator.appName=="Netscape") {
			screen_center_x = window.innerWidth / 2;
			screen_center_y = window.innerHeight / 2;
		 }
		 if (navigator.appName.indexOf("Microsoft")!=-1) {
			screen_center_x = document.body.offsetWidth / 2;
			screen_center_y = document.body.offsetHeight / 2;
		 }
		}
		
		x = (screen_center_x + ((Math.random() * (2*max_offset_x)) - max_offset_x)) - 170;
		y = screen_center_y + ((Math.random() * (2*max_offset_y)) - max_offset_y);
		
		$("div#draginfo").css("top", y + "px");
		$("div#draginfo").css("left", x + "px");
		
		stoerer_move_count++;
}

var do_the_shake = false;
var do_the_shake_timer = null;

function start_shake_stoerer(duration) {
	if (do_the_shake == false) {
		do_the_shake = true;
		do_the_shake_timer = window.setInterval('shake_stoerer();',80);
		
		window.setTimeout('stop_shake_stoerer();',duration);
	}
}

function shake_stoerer() {
	if (do_the_shake) {
		random_move_stoerer();
	}
}

function stop_shake_stoerer() {
	if (do_the_shake == true) {
		do_the_shake = false;
		window.clearInterval(do_the_shake_timer);
				stoerer_move_count = 0;
	}
}
