$(document).ready(function(){
	// Mouse over Bilder vorladen
    $('.menuboth').each(function() {
		var src;
		if ($('a:first-child img:first-child', this).lenght) {
			if ($('a:first-child img:first-child', this).attr("src").search(/_over.+/) != -1) src = $('a:first-child img:first-child', this).attr("src").replace("_over", "");
			else src = $('a:first-child img:first-child', this).attr("src").match(/[^\.]+/) + "_over.jpg";
			$(function () {
			  var img = new Image();
			  $(img)
				.load(function () {
				  $(this).hide();
				  $('#preloader')
					.removeClass('loading')
					.append(this);
				  $(this).fadeIn();
				})
				.attr('src', src);
			});	
		}
	});
	//Drop-Down Menu	
	$('.menuboth').mouseover(function(){
		var containerID = '#'+$('a:first-child', this).attr('menudata'); //Get Menu container ID
		var tall = $('a:first-child', this).attr('menuheight'); //Get Menu container Height
		var wide = $('a:first-child', this).attr('menuwidth'); //Get Menu container Width
		
		// PTT Menu _over Bilder
		var bildID = $('a:first-child img:first-child', this).attr('id'); //Get Menu container ID
	
		if( ($('#'+bildID).attr("class") == 'menu_button') && ($('#'+bildID).attr("src").search(/_over.+/) == -1) ){
		  var src = $('#'+bildID).attr("src").match(/[^\.]+/) + "_over.jpg";
		  $('#'+bildID).attr("src", src);
		}
		$(containerID).css({display:'block'});
		$(containerID).stop().animate({
				height:tall,
				width:wide
			}, {
				queue:false,
				duration:50,
		});
	});
	//Hide Drop-Down Menu
	$('.menuboth').mouseout(function(){
		var containerID = '#'+$('a:first-child', this).attr('menudata');
		var bildID = $('a:first-child img:first-child', this).attr('id'); // PTT 
		
		$(containerID).stop().animate({
			width: 0,
			height: 0
		  }, {
			duration: 1,
			queue:false,
			complete: function() {
				if($('#'+bildID).attr("class") == 'menu_button'){
				  var src = $('#'+bildID).attr("src").replace("_over", "");
				  $('#'+bildID).attr("src", src);
				}
			}
		});
	});

});
