function pb_contentReady(callback){
    // Dean Edwards/Matthias Miller/John Resig

    function init() {
	 // quit if this function has already been called
	 if (arguments.callee.done) return;
    
	 // flag this function so we don't do the same thing twice
	 arguments.callee.done = true;
    
	 // kill the timer
	 if (_timer) clearInterval(_timer);
    
	 // do stuff
	   callback();
    };
    
    /* for Mozilla/Opera9 */
    if (document.addEventListener) {
	 document.addEventListener("DOMContentLoaded", init, false);
    }

    /* for Internet Explorer */
    /*@cc_on @*/
    /*@if (@_win32)
	 document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
	 var script = document.getElementById("__ie_onload");
	 script.onreadystatechange = function() {
	   if (this.readyState == "complete") {
		init(); // call the onload handler
	   }
	 };
    /*@end @*/
    
    /* for Safari */
    if (/WebKit/i.test(navigator.userAgent)) { // sniff
	 var _timer = setInterval(function() {
	   if (/loaded|complete/.test(document.readyState)) {
		init(); // call the onload handler
	   }
	 }, 10);
    }
    
    /* for other browsers */
    window.onload = init;
}

var pb = function(pbElement){
    
    function tabs(id,event){
	   var tabArea = document.getElementById(id);
	   var tabs;
	   var contents;
	   
	   init();//Start the tabs
        
        var event = event || 'click'; //set the trigger event
        
        switch(event){
            case 'click':
                tabs.onclick = tabChange;
            break;
            case 'hover':
                tabs.onmouseover = tabChange;
            break;
        }
        
        function tabChange(e){
            e = e || window.event;
            var target = e.srcElement || e.target;
		  activate(target.href);
		  return false;
	   }
	   
	   function init(){
		  //Set specific elements in the tab area
		  for(var i=0;i<tabArea.childNodes.length;i++){
			 var current = tabArea.childNodes[i];
			 if(typeof(current) == 'object'){
				cl = current.className || '';
				tabs = (cl == 'tabs') ? current : tabs;
				contents = (cl == 'content') ? current : contents;
			 }
		  }
            if(window.location.hash){ //Check for a hash in the url, if there is one, activate that tab
                activate(window.location.hash);
            }else{ //Activate the first tab 
                var links = tabs.getElementsByTagName('a');
                activate(links[0].href);
            }
	   }
	   
	   function activate(tabHref){
            var contentId = tabHref.match(/[a-zA-Z0-9-_]+$/);
            var singleTabs = tabs.getElementsByTagName('a');
            var sections = contents.childNodes;
		  for(var i=0;i<sections.length;i++){ //Activate the tab content
                if(sections[i].nodeType == 1){
                    sections[i].style.display = (sections[i].getAttribute('id') == contentId) ? 'block' : 'none';
                }
            }
            for(var i=0;i<singleTabs.length;i++){//Set the link class to active
                var currentTab = singleTabs[i].href.match(/[a-zA-Z0-9-_]+$/);
                var pattern = new RegExp(contentId);
                singleTabs[i].className = (pattern.test(currentTab)) ? 'active' : '';
            }
	   }
	   
	   return{
		  init:init,
		  change:activate
	   }
    }
    
    function gallery(id){
        var gal = document.getElementById(id);
        var imgArea = gal.getElementsByClassName('loadarea')[0];
        var preview = imgArea.getElementsByTagName('img')[0];
        var thumbs = gal.getElementsByTagName('a');
        
        init();
        
        function init(){
            for(var i=0;i<thumbs.length;i++){
                thumbs[i] = new tn(thumbs[i]);
            }
        }
        
        function tn(obj){
            this.el = obj;
            this.el.onmouseover = function(){
                changePreview(this.href.replace('/full/','/prev/'));
            }
            this.el.onclick = function(){
                popup(obj.href);
            }
        }
        
        function changePreview(source){
            preview.src = source;
        }
        
        function popup(source){
        
        }
        
        return{
            change:changePreview,
            popup:popup
        }
    }
    
    function toolTip(element,html){
        element.addEventListener('mouseover',showTip,true);
        element.addEventListener('mouseout',hideTip,true);
        
        var tip = document.createElement('div');
        tip.className = 'toolTip';
        tip.style.position = 'absolute';
        tip.style.display = 'none';
        tip.innerHTML = html;
        document.body.appendChild(tip);
        
        function showTip(){
            tip.style.display = 'block';
            element.addEventListener('mousemove',moveTip,false);
        }
        
        function hideTip(){
            tip.style.display = 'none';
            element.removeEventListener('mousemove');
        }
        
        function moveTip(e){
            var pos = cursor(e);
            pos.x += 20;
            tip.style.top = pos.y+'px';
            tip.style.left = pos.x+'px';
        }
    }
    
    function highlightTable(tableId,options){

        var table = document.getElementById(tableId);
        var tbody = table.getElementsByTagName('tbody');
        var tbody = tbody[0];
       
        var defaults = {
            active:'highlight',
            lock:'lock'
        }
               
        if(tbody.addEventListener){
            tbody.addEventListener('mouseover',highlight,true);
            tbody.addEventListener('click',highlight,true);
        }else{
            tbody.attachEvent('onmouseover',highlight);
            tbody.attachEvent('onclick',highlight);
        }
        
        function highlight(e){
            e = e || window.event;
            var target = e.srcElement || e.target;
            rowColor(target.parentNode,e.type);
		  return false;
	   }
        
        function rowColor(el,event){
            var cl = (event == 'click') ? defaults.lock : defaults.active;
            if(event == 'click'){
                for(i=0;i<tbody.childNodes.length;i++){
                    removeClass(tbody.childNodes[i],defaults.lock);
                }
            }
            addClass(el,cl);
            el.onmouseout = function(){
                removeClass(this,defaults.active);
            }
        }
    }
    
    function cards(clName, parent) {
        var els = getElementsByClass(clName, parent);
        
        function Card(el) {
            this.el = el;
            this.loc = null;
            this.bg = getBackgroundColor(el);
            var links = el.getElementsByTagName('a');
            if (links.length > 0) {
                var same = true;
                for (var i = 0; i < links.length; i++) {
                    if (i > 0) {
                        if (links[i].href !== links[i - 1].href) {
                            same = false;
                        }
                    }
                }
                this.loc = (same) ? links[0].href : false;
            }
            
            if (this.loc) {
                var that = this;
                /*this.el.style.cursor = 'pointer';
                this.el.onclick = function () {
                    window.location = that.loc;
                }
                this.el.onmouseover = function () {
                    addClass(that.el,'active');
                }
                this.el.onmouseout = function () {
                    removeClass(that.el,'active');
                }*/
                addClass(that.el,'expanded');
                this.el.onclick = function(){
                    window.location = that.loc;
                }
            }
        }
                
        for(var i = 0; i < els.length; i++){
            var c = new Card(els[i]);
        }
    }
    
    function equalHeight(className,parent){
        
        var els = getElementsByClass(className,parent);
        
        var height = 0;
        
        for(var i=els.length;i;i--){
            var h = els[i-1].offsetHeight || 0;
            height = (h > height) ? h : height;
        }
            
        for(var i=els.length;i;i--){
            els[i-1].style.height = height + 'px';
        }
    }
   
//Helper functions below   
 
    function getElementsByClass(clName,parent){
        var arr = [], cl = new RegExp('/'+clName+'/g');
    
        if(parent){
            if(typeof parent == 'string'){
                parent = document.getElementById(parent);
            }
        }else{
            parent = document.body;
        }
        
        if(parent.getElementsByClassName){
            arr = parent.getElementsByClassName(clName);
        }else{
            var nodes = parent.getElementsByTagName('*');
            for(var i=0;i<nodes.length;i++){
                var node = nodes[i];
                if(node.className.search(cl)){
                    arr.push(node);
                }
            }
        }
        return arr;
    }
    
    function getBackgroundColor(el){
        if(document.defaultView && document.defaultView.getComputedStyle){
            return document.defaultView.getComputedStyle(el,null)['backgroundColor'];
        }else if(el.computedStyle){
            return el.currentStyle.backgroundColor;
        }else{
            return el.style.backgroundColor;
        }
    }
    
    function listen(evnt, func) {
        if (this.addEventListener)  // W3C DOM
            this.addEventListener(evnt,func,false);
        else if (this.attachEvent) { // IE DOM
             var r = this.attachEvent("on"+evnt, func);
         return r;
        }
    }
    
    function cursor(e){
        e = e || window.event;
        var cursor = {x:0, y:0};
        if (e.pageX || e.pageY) {
            cursor.x = e.pageX;
            cursor.y = e.pageY;
        }
        else {
            var de = document.documentElement;
            var b = document.body;
            cursor.x = e.clientX + 
                (de.scrollLeft || b.scrollLeft) - (de.clientLeft || 0);
            cursor.y = e.clientY + 
                (de.scrollTop || b.scrollTop) - (de.clientTop || 0);
        }
        return cursor;
    }
    
    function addClass(el,clName){
        if(el.className){
            if(el.className.indexOf(clName) < 0){
                el.className += ' '+clName;
            }
        }else{
            el.className = clName;
        }
    }
    
    function removeClass(el,clName){
        var classPosition = el.className.indexOf(clName);
        var cl = el.className.replace(clName,'');
        cl = cl.replace(/(^\s+|\s+$|\s{2})/,'');
        el.className = cl;
    }
    
    return {
	   tabs:tabs,
        gallery:gallery,
        tooltip:toolTip,
        table:highlightTable,
        cards:cards,
        equalHeight:equalHeight
    }
}();