var list;
var base;
var width;

function setwidth(pos){
  $("#popup > table").width($("#popup").width())
        if(base+980>pos+width+100){
          c=100
        }else{
          c=35
        }
        $("#popup").width(width+c)
        $("#popup table").width(width+c)
        $("#ppc").width(width+c)
}

function nop(){
  
}

function findPos(obj) {
    var pos = 0;
    tmp = obj.offset()
    pos = tmp.left
    return pos;
}

function show(){
  $("#menu_img").css("z-index","1");
}

$(document).ready(function(){
  base = (document.body.clientWidth-980)/2;
  $("#popup").hide("");
  
  $().click(function(){
    $("#menu .m_first").css("background-color","#2a3c84")
    $("#menu .m_first a").css("color","white")
    $("#popup").hide("");
  })

  $("#show_btn").click(function() {
    if($("#menu").css("height")=="37px"){
      $("#show_btn img").attr("src","/img/r_btn.jpg")
      $("#menu_img").css("z-index","-1")
      $("#menu").animate({"height":"+=300px"},"fast")
    }else{
      $("#show_btn img").attr("src","/img/show_menu_btn.jpg")
      $("#menu").animate({"height":"-=300px"},"fast",show)
    }
  })

  $("#popup").hover(nop,function(){
    $("#menu .m_first").css("background-color","#2a3c84")
    $("#menu .m_first a").css("color","white")
    $("#popup").hide("");
  })

  $(".m_first a").hover(function(){
    var list = $(this).parents("ul")
    if($("#menu").css("height")=="37px"){
      if(!list.parent("#ppc").css("width")){
        $("#ppc").empty()
        $("#menu .m_first").css("background-color","#2a3c84")
        $("#menu .m_first a").css("color","white")
        width = $(this).parent().width()+3
        pos = findPos($(this))
        $("#popup").css("left",pos)
        setwidth(pos);
        list.clone(true).appendTo("#ppc")
        $("#ppc li:first-child").remove()
        $("#popup").show("",setwidth)
        $("#popup").css("top","198px")
        $(this).parent().css("background-color","#e7f3ff")
        $(this).css("color","black")
      }
    }
  })
})

function ShortWindow(x,ww,wh){
  var sc="yes";
  if(x.substr(1,5)=="photo") sc="no";
  var l=(screen.width-ww)/2;
  var h=(screen.height-wh)/2;
  var a=window.open(x,"smallwindow","left="+l+",width="+ww+", height="+wh+",top="+h+", status=no, toolbar=no, menubar=no, resizable=yes, scrollbars="+sc);
  a.focus();
  return false;
}


