//pop up

function ap_getObj(name) {
  if (document.getElementById) 
    return document.getElementById(name).style;
  else
    if (document.all) 
      return document.all[name].style;
    else
      if (document.layers) 
        return document.layers[name];
}

jestisknuto=false;

function Hlavicka_onMouseDown()
{
 jestisknuto=true;
}

function PohybMysi(e){
 if (jestisknuto)
  {
   if (navigator.appName=="Microsoft Internet Explorer" || navigator.appName=="Google Chrome")
    {
     document.getElementById("tabulka").style.left=window.event.x-100;
     document.getElementById("tabulka").style.top=window.event.y-15;
    }

   if (navigator.appName=="Netscape")
    {
     document.getElementById("tabulka").style.left=e.pageX-100;
     document.getElementById("tabulka").style.top=e.pageY-15;
    }
  }
}

function UkonceniPresunu(){
jestisknuto=false;
if(document.getElementById("tabulka").style.left < "0" && document.getElementById("tabulka").style.left != "")
    document.getElementById("tabulka").style.left = 0;
if(document.getElementById("tabulka").style.top < "0" && document.getElementById("tabulka").style.top != "")
    document.getElementById("tabulka").style.top = 0;
}

function SkryjTabulku(){
 document.getElementById('tabulka').style.visibility='hidden';     
}

function ZobrazTabulku(){
 document.getElementById('tabulka').style.visibility='visible';
 return false;
}

function priradfunkce(){

var x = ap_getObj('tabulka');

document.onmouseup = UkonceniPresunu;
document.onmousemove = PohybMysi;
document.getElementById("ukaz").onclick = ZobrazTabulku;
document.getElementById("hlavicka").onmousedown = Hlavicka_onMouseDown;
document.getElementById("kriz").onclick = SkryjTabulku;
}


//zbytek


$(document).ready(function(e) {
    // gray
    $(".gray_shape .label li").hover(function() { $(this).find("span").css({ color: "#84d73f", backgroundPosition: "left bottom" }); }, function() { $(this).find("span").css({ color: "White", backgroundPosition: "left top" }); });
    $(".gray_shape .label li").click(function() { $("#side_content").load($(this).attr("url")); });
    $(".gray_shape .label tr .space").hover(function() { $(this).find("span").css({ color: "#84d73f", backgroundPosition: "left bottom" }); }, function() { $(this).find("span").css({ color: "White", backgroundPosition: "left top" }); });
    // green
    $(".green_shape .label li").hover(function() { $(this).find("span").css({ color: "#84d73f", backgroundPosition: "left bottom" }); }, function() { $(this).find("span").css({ color: "#61696C", backgroundPosition: "left top" }); });
    $(".green_shape .label li").click(function() { $("#side_content").load($(this).attr("url")); });
    $(".green_shape .label tr .space").hover(function() { $(this).find("span").css({ color: "#84d73f", backgroundPosition: "left bottom" }); }, function() { $(this).find("span").css({ color: "#61696C", backgroundPosition: "left top" }); });
    //
    // LEFT MENU CLICK
    //
    $(".left_menu .rollete").closest("tr").click(function() {
        // show.hide elements
        var elements = $(this).closest("table").find(".hidelem");
        //alert($(elements[0]).attr("v"));
        if ($(elements[0]).attr("v") == "0") { //is(":hidden")
            $(".left_menu .hidelem").hide();
            $(".left_menu .hidelem").attr("v", "0");
            elements.show();
            elements.attr("v", "1");
            //alert("hide and show");
        }
        else {
            $(".left_menu .hidelem").hide();
            $(".left_menu .hidelem").attr("v", "0");
            //alert("hide all");
        }
        // resize gray shape
        elements = $(".left_menu .space");
        var height = elements.length * 24;
        elements = $(".left_menu tr[v=1]");
        height += elements.length * 20;
        if (elements.length > 0)
            height += 10;
        height += 37;
        //alert(height);
        if ($(this).closest(".green_shape").attr("resizeable") == "1") {
            $(this).closest(".green_shape").css("height", height);
            $(this).closest(".green_shape").find(".gl").css("height", height - 52);
            $(this).closest(".green_shape").find(".gr").css("height", height - 52);
            $(this).closest(".label").css("height", height - 32);
        }
    });
    //
    // MENU ITEMS CLICK
    //
    $(".left_menu .hidelem").click(function() {
        // load content from menu
        var target = $(this).attr("target");
        var url = $(this).attr("url");
        $(".left_menu .active").removeClass("active");
        $(this).addClass("active");
        if (target != null && url != null) {
            if (target == "_blank")
                location.href = url;
            else
                $("#" + target).load(url);
        }
    });
    //
    // MENU ITEMS CLICK
    //
    $(".left_menu .linkelem").click(function() {
        // load content from menu
        var target = $(this).attr("target");
        var url = $(this).attr("url");
        //$(".left_menu .active").removeClass("active");
        //$(this).addClass("active");
        if (target != null && url != null) {
            if (target == "_blank")
                location.href = url;
            else
                $("#" + target).load(url);
        }
    });
});


