/* Please start using the YUKU object instead of the functions
   bellow it. I really want to deprecate that mess. */
var ids = 0;			/* ??? */
var isIE = document.all && !window.opera;
var isSafari = /safari/gi.test(navigator.userAgent);

YUKU = {
 counter: 0, /* just a counter used for incrementing */
 bind: function(obj, method)
 {
   var args = Array.prototype.slice.apply(arguments, [2]);

   if (typeof method === 'string')
     method = obj[method];
   return function()
   {
     return method.apply(obj,
			 Array.prototype.concat.apply(Array.prototype.slice.apply(arguments, [0]),
						      args));
   }
 },


 el_from_html: function(html)
 {
   var tmp = document.createElement('DIV');
   tmp.innerHTML = html;
   return tmp.firstChild;
 },

 make_el: function(elName)
 {
  var el = document.createElement(elName);
  for(var i=1,l=arguments.length; i<l; i++){
    var arg = arguments[i];
    if(arg)
      if(arg.constructor == Object && !arg.tagName)
	for(var key in arg){
	  if(el[key]) {
	    try{el[key](arg[key])}
	    catch(e){
	      if(arg[key].constructor != Object || arg[key].tagName)el[key] = arg[key];
	      else if(arg[key].constructor == Object && !arg[key].tagName)
		for(var stRule in arg[key])
		  el[key][stRule] = arg[key][stRule];
	    }
	  }
	  else el[key] = arg[key];
	}
      else if(arg.constructor == String || arg.constructor == Number) el.appendChild(document.createTextNode(arg));
      else if(arg.tagName) arg.appendChild(el);
  };
  return el;

 },


 get_by_name: function(name)
 {
   return document.getElementsByName(name);
 },


 get_by_tag: function(tag,el)
 {
   var owner = el || document;
   return owner.getElementsByTagName(tag);
 },



 get_by_id: function(id)
 {
   return document.getElementById(id);
 },



 insert_before: function(newEl,oldEl)
 {
   return oldEl.parentNode.insertBefore(newEl, oldEl);
 },



 remove_el: function(el)
 {
   return el.parentNode.removeChild(el);
 },



 replace_el: function(newEl, oldEl)
 {
   return oldEl.parentNode.replaceChild(newEl,oldEl);
 },



 get_id: function(el)
 {
   if (!el.id) {
     /* create random id that starts with a letter [a-z]
	and is followed by  increased getId.counter */
     var a = 'a'.charCodeAt(0);		/* ascii val */
     var z = 'z'.charCodeAt(0);;		/* ascii val */
     el.id = String.fromCharCode(a + (++YUKU.counter % (z-a)) ) +'-'+YUKU.counter;
   }
   return el.id;
 },



 className: {
  add: function(el,cName)
  {
    className.kill(el,cName);
    el.className += el.className.length?(' '+cName):cName;
  },
  kill: function(el,cName)
  {
    var re = new RegExp('^' + cName + '(?:(?:\\s+|$)(?:' + cName + '(?=\\s|$))?)+|\\s+' + cName + '(?=\\s|$)', 'g');
    el.className = el.className.replace(re,'');
  },
  replace: function(el,ncName,ocName)
  {
    className.kill(el,ocName);
    className.add(el,ncName);
  },
  test: function(obj,cName)
  {
    return (!obj || !obj.className) ? false : (new RegExp("\\b"+cName+"\\b")).test(obj.className);
  }
 },



 get_by_test: function(el, step, test, depth)
 {
   if (!depth)
     depth = 0;

   if (test(el))
     return el;

   for ( ; el && --depth; el = step(el))
     if (test(el))
       break;

   if (el && !test(el))
     el = null;

   return el;
 },


 test: {
  for_tag: function(tag)
  {
    return YUKU.test.for_prop_val('tagName', tag);
  },
  for_prop_val: function(prop, val)
  {
    return function(el)
    {
      return el[prop] && el[prop] === val;
    }
  }
 },


 step: {
  by_prop: function(prop)
  {
    return function(el)
    {
      return el[prop];
    }
  },

  by_indx: function(indx, dir)
  {
    return function(obj)
    {
      return obj[(indx += dir)];
    }
  }
 },



 add_event: function(el, eType, fn, useCapt)
 {
   if (document.attachEvent)
     return el.attachEvent('on' + eType, fn);
   else if(document.addEventListener)
     return el.addEventListener(eType, fn, useCapt);

   el['on' + eType] = fn;
   return true;
 },



 remove_event: function(el, eType, fn, useCapt)
 {
   if (document.detachEvent)
     return el.detachEvent('on' + eType, fn);
   else if(document.addEventListener)
     return el.removeEventListener(eType, fn, useCapt);

   el['on' + eType] = null;
   return true;
 },



 cancel_bubble: function(e)
 {
   if (!e)
     e = event;
   e.cancelBubble = true;
   if (e.stopPropagation)
     e.stopPropagation();
 },



 prevent_default: function(e)
 {
   if (!e)
     e = event;
   if (e.preventDefault)
     e.preventDefault();
   return (e.returnValue = false);
 },



 get_target: function(e)
 {
   if(!e)
     e = event;
   var el = e.srcElement || e.target;
   if (el && el.nodeType === 3)
     el = el.parentNode;
   return el;
 },

 find_xy: function (el)
 {
   var y = 0, x = 0;
   while ( el ) {
     y+=el.offsetTop;
     x+=el.offsetLeft;
     el=el.offsetParent;
   };

   return { x:x, y:y };
 },


 get_frame_size: function (win)
 {
   var myWidth, myHeight;
   if ( !win ) win = window;
   if( typeof( win.innerWidth ) == 'number' ) {
     //Non-IE
     myWidth = win.innerWidth;
     myHeight = win.innerHeight;
   } else if( win.document.documentElement && ( win.document.documentElement.clientWidth || win.document.documentElement.clientHeight ) ) {
     //IE 6+ in 'standards compliant mode'
     myWidth = win.document.documentElement.clientWidth;
     myHeight = win.document.documentElement.clientHeight;
   } else if( win.document.body && ( win.document.body.clientWidth || win.document.body.clientHeight ) ) {
     //IE 4 compatible
     myWidth = win.document.body.clientWidth;
     myHeight = win.document.body.clientHeight;
   }
   return {x:myWidth, y:myHeight};
 },

 doc_size: function ()		/* ??? */
 {
  var y = 0,x = 0;
  if(document.documentElement) {
    x = document.documentElement.scrollWidth;
    y = document.documentElement.scrollHeight;
  };
  if(x<document.body.scrollWidth)
    x = document.body.scrollWidth;
  if(y<document.body.scrollHeight)
    y = document.body.scrollHeight;
  return {x:x,y:y};
 },

 find_scroll_offset: function (win)
 {
   if (!win)
    win = window;
  var body = win.document.body;
  var html = win.document.documentElement;
  var x = (body && body.scrollLeft) || 0;
  var y = (body && body.scrollTop) || 0;
  if (html && typeof(html.scrollTop) == 'number') {
    x = Math.max(x, html.scrollLeft);
    y = Math.max(y, html.scrollTop);
  }
  else if (typeof(window.pageYOffset) == 'number') {
    x = window.pageXOffset;
    y = window.pageYOffset;
  }
  return {x: x, y: y};
 },

 set_opacity: function (el,value) {
   value = Math.round(value);
   value = value>100?100:value<0?0:value;
   el.style.KHTMLOpacity = value/100;
   el.style.MozOpacity = value/100;
   el.style.opacity = value/100;
   el.style.filter='alpha(opacity='+value+')';
 },

 style_el: function (el,styles)
 {
   var style = el.style;
   for (var key in styles)
     style[key] = styles[key];
 },

 current_style: function (el,prop) {
  var viewCSS = (typeof document.defaultView=='function') ? document.defaultView() : document.defaultView;
  if (viewCSS && viewCSS.getComputedStyle){
    var s = viewCSS.getComputedStyle(el,null);
    return s && s.getPropertyValue(prop);
  }
  return el.currentStyle && (el.currentStyle[prop] || null) || null;
 }
};
if (isIE) {
  YUKU.find_mouse_xy = function(e)
    {
      if( !e ) e = window.event;

      var body = document.body;
      var html = document.documentElement;
      var x = (body && body.scrollLeft) || 0;
      var y = (body && body.scrollTop) || 0;
      if (html && typeof(html.scrollTop) == 'number') {
	x = Math.max(x, html.scrollLeft);
	y = Math.max(y, html.scrollTop);
      }
      return { y:e.clientY+y, x:e.clientX+x };
    }
 } else if (window.opera || isSafari) {
   YUKU.find_mouse_xy = function(e)
     {
       return {y:e.clientY+document.documentElement.scrollTop,
	     x:e.clientX+document.documentElement.scrollLeft};
     }
 } else {
  YUKU.find_mouse_xy = function(e)
    {
      return {y:e.clientY+window.scrollY,
	      x:e.clientX+window.scrollX};
    }
 }

String.prototype.trimStart=function(){return this.replace(/^\s+/,'');};
String.prototype.trimEnd=function(){return this.replace(/\s+$/,'');};
String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g, '');};

String.prototype.truncate = function(maxlength , extension ) {
  maxlength = maxlength||250;
  extension = extension || '...';
  var newstr =  this.trim();
  if (newstr.length <= maxlength )
    return newstr;
  else {
    if (!newstr.match(/\s/))
      return newstr.substr(0, maxlength)+extension;
    else {
      newstr = newstr.split(/\s/);
      var splitStr = newstr.shift();
      while(splitStr.length < maxlength)
	splitStr += ' '+newstr.shift();
      return splitStr + extension;
    }
  }
};

String.prototype.stripHTML = function() { return this.replace(/<.*?>/g,''); };

/* temp */
YUKU.class_name = YUKU.className;
/* legacy */
var make_el = YUKU.make_el;
var get_by_id = YUKU.get_by_id;
var get_by_tag = YUKU.get_by_tag;
var get_by_name = YUKU.get_by_name;
var replace_el = YUKU.replace_el;
var remove_el = YUKU.remove_el;
var insert_before = YUKU.insert_before;
var FindXY = YUKU.find_xy;
var FindScrollOffset = YUKU.find_scroll_offset;
var getScrollPos = YUKU.find_scroll_offset;
var doc_size = YUKU.doc_size;
var window_size = YUKU.get_frame_size;
var getFrameSize = YUKU.get_frame_size;
var set_opacity = YUKU.set_opacity;
var style_el = YUKU.style_el;
var CurrentStyle = YUKU.current_style;
var addEvent = YUKU.add_event;
var removeEvent = YUKU.remove_event;
var cancelBubble = YUKU.cancel_bubble;
var preventDefault = YUKU.prevent_default;
var FindMouseXY = YUKU.find_mouse_xy;
var get_srcEl = YUKU.get_target;
var className = YUKU.class_name;
var getId = YUKU.get_id;

/* undecided on/ needs to be cleaned up */
function copy(obj)		/* punny javascript */
{
  var foo = {};
  for (var key in obj)
    if (typeof obj[key] == 'object')
      foo[key] = copy(obj[key]);
    else
      foo[key] = obj[key];
  return foo;
}

function make_text(str,where) {
  str = document.createTextNode(str);
  if(where)where.appendChild(str);
  return str;
};

function get_parent_by_tag(el,tag) {
  while(el && el.tagName != tag) el = el.parentNode;
  return el;
};

function get_parent_by_prop(el,prop) {
  while(el && !el[prop]) el = el.parentNode;
  return el;
};

function kill_children(node) { while(node.hasChildNodes()) node.removeChild(node.firstChild); };
function kill_textNodes(node) { var kids = node.childNodes; for(var i=kids.length;i--;) if(kids[i].nodeType == 3)node.removeChild(kids[i]);};
function clone_el(el,arg) { return el.cloneNode(arg); };
function insert_after(newEl,oldEl) {
  if(oldEl.nextSibling)
    return insert_before(newEl,oldEl.nextSibling);
  else
    return oldEl.parentNode.appendChild(newEl);
};

var get_toEl,get_fromEl;
if(isIE) {
  get_toEl = function(e) { if( !e ) e = window.event; return e.toElement; };
  get_fromEl = function(e) { if( !e ) e = window.event; return e.fromElement; };

 }
else {
  get_toEl = function(e) { return e.currentTarget; };
  get_fromEl = function(e) { return e.relatedTarget; };
};
/* must stop using this */
Function.prototype.bind = function(obj) { var f = this; return function(par) { return f.call(obj, par);} }
function getRef(o,call) { return function() { return o[call].apply(o, arguments); }; };
function getRef2(o,func) { return function() { return func.apply(o, arguments); }; };

function ObjectEvents() { this.events =[]; };
ObjectEvents.prototype.scopeFunc = function(func) { var me = this; return function(e) {me[func](e)}; };
ObjectEvents.prototype.addEvent = function(el,event,func) {
  func = this.scopeFunc(func);
  this.events[this.events.length] = {func:func,event:event};
  addEvent(el,event,func,false);
  return this.events.length - 1;
};
ObjectEvents.prototype.removeEvent = function(el,id) {
  if( this.events[id] ) {
    var obj = this.events[id];
    removeEvent(el,obj.event,obj.func,false);
    this.events[id] = null;
    obj = null;
  }
};

function getXmlHttpObject() {
  var xmlhttp = null;
  try {xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");}
  catch (e) {
    try {xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");}
    catch (e) {
      try {xmlhttp = new XMLHttpRequest();}
      catch (e) {xmlhttp = false;}
    }
  }
  return xmlhttp;
};

function get_iframe_doc(iframe) {
  if( iframe.name )
    return window.frames[iframe.name].document;
  var oDoc = (iframe.contentWindow || iframe.contentDocument);
  if (oDoc.document) oDoc = oDoc.document;
  return oDoc;
};

function get_iframe_win(iframe) {
  if( iframe.name )
    return window.frames[iframe.name];
  var oDoc = (iframe.contentWindow || iframe.contentDocument);
  if (oDoc) return oDoc;
  return null;
};

/* getAncestor: returns ancestor element of `el' if it matches `test'
   func. otherwise return null; Search can be limited by seting `depth'
*/
function getAncestor(el,test,depth)
{
  if (!depth)
    depth = 0;

  for ( ; el && --depth; el=el.parentNode)
    if (test(el))
      break;

  if (el && !test(el))
    el = null;

  return el;
};
getAncestor.isTD = function(el)
{
  return el.tagName == 'TD';
};
getAncestor.isTR = function(el)
{
  return el.tagName == 'TR';
};

/* getChilds: returns Array of `el' childNodes based on `test' func  */
function getChilds(el,test) {
  var childs = [];
  el = el.firstChild;
  while(el) {
    if(test(el))
      childs.push(el);
    el = el.nextSibling;
  }
  return childs;
};

/** XHConn - Simple XMLHTTP Interface - bfults@gmail.com - 2005-04-08        **
 ** Code licensed under Creative Commons Attribution-ShareAlike License      **
 ** http://creativecommons.org/licenses/by-sa/2.0/                           **/
function XHConn()
{
  var xmlhttp, bComplete = false;
  try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
  catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
    catch (e) { try { xmlhttp = new XMLHttpRequest(); }
      catch (e) { xmlhttp = false; }}}
  if (!xmlhttp) return null;
  this.connect = function(sURL, sMethod, sVars, fnDone)
    {
      if (!xmlhttp) return false;
      bComplete = false;
      sMethod = sMethod.toUpperCase();
      try {
	if (sMethod == "GET")
	  {
	    xmlhttp.open(sMethod, sURL+"?"+sVars, true);
	    sVars = "";
	  }
	else
	  {
	    xmlhttp.open(sMethod, sURL, true);
	    xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");
	    xmlhttp.setRequestHeader("Content-Type",
				     "application/x-www-form-urlencoded");
	  }
	xmlhttp.onreadystatechange = function(){
	  if (xmlhttp.readyState == 4 && !bComplete)
	    {
	      bComplete = true;
	      if ( fnDone )
		fnDone(xmlhttp);
	    }};
	xmlhttp.send(sVars);
      }
      catch(z) { return false; }
      return true;
    };
  return this;
}

/* common yuku stuff */
YUKU.dropDown = {
  classes:{ x:['left','right'], y:['top','bottom'] },
  active: null,
  x: null,
  y: null,
  drop: function(e)
  {
    var srcEl = get_srcEl(e);
    var active = this.active;
    var cl = this.classes;
    var x = this.x;
    var y = this.y;
    var SubMenu = YUKU.get_by_test(srcEl, YUKU.step.by_prop('parentNode'),
				     YUKU.test.for_tag('UL'), 5);
    if (SubMenu && YUKU.className.test(SubMenu.parentNode, 'dropdown'))
      return;

    if (active) {
      YUKU.className.kill(active, cl.y[y]+'-'+cl.x[x]+'-dropdown');
      var ul = get_by_tag('UL', active)[0];
      if (ul) {
	ul.marginTop = '';
	ul.marginBottom = '';
	this.active = null;
      }
    };
    while (!className.test(srcEl,'dropdown')
	   && (srcEl = srcEl.parentNode))
      ;
    if (srcEl != active
	&& className.test(srcEl,'dropdown')) {
      var screenSize = getFrameSize();
      var screenOffset = getScrollPos();
      var mousePos = FindMouseXY(e);
      x = Math.round((mousePos.x - screenOffset.x) / screenSize.x*0.7);
      y = Math.round((mousePos.y - screenOffset.y) / screenSize.y*0.7);
      className.add(srcEl,cl.y[y]+'-'+cl.x[x]+'-dropdown');
      this.active = srcEl;
      this.x = x;
      this.y = y;
      var sHeight = screenSize.y + screenOffset.y - FindXY(srcEl).y - srcEl.offsetHeight*Math.abs(y-1);
      var ul = get_by_tag('UL', srcEl)[0];
      if (ul) {
	ul.style.marginTop = ul.style.marginBottom = '';
	if ( y == 0 && sHeight < ul.offsetHeight)
	  ul.style.marginTop = sHeight - ul.offsetHeight + 'px';
      }
    }
  }
};

get_by_tag('html')[0].className = 'hasJS';//<-- bad hack but it'll do for now

(function()
 {
   function clickCheck(e)
   {
     var depth = 3;
     var srcEl = get_srcEl(e);
     while (--depth && !className.test(srcEl,'dropdown')
	    && (srcEl = srcEl.parentNode));
     if (srcEl && depth)
       preventDefault(e);
   };
   addEvent(document,'click',clickCheck,false);
   function mouseUpCheck(e) { YUKU.dropDown.drop(e); };
   addEvent(document,'mouseup',mouseUpCheck,false);
   addEvent(window,'unload',function(){YUKU.dropDown.active = null;},false);
 })();


/* tab menu stuff */
function _mgr_tab_menu(e) {
  var el = get_srcEl(e), lis;
  /* litle nasty hack to make admin menu just act as a link */
  if (el.tagName != 'A')
    el = YUKU.get_by_test(el, YUKU.step.by_prop('parentNode'),
			  YUKU.test.for_tag('A'), 4);
  if (el && el.title == 'Admin-Menu') {
    var loc = location.href;
    if (loc.lastIndexOf('opened') + 'opened'.length == loc.length)
      return preventDefault(e);
    else
      el.href += '/t/opened';
    return true;
  }

  while(el.tagName != 'LI'
	&& (el = el.parentNode))
    ;

  if(el) {
    if(className.test(el.parentNode, 'mgr-tab-menu')) {
      lis = el.parentNode.childNodes;
      for(var i = 0, li; (li = lis[i]); i++)
        if(li.className)
          className.kill(li, 'mgr-tab-selected');
      preventDefault(e);
    }
    else if(className.test(el.parentNode, 'mgr-tab-sub-menu')) {
      lis = el.parentNode;
      while((lis = lis.parentNode)
            && !className.test(lis, 'mgr-tab-menu'));
      if(lis) {
	lis = get_by_tag('LI', lis);
	for(var i = 0, li; (li = lis[i]); i++)
	  if(el.parentNode != li
	     && !className.test(li.parentNode, 'mgr-tab-menu'))
	    className.kill(li, 'mgr-tab-selected');
      }
    }
    className.add(el, 'mgr-tab-selected');
    return className.test(el.parentNode, 'mgr-tab-sub-menu');
  }
  return true;
};

function addEditor(textAreaId, smileyUrl, frameheight, focusEl, addSmileys)
{
  if (isSafari)
    return;

  var ta = get_by_id(textAreaId);
  var div = make_el('DIV', { className: 'wysiwyg' });
  var name = 'editor-'+addEditor.counter++;
  var obj = {
  frameid: name,
  focusEl: focusEl,
  addSmileys: addSmileys
  };

  if (ta.value)
    obj.textareaid = textAreaId;

  if (frameheight)
    obj.frameheight = frameheight;

  obj.gs = {};
  obj.gs.isLoged = window.gs && window.gs.isLoged;
  if (smileyUrl)
    obj.gs.smileyUrl = smileyUrl;

  addEditor[name] = obj;
  div.innerHTML = '<iframe scrolling="no" allowtransparency="true" frameborder="no" \
src="/editor/view#'+name+'" name="'+name+'" id="'+name+'" style="border: none; overflow: hidden; outline: none; margin: auto; width: 99%; background: transparent;"></iframe>\
    <p class="editor-shortcuts"><strong>Shortcuts:</strong> bold: <dfn title="shortcut for bold">CTRL-b</dfn>,\
    italic: <dfn title="shortcut for italic">CTRL-i</dfn>,\
    underline: <dfn title="shortcut for underline">CTRL-u</dfn>,\
    cut: <dfn title="shortcut for cut">CTRL-x</dfn>,\
    copy: <dfn title="shortcut for copy">CTRL-c</dfn>,\
    paste: <dfn title="shortcut for paste">CTRL-v</dfn></p>';
  insert_before(div, ta);

  function update(e) {
/*     preventDefault(e); */
    var editor = window.frames[name].wys.editor;
    if (editor.iHTML)
      editor.commandInterfaces.html(editor);
    else if(editor.isSpellChecking)
      editor.commandInterfaces._removeCorrections(editor);
    get_by_id(textAreaId).value = editor.getHtml();
    removeEvent(get_by_id(textAreaId).form, 'submit', update, false);
/*     get_by_id(textAreaId).form.submit(); */
  }

  addEvent(ta.form, 'submit', update, false);
  ta.style.display = 'none';
  div = ta = null;
}
addEditor.counter = 0;

function Nav(topId, bottomId, contentId) {
  this.topId = topId;
  this.bottomId = bottomId;
  this.contentId = contentId;
  this.setupMenu();
  //this.checkForBottomLocation();
  //this.addEvent(window,'resize','checkForBottomLocation');
};
Nav.prototype = new ObjectEvents();

Nav.prototype.setupMenu = function() {
  var topContent = get_by_id(this.topId);
  var bottomContent = get_by_id(this.bottomId);
  var sliver = topContent.firstChild;
  while(sliver && !/\bmgr-navigation-sliver\b/.test(sliver.className))
    sliver = sliver.nextSibling;
  if(!sliver) return false;
  className.add(bottomContent,'mgr-navigation-content-hidden');
  //insert_before(sliver.cloneNode(true),get_by_id(this.contentId));
  if( window.gs && window.gs.opennav )
    insert_before(get_by_id(this.contentId), topContent.firstChild);
  else
    className.add(topContent,'mgr-navigation-content-hidden');
  this.addEvent(topContent,'click','checkClick');
  //this.addEvent(bottomContent,'click','checkClick');
  return true;
};

Nav.prototype.checkForBottomLocation = function() {
  var bottomContent = get_by_id(this.bottomId);
  var y = FindXY(bottomContent).y;
  var pY = getFrameSize().y;
  if(y<pY)
    className.add(bottomContent,'mgr-navigation-never-display');
  else
    className.kill(bottomContent,'mgr-navigation-never-display');
};

Nav.prototype.checkClick = function(e) {
  var srcEl = get_srcEl(e);
  var depth = 3;
  var rE = new RegExp('#'+this.contentId);
  while(!rE.test(srcEl.href)
	&& (srcEl = srcEl.parentNode) && --depth);
  if( rE.test(srcEl.href) ) {
    preventDefault(e);
    depth = 5;
    while((srcEl = srcEl.parentNode))
      if( srcEl.id == this.topId
	  || srcEl.id == this.bottomId )
	break;
    if( srcEl.id == this.topId
	|| srcEl.id == this.bottomId ) {
      if( className.test(srcEl, 'mgr-navigation-content-hidden') ) {
	className.kill(srcEl, 'mgr-navigation-content-hidden');
	if( srcEl.id == this.topId ) {
	  className.add(get_by_id(this.bottomId), 'mgr-navigation-content-hidden');
	  insert_before(get_by_id(this.contentId), srcEl.firstChild);
	}
	else {
	  className.add(get_by_id(this.topId),'mgr-navigation-content-hidden');
	  srcEl.appendChild(get_by_id(this.contentId));
	}
      }
      else
	className.add(srcEl,'mgr-navigation-content-hidden');

      if( srcEl.id == this.bottomId )
	window.scrollTo(FindScrollOffset().x, 100000000);
      else
	window.scrollTo(FindScrollOffset().x, 0);
    }
    this.checkForBottomLocation();
  }
};

/* Nav widget JS: -- For the lack of better place I am leaving this JS here */
function _mgr_navWidgets(widgetContentId, loadingIndicatorId, tabMenuClass,subTabMenuClass, selectedTabClass ) {
  var currentWidgetId = getId(get_by_tag('DIV', get_by_id(widgetContentId))[0]);

  function _mgr_widgetHide() {
    var op = 100;
    get_by_id(currentWidgetId).style.display = 'none';
    get_by_id(loadingIndicatorId).style.display = '';
  }

  function _mgr_widgetShow(id) {
    get_by_id(id).style.display = '';
    get_by_id(loadingIndicatorId).style.display = 'none';
    currentWidgetId = id;
  }

  var request = false;
  function _mgr_widgetLoad(a) {
    if(request) return;
    request = true;
    var uri = a.href;
    a = getId(a);
    (new XHConn()).connect(uri, 'GET', '', function(x) {
	var div = make_el('DIV');
	div.innerHTML = x.responseText;
	a = get_by_id(a); a.widgetId = a.id; a.id = '';

	var widget = div.firstChild;
	while(widget.nodeType == 3 && (widget = widget.nextSibling));
	if(widget) {
	  widget.id = a.widgetId;
	  get_by_id(widgetContentId).appendChild(widget);
	  _mgr_widgetShow(widget.id);
	  request = false;
	}
      });
  }

  function _mgr_widgetTriger(e) {
    var srcEl = get_srcEl(e), a = null;

    while( srcEl && !className.test(srcEl, subTabMenuClass) ) {
      if( srcEl.tagName == 'A' ) a = srcEl;
      srcEl = srcEl.parentNode;
    }

    if( a && !className.test(a, selectedTabClass) && srcEl ) {
      preventDefault(e);
      _mgr_widgetHide();
      if( a.widgetId ) _mgr_widgetShow(a.widgetId);
      else _mgr_widgetLoad(a);
    }
  }

  var uls = get_by_tag('UL');
  for( var i = uls.length-1, ul;
       (ul=uls[i]) && !className.test(ul, tabMenuClass); i-- );

  if( ul )
    addEvent(ul,'click',_mgr_widgetTriger,false);
  var lis = get_by_tag('LI', ul), li;

  for( i=0; (li = lis[i]); i++ )
    if( className.test(li, selectedTabClass)
	&& className.test(li.parentNode, subTabMenuClass) ) {
      get_by_tag('A', li)[0].widgetId = currentWidgetId;
      break;
    }
  uls = ul = lis = li = null;
}


function ScreenCover() {
  ScreenCover.prototype.ids++;
  this.coverId ='screen-cover-'+ScreenCover.prototype.ids;
  make_el('DIV',{className:'screen-cover',
			     id:this.coverId,
			     style:{display:'none'}},document.body);
  var me = this;
  addEvent(window,'resize',function(){me.sizeCover();},false);
};
ScreenCover.prototype.ids = 0;

ScreenCover.prototype.addCover = function() {
  this.isAdded = true;
  var div = get_by_id(this.coverId);
  className.add(get_by_tag('html')[0],'grayedout');
  div.style.display = 'block';
  set_opacity(div,50);
  this.sizeCover();

};

ScreenCover.prototype.sizeCover = function(div) {
  if(this.isAdded) {
    if(!div) div = get_by_id(this.coverId);
    var html = get_by_tag('html')[0];
    div.style.width = '99%';
    div.style.height = '150%';
    var docXY = doc_size();
    div.style.width = docXY.x+'px';
    div.style.height = docXY.y+'px';
  }
};
ScreenCover.prototype.hideCover = function(div) {
  if(!div) div = get_by_id(this.coverId);
  div.style.display = 'none';
};
ScreenCover.prototype.fadeCover = function() {
  var div = get_by_id(this.coverId);
  this.hideCover(div);
  //Fade.Out(div,this.hideCover,0);
  this.isAdded = false;
  className.kill(get_by_tag('html')[0],'grayedout');
};

function IFramePop() {
//   this.loaderBar = new LoaderBar();
  this.screenCover = new ScreenCover();
  IFramePop.prototype.ids++;
  this.frameId = 'frame-pop-'+IFramePop.prototype.ids;
  this.popId = 'pop-'+IFramePop.prototype.ids;
  var div = make_el('DIV',{className:'box iframe-box',
			   id:this.popId,
			   style:{display:'none'}},document.body);
  for(var i=1; i<4; i++)
    div = make_el('DIV',{className:'unionskin'+i},div);
};
IFramePop.prototype.ids = 0;

IFramePop.prototype.addFrame = function(url,arg) {
  if (arg)
    this.kill();
  var div = get_by_id(this.popId);
  div.style.top = FindScrollOffset().y+50+'px';
  var frameHolder = div.firstChild.firstChild.firstChild;//<-- Perhaps we should kill the rounded corners so we dont have to do this.
  var iframe = make_el('IFRAME',{src:url,id:this.frameId,
                                	name:this.frameId,
					allowTransparency:true,
					frameBorder:0,
					style:{height:0 ,border: 'none'}},frameHolder);
//   this.loaderBar.addLoader(frameHolder);
//   this.screenCover.addCover();

  div.style.display = 'block';
};

IFramePop.prototype.reloadPage = function(url) {
  var iframe = get_by_id(this.frameId);
  this.kill();
  if(url){
    window.location.href=url;
  }
  else{
    if(window.location.href.indexOf('?') != -1)
      window.location.href = window.location.href.replace(/\?.*/,'');
    else window.location.href +='?rt='+(new Date).getTime();
  }
};

IFramePop.prototype.frameLoad = function() {
  var iframe = get_by_id(this.frameId);
  if(iframe) {
    var oDoc = get_iframe_doc(iframe);
    this.frameResize(iframe,oDoc);
    this.screenCover.addCover();
/*     this.screenCover.sizeCover(); */
  }
};

IFramePop.prototype.frameResize = function(iframe,oDoc) {
  if(!iframe) iframe = get_by_id(this.frameId);
  if(!oDoc) oDoc = get_iframe_doc(iframe);
  if(oDoc.body) {
    var y = oDoc.body.offsetHeight+1;
    iframe.style.height = y+'px';
    oDoc.body.style.overflowY = 'hidden';
  }
};

IFramePop.prototype.frameUnLoad = function() {
//   if(!this.noLoader) {
//     var iframe = get_by_id(this.frameId);
//     if(iframe.src.toLowerCase() != 'about:blank') {
//       this.loaderBar.addLoader(iframe.parentNode);
//       iframe.style.height = 0;
//     }
//   }
};

IFramePop.prototype.kill = function() {
  var div = get_by_id(this.popId);
  if (!div)
    return;
  this.noLoader = true;
  //div.innerHTML = '';
  remove_el(div);
  this.noLoader = false;
  this.screenCover.fadeCover();
};

function checkForGrayout(e) {
  var srcEl = get_srcEl(e);
  while(!className.test(srcEl,'grayout')
	&& (srcEl = srcEl.parentNode));
  if(srcEl) {
    preventDefault(e);
    window.Grayout = new IFramePop();

    window.Grayout.addFrame(srcEl.href.replace(srcEl.hash, '')+"?js=grayout");
    return false;
  };
  return true;
};

addEvent(document,'click',checkForGrayout,false);
addEvent(window,'unload',function(){
    if(window.Grayout)
      window.Grayout.kill();
},false);

/*ugly bad hack for safari follows*/
if(isSafari) {
  function grayout_prevent_a_action() {
    var As = get_by_tag('A');
    for(var i=0,l=As.length; i<l; i++)
      if(className.test(As[i],'grayout'))
	As[i].onclick = function(){return false;}
  };
  addEvent(window,'load',grayout_prevent_a_action,false);
};


function pagerJumpShow(el) {
  if ( !el.isOpened && document && document.body ) {
    el.isOpened = true;
    var box = make_el("div", { className: "'.$class_prefix.'pager-jump-holder", innerHTML: el.formText });
    el = getId(el);
    box.style.position = "absolute";
    box.style.zIndex = "99999999";

    function posBox() {
      var b = get_by_id(box);
      var l = get_by_id(el);
      var pos = FindXY(l);
      b.style.top = pos.y+l.offsetHeight+"px";
      b.style.left = pos.x+"px";
    }

    document.body.appendChild(box);
    box = getId(box);
    posBox();

    function onclick(e) {
      var srcEl = get_srcEl(e);
      while( srcEl.id != box && (srcEl = srcEl.parentNode) );
      if ( !srcEl ) {
	removeEvent(document, "click", onclick, false);
	removeEvent(window, "resize", posBox, false);
	remove_el(get_by_id(box));
	get_by_id(el).isOpened = false;
      }
    }

    setTimeout(function() {
	addEvent(document, "click", onclick, false);
	addEvent(window, "resize", posBox, false);
      }, 0);
  }
}


function google_ad_request_done(google_ads)
{
  if (!google_ads.length)
    return;
  var i = 0, l = google_ads.length;
  var adsPerUnit = Math.floor(google_ads.length/google_ad_request_done.ads_ids.length);
  var classes = ['resultboxeven','resultboxodd'];
  var addHolder;
  while ((addHolder = document.getElementById(google_ad_request_done.ads_ids.shift()))) {
    var res = ['<p><strong>Sponsored Matches</strong></p>'];
    var lim = Math.min(adsPerUnit+i, l);
    for ( ;i < lim; i++) {
      res.push('<div class="', classes[i%2], '"><a style="font-size:13px" href="', google_ads[i].url, '" target="_blank">', google_ads[i].line1, '</a><br><p style="margin-bottom:5px;">', google_ads[i].line2, '<br>', google_ads[i].line3, '</p><p><small>', google_ads[i].visible_url, '</small></div>');
    }
    res.push('<div style="margin: 10px 0 30px 0;">Ads by Google</div>');
    addHolder.innerHTML = res.join('');
  }
}
google_ad_request_done.ads_ids = [];
