function init() {
 document.onmouseup = function(){hideTip();};

 if (navigator.userAgent.toLowerCase().indexOf('msie 5')!=-1 || navigator.userAgent.toLowerCase().indexOf('msie 6')!=-1) {
  document.write('<style type="text/css">* html .tl, * html .tr, * html .bl, * html .br, * html .cc, * html .tc, * html .bc, * html .cl, * html .cr {background-image: url(img/bub.gif);}</style>');

 }

}

function $(eid) {
 return document.getElementById(eid);
}


function filterThis(link, filnum, filter) {
 var i=0, item; 
 while (item = $('gallery').getElementsByTagName('a')[i++]) {
  if (item.className.indexOf('item')==-1) continue;
  item.style.display = (item.className.indexOf(filter)==-1) ? 'none' : 'block';
 }
 //$('filtertext').innerHTML = link.innerHTML;
 $('removefilter').style.display='none';
 $('removefilter2').style.display='none';
 $('removefilter'+filnum).style.display='inline';
 return false;
}
function viewAll() {
 filterThis(false, '', 'item');
 $('removefilter').style.display='none';
 $('removefilter2').style.display='none';
}

function viewThis(item) {
 if (item.id=='activeitem') {
  hideTip();
  return false;
 }
 showTip(item, item.nextSibling.innerHTML, function() {
   if ($('activeitem')) $('activeitem').id='';
   $('gallery').className='';
 });
 $('gallery').className='focused';
 item.blur();
 item.id='activeitem';
 return false;
}

hidetiphandler = false;
function showTip(obj, tipcontent, handler) {
 hideTip();
 hidetiphandler = handler;

 $('tipcontent').style.top = $('tipcontent').style.left = '-100px';
 $('tipcontent').style.visibility='hidden';
 $('tipcontent').style.display='block';

 $('tipcontent').style.width='auto';
 $('tipcontent').innerHTML = tipcontent;
 if ($('tipcontent').offsetWidth > 210) {
  $('tipcontent').style.width='210px';
 }

 var pos = getPos(obj);
 var tpos = pos.y - $('tipcontent').offsetHeight;
 var lpos = Math.round(pos.x + (obj.offsetWidth/2) - ($('tipcontent').offsetWidth/2));
 if (lpos < 0) lpos=0;

 $('tipcontent').style.top = tpos +'px';
 $('tipcontent').style.left = lpos +'px';
 $('tipcontent').style.visibility='visible';

 $('tip').style.left = lpos-17 +'px';
 $('tip-in').style.width = $('tipcontent').offsetWidth+2 +'px';
 $('tip').style.top = tpos-14 +'px';
 $('tip-in').style.height = $('tipcontent').offsetHeight-2 +'px';
 $('tip').style.display='block';
}

function hideTip() {
 $('tip').style.display='none';
 $('tipcontent').style.display='none';
 if (hidetiphandler) hidetiphandler();
 hidetiphandler=false;
}



function getPos(obj, stopclass) {
 if (!stopclass) stopclass='#';
 var coord={x:obj.offsetLeft, y:obj.offsetTop};
 while (obj = obj.offsetParent) {
  if (obj.className == stopclass || obj.id == stopclass) return coord;
  coord.x += obj.offsetLeft;
  coord.y += obj.offsetTop;
 }
 return coord;
}

function stopEvent(e) {
 if (! e) e = window.event;
 e.cancelBubble=true;
 if (e.stopPropagation) e.stopPropagation();
}

function killEvent(e) {
 if (! e) e = window.event;
 e.returnValue=false;
 e.cancelBubble=true;
 if (e.stopPropagation) e.stopPropagation();
 if (e.preventDefault) e.preventDefault();
 return false;
}