/**
  *  Comments have been removed to keep filesize small.
  *  See ./comments.txt
  */

zeus = {}
zeus.init = function()
{

  if(page!='webcam') {
    document.body.style.overflow = 'hidden';
  }
  if(document.toplogin) {
    if(document.toplogin.login.value) {
      document.toplogin.login.onfocus();
      document.toplogin.login.focusReceived=1;
    }
  }
}

window.onerror = myOnError
  msgArray = new Array()
  urlArray = new Array()
  lnoArray = new Array()
  function myOnError(msg, url, lno) {
  msgArray[msgArray.length] = msg
  urlArray[urlArray.length] = url
  lnoArray[lnoArray.length] = lno
  return true
}
function displayErrors() {
  win2=window.open('','window2','scrollbars=yes')
  win2.document.writeln('<B>Error Report</B><P>')
  for (var i=0; i < msgArray.length; i++) {
  win2.document.writeln('<B>Error in file:</B> '
   + urlArray[i] + '<BR>')
  win2.document.writeln('<B>Line number:</B> '
   + lnoArray[i] + '<BR>')
  win2.document.writeln('<B>Message:</B> '
   + msgArray[i] + '<P>')
  }
  win2.document.close()
}
focusElement = null;

function getHiddenField(el,name){
  var inps=el.getElementsByTagName('input');
  for (var i=0;i<inps.length;i++) {
    var inp=inps[i];
    if(inp.type=='hidden' && inp.name==name) {
      return inp.value;
    }
  }
  return null;
}


;debug = {}
debug.trace = function(str)
{
  
  var display = document.getElementById('trace_display')
  if(display)
  {
    display.style.display = 'block';
    display.innerHTML = display.innerHTML+'<br>'+'&raquo; '+str;
  }
}


;dom = {

};

dom.parentNode=function(el,n){
  
  var p=el.parentNode;
  var str = '';
  for (var i=0;i<n-1;i++) {
    str+='tag: '+p.tagName+', class: '+p.className+', id: '+p.id+' '+'\n';
    p=p.parentNode;
  }

  return p;

}

dom.initEvents = function(el) {
  el.listeners = [];
  el.addEventListener = function(evnt, elmnt, fn) {
    var l = this.listeners;
    for (var i=0; i<l.length; i++) {
      if(l[i][0]==evnt && l[i][1]==elmnt && l[i][2]==fn) {
        return false;
      }
    }
    l.push([evnt,elmnt,fn])
  };
  el.removeEventListener = function(evnt, elmnt, fn) {
    var l = this.listeners;
    for (var i=0; i<l.length; i++) {
      if(l[i][0]==evnt && l[i][1]==elmnt && l[i][2]==fn) {
        l.splice(i,1);
      }
    }
    l.push([evnt,elmnt,fn])
  };
  el.dispatchEvent = function(evnt) {
    var l = this.listeners;
    for (var i=0; i<l.length; i++) {
      if(l[i][0]==evnt) {
        var el = l[i][1];
        var fn = l[i][2];
        if(fn && el) {
          fn.apply(el,[evnt]);
        }
      }
    }
  };

};
dom.nopx = function(pxStr)
{
  if(pxStr.indexOf('px')==-1) return pxStr;
  return Number(pxStr.split('px')[0]);
}
dom.browser = function()
{
  if(navigator.userAgent.indexOf('MSIE')!=-1 )
  {
    return 'ie';
  }
  if(navigator.userAgent.indexOf('Opera')!=-1  )
  {
    return 'op';
  }
  if(navigator.userAgent.indexOf('Netscape')!=-1 )
  {
    return 'ns';
  }
  if( navigator.userAgent.indexOf('Safari')!=-1 )
  {
    return 'sa';
  }
  if( navigator.userAgent.indexOf('Firefox')!=-1 )
  {
    return 'ff';
  }
  return undefined;
}
dom.ff3=function(){
  return (navigator.oscpu && navigator.userAgent.match("rv:1\.9"));
}
dom.setStyle = function (id, styleObj)
{
  var el = dom.element(id);
  for (var prop in styleObj)
  {
    el.style[prop] = styleObj[prop];
  }
}

dom.element = function(id)
{
  if(typeof(id)=='string')
  {
    return document.getElementById(id);
  }
  else
  {
    return id;
  }
}
$ = dom.element
dom.removeElement = function(el)
{
  el.parentNode.removeChild(el);
}
dom.createElement = function(elTagName,parentElement,propsObj)
{
  parentElement = dom.element(parentElement) ? dom.element(parentElement) : document.body;

  var el = document.createElement(elTagName);
  parentElement.appendChild(el);
  if(!propsObj) return el;
  for (var i in propsObj)
  {
    el[i] = propsObj[i];
  }
  return el
}
dom.toggle = function()
{
  var arguments = dom.toggle.arguments
  for (var i=0; i<arguments.length;i++)
  {
    var mode = 'block';
    var id;
    var el;

    if (typeof(arguments[i])=='string')
    {
      if(arguments[i].indexOf(':')!=-1) {
        id = arguments[i].split(':')[0];
        mode = arguments[i].split(':')[1];
      }
      else
      {
        id = arguments[i];
      }

      el = dom.element(id);

    }

    else

    {
      el = id
    }
    
    if (el.style.display != 'none')
    {
      mode = 'none';
    }

    
    el=dom.element(el)
    el.style.display = mode;


  }

}
dom.href = function(url)
{
  document.location.href = url;
}
dom.addEvent = function ( el, type, fn ) {
  
  if ( el.attachEvent ) {
    el['e'+type+fn] = fn;
    el[type+fn] = function(){el['e'+type+fn]( window.event );}
    el.attachEvent( 'on'+type, el[type+fn] );
  } else
    el.addEventListener( type, fn, false );
}
dom.removeEvent = function( el, type, fn ) {
  
  if ( el.detachEvent ) {
    el.detachEvent( 'on'+type, el[type+fn] );
    el[type+fn] = null;
  } else
    el.removeEventListener( type, fn, false );
}



dom.getChildNodes = function(el, obj) {
  var arr = [];
  if(!el.childNodes || el.childNodes.length==0) {
    return null;
  }
  for (var i=0; i<el.childNodes.length; i++) {
    if (el.childNodes[i].nodeType == 1) {
      if(!obj) {
        
        arr.push(el.childNodes[i])
      } else {
        
        var pass = true;
        for (var j in obj) {
          if (obj.containsClass)
          {
            if (el.childNodes[i].className.indexOf(' ') == -1)
            {
              var classes = el.childNodes[i].className.split(' ');
              var contained = false;
              for (var c=0; c<classes.length; c++)
              {
                if(classes[i]==obj.containsClass)
                {
                  contained = true;
                }
              }
              if(!contained)
              {
                pass = false;
              }
            }
          }
          else
          if (el.childNodes[i][j]!=obj[j]) {pass = false};
        }

        if(pass) {
          arr.push(el.childNodes[i]);
        }
      }
      
      var children = dom.getChildNodes(el.childNodes[i], obj);
      if(children) {
        if(children.length>0) {
           arr = arr.concat(children);
        }
      }
    }
  }
  return arr;
}


dom.addClass = function (el, className)
{
  if(el && className)
  {
    el = dom.element(el);
      if ( !dom.containsClass(el, className) )
      {
        el.className += ( el.className ? " " : "" ) + className
      }

  }
}


dom.removeClass = function (el, className)
{
  if(el && className)
  {
    if ( dom.containsClass(el,className) )
    {
      var elClasses = el.className.split(" ");
      var newClassName = "";
      for (var i=0; i<elClasses.length; i++)
      {
        if (elClasses[i]!=className)
        {
          newClassName += elClasses[i] + " ";
        }
      }
      if (newClassName.charAt(newClassName.length-1) == " ") newClassName = newClassName.substr(0, newClassName.length-1);
      el.className = newClassName;
    }
  }
}


dom.containsClass = function (el, className)
{
  if(el && className)
  {
    if(el.className)
    {
      return el.className.indexOf(className)!=-1;
    }
  }
  return false;
}


dom.getBaseClass = function (el)
{
  if(el)
  {
    if(el.className)
    {

      if(el.className.indexOf(' ') == -1)
      {
        return el.className;
      }
      else
      {
        return el.className.split(' ')[0];
      }

    }
  }

}



dom.disableSelection = function (target,leaveCursor){
  target=dom.element(target);
  if (typeof target.onselectstart!="undefined") 
  {
    target.unselectable = "on";
  	target.onselectstart=function(){return false}
  }
  else if (typeof target.style.MozUserSelect!="undefined") 
  {
  	target.style.MozUserSelect="none"
  }
  else 
  {
  	target.onmousedown=function(){return false}
  }
  if(!leaveCursor) target.style.cursor = "default"
}


dom.getClickedElement = function (e)
{

  var targ;
  if (!e)
  {
    var e=window.event;
  }
  if (e.target)
  {
    targ=e.target;
  }
  else if (e.srcElement)
  {
    targ=e.srcElement;
  }
  if (targ.nodeType==3) 
  {
    targ = targ.parentNode;
  }
  return targ;
}






dom.getElementPosition = function(obj)
{
  if(!obj) return false;
	var curleft = curtop = 0;
  if (obj.offsetParent) {
    do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
  }
  return {x:curleft,y:curtop};
}



dom.getMousePosition = function (e)
{
  var posx = 0;
	var posy = 0;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY) 	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY) 	{
		posx = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}
	
	
	return {x:posx,y:posy};
}



dom.getViewportDimensions = function() {
    var intH = 0, intW = 0;

    if(self.innerHeight) {
       intH = window.innerHeight;
       intW = window.innerWidth;
    }
    else {
        if(document.documentElement && document.documentElement.clientHeight) {
            intH = document.documentElement.clientHeight;
            intW = document.documentElement.clientWidth;
        }
        else {
            if(document.body) {
                intH = document.body.clientHeight;
                intW = document.body.clientWidth;
            }
        }
    }

    return {
        height: parseInt(intH, 10),
        width: parseInt(intW, 10)
    };
}


dom.scriptLoaded = function(file)
{
  
  var scripts = document.getElementsByTagName('script');
  for (var i=0; i<scripts.length; i++)
  {
    if(scripts[i].src.indexOf(file)!=-1)
    {
      return true
    }
  }

  return false;
}

dom.loadScript = function(file)
{
  if(dom.scriptLoaded(file))
  {
    return;
  }

  var s = document.createElement('script');
  s.setAttribute('src',file);
  s.setAttribute('type','text/javascript');
  s.setAttribute('language','javascript');
  document.getElementsByTagName('head')[0].appendChild(s);
  return s;

}


dom.hitTest = function (el, point)
{
  var el_pos = dom.getElementPosition(el);

  return ( point.x >= el_pos.x && point.x <= (el_pos.x + el.offsetWidth) && point.y >= el_pos.y && point.y <= (el_pos.y + el.offsetHeight) )
}

dom.reload = function() {
  window.location.reload( false );
}

dom.getParent = function(element, parent){
  if(typeof element=="string"){element=document.getElementById(element);};
  if(!element){return null;};
  var elements=[];
  if(typeof parent!="string"){
  	while(element.parentNode){
    	element=element.parentNode;
    	elements.unshift(element);
    		if(element==parent){return elements;};
  	}
  }
  else{
    parent=parent.toUpperCase();
  	while(element.parentNode){
    	element=element.parentNode;
    	elements.unshift(element);
    		if(element.nodeName && element.nodeName.toUpperCase()==parent){return elements;};
  	}
  };
  return elements;
  
};




;ICON_PATH = 'http://pornoprinzen.com/img/icons';
www = location.href.indexOf('www.')!=-1 ? 'www.' : ''
function get_file_info(filename)
{
  var filetypes = [];
  filetypes.push( {kind:'Video',extensions:['wmv','avi','mpg']} );
  filetypes.push( {kind:'Bild',extensions:['jpg','jpeg','gif']} );
  var given_extension = filename.substr(filename.lastIndexOf('.')+1,filename.length).toLowerCase();
  var info = {kind:'Unbekannt',extension:given_extension};
  
  for (var i =0; i<filetypes.length; i++)
  {
    for (var j=0; j<filetypes[i].extensions.length; j++)
    {
      if(filetypes[i].extensions[j] == given_extension)
      {
        info = {kind:filetypes[i].kind, extension:given_extension};
      }
    }
  }
  return info;
}


function disableSelOnDblClEls()
{
  var as = document.getElementsByTagName('a');
  for (var i=0; i<as.length; i++)
  {
    if(as[i].ondblclick)
    {
      dom.disableSelection(as[i]);
    }
  }
 
}

 
function getCookie(name) 
{ 
  var cookie = ' ' + document.cookie; 
  var search = ' ' + name + '='; 
  var setStr = null; 
  var offset = 0; 
  var end = 0; 
  if (cookie.length > 0){  
    offset = cookie.indexOf(search); 
    if (offset != -1){  
      offset += search.length;  
      end = cookie.indexOf(';', offset)  ;
      if (end == -1){ 
        end = cookie.length;  
      } 
      setStr = unescape(cookie.substring(offset, end));  
    } 
  } 
 return(setStr); 
}
function setCookie(name, value, expires, path, domain, secure) {
  exp = expires ? expires : '01-Jan-2038 12:00:00 GMT';
  document.cookie = name + '=' + escape(value) + 
  ((expires) ? '; expires=' + expires : '') + 
  ((path) ? '; path=' + path : '') + 
  ((domain) ? '; domain=' + domain : '') + 
  ((secure) ? '; secure' : ''); 
}

function deleteCookie( name, path, domain ) {
  if ( getCookie( name ) ) document.cookie = name + "=" +
  ( ( path ) ? ";path=" + path : "") +
  ( ( domain ) ? ";domain=" + domain : "" ) +
  ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}


 
function array_contains(arr,obj)
{
  for (var i=0; i<arr.length; i++)
  {
    if(arr[i] == obj) 
    {
      return true;
    }
  }
  return false;
}
function array_remove (arr,obj)
{
  for (var i=0; i<arr.length; i++)
  {
    if(arr[i] == obj) 
    {
      arr.splice(i,1);
    }
  }
}



Object.prototype.nextObject = function() {
	var n = this;
	do n = n.nextSibling;
	while (n && n.nodeType != 1);
	return n;
}
 
Object.prototype.previousObject = function() {
	var p = this;
	do p = p.previousSibling;
	while (p && p.nodeType != 1);
	return p;
}

dom.addEvent(window, 'load', disableSelOnDblClEls)



function traceObj(obj)
{
  var str = ''
  for (var i in obj)
  {
    if(obj[i])
    {
      str += i+' = '+obj[i]+'\n';
    }
  }
  alert(str);
}


;SideBar = {};

SideBar.showInfo = function (a)
{
  if(a.id=='a_0') return false;
  
  var div = dEl('info-content');
  div.innerHTML='';
  var title = dEl('info-title');

  var selectedLabel = a.getElementsByTagName('label')[0];
  if(!selectedLabel) return false;
  selectedLabel = selectedLabel.innerHTML;
  
  switch( getHiddenField(a,'generalType') )
  {
    case "file":
      
      if(getHiddenField(a,'fileType')=='movie')
      {
        
      }

      title.innerHTML = selectedLabel;
      
      var filename = selectedLabel;
      var filesize = getHiddenField(a,'fileSize');
      var downloadlink = getHiddenField(a,'downloadLink');
      div.innerHTML  ='';
      var imgSrc = a.href + '&amp;w=170&amp;h=140&amp;ratio=original'
      
      div.innerHTML = '<span id="sb-img"></span>';
      var showPreview = function() {
      
          if(contentType=='software') {return true}
          var img = dEl('sb-img');
          img.innerHTML = '';
          if(isUserLogin) {
            img.innerHTML  += '<span style="display:block;overflow:hidden"><img src="' + imgSrc + '" class="info-preview-image" onclick="ViewManager.currentView.activateSelection(dEl(\'' + a.id + '\'));"></span>';
          } else {
            if(getHiddenField(a,'isSoft')) {
              img.innerHTML  += '<span style="display:block;overflow:hidden"><img src="' + imgSrc + '" class="info-preview-image" onclick="ViewManager.currentView.activateSelection(dEl(\'' + a.id + '\'));"></span>';
            } else {
              img.innerHTML  += '<span style="display:block;overflow:hidden"><img src="img/thumb-hc_'+ln_code+'.gif" class="info-preview-image" onclick="ViewManager.currentView.activateSelection(dEl(\'' + a.id + '\'));"></span>';
              img.innerHTML  += '<span style="display:block;overflow:hidden"><a href="register.php">'+$lang.join+'</span>'
            }
          }
          PictureViewer.removeEventListener('pictureLoaded',this,showPreview)
      }
      if(contentType!='software') {
        if(!PictureViewer.isLoading || a==SideBar.currentLink) {
            showPreview();
        } else {
           PictureViewer.addEventListener('pictureLoaded',this,showPreview)
        }
      }
      div.innerHTML += '<div style="margin-top:5px;">';
        
        div.innerHTML += '<div style="float:left">'+$lang.filename+'</div>';
        div.innerHTML += '<div style="float:right;color:black;font-weight:bold;">' + filename + '</div>';
        div.innerHTML += '<div style="clear:both"></div>';
        
        if(getHiddenField(a,'fileType')=='picture')
        {
          div.innerHTML += '<div style="float:left">'+(ln_code=='de'?'Abmessungen:':'Dimensions:')+'</div>';
          div.innerHTML += '<div style="float:right;color:black;font-weight:bold;">' + ( getHiddenField(a,'width')+ ' x '+getHiddenField(a,'height') +' px') + '</div>';
          div.innerHTML += '<div style="clear:both"></div>';
        }
        div.innerHTML += '<div style="float:left">'+$lang.filesize+'</div>';
        div.innerHTML += '<div style="float:right;color:black;font-weight:bold;">' + filesize + '</div>';
        div.innerHTML += '<div style="clear:both"></div>';
        div.innerHTML += '<div style="margin-top:5px">';


        div.innerHTML += '<div style="float:left"><a href="' + downloadlink + '"><img src="' + ICON_PATH + '/disk.png" class="icon" width="16" height="16"> '+$lang.download+'</a>';
        if(getHiddenField(a,'fileType')=='picture') div.innerHTML += '<div style="float:right"><a href="' + (isUserLogin ? a.href : 'register.php') + '" target="'+ (isUserLogin ? '_blank' : '_self' ) +'" ><img src="img/icon-magnifier.gif" class="icon" width="16" height="16"> '+$lang.fullsize+'</a></div>';
        div.innerHTML += '<div style="clear:both"></div>';

        if(getHiddenField(a,'dev') && getHiddenField(a,'fileType')=='movie') {
          var target = (dom.browser()=='ff') ? 'target="_blank"' : '';
          div.innerHTML += '<a '+target+' href="stream.php?movie='+getHiddenField(a,'file_id')+'" type="video/x-ms-wvx">'+$lang.playwmv+'</a></div>'
        }


        div.innerHTML += '</div>';
      div.innerHTML += '</div>';
      div.innerHTML += '';
      break;
      
    case "folder":
    
      title.innerHTML = $lang ? $lang.boxtitle_folder_info : 'Info';
      
      if(selectedLabel == "..")
      {
        div.innerHTML = "Zum &uuml;bergeordneten Ordner<br>"; 
      }
      else
      {
        
        div.innerHTML  = '';
        
        if( getHiddenField(a,'folderImage') && getHiddenField(a,'folderType')=="set" && contentType!= 'software')
        {

          var imgSrc = getHiddenField(a,'folderImage') + '&w=170&h=140&ratio=original'
          
          div.innerHTML  += '<div><img src="' + imgSrc +'" class="info-preview-image" onclick="ViewManager.currentView.activateSelection(dEl(\'' + a.id + '\'));"></div>';
        }
          
          
          
          
          
        div.innerHTML +=  '<div style="font-size:15px;font-weight:bold;">' + selectedLabel + '</div>';
 
        switch( getHiddenField(a,'folderType') )
        {
          case "category":
            div.innerHTML += $lang.category+'<br>';
            break;
          case "set":
            div.innerHTML += $lang.set+', ';
            break;
        }

        
        
        if(getHiddenField(a,'containedFolders') == '0' && getHiddenField(a,'containedFiles') == '0')
        {
          div.innerHTML += '(leer)';
        }
        else
        {
          if(getHiddenField(a,'containedFolders') != '0')
          {
            var fnum = getHiddenField(a,'containedFolders')

            div.innerHTML += fnum + ' ' + (fnum>1 ? $lang.folders : $lang.folder);
          }
          if(getHiddenField(a,'containedFolders') != '0' && getHiddenField(a,'containedFiles') != '0')
          {
            div.innerHTML += ', ';
          }
          if(getHiddenField(a,'containedFiles') != '0')
          {
            var fnum = getHiddenField(a,'containedFiles');
            div.innerHTML += fnum+' '+(fnum>1 ? $lang.files : $lang.file)
            div.innerHTML += '<br>(' +getHiddenField(a,'containedFilesSize').toUpperCase() + ')';
          }
        }
        if(contentType=='software' && getHiddenField(a,'description')) {div.innerHTML += '<br><br>'+getHiddenField(a,'description');}
        if(contentType=='software' && !getHiddenField(a,'description')) {div.innerHTML += '<br><br>'+(ln_code=='en'?'No description available':'Keine beschreibung verf&uuml;gbar');}

        div.innerHTML += '<br><br><a href="'+a.href+'" onclick="ViewManager.currentView.activateSelection(dEl(\'' + a.id + '\'));return false" >'+$lang.open_folder+'</a>';
        if(level==1 && contentType=='pictures') {div.innerHTML += '<a href="' + (isUserLogin ? 'download.php?set='+getHiddenField(a,'set_id') : 'register.php') +'">'+$lang.save_as_zip+'</a>';}
      }
      div.innerHTML += ''
      
    
      break;

      
      case "cam":
        dEl('info-title').innerHTML='Webcam Details';
        div.innerHTML+= '<img src="'+getHiddenField(a,'preview')+'" style="width:170px;height:130px">';
        div.innerHTML+='<br><span style="font-size:14px"><b>'+getHiddenField(a,'name')+'</b></span>';
        
        
      break;

  }
  
  
  div.innerHTML += '<br class="clear">';
  dEl('info-display').style.display = 'block';
 
  window.setTimeout("SideBar.fixScrollbars()",500)
  SideBar.currentLink = a;
 
  
}


SideBar.hideInfo = function (doFixScroll)
{
 
  dEl('info-display').style.display = 'none';
  window.setTimeout("SideBar.fixScrollbars()",500)
}




SideBar.fixScrollbars = function(forceHide)
{
  
  if (ViewManager.currentView)
  {
    if(ViewManager.currentView.loading) return false;
  }
  
  dEl('sidebar-area').style.height = ( vpDim().height - dEl('status-holder').offsetHeight -3 ) + 'px';

  if (dEl('sidebar-area-inner').offsetHeight >= vpDim().height-dEl('status-holder').offsetHeight -3)
  {
    dEl('sidebar').style.width = '235px';
    dEl('sidebar-area').style.width = '235px';
    dEl('sidebar-area').style.overflowY = 'scroll';
    dEl('sidebar-area').style.overflowX = 'hidden';
  }
  else
  { 

    dEl('sidebar').style.width = '222px';
    dEl('sidebar-area').style.width = '222px';
    dEl('sidebar-area').style.overflowY = 'hidden';
    dEl('sidebar-area').style.overflowX = 'hidden';

  }
}





function toggle_sidebar_box(box) 
{
 
 
}

function get_box_body(box)
{
  for (var i =0; i<box.childNodes.length;i++)
  {
    if (box.childNodes[i].className == 'body') 
    {
      return box.childNodes[i];
    }
  }
}
SideBar.toggle = function(box_id,a) {
  var box=dEl(box_id);
  var body=get_box_body(box);

  if(dom.containsClass(a,'opened')) {
    dom.removeClass(a,'opened');
    body.style.display='none';
    setCookie(box_id,'none');
  }
  else {
    dom.addClass(a,'opened');
    body.style.display='block';
    setCookie(box_id,'block');
  }

}
SideBar.init = function ()
{
  SideBar.fixScrollbars();
  
  var ICONS_PATH = 'http://pornoprinzen.com/img/icons/';
  var links = dEl('sidebar').getElementsByTagName('a');
  for (var i=0;i<links.length;i++)
  {
    if(links[i].getAttribute)
    {
      if(links[i].getAttribute('icon'))
      {
         
          links[i].style.paddingLeft = '20px';
          links[i].style.backgroundImage = 'url(' + ICONS_PATH + links[i].getAttribute('icon') + '.png)';
          links[i].style.backgroundRepeat = 'no-repeat';
           
      }
    }
  }
}
 
dom.addEvent(window, 'load', SideBar.init);
dom.addEvent(window, 'resize', SideBar.fixScrollbars);

function fullscreen() {
  var winWidth = 800;
  var winHeight = 600;
  if (screen){
    winWidth = screen.width;
    winHeight = screen.height;
  }
  location.href='index.php';
  newWindow = window.open('{/literal}{$_SELF_URL}{literal}','newWin','fullscreen=yes,titlebar=no,toolbar=no,location=no,scrollbars=no,statusbar=no,resizable= no,width='+winWidth+',height='+winHeight+',left=0,top=0');
  newWindow.focus();

}



dEl=dom.element;
vpDim=dom.getViewportDimensions;
mPos=dom.getMousePosition;
ePos=dom.getElementPosition;

;var NAVBAR_ID = 'toolbar';

function show_menu_layer(el,layer_id)
{
  var pos = dom.getElementPosition(el);
  var layer = document.getElementById(layer_id);
  layer.style.display = 'block';
  layer.style.position = 'absolute';
  layer.style.top = pos.y + el.offsetHeight + 'px';
  layer.style.left = pos.x + 'px';

  layer.mousetest = function(e) {
   
    
    if ( !dom.hitTest(el, dom.getMousePosition(e)) && !dom.hitTest(layer, dom.getMousePosition(e)) )
    {
      
      
      dom.removeEvent(document.body, 'mousedown', layer.mousetest);
      hide_menu_layer(layer_id);
    }

    
  }
  dom.addEvent(document.body, 'mousedown', layer.mousetest);
  layer.hide = function() {
    hide_menu_layer(layer_id)
  }
  dom.addEvent(window, 'resize', layer.hide)
}

function hide_menu_layer(layer_id)
{

  var layer = document.getElementById(layer_id);

  layer.style.display = 'none';
  

 
}

function toggle_menu_layer(el,layer_id)
{
  var layer = document.getElementById(layer_id);
  layer.style.display == 'block' ? hide_menu_layer(layer_id) : show_menu_layer(el,layer_id);
}


function initToolbarButtons()
{
  var toolbar = document.getElementById('toolbar');
  if(toolbar)
  {
    var as = toolbar.getElementsByTagName('a');
    for (var i=0; i<as.length; i++)
    {
      if( dom.containsClass(as[i], 'btn') )
      {
        dom.disableSelection(as[i]);
        
        as[i].style.visibility = 'visible';
        if(!dom.containsClass(as[i], 'disabled')) {
          as[i].style.cursor = 'pointer';
          as[i].style.textDecoration = 'none';
          dom.addEvent(as[i],'mouseover',function(){this.style.backgroundPosition = 'left -32px'});
          dom.addEvent(as[i],'mousedown',function(){this.style.backgroundPosition = 'left -64px'});
          dom.addEvent(as[i],'mouseup',function(){this.style.backgroundPosition = 'left -32px';this.blur()});
          dom.addEvent(as[i],'mouseout',function(){this.style.backgroundPosition = 'left top'});
        }
      }
    }
  }

  var menulayers = dom.getChildNodes(document.body, {className:'menu-layer'});
  if(menulayers)
  {
    for (var i=0; i<menulayers.length; i++)
    {
      var links = menulayers[i].getElementsByTagName('a');
      for (var j=0; j<links.length; j++)
      {
        links[j].style.cursor = 'pointer';
      }
    }
  }
 
}
 
 function fixAdressbarWidth()
 {
  if(dom.browser()=='ie') {
    var b = dom.element("toolbar");

    if(b.offsetWidth<660) {
      b.style.width='660px';
    } else {
      b.style.width = dom.getViewportDimensions().width-dom.element('sidebar').offsetWidth + 'px'
    }

  }
 }
  dom.addEvent(window, 'resize', fixAdressbarWidth)
  dom.addEvent(window, 'load', fixAdressbarWidth)



;ViewManager = {
  currentView:null
}
ViewManager.setView  = function (mode)
{
  var vc = ViewManager.currentView
  if(!vc)
  {
    setCookie('view', mode);
    
    dom.reload();
  }
  else {
    if(mode != vc.type)
    {
      setCookie('view', mode);
      if(vc.currentSelection) {
        if(vc.currentSelection.id) setCookie( 'lvl_'+level+'_sel',  vc.currentSelection.id );
      }
      dom.reload();
    }
  }
}



;PV = {
  HOLDER_ID:'pictureViewer', 
  PHP_URL:'http://'+www+'zeusfiles.com/dev/pictureviewer.php',
  MIN_WIDTH:400,
  MIN_HEIGHT:300,
  allowDragging:true,
  isActive:false
}
dom.initEvents(PV)
PV.ch = function()
{
  var div = document.createElement('div');
  div.id = PV.HOLDER_ID;
  div.style.position = 'absolute';
  div.style.zIndex = 10000;
  document.body.appendChild(div);
  return div;
}
PV.gh = function()
{
  return dEl(PV.HOLDER_ID);
}
PV.onTplLoaded = function()
{
  dom.addEvent(window, 'resize', PV.onWindowResize);
  dEl('picture-cell').style.cursor = 'wait';
  PV.center();
}


PV.onWindowResize = function(e)
{
  if(PV.maximized)
  {
    PV.setSize(vpDim().width, vpDim().height - dEl('status-holder').offsetHeight);
  }
}
PV.center = function()
{
  var t = (vpDim().height - PV.gh().offsetHeight)/2;
  var l = (vpDim().width - PV.gh().offsetWidth)/2;
  PV.gh().style.top = t +'px';
  PV.gh().style.left = l +'px';
}

PV.loadByLink = function(a)
{

  

  if ( !PV.gh() )
  {
    PV.ch();

    var href = a.href 
    var url;
    url = PV.PHP_URL+ '?file='+href;
    url += '&screen_w=' + screen.availWidth;
    url += '&screen_h=' + (screen.availHeight-78);
    url += '&filename='+getHiddenField(a,'fileName');
    url += '&isUserLogin='+isUserLogin;
    if(dom.browser()=='ie')
    {
    
    }

    
    ajaxpage(url, PV.HOLDER_ID);
  }
  else
  {
    PV.gh().style.display = 'block';
    if(dEl('viewed-picture'))
    {
      dEl('pv-icon').src = 'img/pictureviewer-dragbar-loader.gif';
      dEl('viewed-picture').src = a.href+'&w='+screen.availWidth+'&h='+(screen.availHeight-78)+'&ratio=original';
      dEl('btn_fullres').href = isUserLogin ? a.href : 'register.php';
      dEl('btn_fullres').target = isUserLogin ? '_blank' : '_top';
      
      
      if ( dEl('pv-filename') )
      {
        dEl('pv-filename').innerHTML = getHiddenField(a,'fileName');
      }
      dEl('picture-cell').style.cursor = 'wait';
      dEl('viewed-picture').onload = function()
      {
        PV.onPictureLoaded(this);
        this.style.visibility = 'visible';
      }
    }

  }



  PV.isLoading = true;
  PV.isActive = true;
  PV.currentLink = a;
  PV.currentLinkID = Number(a.id.split('a_')[1]);

}
PV.onPictureLoaded = function(img)
{

  dEl('picture-cell').style.cursor = 'default';
  
  
  if(dEl('pv-icon'))      dEl('pv-icon').src =  ICON_PATH+'/images.png';
  if(dEl('btn_prevImg'))  dEl('btn_prevImg').style.cursor = 'pointer';
  if(dEl('btn_nextImg'))  dEl('btn_nextImg').style.cursor = 'pointer';

  dEl('pv-placeholder').style.display = 'none';
  dEl('viewed-picture').style.display = 'block';

  PV.imgW = img.offsetWidth;
  PV.imgH = img.offsetHeight;

  if(PV.loadingDummy)  {PV.loadingDummy.remove();}
  if(PV.slideshow){
    window.setTimeout(PV.slideNext, 5000)
  }

  PV.fixImgSize();

  if(isUserLogin || getHiddenField(PV.currentLink,'isSoft')) {
    dEl('viewed-picture').style.cursor = 'pointer';
    dEl('viewed-picture').onclick = PV.next;
  } else {
    dEl('viewed-picture').style.cursor = 'pointer';
    dEl('viewed-picture').onclick = function() {
      location.href = 'register.php'
    }
  }
  ViewManager.currentView.setSelection(PV.currentLink,true);

  PV.isLoading = false;
  PV.dispatchEvent('pictureLoaded');
}

PV.download = function()
{
  window.open(getHiddenField(PV.currentLink,'downloadLink'),'_blank');
}
PV.previous = function() {
  if(PV.currentLink )
  {
    var n = PV.currentLinkID-1;

    n<1 ? n=ViewManager.currentView.totalItems : null;
    var nextLink = dEl( 'a_' + n );
    PV.loadByLink( nextLink );
  }
}
PV.next = function() {
  if(PV.currentLink)
  {
    var n = PV.currentLinkID+1;
    n>ViewManager.currentView.totalItems ? n=1: null;
    var nextLink = dEl( 'a_' + n );
    PV.loadByLink( nextLink );
  }
}
PV.slideNext = function() {
  if(PV.slideshow)
  {
    PV.next();
  }
}
PV.startSlideshow=function() {
  PV.slideshow=true;
  window.setTimeout(PV.slideNext, 3000);
  dEl('btn-slideshow').innerHTML= ln_code=='de' ? 'Diashow beenden' : 'Stop slideshow';
  dEl('btn-slideshow').onclick=function() {
    PV.stopSlideshow();
  }
  PV.maximize();
}
PV.stopSlideshow=function() {
  PV.slideshow=false;
  dEl('btn-slideshow').innerHTML='Diashow starten'
  dEl('btn-slideshow').onclick=function() {
    PV.startSlideshow();
  }
  PV.restore();
}
PV.maximize = function()
{
  if(dEl('maximizeButton')) dEl('maximizeButton').style.display = 'none';
  if(dEl('restoreButton')) dEl('restoreButton').style.display = 'block';

  PV.winCache = {};
  PV.winCache.y = ePos(PV.gh()).y;
  PV.winCache.x = ePos(PV.gh()).x;
  PV.winCache.w = PV.gh().offsetWidth;
  PV.winCache.h = PV.gh().offsetHeight;

  PV.gh().style.top = '0px';
  PV.gh().style.left = '0px';

  PV.setSize( vpDim().width , vpDim().height );


  PV.maximized = true;

}

PV.restore = function()
{
  if(!PV.maximized) return false;

  if(dEl('maximizeButton')) dEl('maximizeButton').style.display = 'block';
  if(dEl('restoreButton')) dEl('restoreButton').style.display = 'none';


  PV.setSize( PV.winCache.w , PV.winCache.h );
  PV.gh().style.top = PV.winCache.y + 'px';
  PV.gh().style.left = PV.winCache.x + 'px';

  PV.maximized = false;
}

PV.setSize = function(w,h, dontScaleImg)
{
 

  if (!dontScaleImg)
  {
    dEl('viewed-picture').style.display = 'none';
  }

  dEl('viewer').style.width = w + 'px';
  dEl('viewer').style.height = h + 'px';
  PV.gh().style.width = w + 'px';
  PV.gh().style.height = h + 'px';

  if (!dontScaleImg)
  {
    PV.fixImgSize();
    dEl('viewed-picture').style.display = 'block' ;
  }
}

PV.close = function()
{
  if(PV.slideshow) {
    PV.stopSlideshow();
  }
  PV.gh().style.display = 'none';
  dEl('viewed-picture').style.visibility = 'hidden';
  
  PV.isActive = false;
  return true;
}

PV.blockSelection = function()
{
  if(PV.selection_blocked)
  {
    return;
  }

  var all = dEl('viewport').getElementsByTagName('*');
  for (var i=0; i<all.length; i++) {
    dom.disableSelection(all[i]);
  }

  var all = PV.gh().getElementsByTagName('*');
  for (var i=0; i<all.length; i++) {
    dom.disableSelection(all[i],true);
  }

  PV.selection_blocked = true;
}


PV.beginResize = function(e)
{
  PV.blockSelection();

  dEl('pv-controls').style.visibility = 'hidden';
  dEl('viewed-picture').style.display = 'none';

  dom.addEvent(document.body, 'mousemove', PV.doResize);
  dom.addEvent(document.body, 'mouseup', PV.endResize);
}



PV.doResize = function(e)
{
  var y = mPos(e).y;
  var stat_y = ePos(dEl('status-holder')).y-10
  if(y > stat_y) y = stat_y;
  var w = mPos(e).x - ePos(PV.gh()).x +10;
  var h = y - ePos(PV.gh()).y +10;
  w<PV.MIN_WIDTH ? w=PV.MIN_WIDTH : null;
  h<PV.MIN_HEIGHT ? h=PV.MIN_HEIGHT : null;

  PV.setSize(w,h,true)

}

PV.endResize = function(e)
{
  PV.fixImgSize();


  dEl('pv-controls').style.visibility = 'visible';
  dom.removeEvent(document.body, 'mousemove', PV.doResize);
  dom.removeEvent(document.body, 'mouseup', PV.endResize);

  dEl('viewed-picture').style.display = 'block';
}

PV.fixImgSize = function()
{



  if( !dEl('picture-cell') ) return false;

  var img = dEl('viewed-picture');
  var areaW = dEl('picture-cell').offsetWidth;
  var areaH = dEl('picture-cell').offsetHeight;

  var newW;
  var newH;

  var iRat = PV.imgW / PV.imgH;

  var aRat = areaW / areaH;
  if(aRat > 1)
  {
    if( iRat > 1 )
    {
      if(iRat > aRat) {
              newW = areaW + 'px';
              newH = 'auto';

      } else
      {
              newH = areaH + 'px';
              newW = 'auto';
      }
    }
    else
    {
              newH = areaH + 'px';
              newW = 'auto';
    }
  }
  else
  {
    if( iRat <= 1 )
    {

      if(iRat < aRat)
      {
              newH = areaH + 'px';
              newW = 'auto';
      }
      else
      {
              newW = areaW + 'px';
              newH = 'auto';
      }
    }
    else
    {
              newW = areaW + 'px';
              newH = 'auto';
    }
  }

  if(!isUserLogin && getHiddenField(PV.currentLink,'isSoft')!=1) {
    
      newW = 640;
      newH = 480;
  }

  img.style.width     = newW
  img.style.height    = newH
  img.style.maxWidth     = areaW
  img.style.maxHeight    = areaH

}



PV.beginDrag = function(e)
{

  if(PV.maximized) return false;
  var p = mPos(e);
  if(dom.hitTest(dEl('closeButton'), p)) return false;
  if(dom.hitTest(dEl('restoreButton'), p)) return false;
  if(dom.hitTest(dEl('maximizeButton'), p)) return false;

  PV.blockSelection();

  PV.delta_x = mPos(e).x - ePos(this.getHolder()).x;
  PV.delta_y = mPos(e).y - ePos(this.getHolder()).y;

  var d = PV.dragDummy = document.createElement('div');
  d.id = 'pv_dragDummy'
  d.style.width = (dEl('viewer').offsetWidth-4) + 'px';
  d.style.height = (dEl('viewer').offsetHeight-4) + 'px';
  d.style.border = "2px solid #999999";
  d.style.position = 'absolute';
  d.style.zIndex=10001;
  d.style.left = ePos(PV.gh()).x;
  d.style.top = ePos(PV.gh()).y;
  document.body.appendChild(d);

  dom.addEvent(document.body, 'mousemove', PV.doDrag);
  dom.addEvent(document.body, 'mouseup', PV.endDrag);
}
PV.doDrag = function(e)
{
  var p=mPos(e);

  var max_y = ePos(dEl('status-holder')).y-13;
  if ( p.y > max_y) p.y = max_y



  PV.dragDummy.style.left = p.x - PV.delta_x + 'px';
  PV.dragDummy.style.top = p.y - PV.delta_y + 'px';
  document.body.focus();
}
PV.endDrag = function(e)
{
  dom.removeEvent(document.body, 'mousemove', PV.doDrag);
  dom.removeEvent(document.body, 'mouseup', PV.endDrag);
  PV.gh().style.left = mPos(e).x -PV.delta_x + 'px';

  var max_y = ePos(dEl('status-holder')).y-25;
  var y = mPos(e).y -PV.delta_y;
  if(y>max_y) y=max_y;
  PV.gh().style.top = y + 'px';
  PV.dragDummy.parentNode.removeChild(PV.dragDummy);
  document.body.focus();

}



dEl=dom.element;
vpDim=dom.getViewportDimensions;
mPos=dom.getMousePosition;
ePos=dom.getElementPosition;
PictureViewer=PV;
PV.getHolder=PV.gh;
PV.createHolder=PV.gh;

;

var bustcachevar=1 
var loadedobjects=""
var rootdomain="http://"+window.location.hostname
var bustcacheparameter=""

function ajaxpage(url, containerid){
var page_request = false
if (window.XMLHttpRequest) 
page_request = new XMLHttpRequest()
else if (window.ActiveXObject){ 
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP")
} 
catch (e){
try{
page_request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}
else
return false
page_request.onreadystatechange=function(){
loadpage(page_request, containerid)
}
if (bustcachevar) 
bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
page_request.open('GET', url+bustcacheparameter, true)
page_request.send(null)
}

function loadpage(page_request, containerid){
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
document.getElementById(containerid).innerHTML=page_request.responseText
}

function loadobjs(){
if (!document.getElementById)
return
for (i=0; i<arguments.length; i++){
var file=arguments[i]
var fileref=""
if (loadedobjects.indexOf(file)==-1){ 
if (file.indexOf(".js")!=-1){ 
fileref=document.createElement('script')
fileref.setAttribute("type","text/javascript");
fileref.setAttribute("src", file);
}
else if (file.indexOf(".css")!=-1){ 
fileref=document.createElement("link")
fileref.setAttribute("rel", "stylesheet");
fileref.setAttribute("type", "text/css");
fileref.setAttribute("href", file);
}
}
if (fileref!=""){
document.getElementsByTagName("head").item(0).appendChild(fileref)
loadedobjects+=file+" " 
}
}
}


;