//TODO fix language selector
z.document.ready(function(){
  z.select({'className':'dd'}).select({tag:'a'}).click(function(e){
  	showDropDown(this.p('rel'),this.origin);
  	e.halt();
  });
  
  
  z.select({'className':'dd'}).select({tag:'span'}).click(function(e){
    var parent = z(this.p('parentNode'));
    var a = parent.select({tag:'a'});
    
    a = a.get(0).origin;
    
  	showDropDown(a.rel,a);
  	e.halt();
  });  
  
  z.select({'className':'dd'}).click(function(){
    var a = this.origin.firstChild;
    showDropDown(a.rel,a);
  });
  
  z.document.click(function(){
    if (showDropDown.dd){
      z(showDropDown.dd).addClass('invisible');
      showDropDown.dd = null;
    }
  });  
  
  
  //z('lang_dd').select({'tag':'a'}).click(function(e){
  //  ajaxSetLanguage(this.p('rel'));
  //});
});

function showDropDown(dd_id,a){
  var d = z(dd_id).origin;
  
  if (showDropDown.dd){
    if (showDropDown.dd==d) return;
    z(showDropDown.dd).addClass('invisible');
  }
  
  showDropDown.dd = d;
  
  z(d).removeClass('invisible');
  var c = z(a).getCoordinates();
  
  //alert(a.clientHeight);
  z(d).css('left',c.left+'px');
  z(d).css('top',(a.offsetHeight+c.top)+'px');
}

z.popup = function(url,width,height,scrollbars){
    day = new Date();
    id = "window_"+day.getTime();
    s = scrollbars?'1':'0';
    var left = (window.screen.width-width)/2;
    var top = (window.screen.height-height)/2;
    return window.open(url, id ,'left='+left+',top='+top+',scrollbars='+s+',width='+width+',height='+height+',status=0');	
}