// Set up Event Listener - the script that allows us to use the addEvent call below

function addEvent(elm, evType, fn, useCapture) {
  if (elm.addEventListener) {
  elm.addEventListener(evType, fn, useCapture);
  return true;
  } else if (elm.attachEvent) {
  var r = elm.attachEvent('on' + evType, fn);
  return r;
  } else {
  elm['on' + evType] = fn;
  }
}

/* tabs function on */
function Tabs(ulId, divId, activeN){
  var UL,DIV,T = this;
  
  this.show = function(n){
    hideAll();
    getChildren(DIV)[n].style.display="block";
    var c = getChildren(UL);
    c[n].className="active "+(n==0?"activeL":((n==c.length-1)?"activeR":"activeC"));
    
  }
  
  function hideAll(){
    var ulc = getChildren(UL);
    var divc = getChildren(DIV);
    for(var i=0;i<ulc.length;i++){
      ulc[i].className="";
      divc[i].style.display="none";
    }
  }
  
  function getChildren(o){
    var arr=[], c = o.childNodes;
    for(var i=0;i<c.length;i++) if(c[i].tagName) arr.push(c[i]);
    return arr;
  }
  
  function init(){
    UL = document.getElementById(ulId);
    DIV = document.getElementById(divId);
    if(!UL || !DIV) return;
    var fix=0,i,li = getChildren(UL),w = Math.ceil(UL.offsetWidth/li.length), f = UL.offsetWidth%li.length;
    
    for(i=0;i<li.length;i++){
      li[i].onclick = new Function("this.tabs.show("+i+")");
      li[i].tabs = T;
      fix = (i==li.length-1)?f:0;
      if(f==0) fix+=1;
      li[i].style.width=(w + fix)+"px";
    }
    T.show(activeN||0)
  }
  init();
}
/* tabs function off */
function showComment(id){
var react = document.getElementById(id);
if (react.style.display == "none") {react.style.display = "block"}
else {react.style.display = "none"}
}

var Effect = {
  _elementDoesNotExistError: {
    name: 'ElementDoesNotExistError',
    message: 'The specified DOM element does not exist, but is required for this effect to operate'
  },
  tagifyText: function(element) {
    if(typeof Builder == 'undefined')
      throw("Effect.tagifyText requires including script.aculo.us' builder.js library");
      
    var tagifyStyle = 'position:relative';
    if(/MSIE/.test(navigator.userAgent) && !window.opera) tagifyStyle += ';zoom:1';
    
    element = $(element);
    $A(element.childNodes).each( function(child) {
      if(child.nodeType==3) {
        child.nodeValue.toArray().each( function(character) {
          element.insertBefore(
            Builder.node('span',{style: tagifyStyle},
              character == ' ' ? String.fromCharCode(160) : character), 
              child);
        });
        Element.remove(child);
      }
    });
  },
  multiple: function(element, effect) {
    var elements;
    if(((typeof element == 'object') || 
        (typeof element == 'function')) && 
       (element.length))
      elements = element;
    else
      elements = $(element).childNodes;
      
    var options = Object.extend({
      speed: 0.1,
      delay: 0.0
    }, arguments[2] || {});
    var masterDelay = options.delay;

    $A(elements).each( function(element, index) {
      new effect(element, Object.extend(options, { delay: index * options.speed + masterDelay }));
    });
  },
  PAIRS: {
    'slide':  ['SlideDown','SlideUp'],
    'blind':  ['BlindDown','BlindUp'],
    'appear': ['Appear','Fade']
  },
  toggle: function(element, effect) {
    element = $(element);
    effect = (effect || 'appear').toLowerCase();
    var options = Object.extend({
      queue: { position:'end', scope:(element.id || 'global'), limit: 1 }
    }, arguments[2] || {});
    Effect[element.visible() ? 
      Effect.PAIRS[effect][1] : Effect.PAIRS[effect][0]](element, options);
  }
};
/* transitions */
Effect.Transitions = {
  linear: Prototype.K,
  sinoidal: function(pos) {
    return (-Math.cos(pos*Math.PI)/2) + 0.5;
  },
  reverse: function(pos) {
    return 1-pos;
  },
  flicker: function(pos) {
    return ((-Math.cos(pos*Math.PI)/4) + 0.75) + Math.random()/4;
  },
  wobble: function(pos) {
    return (-Math.cos(pos*Math.PI*(9*pos))/2) + 0.5;
  },
  pulse: function(pos, pulses) { 
    pulses = pulses || 5; 
    return (
      Math.round((pos % (1/pulses)) * pulses) == 0 ? 
            ((pos * pulses * 2) - Math.floor(pos * pulses * 2)) : 
        1 - ((pos * pulses * 2) - Math.floor(pos * pulses * 2))
      );
  },
  none: function(pos) {
    return 0;
  },
  full: function(pos) {
    return 1;
  }
};
/* core effects */
/* effect on */
Effect.ScopedQueue = Class.create();
Object.extend(Object.extend(Effect.ScopedQueue.prototype, Enumerable), {
  initialize: function() {
    this.effects  = [];
    this.interval = null;
  },
  _each: function(iterator) {
    this.effects._each(iterator);
  },
  add: function(effect) {
    var timestamp = new Date().getTime();
    
    var position = (typeof effect.options.queue == 'string') ? 
      effect.options.queue : effect.options.queue.position;
    
    switch(position) {
      case 'front':
        // move unstarted effects after this effect  
        this.effects.findAll(function(e){ return e.state=='idle' }).each( function(e) {
            e.startOn  += effect.finishOn;
            e.finishOn += effect.finishOn;
          });
        break;
      case 'with-last':
        timestamp = this.effects.pluck('startOn').max() || timestamp;
        break;
      case 'end':
        // start effect after last queued effect has finished
        timestamp = this.effects.pluck('finishOn').max() || timestamp;
        break;
    }
    
    effect.startOn  += timestamp;
    effect.finishOn += timestamp;

    if(!effect.options.queue.limit || (this.effects.length < effect.options.queue.limit))
      this.effects.push(effect);
    
    if(!this.interval) 
      this.interval = setInterval(this.loop.bind(this), 15);
  },
  remove: function(effect) {
    this.effects = this.effects.reject(function(e) { return e==effect });
    if(this.effects.length == 0) {
      clearInterval(this.interval);
      this.interval = null;
    }
  },
  loop: function() {
    var timePos = new Date().getTime();
    for(var i=0, len=this.effects.length;i<len;i++) 
      if(this.effects[i]) this.effects[i].loop(timePos);
  }
});

Effect.Base = function() {};
Effect.Base.prototype = {
  position: null,
  start: function(options) {
    this.options      = Object.extend(Object.extend({},Effect.DefaultOptions), options || {});
    this.currentFrame = 0;
    this.state        = 'idle';
    this.startOn      = this.options.delay*1000;
    this.finishOn     = this.startOn + (this.options.duration*1000);
    this.event('beforeStart');
    if(!this.options.sync)
      Effect.Queues.get(typeof this.options.queue == 'string' ? 
        'global' : this.options.queue.scope).add(this);
  },
  loop: function(timePos) {
    if(timePos >= this.startOn) {
      if(timePos >= this.finishOn) {
        this.render(1.0);
        this.cancel();
        this.event('beforeFinish');
        if(this.finish) this.finish(); 
        this.event('afterFinish');
        return;  
      }
      var pos   = (timePos - this.startOn) / (this.finishOn - this.startOn);
      var frame = Math.round(pos * this.options.fps * this.options.duration);
      if(frame > this.currentFrame) {
        this.render(pos);
        this.currentFrame = frame;
      }
    }
  },
  render: function(pos) {
    if(this.state == 'idle') {
      this.state = 'running';
      this.event('beforeSetup');
      if(this.setup) this.setup();
      this.event('afterSetup');
    }
    if(this.state == 'running') {
      if(this.options.transition) pos = this.options.transition(pos);
      pos *= (this.options.to-this.options.from);
      pos += this.options.from;
      this.position = pos;
      this.event('beforeUpdate');
      if(this.update) this.update(pos);
      this.event('afterUpdate');
    }
  },
  cancel: function() {
    if(!this.options.sync)
      Effect.Queues.get(typeof this.options.queue == 'string' ? 
        'global' : this.options.queue.scope).remove(this);
    this.state = 'finished';
  },
  event: function(eventName) {
    if(this.options[eventName + 'Internal']) this.options[eventName + 'Internal'](this);
    if(this.options[eventName]) this.options[eventName](this);
  },
  inspect: function() {
    var data = $H();
    for(property in this)
      if(typeof this[property] != 'function') data[property] = this[property];
    return '#<Effect:' + data.inspect() + ',options:' + $H(this.options).inspect() + '>';
  }
}

Effect.Queues = {
  instances: $H(),
  get: function(queueName) {
    if(typeof queueName != 'string') return queueName;
    
    if(!this.instances[queueName])
      this.instances[queueName] = new Effect.ScopedQueue();
      
    return this.instances[queueName];
  }
}

Effect.Queue = Effect.Queues.get('global');
Effect.DefaultOptions = {
  transition: Effect.Transitions.sinoidal,
  duration:   1.0,   // seconds
  fps:        60.0,  // max. 60fps due to Effect.Queue implementation
  sync:       false, // true for combining
  from:       0.0,
  to:         1.0,
  delay:      0.0,
  queue:      'parallel'
}


Effect.Move = Class.create();
Object.extend(Object.extend(Effect.Move.prototype, Effect.Base.prototype), {
  initialize: function(element) {
    this.element = $(element);
    if(!this.element) throw(Effect._elementDoesNotExistError);
    var options = Object.extend({
      x:    0,
      y:    0,
      mode: 'relative'
    }, arguments[1] || {});
    this.start(options);
  },
  setup: function() {
    // Bug in Opera: Opera returns the "real" position of a static element or
    // relative element that does not have top/left explicitly set.
    // ==> Always set top and left for position relative elements in your stylesheets 
    // (to 0 if you do not need them) 
    this.element.makePositioned();
    this.originalLeft = parseFloat(this.element.getStyle('left') || '0');
    this.originalTop  = parseFloat(this.element.getStyle('top')  || '0');
    if(this.options.mode == 'absolute') {
      // absolute movement, so we need to calc deltaX and deltaY
      this.options.x = this.options.x - this.originalLeft;
      this.options.y = this.options.y - this.originalTop;
    }
  },
  update: function(position) {
    this.element.setStyle({
      left: Math.round(this.options.x  * position + this.originalLeft) + 'px',
      top:  Math.round(this.options.y  * position + this.originalTop)  + 'px'
    });
  }
});
/* for backwards compatibility */
Effect.MoveBy = function(element, toTop, toLeft) {
  return new Effect.Move(element, 
    Object.extend({ x: toLeft, y: toTop }, arguments[3] || {}));
};
/* effect off */

/* scroll on */
function ScrollControl(btnId, contentId, aDot, dDot, ajaxDivId){

 /* main scroll on (domestic & intl) */
 var cnnMpVpCurPage = 1;
 var cnnMpVpLock = false;
 var BTNCONTAINER, ULCONTAINER, AJAXDIV, NUM, BTNL, BTNR;
 var T = this;
 this.activeDot = aDot;
 this.deactiveDot = dDot;
 function init(){
  BTNCONTAINER = document.getElementById(btnId);
  ULCONTAINER = document.getElementById(contentId);
  if(!BTNCONTAINER || !ULCONTAINER) return;
  BTNL = BTNCONTAINER.parentNode.getElementsByTagName("A")[0];
  BTNR = BTNCONTAINER.parentNode.getElementsByTagName("A")[1];
  BTNR.scrollControl = BTNL.scrollControl = T;
  BTNL.onclick = function(){this.scrollControl.cnnMpVpPrev(this)}
  BTNR.onclick = function(){this.scrollControl.cnnMpVpNext(this)}
  ULCONTAINER = ULCONTAINER.getElementsByTagName("DIV")[0];
  var w=0,uls = getCh(ULCONTAINER);
  NUM = uls.length;
  for(var i=0;i<NUM;i++){
   var a = document.createElement("A");
   a.href="#";
   a.innerHTML = i==0?'<img src="'+T.activeDot+'" alt=""/>':'<img src="'+T.deactiveDot+'" onmouseover="this.src=\''+T.activeDot+'\'" onmouseout="this.src=\''+T.deactiveDot+'\'" alt="" />';
   a.onclick = new Function("this.scrollControl.cnnMpVpPage("+(i+1)+",this);return false");
   a.scrollControl = T;
   BTNCONTAINER.appendChild(a);
   w += uls[i].offsetWidth;
  }
  ULCONTAINER.style.width = w + "px";
  a = ULCONTAINER.getElementsByTagName("A");
  for(var i=0;i<a.length;i++){
  a[i].onclick=function(){return ajaxDivUpdate(this);}
  }
  
  cnnMpVpUpdateBtns();
 }

 init();
  
  function ajaxDivUpdate(a){
    AJAXDIV = document.getElementById(ajaxDivId);
    if(!AJAXDIV) return true;
    clearTDClasses(ULCONTAINER);
    a.parentNode.className="active";
    AJAXDIV.innerHTML="Loading...";
    new Ajax(a.href, function(txt){AJAXDIV.innerHTML=txt}).send();
    return false;
  }
  
  function clearTDClasses(o){
    var td = o.getElementsByTagName("TD");
    for(var i=0;i<td.length;i++) td[i].className="";
  }
  
  function getCh(o){
    var arr=[];
    var ch = o.childNodes;
    for(var i=0;i<ch.length;i++) if(ch[i].tagName) arr.push(ch[i]);
    return arr;
  }
  
  function cnnMpVpBlur( lnk ) {
    try {
      lnk.blur();
    } catch(e) {};
  }
  
  /*
   * cnnMpVpNext() and cnnMpVpPrev()
   * are called from previous and next buttons
   */
  function cnnMpVpNext( lnk ) {
    cnnMpVpBlur( lnk );
    if((cnnMpVpCurPage < NUM)&&(!cnnMpVpLock)) {
      cnnMpVpSlideLeft();
    }
  }
  this.cnnMpVpNext = cnnMpVpNext;
  
  function cnnMpVpPrev( lnk ) {
    cnnMpVpBlur( lnk );
    if((cnnMpVpCurPage > 1)&&(!cnnMpVpLock)) {
      cnnMpVpSlideRight();
    }
  }
  this.cnnMpVpPrev = cnnMpVpPrev;
  /*
   * cnnMpVpPage( intPage )
   * called from clicking on gray dot icon
   */
  function cnnMpVpPage( intPage, lnk ) {
    if(intPage==cnnMpVpCurPage) return false;
    cnnMpVpBlur( lnk );
    if((cnnMpVpCurPage != intPage)&&(!cnnMpVpLock)) {
      if(cnnMpVpCurPage < intPage) {
        if((intPage - cnnMpVpCurPage) > 1) {
          cnnMpVpSlideDoubleLeft(intPage - cnnMpVpCurPage);
        }
        else {
          cnnMpVpSlideLeft();
        }
      }
      else {
        if((cnnMpVpCurPage - intPage) > 1) {
          cnnMpVpSlideDoubleRight(cnnMpVpCurPage - intPage);
        }
        else {
          cnnMpVpSlideRight();
        }
      }
    }
  }
  this.cnnMpVpPage = cnnMpVpPage;
  
  function cnnLockMpVp( intDur ) {
    var cnnLockDur = intDur * 100;
    cnnMpVpLock = true;
    setTimeout(function() { cnnMpVpLock = false; },cnnLockDur);
  }
  this.cnnLockMpVp = cnnLockMpVp;
  
  function cnnMpVpSlideLeft(id) {
    cnnLockMpVp(3);
    var w = ULCONTAINER.parentNode.offsetWidth;
    new Effect.MoveBy( ULCONTAINER, 0, -w , {duration: 0.3} );
    cnnMpVpCurPage++;
    cnnMpVpMoveDot();
    cnnMpVpUpdateBtns();
  }
  this.cnnMpVpSlideLeft = cnnMpVpSlideLeft;

  function cnnMpVpSlideDoubleLeft(n) {
    cnnLockMpVp(3*n);
    var w = ULCONTAINER.parentNode.offsetWidth;
    new Effect.MoveBy( ULCONTAINER, 0, -w*n , {duration: 0.6} );
    cnnMpVpCurPage+=n;
    cnnMpVpMoveDot();
    cnnMpVpUpdateBtns();
  }
  this.cnnMpVpSlideDoubleLeft = cnnMpVpSlideDoubleLeft;
  
  function cnnMpVpSlideRight() {
    cnnLockMpVp(3);
    var w = ULCONTAINER.parentNode.offsetWidth;
    new Effect.MoveBy( ULCONTAINER, 0, w , {duration: 0.3} );
    cnnMpVpCurPage--;
    cnnMpVpMoveDot();
    cnnMpVpUpdateBtns();
  }
  this.cnnMpVpSlideRight = cnnMpVpSlideRight;

  function cnnMpVpSlideDoubleRight(n) {
    cnnLockMpVp(3*n);
    var w = ULCONTAINER.parentNode.offsetWidth;
    new Effect.MoveBy( ULCONTAINER, 0, w*n , {duration: 0.6} );
    cnnMpVpCurPage-=n;
    cnnMpVpMoveDot();
    cnnMpVpUpdateBtns();
  }
  this.cnnMpVpSlideDoubleRight =cnnMpVpSlideDoubleRight;

  function cnnMpVpMoveDot() {
    for(i=0;i<NUM;i++) {
      var b = BTNCONTAINER.childNodes[i].getElementsByTagName("IMG")[0];
      b.src = T.deactiveDot;
      b.onmouseover = function() {this.src = T.activeDot;}
      b.onmouseout = function() {this.src = T.deactiveDot;}
    }
    b = BTNCONTAINER.childNodes[cnnMpVpCurPage-1];
    b.getElementsByTagName("IMG")[0].src = T.activeDot;
    b.getElementsByTagName("IMG")[0].onmouseover = function() {}
    b.getElementsByTagName("IMG")[0].onmouseout = function() {}
  }
  this.cnnMpVpMoveDot= cnnMpVpMoveDot;
  
  function cnnMpVpUpdateBtns() {
    if(cnnMpVpCurPage > 1) {
      BTNL.style.cursor ='pointer';
      BTNL.className = '';
    }
    else {
      BTNL.style.cursor ='default';
      BTNL.className = 'disabled';
    }

    if(cnnMpVpCurPage < NUM) {
      BTNR.style.cursor ='pointer';
      BTNR.className = '';
    }
    else {
      BTNR.style.cursor ='default';
      BTNR.className = 'disabled';
    }
  }
  this.cnnMpVpUpdateBtns = cnnMpVpUpdateBtns;
  /* main scroll off */
}
/* scroll off */

/* divide ul on */
function divideUls(){
  var c = 0;
  var uls = document.body.getElementsByTagName("UL");
  for(var i=0;i<uls.length;i++){
   if(uls[i].className=="twoColums" && uls[i].id.indexOf(String("__dividedUL_"+c))!=0){
    c++;
    divideList(uls[i],2,String("__dividedUL_"+c));
   }
  }
}

function divideList(parentId,n,prefix){
 var counter=1;
 var tag=(typeof parentId=="object")?parentId:document.getElementById(parentId);
 var ch = getChildren(tag);
 if(tag.tagName=="DL") assignSubChildren(ch);
 for(var x=n;x>1;x--){
  var arrA = getChildren(tag);
  var newTag = document.createElement(tag.tagName);
  newTag.className = tag.className;
  var dividedListnum = Math.ceil(arrA.length/x);
  newTag.id = prefix+counter;
  if(tag.nextSibling) tag.parentNode.insertBefore(newTag,tag.nextSibling);
  else tag.parentNode.appendChild(newTag);
  for(i=dividedListnum;i<arrA.length;i++){
   var newChild = arrA[i].cloneNode(true);
   appendNewChild(newTag.id,newChild);
  }
  for(var j=arrA.length-1;j>=dividedListnum;j--){
   if(arrA[j].removeNode) arrA[j].removeNode(true);
   else if(arrA[j].parentNode.removeChild) arrA[j].parentNode.removeChild(arrA[j]);
  }
  tag = document.getElementById(newTag.id);
  counter++;
 }
 if(tag.tagName=="DL") appendSubChildren(n,prefix);
}

function getChildren(o){
 if(o.tagName=="UL") return o.getElementsByTagName("LI");
 else if(o.tagName=="DL") return o.getElementsByTagName("DT");
}

function assignSubChildren(dtArr){
  var resArr = [];
  for(var i=0;i<dtArr.length;i++){
   var ddArr = [];
   dtArr[i].setAttribute("__index__",String(i))
   var dd = dtArr[i].nextSibling;
   while(dd){
    if(dd.tagName){
     ddArr[ddArr.length] = dd;
    }
    dd = dd.nextSibling;
    if(dd && dd.tagName && dd.tagName=="DT") break;
   }
   resArr[resArr.length] = [String(i),ddArr];
  }
  window.tempNodesArray = resArr;
}

function appendNewChild(newTagId,o){
 if(o.tagName=="LI") document.getElementById(newTagId).appendChild(o);
 else if(o.tagName=="DT"){
  document.getElementById(newTagId).appendChild(o);
 }
}

function appendSubChildren(n,prefix){
 for(var z=1;z<n;z++){
  var dl = document.getElementById(prefix+z);
  var dtChildren = dl.getElementsByTagName("DT");
  for(var v=0;v<dtChildren.length;v++){
   for(var i=0;i<window.tempNodesArray.length;i++){
    if(window.tempNodesArray[i][0]==dtChildren[v].getAttribute("__index__")){
     for(var j=0;j<window.tempNodesArray[i][1].length;j++){
      var cloneDD = window.tempNodesArray[i][1][j].cloneNode(true);
      if(window.tempNodesArray[i][1][j].removeNode) window.tempNodesArray[i][1][j].removeNode(true);
      else if(window.tempNodesArray[i][1][j].parentNode.removeChild) window.tempNodesArray[i][1][j].parentNode.removeChild(window.tempNodesArray[i][1][j]);
      if(dtChildren[v+1]){
       dl.insertBefore(cloneDD,dtChildren[v+1]);
      }else{
       dl.appendChild(cloneDD);
      }
     }
     break;
    }
   }
  }
 }
}


/* foto player */
function ImageViewer() {
  this.timer=null;
  this.active=null;

  
  this.templates=[];
  this.setTemplate=function(str,id){
    this.templates[this.templates.length]={id:id,str:str};
  };
  
  this.show=function(a,src){
    var cache=ImageViewer.cache(src);
    var div=this.previewer;
    if(div){
      var img=div.firstChild;
      var span=div.lastChild;
      if(img&&span){
        if(this.active)this.active.className="";
        this.active=a;
        this.active.className="active";
        span.style.display="none";
        img.style.display="block";
        if (window.opera) {// se: nothing clever :(
          img.style.display="inline";
        } else {
          img.onload=function(e){
            img.style.display="inline";
          }
        } 
        img.src=cache.src;
        img.title=(a.title)?a.title:(a.alt)?a.alt:"";
        this.parseTemplates();
      }
    } else {// se added
      setTimeout(function(){viewer.show(a,src)},200);
    }
    return false;
  };

  this.getImagePath=function(){
    var path="";
    var div=this.previewer;
    if(div){
      var img=div.firstChild;
      if(img){
        /*
        path=img.src.split("/");
        path=path[path.length-1];
        */
        img.galleryImg=false;
        path=(img.title!="")?img.title:img.alt;
      }
    }
    return path;
  };
  
  this.getCurrentImageIndex=function(){
    if(this.thumbnail){
      var pos=0;
      var layer = Scrollbar.getFirstChild(this.thumbnail);
      if(layer){
        for(i=0;i<layer.childNodes.length;i++){
          a=layer.childNodes[i];
          if(a.tagName=="A"){ //se fix
            pos++;
            if(a==this.active){
              return pos;
            }
          }
        }
      }
    }
    return 1;
  };

  this.getCurrentImageInfo=function(){
    if(this.thumbnail){
      var pos=0;
      var info="a";
      var layer = Scrollbar.getFirstChild(this.thumbnail);
      if(layer){
        for(i=0;i<layer.childNodes.length;i++){
          a=layer.childNodes[i];
          if(a.tagName=="A"){ //se fix
            pos++;
            if(a==this.active){
              for(y=0;y<a.firstChild.childNodes.length;y++){
                if(a.firstChild.childNodes[y].tagName == "SPAN"){
                  return a.firstChild.childNodes[y].innerHTML;
                }
              }
            }
          }
        }
      }
    }
    return "";
  };
  
  this.getImagesCount=function(){
    var total=0;
    if(this.thumbnail){
      var i,layer = Scrollbar.getFirstChild(this.thumbnail);
      if(layer){
        for(i=0;i<layer.childNodes.length;i++){
          a=layer.childNodes[i];
          if(a&&a.tagName=="A"){
            total++;
          }
        }
      }
    }
    return total;
  };
  
  this.init=function(id){
    this.previewer=document.getElementById(id);
    if(!this.previewer){
      var viewer=this;
      EventUtil.add(window,"load",function(){viewer.init(id)},false);
    }else{
      this.parseTemplates();
    }
  };
  
  this.parseTemplates=function(){
    for(var i=0;i<this.templates.length;i++){
      var tpl=this.templates[i];
      var obj=document.getElementById(tpl.id);
      if(obj){
        var str=tpl.str;
        str = str.replace(/\{current\}/g,this.getCurrentImageIndex());
        str = str.replace(/\{total\}/g,this.getImagesCount());
        str = str.replace(/\{fileName\}/g,this.getImagePath());
        str = str.replace(/\{info\}/g,this.getCurrentImageInfo());
        obj.innerHTML=str;
      }
    }
  };
  
  this.resize=function(id){
    this.thumbnail=document.getElementById(id);
    if(this.thumbnail){
      var w,a,i,layer = Scrollbar.getFirstChild(this.thumbnail);
      if(layer){
        w=0;
        for(i=0;i<layer.childNodes.length;i++){
          a=layer.childNodes[i];
          if(a&&a.tagName=="A"){
            w+=a.offsetWidth;
            if(a.className=="active"){
              this.active=a;
            }
          }
        }
        w+=4;
      }
      layer.style.width=w+"px";
      Scrollbar.create(id);
      this.parseTemplates();
      
      if(this.active){
        this.scrollIntoView();
      }
      
    }else{
      var viewer=this;
      EventUtil.add(window,"load",function(){viewer.resize(id)},false);
    }
  };
  
  this.scrollIntoView=function(){
    var o,s=Scrollbar;
    var id=this.thumbnail.id;
    o=s.map[id];
    //alert(this.active.offsetLeft);
    if(o) {
      var viewer=this;
      s.initScroll(id,"right",Scrollbar.speed);
      var foo = function(){
        if(viewer.active.offsetLeft <= (o.lyr.offsetLeft*-1)+2){
          s.stopScroll(id);
          //o.startScroll(Scrollbar.speed);
          s.stopScroll(id);
          var a=viewer.active;
          if(a.click)a.click();
          else if(a.onclick)a.onclick();
        }else{
          setTimeout(foo,5);
        }
      };
      foo();
    }
  };
  
  var a=arguments;
  if(a[0])this.init(a[0]);
  if(a[1])this.resize(a[1]);
}

ImageViewer.step = 10;
ImageViewer.timeout = 5;

ImageViewer.cache=function(src){
  if(!ImageViewer.images)ImageViewer.images={};
  var i,a=arguments;
  for(i=0;i<a.length;i++) {
    src=a[i];
    if(!ImageViewer.images[src]){
      ImageViewer.images[src]=new Image();
      ImageViewer.images[src].src=src;
    }
  }
  return ImageViewer.images[src];
};

ImageViewer.slowDisplay=function(maxWidth,img,viewer){
  try {
    if(!ImageViewer.stack)ImageViewer.stack={};
    if(typeof img=="string")img=ImageViewer.stack[img].image;
    else if(img.tagName=="IMG")ImageViewer.stack[img.src]={image:img,viewer:viewer};
  
    if(ImageViewer.stack[img.src].viewer.timer) {
      clearTimeout(ImageViewer.stack[img.src].viewer.timer)
    }
    var ie_opacity = (window.VBArray)?parseInt(img.style.filter.match(/(\d)+/)):null;
    var moz_opacity = parseFloat(img.style.MozOpacity);
    var opacity = parseFloat(img.style.opacity);
    if(img){
      var timeout = ImageViewer.timeout;
      if(ie_opacity && ie_opacity<100){
        img.style.filter="Alpha(opacity="+(ie_opacity+10)+")";
        timeout += 25;
        ImageViewer.stack[img.src].viewer.timer=setTimeout("ImageViewer.slowDisplay("+maxWidth+",'"+img.src+"')",timeout);
      } else if(moz_opacity<1&&!window.opera){
        img.style.MozOpacity=moz_opacity+0.1;
        timeout += 15;
        ImageViewer.stack[img.src].viewer.timer=setTimeout("ImageViewer.slowDisplay("+maxWidth+",'"+img.src+"')",timeout);
      } else if(opacity<1){
        img.style.opacity=opacity+0.1;
        timeout-=10;
        ImageViewer.stack[img.src].viewer.timer=setTimeout("ImageViewer.slowDisplay("+maxWidth+",'"+img.src+"')",timeout);
      }
    }
  }
  catch(e) {

  };
}
ImageViewer.slowResize=function(maxWidth,img,viewer) {
  if(!ImageViewer.stack)ImageViewer.stack={};
  if(typeof img=="string")img=ImageViewer.stack[img].image;
  else if(img.tagName=="IMG")ImageViewer.stack[img.src]={image:img,viewer:viewer};
  
  clearTimeout(ImageViewer.stack[img.src].viewer.timer);
  if(img&&img.offsetWidth<=maxWidth){
    img.style.width=img.offsetWidth+ImageViewer.step+"px";
    ImageViewer.stack[img.src].viewer.timer=setTimeout("ImageViewer.slowResize("+maxWidth+",'"+img.src+"')",ImageViewer.timeout);
  }
};

var Scrollbar={
  speed:200,
  map:{},
  //c=container;t=track;l=layer;f=face;
  bind:function(c,t){
    var h=function(){
      Scrollbar.create(c,t);
    }
    if(window.attachEvent)window.attachEvent("onload",h);
    else window.addEventListener("load",h,false)
  },
  create:function(c,t){
    var l,f,o,s=Scrollbar;o=s.getObject(c);
    if(o){
      l=s.getFirstChild(o);
      if(l){
        c=new Scroller(c,l);
        t=s.getObject(t);
        if(t){
          f=s.getFirstChild(t);
          if(f)c.setUpScrollbar(f,t,"v",1,1)
        }
        s.__fix__(c)
      }
    }
  },
  //a=arrow;w=div;d=direction;s=Scrollbar;
  bindArrow:function(a,w,d){
    a=this.getObject(a);
    if(a){
      var s=Scrollbar;
      var o=Scrollbar.map[w];
      if(o){
        if(!o.arrows)o.arrows={};
        o.arrows[d]=a;
      }
      function over(){
        if(o){
          if(d=="left"){var b=o.arrows["right"];if(b)b.className=""}
          else if(d=="right"){var b=o.arrows["left"];if(b)b.className=""}
          else if(d=="up"){var b=o.arrows["down"];if(b)b.className=""}
          else if(d=="down"){var b=o.arrows["up"];if(b)b.className=""}
        }
        s.initScroll(w,d);
      }
      over();
      a.onmouseover=function(){over()};
      a.onmouseout=function(){s.stopScroll(w)};
      a.onmousedown=function(){s.doubleSpeed(w)};
      a.onmouseup=function(){s.resetSpeed(w)};
      a.onclick=function(){return false}
    }
  },
  getFirstChild:function(o){o=o.firstChild;if(o.nodeType!=1)o=this.getNextSibling(o);return o},
  getNextSibling:function(o){o=o.nextSibling;while(o.nodeType!=1)o=o.nextSibling;return o},
  getObject:function(o){if(typeof o=="string") o=document.getElementById(o);return o},
  init:function(){try{document.execCommand("BackgroundImageCache",false,true)}catch(e){}},
  stopScroll:function(w){var o=Scrollbar.map[w];if(o)o.endScroll()},
  doubleSpeed:function(w){var o=Scrollbar.map[w];if(o)o.speed*=2},
  resetSpeed:function(w){var o=Scrollbar.map[w];if(o)o.speed/=2},
  initScroll:function(w,d,sp){
    var a,s,c,o=Scrollbar.map[w];
    if(o){
      if(typeof d=="string"){ switch(d){case "up":d=90;break;case "down":d=270;break;case "left":d=180;break;case "right":d=0;break}}
      d=d%360;
      if(d%90==0){c=(d==0)?-1:(d==180)?1:0;s=(d==90)?1:(d==270)?-1:0}
      else{a=d*Math.PI/180;c=-Math.cos(a);s=Math.sin(a)}
      o.fx=c/(Math.abs(c)+Math.abs(s));
      o.fy=s/(Math.abs(c)+Math.abs(s));
      o.endX=(d==90||d==270)?o.x:(d<90||d>270)?-o.maxX:0;o.endY=(d==0||d==180)?o.y:(d<180)?0:-o.maxY;
      o.startScroll(sp)
    }
  },
  getWndoLyrRef:function(){this.wnLyr=Scrollbar.getObject(this.wn.layer)},
  tossWndoLyrRef:function(){this.wnLyr=null},
  __pos__:function(x,y){var nx,ny;if(this.axis=="v"){nx=this.wn.x;ny=-(y-this.minY)*(this.wn.maxY/(this.maxY-this.minY))||0}else{ny=this.wn.y;nx=-(x-this.minX)*(this.wn.maxX/(this.maxX-this.minX))||0}this.wn.shiftTo(this.wnLyr,nx,ny)},
  __fix__:function(){var s,ua=navigator.userAgent;s=Scrollbar;if(ua.indexOf("Gecko")>-1&&ua.indexOf("Firefox")==-1&&ua.indexOf("Safari")==-1&&ua.indexOf("Konqueror")==-1){s.hold=[];for(var i=0;arguments[i];i++){if(s.map[arguments[i]]){var wndo=s.getObject(arguments[i]);var holderId=wndo.parentNode.id;var holder=s.getObject(holderId);document.body.appendChild(holder.removeChild(wndo));wndo.style.zIndex=1000;var pos=s.getPageOffsets(holder);wndo.style.left=pos.x+"px";wndo.style.top=pos.y+"px";s.hold[i]=[arguments[i],holderId]}}window.addEventListener("resize",s.rePositionGecko,true)}},
  rePositionGecko:function(){var p,h,i,w,s=Scrollbar;if(s.hold){for(i=0;s.hold[i];i++){w=s.getObject(s.hold[i][0]);h=s.getObject(s.hold[i][1]);p=s.getPageOffsets(h);with(w.style){left=p.x+"px";top=p.y+"px"}}}},
  getPageOffsets:function(e){var t,l=e.offsetLeft;t=e.offsetTop;if(e.offsetParent&&e.offsetParent.clientLeft||e.offsetParent.clientTop){l+=e.offsetParent.clientLeft;t+=e.offsetParent.clientTop}while(e=e.offsetParent){l+=e.offsetLeft;t+=e.offsetTop}return{x:l,y:t}}
};
Scrollbar.init();
function Scroller(win,layer) {
    this.id=win;
    Scrollbar.map[this.id]=this;
    this.animString="Scrollbar.map."+this.id;
    this.load=function(layer){if(this.layer){layer=Scrollbar.getObject(this.layer);layer.style.visibility="hidden"}layer=Scrollbar.getObject(layer);var win=Scrollbar.getObject(this.id);layer.style.top=this.y=0;layer.style.left=this.x=0;this.maxY=(layer.offsetHeight-win.offsetHeight>0)?layer.offsetHeight-win.offsetHeight:0;this.wd=layer.offsetWidth;this.maxX=(this.wd-win.offsetWidth>0)?this.wd-win.offsetWidth:0;this.layer=layer;layer.style.visibility="visible";this.onload();this.ready=true};
    this.shiftTo=function(layer,x,y){if(!layer||!layer.style)return;layer.style.left=(this.x=x)+"px";layer.style.top=(this.y=y)+"px"};
    this.startScroll=function(speed){if(!this.ready)return;if(this.timerId)clearInterval(this.timerId);this.speed=speed||Scrollbar.speed;this.lyr=Scrollbar.getObject(this.layer);this.lastTime=(new Date()).getTime();this.on_scroll_start();this.timerId=setInterval(this.animString+".scroll()",10)};
    this.scroll=function(){
      var now=(new Date()).getTime();
      var y,x,d=(now-this.lastTime)/1000*this.speed;
      if(d>0){
      x=this.x+this.fx*d;y=this.y+this.fy*d;
      if(this.fx==0||this.fy==0){
        if((this.fx==-1&&x>-this.maxX)||(this.fx==1&&x<0)||(this.fy==-1&&y>-this.maxY)||(this.fy==1&&y<0)){this.lastTime=now;this.shiftTo(this.lyr,x,y);this.on_scroll(x,y)}
        else{clearInterval(this.timerId);this.timerId=0;this.shiftTo(this.lyr,this.endX,this.endY);this.on_scroll_end(this.endX,this.endY)}
      }else{
        if((this.fx<0&&x>=-this.maxX&&this.fy<0&&y>=-this.maxY)||(this.fx>0&&x<=0&&this.fy>0&&y<=0)||(this.fx<0&&x>=-this.maxX&&this.fy>0&&y<=0)||(this.fx>0&&x<=0&&this.fy<0&&y>=-this.maxY)){this.lastTime=now;this.shiftTo(this.lyr,x,y);this.on_scroll(x,y)}
        else{clearInterval(this.timerId);this.timerId=0;this.on_scroll_end(this.x, this.y)}
      }
      }
    };
    this.endScroll=function(){if(!this.ready)return;if(this.timerId)clearInterval(this.timerId);this.timerId=0;this.lyr=null};
    this.bSizeDragBar = false;
    this.setUpScrollbar = function(id, trkId, axis, offx, offy) {
      var bar = Scrollbar.getObject(id);
      var trk = Scrollbar.getObject(trkId);
      Slider.init(bar, trk, axis, offx, offy);
      bar.wn = Scrollbar.map[this.id];
      if (axis == "v") this.vBarId = id;else this.hBarId = id;
      if (this.bSizeDragBar) this.setBarSize();
      bar.on_drag_start = bar.on_slide_start = Scrollbar.getWndoLyrRef;
      bar.on_drag_end =   bar.on_slide_end =   Scrollbar.tossWndoLyrRef;
      bar.on_drag =       bar.on_slide =       Scrollbar.__pos__;
    };
  
    // Keep position of dragBar in sync with position of layer onscroll
    this.updateScrollbar = function(x, y) {
      var nx, ny;
      if ( this.vBarId ) {
      if (!this.maxY) return;
      ny = -( y * ( (this.vbar.maxY - this.vbar.minY) / this.maxY ) - this.vbar.minY );
      ny = Math.min( Math.max(ny, this.vbar.minY), this.vbar.maxY);  
      nx = parseInt(this.vbar.style.left);
      this.vbar.style.left = nx + "px"; this.vbar.style.top = ny + "px";
      } if ( this.hBarId ) {
      if (!this.maxX) return;
      nx = -( x * ( (this.hbar.maxX - this.hbar.minX) / this.maxX ) - this.hbar.minX );
      nx = Math.min( Math.max(nx, this.hbar.minX), this.hbar.maxX);
      ny = parseInt(this.hbar.style.top);
      this.hbar.style.left = nx + "px";
      this.hbar.style.top = ny + "px";
      } 
      
    };

    // Restore dragBar to start position when loading new layer
    this.restoreScrollbars = function() {
      var bar;
      if (this.vBarId) {
      bar = Scrollbar.getObject(this.vBarId);
      bar.style.left = bar.minX + "px"; bar.style.top = bar.minY + "px";
      }
      if (this.hBarId) {
      bar = Scrollbar.getObject(this.hBarId);
      bar.style.left = bar.minX + "px"; bar.style.top = bar.minY + "px";
      }
    };
    
    // Size dragBar in proportion to size of content in layer
    // called on_load of layer if bSizeDragBar prop true
    this.setBarSize = function() {
      var bar;
      var lyr = Scrollbar.getObject(this.layer);
      var wn = Scrollbar.getObject(this.id);
      if (this.vBarId) {
      bar = Scrollbar.getObject(this.vBarId);
      bar.style.height = (lyr.offsetHeight > wn.offsetHeight)? bar.trkHt / ( lyr.offsetHeight / wn.offsetHeight ) + "px": bar.trkHt - 2*bar.minY + "px";
      bar.maxY = bar.trkHt - bar.offsetHeight - bar.minY; 
      }
      if (this.hBarId) {
      bar = Scrollbar.getObject(this.hBarId);
      bar.style.width = (this.wd > wn.offsetWidth)? bar.trkWd / ( this.wd / wn.offsetWidth ) + "px": bar.trkWd - 2*bar.minX + "px";
      bar.maxX = bar.trkWd - bar.offsetWidth - bar.minX; 
      }
    }

    this.on_scroll = function(x,y) { this.updateScrollbar(x,y); };
    this.on_slide = this.on_scroll;
    
    this.on_scroll_start=function(){
      if ( this.vBarId ) this.vbar = Scrollbar.getObject(this.vBarId);
      if ( this.hBarId ) this.hbar = Scrollbar.getObject(this.hBarId);
    };
    this.on_slide_start = this.on_scroll_start;
  
    this.on_scroll_end=function(x, y) { 
      this.updateScrollbar(x,y);
      this.lyr = null;
      this.bar = null;
      
      var dir=(x==0)?"left":"right";
      var a=this.arrows[dir];
      if(a)a.className="disabled";
      
      var dir=(y==0)?"up":"down";
      var a=this.arrows[dir];
      if(a)a.className="disabled";
    };
    this.on_slide_end = this.on_scroll_end;
    
    this.onload=function(){
      this.restoreScrollbars();
      if (this.bSizeDragBar) this.setBarSize();
    };
    
    
    this.load(layer);
  }

Scrollbar.map = {};



var EventUtil={
  add:function(o,e,h,c){if(o.addEventListener)o.addEventListener(e,h,(c||false));else if(o.attachEvent)o.attachEvent("on"+e,h)}, 
  remove:function(o,e,h,c){if(o.removeEventListener)o.removeEventListener(e,h,(c||false));else if(o.detachEvent)o.detachEvent("on"+e,h)}, 
  getEvent:function(e){e=e?e:window.event;e.tgt=e.srcElement?e.srcElement:e.target;if(!e.preventDefault)e.preventDefault=function(){return false};if(!e.stopPropagation)e.stopPropagation=function(){if(window.event)window.event.cancelBubble=true};return e}
}


// model: Aaron Boodman's dom drag at www.youngpup.net
var Slider = {
  obj: null,
  slideDur: 500,  // duration of glide onclick of track  
  init: function (bar, track, axis, x, y) {
    x = x || 0; y = y || 0;
    bar.style.left = x + "px"; bar.style.top = y + "px";
    bar.axis = axis; track.bar = bar;
    if (axis == "h") {
      bar.trkWd = track.offsetWidth; // hold for setBarSize
      bar.maxX = bar.trkWd - bar.offsetWidth - x; 
      bar.minX = x; bar.maxY = y; bar.minY = y;
    } else {
      bar.trkHt = track.offsetHeight;
      bar.maxY = bar.trkHt - bar.offsetHeight - y; 
      bar.maxX = x; bar.minX = x; bar.minY = y;
    }
    bar.on_drag_start =  bar.on_drag =   bar.on_drag_end = 
    bar.on_slide_start = bar.on_slide =  bar.on_slide_end = function() {}
    bar.onmousedown = this.startDrag; track.onmousedown = this.startSlide;
  },
  
  startSlide: function(e) { // called onmousedown of track 
    if ( Slider.aniTimer ) clearInterval(Slider.aniTimer);
    e = e? e: window.event;
    var bar = Slider.obj = this.bar; // i.e., track's bar
    e.offX = (typeof e.layerX != "undefined")? e.layerX: e.offsetX;
    e.offY = (typeof e.layerY != "undefined")? e.layerY: e.offsetY;
    bar.startX = parseInt(bar.style.left); bar.startY = parseInt(bar.style.top);
    if (bar.axis == "v") {
      bar.destX = bar.startX;
      bar.destY = (e.offY < bar.startY)? e.offY: e.offY - bar.offsetHeight;
      bar.destY = Math.min( Math.max(bar.destY, bar.minY), bar.maxY );
    } else {
      bar.destX = (e.offX < bar.startX)? e.offX: e.offX - bar.offsetWidth;
      bar.destX = Math.min( Math.max(bar.destX, bar.minX), bar.maxX );
      bar.destY = bar.startY;
    }
    bar.distX = bar.destX - bar.startX; bar.distY = bar.destY - bar.startY;
    Slider.per = Math.PI/(2 * Slider.slideDur);
    Slider.slideStart = (new Date()).getTime();
    bar.on_slide_start(bar.startX, bar.startY);
    Slider.aniTimer = setInterval("Slider.doSlide()",10);
  },
  
  doSlide: function() {
    if ( !Slider.obj ) { clearInterval(Slider.aniTimer); return; }    
    var bar = Slider.obj;     
    var elapsed = (new Date()).getTime() - this.slideStart;
    if (elapsed < this.slideDur) {
      var x = bar.startX + bar.distX * Math.sin(this.per*elapsed);
      var y = bar.startY + bar.distY * Math.sin(this.per*elapsed);
      bar.style.left = x + "px"; bar.style.top = y + "px";
      bar.on_slide(x, y);
    } else {  // if time's up
      clearInterval(this.aniTimer);
      bar.style.left = bar.destX + "px"; bar.style.top = bar.destY + "px";
      bar.on_slide_end(bar.destX, bar.destY);
      this.obj = null;
    }
  },
  
  startDrag:function(e){
    e=EventUtil.getEvent(e);
    if(Slider.aniTimer)clearInterval(Slider.aniTimer);
    var bar = Slider.obj = this;
    bar.downX = e.clientX; bar.downY = e.clientY;
    bar.startX = parseInt(bar.style.left);
    bar.startY = parseInt(bar.style.top);
    bar.on_drag_start(bar.startX, bar.startY);
    EventUtil.add( document, "mousemove", Slider.doDrag, true );
    EventUtil.add( document, "mouseup",   Slider.endDrag,  true );
    e.stopPropagation();
  },

  doDrag: function (e) {
    e = e? e: window.event;
    if (!Slider.obj) return;
    var bar = Slider.obj; 
    var nx = bar.startX + e.clientX - bar.downX;
    var ny = bar.startY + e.clientY - bar.downY;
    nx = Math.min( Math.max( bar.minX, nx ), bar.maxX);
    ny = Math.min( Math.max( bar.minY, ny ), bar.maxY);
    bar.style.left = nx + "px"; bar.style.top  = ny + "px";
    bar.on_drag(nx,ny);
    return false;  
  },
  endDrag:function(){
    EventUtil.remove(document,"mousemove",Slider.doDrag,true);
    EventUtil.remove(document,"mouseup",Slider.endDrag,true);
    if(!Slider.obj)return;
    Slider.obj.on_drag_end(parseInt(Slider.obj.style.left),parseInt(Slider.obj.style.top));
    Slider.obj=null;
  } 
}

/* popup on */
var w=window;
w.getWidth=function(w){var v,b,e,d,w=w?w:window;d=w.document;e=d.documentElement;b=d.body;v=0;if(typeof w.innerWidth=='number')v=w.innerWidth;else if(e&&e.offsetWidth)v=e.offsetWidth;else if(b&&b.offsetWidth)v=b.offsetWidth;return v};
w.getHeight=function(w){var h,b,e,d,w=w?w:window;d=w.document;e=d.documentElement;b=d.body;h=0;if(typeof w.innerHeight=='number')h=w.innerHeight;else if(e&&e.offsetHeight)h=e.offsetHeight;else if(b&&b.offsetHeight)h=b.offsetHeight;return h};
w.getScrollLeft=function(w){var x,b,e,d,w=w?w:window;d=w.document;e=d.documentElement;b=d.body;x=0;if(typeof w.scrollX=='number')x=w.scrollX;else if(e&&e.scrollLeft)x=e.scrollLeft;else if(b&&b.scrollLeft)x=b.scrollLeft;return x};
w.getScrollTop=function(w){var y,b,e,d,w=w?w:window;d=w.document;e=d.documentElement;b=d.body;y=0;if(typeof w.scrollY=='number')y=w.scrollY;else if(e&&e.scrollTop)y=e.scrollTop;else if(b&&b.scrollTop)y=b.scrollTop;return y};

var popup={

  show:function(e, id, img){
    var leftOffset = (window.VBArray) ? 44 : (window.opera) ?  44 : 44;
    var topOffset = (window.VBArray) ? -72 : (window.opera) ?  -72 : -72;
    
    var d=document.getElementById(id);
    if(!e)e=window.event;
    if(d && e){
      d.style.display="block";
      var w=window;
      var x = (e && e.pageX) ? e.pageX : (e && e.clientX) ? e.clientX : 0;
      var y = (e && e.pageY) ? e.pageY : (e && e.clientY) ? e.clientY : 0;
      var bh = w.getHeight();
      var bw = 0;//w.getWidth();
      var sy = w.getScrollTop();
      var sx = 0;//w.getScrollLeft();
      if(w.VBArray) {
      d.style.top  = y-d.offsetHeight-topOffset+Math.max(document.body.scrollTop,document.documentElement.scrollTop)+"px";
      d.style.left = x-leftOffset+Math.max(document.body.scrollLeft,document.documentElement.scrollLeft)+"px";
      } else {
      d.style.top  = y-d.offsetHeight-topOffset+"px";
      d.style.left = x-leftOffset+"px";
      }
      if(w.VBArray){
        if(!d.fade){
          d.fade = document.createElement("DIV");
          d.parentNode.insertBefore(d.fade,d);
          d.fade.style.position="absolute";
          d.fade.style.zIndex="998";
          d.style.zIndex="999";
          d.fade.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='images/videoplayer-hint-bg.png', sizingMethod='scale')"; 
          d.style.background="none";
          d.fade.style.width=d.offsetWidth+"px";
          d.fade.style.height=d.offsetHeight+"px";
        }
        d.fade.style.top=d.style.top;
        d.fade.style.left=d.style.left;
        d.fade.style.display="block";
        
      }
      this.current=d;
      d.firstChild.src = img;
      //alert(d.firstChild.src);
      this.attach();
      // = img;
      
    }
  },
  attach:function(){
    var w=document;
    if(w.attachEvent)w.attachEvent("onmousedown",popup.hide);
    else w.addEventListener("mousedown",popup.hide,false);
  },
  detach:function(){
    var w=document;
    if(w.detachEvent)w.detachEvent("onmousedown",popup.hide);
    else w.removeEventListener("mousedown",popup.hide,false);
  },
  hide:function(e){
    var d,o=e.target||e.srcElement;
    d=popup.current;
    if(d && o!=d && !popup.contains(o))popup.detach(popup.close());
  },
  contains:function(o,d){
    if(!d)d=popup.current;
    if(d.contains) return d.contains(o);
    for(var e,i=0;i<d.childNodes.length;){
      e=d.childNodes[i++];
      if(e==o || (e.childNodes.length && popup.contains(o,e))) return true;
    }
    return false;
  },
  close:function(){
    if(this.current){
      this.current.style.display="none";
      if(this.current.fade)this.current.fade.style.display="none";
    }
  }
};
var ajax={
  request:function(){
    var r=null;
    try {
      r = new XMLHttpRequest();
    }catch(e){}
    
    if(!r) {
      a = ["Msxml2.XMLHTTP.5.0", "Msxml2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"];
      for(i=0; i<a.length; i++){
        try{
          if(!r) {
            r = new ActiveXObject(a[i]);
            if(r) break;
          }
        }catch(e){}
      }
    }
    return r;
  }
}

function NumbList(listClass) {
  var d =document;
  var divs = d.getElementsByTagName("DIV");
  for (var n = 0; n < divs.length; n++) 
    if (divs[n].className == listClass){
      var OLs = divs[n].getElementsByTagName("OL");
      for (var j = 0; j < OLs.length; j++) {
        RepItem(OLs[j]);
      }
      ULs = divs[n].getElementsByTagName("UL");
      for ( j = 0; j < ULs.length; j++ ) {
        ULs[j].innerHTML = ULs[j].innerHTML.replace(/<li>((\d+\. )*)/gi, "<li>");
      }
    }
  }
function RepItem(element) {
  var undefined='';
  element.style.listStyleType = 'none';
  oM = element.childNodes.length;
  var k = 0;
  for ( i = 0; i < oM; i++ ) {
    var oLI = element.childNodes[i];
    if ( oLI.tagName ){
      k++;
      var re = /((\d+\. )(\d+\. )*)/;
      oLI.innerHTML = '<span>'+k + '. ' + (re.test(oLI.innerHTML)?'':'</span>') + oLI.innerHTML;
      oLI.innerHTML = oLI.innerHTML.replace(/((\d+\. )(\d+\. )*)/, "$1$2</span>");
      oLI.innerHTML = oLI.innerHTML.replace(/\d+\. /, '');
    }
    if ( oLI.tagName && oLI.innerHTML!=undefined ){
      oLI.innerHTML = oLI.innerHTML.replace(/<li>((\d+\. )*)/gi, "<li>$1" + k + '. ');
    }
  }
}

function printen( url ) {
  rPopup = window;
  rPopup.open( url ,"");
}

addEvent(window, "load", function(){NumbList('mdlInfo')}, false);
addEvent(window, "load", function(){NumbList('lstBrEt')}, false);
addEvent(window, "load", function(){new Tabs("tLinkTabs", "tLinkTabsContainer",0)}, false);
addEvent(window, "load", function(){new Tabs("tBeerTabs", "tBeerTabsContainer",0)}, false);

