$(document).ready( function() {
	$(".menueitem").hover( function() {
		var item = "#" + $(this).attr("id").replace("item", "sub");
		$(item).stop().height('auto').slideDown({ duration: 500, easing: "easeOutBounce" });
		$(".menuebody").not(item).stop().slideUp();
	}, function() {
		var item = "#" + $(this).attr("id").replace("item", "sub");
		$(item).stop().slideUp();
	});
	$(".menueimage").hover( function() {
		var image = $(this).attr("src").replace(".jpg", "_hover.jpg");
		$(this).attr("src", image);
	}, function() {
		var image = $(this).attr("src").replace("_hover.jpg", ".jpg");
		$(this).attr("src", image);
	});
	$(".item").hover( function() {
		$(this).addClass("item_hover");
	}, function() {
		$(this).removeClass("item_hover");
	});
	$(".socialnetworks").hover( function() {
		var image = $(this).attr("src").replace(".png", "_hover.png");
		$(this).attr("src", image).attr("height", 50).attr("width", 50);
	}, function() {
		var image = $(this).attr("src").replace("_hover.png", ".png");
		$(this).attr("src", image).attr("height", 46).attr("width", 46);
	});
	setInterval( function() {
		$.ajax({
			type: "get",
			url: "ajax/nowplaying.php",
			success: function(data) {
				$("#nowplaying").html(data);
				$(".playing").animate({ backgroundColor: "#666666" }, 500).animate({ backgroundColor: "#1d1c21" }, 500);
			}
		});
		$.ajax({
			type: "get",
			url: "ajax/servertime.php",
			success: function(data) {
				$("#servertime").html(data);
			}
		});
	}, 30000);
	$("#winamp").hover( function() { $(".playerinfo").html("Winamp"); }, function() { $(".playerinfo").html(""); });
	$("#mediaplayer").hover( function() { $(".playerinfo").html("Media Player"); }, function() { $(".playerinfo").html(""); });
	$("#realplayer").hover( function() { $(".playerinfo").html("Realplayer"); }, function() { $(".playerinfo").html(""); });
	$("#phonostarplayer").hover( function() { $(".playerinfo").html("Phonostar Player"); }, function() { $(".playerinfo").html(""); });
	$("#radiofx").hover( function() { $(".playerinfo").html("Radio fx"); }, function() { $(".playerinfo").html(""); });
	$("#djrotation")
		.after('<div id="nav">')
		.cycle({ 
			fx: "scrollLeft",
			cleartype: true,
			cleartypeNoBg: true,
			timeout: 10000,
			pager: "#nav",
			easeIn: "easeOutBounce"
	});
	$("#djrotation").hover( function(){
		$(this).cycle("pause");
	}, function() {
		$(this).cycle("resume");
	});
	$("#teamslideshow").cycle({ 
		fx: "fade",
		cleartype: true,
		cleartypeNoBg: true,
		timeout: 10000
	});
	$("#banner_adds_start").cycle({ 
		fx: "scrollUp",
		timeout: 5000
	});
	$("#banner_adds_right").cycle({ 
		fx: "scrollUp",
		timeout: 5000
	});
	$("#newsslider").cycle({ 
		fx: "blindY",
		cleartype: true,
		cleartypeNoBg: true,
		timeout: 6000
	});
	$("#newsslider").hover( function(){
		$(this).cycle("pause");
	}, function() {
		$(this).cycle("resume");
	});
	$(".bigimage").fancybox({
		transitionIn: 'elastic',
		transitionOut: 'elastic',
		easingIn: 'easeInOutElastic',
		easingOut: 'easeInOutElastic',
		speedIn: 800,
		speedOut: 800,
		showCloseButton: true,
		hideOnContentClick: true
	});
	$(window).scroll( function() {
		if($(this).scrollTop() != 0) {
			$("#totop").fadeIn(800);
		}
		else {
			$("#totop").fadeOut(800);
		}
	});
	$("#totop").click( function() {
		$("body, html").animate({
			scrollTop: 0
		}, 600);
	});
	$(".show_sendeinfos").click( function() {
		var item = "#" + $(this).attr("id").replace("show_sendeinfos", "sendeinfos");
		$(this).remove();
		$(item).slideDown();
	});
});
function insert(form, element, aTag, eTag) {
  var input = document.forms[form].elements[element];
  input.focus();
  /* für Internet Explorer */
  if(typeof document.selection != 'undefined') {
    /* Einfügen des Formatierungscodes */
    var range = document.selection.createRange();
    var insText = range.text;
    range.text = aTag + insText + eTag;
    /* Anpassen der Cursorposition */
    range = document.selection.createRange();
    if (insText.length == 0) {
      range.move('character', -eTag.length);
    } else {
      range.moveStart('character', aTag.length + insText.length + eTag.length);      
    }
    range.select();
  }
  /* für neuere auf Gecko basierende Browser */
  else if(typeof input.selectionStart != 'undefined')
  {
    /* Einfügen des Formatierungscodes */
    var start = input.selectionStart;
    var end = input.selectionEnd;
    var insText = input.value.substring(start, end);
    input.value = input.value.substr(0, start) + aTag + insText + eTag + input.value.substr(end);
    /* Anpassen der Cursorposition */
    var pos;
    if (insText.length == 0) {
      pos = start + aTag.length;
    } else {
      pos = start + aTag.length + insText.length + eTag.length;
    }
    input.selectionStart = pos;
    input.selectionEnd = pos;
  }
  /* für die übrigen Browser */
  else
  {
    /* Abfrage der Einfügeposition */
    var pos;
    var re = new RegExp('^[0-9]{0,3}$');
    while(!re.test(pos)) {
      pos = prompt("Einfügen an Position (0.." + input.value.length + "):", "0");
    }
    if(pos > input.value.length) {
      pos = input.value.length;
    }
    /* Einfügen des Formatierungscodes */
    var insText = prompt("Bitte geben Sie den zu formatierenden Text ein:");
    input.value = input.value.substr(0, pos) + aTag + insText + eTag + input.value.substr(pos);
  }
}
