// ajax
function sack(_1){this.xmlhttp=null;this.resetData=function(){this.method="POST";this.queryStringSeparator="?";this.argumentSeparator="&";this.URLString="";this.encodeURIString=true;this.execute=false;this.element=null;this.elementObj=null;this.requestFile=_1;this.vars=new Object();this.responseStatus=new Array(2);};this.resetFunctions=function(){this.onLoading=function(){};this.onLoaded=function(){};this.onInteractive=function(){};this.onCompletion=function(){};this.onError=function(){};this.onFail=function(){};};this.reset=function(){this.resetFunctions();this.resetData();};this.createAJAX=function(){try{this.xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");}catch(e1){try{this.xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}catch(e2){this.xmlhttp=null;}}if(!this.xmlhttp){if(typeof XMLHttpRequest!="undefined"){this.xmlhttp=new XMLHttpRequest();}else{this.failed=true;}}};this.setVar=function(_2,_3){this.vars[_2]=Array(_3,false);};this.encVar=function(_4,_5,_6){if(true==_6){return Array(encodeURIComponent(_4),encodeURIComponent(_5));}else{this.vars[encodeURIComponent(_4)]=Array(encodeURIComponent(_5),true);}};this.processURLString=function(_7,_8){encoded=encodeURIComponent(this.argumentSeparator);regexp=new RegExp(this.argumentSeparator+"|"+encoded);varArray=_7.split(regexp);for(i=0;i<varArray.length;i++){urlVars=varArray[i].split("=");if(true==_8){this.encVar(urlVars[0],urlVars[1]);}else{this.setVar(urlVars[0],urlVars[1]);}}};this.createURLString=function(_9){if(this.encodeURIString&&this.URLString.length){this.processURLString(this.URLString,true);}if(_9){if(this.URLString.length){this.URLString+=this.argumentSeparator+_9;}else{this.URLString=_9;}}this.setVar("rndval",new Date().getTime());urlstringtemp=new Array();for(key in this.vars){if(false==this.vars[key][1]&&true==this.encodeURIString){encoded=this.encVar(key,this.vars[key][0],true);delete this.vars[key];this.vars[encoded[0]]=Array(encoded[1],true);key=encoded[0];}urlstringtemp[urlstringtemp.length]=key+"="+this.vars[key][0];}if(_9){this.URLString+=this.argumentSeparator+urlstringtemp.join(this.argumentSeparator);}else{this.URLString+=urlstringtemp.join(this.argumentSeparator);}};this.runResponse=function(){eval(this.response);};this.runAJAX=function(_a){if(this.failed){this.onFail();}else{this.createURLString(_a);if(this.element){this.elementObj=document.getElementById(this.element);}if(this.xmlhttp){var _b=this;if(this.method=="GET"){totalurlstring=this.requestFile+this.queryStringSeparator+this.URLString;this.xmlhttp.open(this.method,totalurlstring,true);}else{this.xmlhttp.open(this.method,this.requestFile,true);try{this.xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");}catch(e){}}this.xmlhttp.onreadystatechange=function(){switch(_b.xmlhttp.readyState){case 1:_b.onLoading();break;case 2:_b.onLoaded();break;case 3:_b.onInteractive();break;case 4:_b.response=_b.xmlhttp.responseText;_b.responseXML=_b.xmlhttp.responseXML;_b.responseStatus[0]=_b.xmlhttp.status;_b.responseStatus[1]=_b.xmlhttp.statusText;if(_b.execute){_b.runResponse();}if(_b.elementObj){elemNodeName=_b.elementObj.nodeName;elemNodeName.toLowerCase();if(elemNodeName=="input"||elemNodeName=="select"||elemNodeName=="option"||elemNodeName=="textarea"){_b.elementObj.value=_b.response;}else{_b.elementObj.innerHTML=_b.response;}}if(_b.responseStatus[0]=="200"){_b.onCompletion();}else{_b.onError();}_b.URLString="";break;}};this.xmlhttp.send(this.URLString);}}};this.reset();this.createAJAX();}




var currentType = '';
function show(e, img){
        if(e==null) e=window.event;
        var type = getType(e);

        var popupdiv = document.getElementById("popupdiv_"+type);
        var top = document.getElementById(type+"_top");
        setOpacity2(popupdiv);
        popupdiv.style.display = 'block';

        top.innerHTML = "<img border=1 src='"+img+"'>";
        currentType = type;
        Locate(e);
}
function hide(){
        var popupdiv = document.getElementById("popupdiv_"+currentType);
        popupdiv.style.display = 'none';

        currentType = '';
}
function setOpacity2(el){
        el.style.filter="alpha(opacity:85)";
        el.style.KHTMLOpacity="0.85";
        el.style.MozOpacity="0.85";
        el.style.opacity="0.85";
}
function Locate(e){
        if (!currentType) currentType = "bottom";
        var offsetX, offsetY;
        offsetY = currentType == "top" ? -245 : 15;
        offsetX = 100;
        var posx=0,posy=0;
        if(e==null) e=window.event;
        if(e.pageX || e.pageY){
                posx=e.pageX; posy=e.pageY;
                }
        else if(e.clientX || e.clientY){
                if(document.documentElement.scrollTop){
                        posx=e.clientX+document.documentElement.scrollLeft;
                        posy=e.clientY+document.documentElement.scrollTop;
                        }
                else{
                        posx=e.clientX+document.body.scrollLeft;
                        posy=e.clientY+document.body.scrollTop;
                        }
        }
        document.getElementById("popupdiv_"+currentType).style.top=(posy+offsetY)+"px";
        document.getElementById("popupdiv_"+currentType).style.left=(posx-offsetX)+"px";
}

function getType(e) {
        var winH = getHeight();
        var cursorY = 0;
        if (typeof(e.pageY) == 'number') {
                var scrollY = getScrollY();
                cursorY = e.pageY - scrollY;
        } else if (typeof(e.clientY) == 'number') {
                cursorY = e.clientY;
        }
        if (cursorY > (winH-cursorY)) {
                return "top";
        } else {
                return "bottom";
        }
}

function getHeight() {
  var height = 0;
  if (typeof(window.innerWidth) == 'number') {
    height = window.innerHeight;
  } else if (document.documentElement && document.documentElement.clientHeight) {
    height = document.documentElement.clientHeight;
  } else if (document.body && document.body.clientHeight) {
    height = document.body.clientHeight;
  }
  return height;
}

function getScrollY() {
        var scrollY = 0;
        if (document.documentElement && document.documentElement.scrollTop) {
    scrollY = document.documentElement.scrollTop;
  } else if (document.body && document.body.scrollTop) {
    scrollY = document.body.scrollTop;
  } else if (typeof(window.pageYOffset) == 'number') {
          scrollY = window.pageYOffset;
  }
        return scrollY;
}








document.write('<div id="popupdiv_top"><div id="top_top"></div><div id="top_bottom"></div></div><div id="popupdiv_bottom"><div id="bottom_top"></div><div id="bottom_bottom"></div></div>');





function hidetrail()
{

      hide();
}


function showtrail(file,event)
{
show(event,file);
        }


function addEvent(objObject, strEventName, fnHandler)
{

         if (objObject.addEventListener)
         {
             objObject.addEventListener(strEventName, fnHandler, false);
         }
         else if (objObject.attachEvent)
         {
              objObject.attachEvent("on" + strEventName, fnHandler);
         }

}
/////////////////////////////////////////////////////////////
              var LoadingHeight = 10
              var marginTop = 25
              var navUserAgent = navigator.userAgent
              function move(){if (navUserAgent.indexOf("Firefox") >= 0 || navUserAgent.indexOf("Opera") >= 0) {$("loading").style.top = (document.body.scrollTop?document.body.scrollTop:document.documentElement.scrollTop) + ((document.body.clientHeight > document.documentElement.clientHeight)?document.documentElement.clientHeight:document.body.clientHeight) - LoadingHeight - marginTop + 'px';}else{$("loading").style.top = (document.body.scrollTop?document.body.scrollTop:document.documentElement.scrollTop) + ((document.documentElement.clientHeight == 0)?document.body.clientHeight:document.documentElement.clientHeight) - LoadingHeight - marginTop + 'px';}loadingtimer = setTimeout("move();",80)}
              function showLoading(){/*document.body.style.cursor = 'wait';*/$('loading').style.display = 'block';move();}
              function hideLoading(){clearTimeout(loadingtimer);document.body.style.cursor = 'default';$('loading').style.display = 'none';}




///////////////////////////////////////////////////////////
var enableCache = true;
var jsCache = new Array();

var dynamicContent_ajaxObjects = new Array();

function ajax_showContent(divId,ajaxIndex,url)
{
        showLoading();
        document.getElementById(divId).innerHTML = dynamicContent_ajaxObjects[ajaxIndex].response;
        if(enableCache){
                jsCache[url] = dynamicContent_ajaxObjects[ajaxIndex].response;
        }
        dynamicContent_ajaxObjects[ajaxIndex] = false;
        hideLoading();
}

function ajax_loadContent(divId,url,dontusecahe)
{
        if ( dontusecahe !== true )
        {
        if(enableCache && jsCache[url]){
                document.getElementById(divId).innerHTML = jsCache[url];
                return;
        }
        }
        var ajaxIndex = dynamicContent_ajaxObjects.length;
        //document.getElementById(divId).innerHTML = '<div dir=ltr>Loading Please Wait...</div><br>';
        showLoading();
        dynamicContent_ajaxObjects[ajaxIndex] = new sack();
        dynamicContent_ajaxObjects[ajaxIndex].requestFile = url;        // Specifying which file to get
        dynamicContent_ajaxObjects[ajaxIndex].onCompletion = function(){ ajax_showContent(divId,ajaxIndex,url);hideLoading(); };        // Specify function that will be executed after file has been found
        dynamicContent_ajaxObjects[ajaxIndex].runAJAX();                // Execute AJAX function


}

///////////////////////////////////////////////////////////

function loadtopphoto(){ajax_loadContent('topphoto','ajax/topphotos.html');}
function loadlastphoto(){ajax_loadContent('lastphoto','ajax/lastphotos.html');}
function loadtopalbums(){ajax_loadContent('topalbums','ajax/topalbums.html');}
function moretopphoto(page){ajax_loadContent('topphoto','ajax/topphotos.html?page='+ page);}
function moretopalbums(page){ajax_loadContent('topalbums','ajax/topalbums.html?page='+ page);}
function morelastphoto(page){ajax_loadContent('lastphoto','ajax/lastphotos.html?page='+ page);}
function random_gallery(){ajax_loadContent('random_photo','ajax/randomphoto.html',true);}
function loadlastalbums(){ajax_loadContent('tabsheet','ajax/lastalbums.html');}


///////////////////////////////////////////////////////////
function init()
{

//loadlastphoto();
//loadtopalbums();
//random_gallery();

}


function include(fileUrl) {   var script = document.createElement("script");   var head = document.getElementsByTagName('head').item(0);    script.src = fileUrl;   head.appendChild(script); }

//////////////////////////////////////////////////////////////
var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
xmlhttp = new XMLHttpRequest();
}

function loadFragmentInToElement(fragment_url, element_id) {
var element = document.getElementById(element_id);

element.innerHTML = '<div id="prepage" style="FONT-SIZE:12px; Z-INDEX:101; RIGHT:27;  WIDTH:76; BACKGROUND-REPEAT:repeat; FONT-FAMILY:arial; POSITION:absolute;  HEIGHT:38; BACKGROUND-COLOR:transparent; layer-background-color:white" dir=ltr><table class="preloaderT1" width="100%" height="100%" align="center"  onClick="return false;"><tr width="100%" height="100%" align="center" valign="middle"><td><table Cellpadding="0"        Cellspacing="0" class="preloaderT2"><tr align="center" valign="middle"><td nowrap><table class="preloaderT3" style="border: 1px solid #E0F4FE;" cellpadding="4" cellspacing="0"><tr align="center" valign="middle"><td nowrap align="left"  bgcolor="#FFFFFF" onClick="return false;"><b>Please wait ...  </b></td></tr></table></td></tr></table></td></tr></table></div>';




xmlhttp.open("GET", fragment_url);
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
element.innerHTML = xmlhttp.responseText;
}
}
xmlhttp.send(null);
}

function get(act) {
loadFragmentInToElement('main.php?act='+act, 'content');
}

function get_content(page,id) {
loadFragmentInToElement(page, id);
}

function doClickTab(evt) {
  //get clicked element
  var clickedEl = evt.srcElement || evt.target;
  if (!clickedEl) return;

  //make sure it's an <a>
  if (clickedEl.nodeName == '#text') clickedEl = clickedEl.parentNode;
  if (clickedEl.nodeName.toLowerCase() != 'a') return;

  //store clicked a-element
  var aEl = clickedEl;

  //get list item
  var liEl = aEl.parentNode;
  if (liEl.nodeName.toLowerCase() != 'li') return;
  if (liEl.className != 'inactive') return;

  //get list
  var ulEl = liEl.parentNode;
  if (ulEl.className != 'tabnav') return;


  for (i=0; i<ulEl.childNodes.length; i++) {
    var childEl = ulEl.childNodes[i];
    if ((childEl.nodeName.toLowerCase() == 'li') && (childEl != liEl) && (childEl.className != 'inactive'))
      childEl.className = 'inactive';
  }


  liEl.className = 'active';



}
//////////////////////////////////////////////
function $(name) {
        if (document.getElementById) {
                return document.getElementById(name);
        } else if (document.all) {
                return document.all[name];
        } else if (document.layers){
                return document[name];
        } else {
                return 0;
        }
}
////////////////////////////////////////////////

function do_vote(pollId)
{
        var ajaxIndex = ajaxObjects.length;
        ajaxObjects[ajaxIndex] = new sack();
        ajaxObjects[ajaxIndex].requestFile = serverSideFile + '?pollId=' + pollId;
        prepareForPollResults(pollId);
        ajaxObjects[ajaxIndex].onCompletion = function(){ showVoteResults(pollId,ajaxIndex); };        // Specify function that will be executed after file has been found
        ajaxObjects[ajaxIndex].runAJAX();                // Execute AJAX function


}

function dovote(pollId,formObj,serverSideFile,divId)
{
        var elements = formObj.options;

        var optionId = false;
        var ajaxObjects = new Array();
        for(x=0;x<elements.length;x++){
        if(elements[x].checked == true) {

        optionId = elements[x].value;
        }
        }


        if(optionId){
                var url = serverSideFile + '?pollid=' + pollId + '&options=' + optionId + '&type=simple&act=do_vote';
                var ajaxIndex = ajaxObjects.length;
                ajaxObjects[ajaxIndex] = new sack();
                ajaxObjects[ajaxIndex].method = "POST";
                ajaxObjects[ajaxIndex].requestFile = url;
                showLoading();
                ajaxObjects[ajaxIndex].onCompletion = function(){
                        $(divId).innerHTML = ajaxObjects[ajaxIndex].response;
                         launchJavascript(ajaxObjects[ajaxIndex].response);
                         hideLoading();
                         };
                ajaxObjects[ajaxIndex].runAJAX();

        }
}


function reload_poll(pollId,divId)
{


                var ajaxObjects = new Array();
                var url = 'vote-' + pollId + '.html?type=simple';
                var ajaxIndex = ajaxObjects.length;
                ajaxObjects[ajaxIndex] = new sack();
                ajaxObjects[ajaxIndex].requestFile = url;
                showLoading();
                ajaxObjects[ajaxIndex].onCompletion = function(){
                        $(divId).innerHTML = ajaxObjects[ajaxIndex].response;
                         launchJavascript(ajaxObjects[ajaxIndex].response);
                         hideLoading();
                         };
                ajaxObjects[ajaxIndex].runAJAX();



}

function launchJavascript(responseText) {
  // RegExp from prototype.sonio.net
  var ScriptFragment = '(?:<script.*?>)((\n|.)*?)(?:</script>)';

  var match    = new RegExp(ScriptFragment, 'img');
  var scripts  = responseText.match(match);

    if(scripts) {
        var js = '';
        for(var s = 0; s < scripts.length; s++) {
            var match = new RegExp(ScriptFragment, 'im');
            js += scripts[s].match(match)[1];
        }
        eval(js);
    }
}

var pollmInterval;
function poll_Bar(myfeelmya,prefix) {pollmInterval = setInterval("do_poll_Progress(" + myfeelmya + "," + prefix +")",10);}
function do_poll_Progress(myfeelmya,prefix) {curWidth = parseInt(document.getElementById("mask"+prefix).offsetWidth);curLeft = parseInt(document.getElementById("mask"+prefix).offsetLeft);curWidth --;curLeft ++;if(curLeft / 141 * 100 > myfeelmya) {clearInterval(pollmInterval);return;}document.getElementById("mask"+prefix).style.left = curLeft + "px";if(parseInt(document.getElementById("mask"+prefix).offsetWidth)>10)document.getElementById("mask"+prefix).style.width = curWidth + "px";document.getElementById("progressIndicator"+prefix).innerHTML = Math.floor((curLeft / parseInt(document.getElementById("gradient"+prefix).offsetWidth))*100) + "%";}




function initfadeIn(id, speed)
{
        var image = document.getElementById(id);
        setOpacity(image, 0);
        //image.style.visibility = "visible";
        fadeIn(id, 0, speed);
}

function initfadeOut(id, speed)
{
        var image = document.getElementById(id);
        setOpacity(image, 100);
        fadeOut(id, 100, speed);
}

function setOpacity(obj, opacity)
{
        obj.style.filter = "alpha(opacity:"+opacity+")";
        obj.style.KHTMLOpacity = opacity/100;
        obj.style.MozOpacity = opacity/100;
        obj.style.opacity = opacity/100;
}

function fadeIn(objId, opacity, speed)
{
        if (document.getElementById)
        {
                obj = document.getElementById(objId);
                if (opacity <= 100)
                {
                        setOpacity(obj, opacity);
                        opacity += 10;
                        window.setTimeout("fadeIn(\""+objId+"\", "+opacity+", "+speed+")", speed);
                }
        }
}

function fadeOut(objId, opacity, speed)
{
        if (document.getElementById)
        {
                obj = document.getElementById(objId);
                if (opacity >= 0)
                {
                        setOpacity(obj, opacity);
                        opacity -= 10;
                        window.setTimeout("fadeOut(\""+objId+"\", "+opacity+", "+speed+")", speed);
                }
        }
}

function logout()
{
         body = document.getElementsByTagName("html");
         body[0].style.filter = "progid:DXImageTransform.Microsoft.BasicImage(grayscale=1)";
         if (confirm('هل تريد بالفعل تسجيل الخروج؟ '))
         {
                return true;
         }
         else
         {
                body[0].style.filter = "";
                return false;
         }
}

function openwindow(url,width,height)
        {
        window.open(url,"","width="+ width +",height="+ height +";toolbar=no,menubar=no,location=no,directories=no,status=yes,scrollbars=1")
        }

function get_radio_val(field)
{
if (field.type == "radio")
{
    if (field.checked)
        return field.value;
    else
        return "";
}
if (field[0].type == "radio")
{
    for (i = 0; i < field.length; i++)
    {
        if (field[i].checked)
            return field[i].value;
    }
    return "";
}
return "";
}


var orginaltext;
function editnote()
{
var cols = 50;
$('note_debug').innerHTML = '';
orginaltext = $('note_text').innerHTML;
var rows = (orginaltext.length / cols) + 3;
notefotm = '<span id="note_editor" style="position:relative;margin-bottom: 5px;"><textarea id="note_edit" class="" name="note_edit" rows="' + rows + '" cols="'+ cols + '" style="width:96%">'+orginaltext+'</textarea><br /><span><input id="note_save" class="button" type="button" onclick="savenewnote()" value="حفظ" /> او <input id="note_cancel" class="button" type="button" onclick="cancelnoteedit()" value="الغاء" /></span></span>';
$('note_text').innerHTML =  notefotm;
$('note_text').ondblclick = cancelnoteedit;

}

function cancelnoteedit()
{
$('note_debug').innerHTML = '';
$('note_text').innerHTML =  orginaltext;
$('note_text').ondblclick = editnote;

}

function savenewnote()
{
var add2query = $('note_edit').value;

ajax_loadContent('note_debug','my/save/my/note/index.html?mynote='+add2query,true);

$('note_text').innerHTML =  $('note_edit').value;
$('note_text').ondblclick = editnote;


}

function add_remove_fav(myobject,type,id,albumid)
{
   if ( type === 'add')
   {
        ajax_loadContent('favdebug','favorite/add/'+ id +'/'+ albumid +'/fav.html',true);
        $(myobject).innerHTML = 'ازالة الصورة من المفضلة';
        $(myobject).href      = 'javascript:add_remove_fav(\''+ myobject +'\',\'remove\',\''+ id +'\',\''+ albumid +'\');';
   }
   else
   {
      ajax_loadContent('favdebug','favorite/remove/'+ id +'/fav.html',true);
      $(myobject).innerHTML = 'اضافة الصورة لمفضلتك';
      $(myobject).href      = 'javascript:add_remove_fav(\''+ myobject +'\',\'add\',\''+ id +'\',\''+ albumid +'\');';
   }
}

// dropmenu
function at_show_aux(parent, child)
{
  var p = document.getElementById(parent);
  var c = document.getElementById(child);



  var top  = (c["at_position"] == "y") ? p.offsetHeight+2 : 0;
  var left = (c["at_position"] == "x") ? p.offsetWidth +2 : 0;

  for (; p; p = p.offsetParent)
  {
    top  += p.offsetTop;
    left += p.offsetLeft;
  }

  c.style.position   = "absolute";
  c.style.top        = top +'px';
  c.style.left       = left+'px';
  //c.style.clip = 'rect(auto, 0px, 0px, auto)'
  c.style.visibility = "visible";
  c.style.filter = "progid:DXImageTransform.Microsoft.shadow(direction=135,color=#8E8E8E,strength=3)";
  c.style.zIndex = 1000000;

}


        function slide_in(str_obj,clipX,clipY) {
            var obj = document.getElementById(str_obj);

            if ((clipX < obj.offsetWidth || clipY < obj.offsetHeight) )
            {
               // n = n - 10;

                 clipX += 10;
                 clipY += 10;
                //obj.style.clip = "rect(" + n + "px 232px 122px 0px)";
                //
               // alert(str_obj.offsetWidth);
                obj.style.clip = "rect(auto " + clipX + "px " + clipY + "px auto)";
                timer = window.setTimeout('slide_in(\'' + str_obj + '\',' + clipX + ',' + clipY + ')', 10);
            }

        }


        function slide_out(str_obj,clipX,clipY) {
            var obj = document.getElementById(str_obj);

          //  if ((clipX < obj.offsetWidth || clipY < obj.offsetHeight) )
          //  {
               // n = n - 10;

           //      clipX += 10;
           //      clipY += 10;
                //obj.style.clip = "rect(" + n + "px 232px 122px 0px)";
           //     obj.style.clip = "rect(auto "+ obj.offsetWidth +"px " + clipX + "px " + clipY + "px)";
          //      timer = window.setTimeout('slide_out(\'' + str_obj + '\',' + clipX + ',' + clipY + ')', 10);
          //  }else
          //  {
            obj.style.visibility = 'hidden'
         //   }

        }


// ----- Show -----

function at_show()
{
  p = document.getElementById(this["at_parent"]);
  c = document.getElementById(this["at_child" ]);

  at_show_aux(p.id, c.id);
  slide_in(this["at_child" ],0,0);
  clearTimeout(c["at_timeout"]);

}

function re_show ()
{

  p = document.getElementById(this["at_parent"]);
  c = document.getElementById(this["at_child" ]);

  at_show_aux(p.id, c.id);

  clearTimeout(c["at_timeout"]);
         //else c.style.visibility = "hidden";

        }

// ----- Hide -----

function at_hide()
{
  c = document.getElementById(this["at_child"]);



   c["at_timeout"] = setTimeout("slide_out('"+c.id+"',0,0)", 333);
}

// ----- Click -----

function at_click()
{
  p = document.getElementById(this["at_parent"]);
  c = document.getElementById(this["at_child" ]);

  if (c.style.visibility != "visible") {at_show_aux(p.id, c.id);
  slide_in(this["at_child" ],0,0);
  clearTimeout(c["at_timeout"]);
  }
  else c.style.visibility = "hidden";

  return false;
}


function at_attach(parent, child, showtype, position, cursor)
{
  p = document.getElementById(parent);
  c = document.getElementById(child);

  p["at_parent"]     = p.id;
  c["at_parent"]     = p.id;
  p["at_child"]      = c.id;
  c["at_child"]      = c.id;
  p["at_position"]   = position;
  c["at_position"]   = position;

  c.style.position   = "absolute";
  c.style.visibility = "hidden";

  if (cursor != undefined) p.style.cursor = cursor;

  switch (showtype)
  {
    case "click":
      p.onclick     = at_click;
      p.onmouseout  = at_hide;
      c.onmouseover = re_show;
      c.onmouseout  = at_hide;
      break;
    case "hover":
      p.onmouseover = at_show;
      p.onmouseout  = at_hide;
      c.onmouseover = re_show;
      c.onmouseout  = at_hide;
      break;
  }
}


// tree menu
var persisteduls=new Object()
var ddtreemenu=new Object()

ddtreemenu.closefolder="images/max.gif"
ddtreemenu.openfolder="images/min.gif"


ddtreemenu.createTree=function(treeid, enablepersist, persistdays){
var ultags=document.getElementById(treeid).getElementsByTagName("ul")
if (typeof persisteduls[treeid]=="undefined")
persisteduls[treeid]=(enablepersist==true && ddtreemenu.getCookie(treeid)!="")? ddtreemenu.getCookie(treeid).split(",") : ""
for (var i=0; i<ultags.length; i++)
ddtreemenu.buildSubTree(treeid, ultags[i], i)
if (enablepersist==true){
var durationdays=(typeof persistdays=="undefined")? 1 : parseInt(persistdays)
ddtreemenu.dotask(window, function(){ddtreemenu.rememberstate(treeid, durationdays)}, "unload")
}
}

ddtreemenu.buildSubTree=function(treeid, ulelement, index){
ulelement.parentNode.className="submenu"
if (typeof persisteduls[treeid]=="object"){
if (ddtreemenu.searcharray(persisteduls[treeid], index)){
ulelement.setAttribute("rel", "open")
ulelement.style.display="block"
ulelement.parentNode.style.backgroundImage="url("+ddtreemenu.openfolder+")"
}
else
ulelement.setAttribute("rel", "closed")
}
else if (ulelement.getAttribute("rel")==null || ulelement.getAttribute("rel")==false)
ulelement.setAttribute("rel", "closed")
else if (ulelement.getAttribute("rel")=="open")
ddtreemenu.expandSubTree(treeid, ulelement)
ulelement.parentNode.onclick=function(e){
var submenu=this.getElementsByTagName("ul")[0]
if (submenu.getAttribute("rel")=="closed"){
submenu.style.display="block"
submenu.setAttribute("rel", "open")
ulelement.parentNode.style.backgroundImage="url("+ddtreemenu.openfolder+")"
}
else if (submenu.getAttribute("rel")=="open"){
submenu.style.display="none"
submenu.setAttribute("rel", "closed")
ulelement.parentNode.style.backgroundImage="url("+ddtreemenu.closefolder+")"
}
ddtreemenu.preventpropagate(e)
}
ulelement.onclick=function(e){
ddtreemenu.preventpropagate(e)
}
}

ddtreemenu.expandSubTree=function(treeid, ulelement){
var rootnode=document.getElementById(treeid)
var currentnode=ulelement
currentnode.style.display="block"
currentnode.parentNode.style.backgroundImage="url("+ddtreemenu.openfolder+")"
while (currentnode!=rootnode){
if (currentnode.tagName=="UL"){
currentnode.style.display="block"
currentnode.setAttribute("rel", "open")
currentnode.parentNode.style.backgroundImage="url("+ddtreemenu.openfolder+")"
}
currentnode=currentnode.parentNode
}
}

ddtreemenu.flatten=function(treeid, action){
var ultags=document.getElementById(treeid).getElementsByTagName("ul")
for (var i=0; i<ultags.length; i++){
ultags[i].style.display=(action=="expand")? "block" : "none"
var relvalue=(action=="expand")? "open" : "closed"
ultags[i].setAttribute("rel", relvalue)
ultags[i].parentNode.style.backgroundImage=(action=="expand")? "url("+ddtreemenu.openfolder+")" : "url("+ddtreemenu.closefolder+")"
}
}

ddtreemenu.rememberstate=function(treeid, durationdays){
var ultags=document.getElementById(treeid).getElementsByTagName("ul")
var openuls=new Array()
for (var i=0; i<ultags.length; i++){
if (ultags[i].getAttribute("rel")=="open")
openuls[openuls.length]=i
}
if (openuls.length==0)
openuls[0]="none open"
ddtreemenu.setCookie(treeid, openuls.join(","), durationdays)
}

ddtreemenu.getCookie=function(Name){
var re=new RegExp(Name+"=[^;]+", "i");
if (document.cookie.match(re))
return document.cookie.match(re)[0].split("=")[1]
return ""
}

ddtreemenu.setCookie=function(name, value, days){
var expireDate = new Date()
var expstring=expireDate.setDate(expireDate.getDate()+parseInt(days))
document.cookie = name+"="+value+"; expires="+expireDate.toGMTString()+"; path=/";
}

ddtreemenu.searcharray=function(thearray, value){
var isfound=false
for (var i=0; i<thearray.length; i++){
if (thearray[i]==value){
isfound=true
thearray.shift()
break
}
}
return isfound
}

ddtreemenu.preventpropagate=function(e){
if (typeof e!="undefined")
e.stopPropagation()
else
event.cancelBubble=true
}

ddtreemenu.dotask=function(target, functionref, tasktype){
var tasktype=(window.addEventListener)? tasktype : "on"+tasktype
if (target.addEventListener)
target.addEventListener(tasktype, functionref, false)
else if (target.attachEvent)
target.attachEvent(tasktype, functionref)
}
