var perform_animation = false;
var menu_open = "";

$(document).ready(function() {
    //Set active menu for not animating
    setActiveMenu();

    //Menü Über
    $('#ueber').mouseover(function() {
        animate_submenu('#sub_ueber');
    });

    //Menü Angebote
    $('#angebote').mouseover(function() {
        animate_submenu('#sub_angebote');
    });

    //Menü Fotogallerie
    $('#fotogallerie').mouseover(function() {
        animate_submenu('#sub_fotogallerie');
    });

//Subemnü
    $('.submenu li').hover(function() {
        $(this).addClass('blue');
    },function(){
        $(this).removeClass('blue');
    });

    //Opening hours
    $('.opening-hours td').hover(function() {
        $(this).addClass('blue');
//        $(this).animate({
//            width: "70%",
//            fontSize: "3em",
//            borderWidth: "2px"
//        }, 1500 );
    },function(){
        $(this).removeClass('blue');
//        $(this).animate({
//            width: "-70%",
//            fontSize: "12px",
//            borderWidth: "1px"
//        }, 0 );
    });

});

function animate_submenu (submenu_name) {
    //Check if other subemenu is open
    if (menu_open != "" && !perform_animation) {
        //Check if not this submenu is open
        if (menu_open != submenu_name) {
            perform_animation = true;
            //$(submenu_name).delay(500);
            $(submenu_name).show('slow', function() {
                //Hide other submenu
                $(menu_open).hide('slow', function() {
                    //Set this as open submenu
                    menu_open = submenu_name;
                    perform_animation = false;
                });
            });
       }
    //If no other submenu is open just open this
    } else if (menu_open == "" && !perform_animation) {
        perform_animation = true;
        $(submenu_name).show('slow', function() {
             menu_open = submenu_name;
             perform_animation = false;
        });
    }
}
/*
 * Set the current selected submenu as active and removes the id so no effect
 * can be performed on this
 */
function setActiveMenu() {
    if($('#sub_ueber').hasClass('submenu_block')) {
        $('#ueber').removeAttr('id');
    }
    if($('#sub_angebote').hasClass('submenu_block')) {
        $('#angebote').removeAttr('id');
    }
    if($('#sub_fotogallerie').hasClass('submenu_block')) {
        $('#fotogallerie').removeAttr('id');
    }
}

function show (ID) {
	document.getElementById(ID).style.display = "block";
	document.getElementById(ID).style.visibility = "visible";
}
function hide (ID) {
	document.getElementById(ID).style.display = "none";
	document.getElementById(ID).style.visibility = "hidden";
}
function verify (ID, target) {
	result = confirm("Wollen Sie den Eintrag " + ID + " wirklich loeschen?");
	if (result) {
		window.location.href = target;
	}
}
function openWindow (ID, Page) {
	Uploader = window.open(Page, "Bilder", "width=860,height=700,left=100,top=0, scrollbars=yes");
 	Uploader.focus();
}
function openWindowSize (Page, Title, w, h) {
	newWnd = window.open(Page, Title, "width="+w+",height="+h+",left=50,top=20, scrollbars=yes");
 	newWnd.focus();
}
function delImage () {
	document.getElementById("tmp_image").style.display = "none";
	document.getElementById("tmp_image").style.visibility = "hidden";
	document.formular.del_img.value = document.formular.old_img.value;
	document.formular.old_img.value = "";
}
function delImageKand () {
	document.getElementById("tmp_image").style.display = "none";
	document.getElementById("tmp_image").style.visibility = "hidden";
	document.formular.old_img.value = "";
}
function hideImage () {
	document.getElementById("tmp_image").style.display = "none";
	document.getElementById("tmp_image").style.visibility = "hidden";
}
function delImage_with_params (ID) {
	document.getElementById('ausgabe_bild' + ID).style.display = "none";
	document.getElementById('ausgabe_bild' + ID).style.visibility = "hidden";
	document.getElementById('eingabe_bild' + ID).style.display = "block";
	document.getElementById('eingabe_bild' + ID).style.visibility = "visible";
	document.getElementById('del_pics' + ID).value = "true";
}
