//addLoadEvent(function () {init_bg_switch('dock')});

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function')
		window.onload = func;
	else
		window.onload =  function() {oldonload(); func();}
}

function image_swap(n) {
	var m = document.getElementById('main_image');
	if(n == '_prev') {
		n = parseInt(m.getAttribute('current')) -1;
		if(n<0)	n = m.getAttribute('count')-1;
	}
	if(n == '_next') {
		n = parseInt(m.getAttribute('current')) +1;
		if(n >= m.getAttribute('count')) n=0;
	}

	/* Change Image */
	m.src = (document.getElementById('relimages_'+n)).getAttribute('large_src');
	m.setAttribute('current', n);
	
	/* Change Caption */
	(document.getElementById('caption')).innerHTML = 
		(document.getElementById('caption_'+n)).innerHTML;
	
	
	/* Change Link to Gallery */
	if(m.parentNode.href) {
		h = m.parentNode.href;
		m.parentNode.href = h.substring(0, h.indexOf('?')) + '?i='+n;
	}
	
	/* Send Photo View to Analytics */
	var pageTracker = _gat._getTracker("UA-2621936-1");
	pageTracker._trackPageview('photos'+location.pathname+'/'+n);
	
	return false;
}

function popular(id, title) {
	var m = new Image();
	m.src = "http://media.herald-dispatch.com/z4m/popular.php?id="+id+"&t="+title;
}

function getHTTP(elementID,URL, onsuccess, onerror, event) {  
    wpanel= document.getElementById(elementID);  
    wpanel.style.visibility = 'visible';  
  
    var req = null;  
    if(window.XMLHttpRequest) {  
    	try {
        req = new XMLHttpRequest();   
      } catch (e) {}
    } else {
    	if (window.ActiveXObject)  {
    		try {
        	req  = new ActiveXObject('Microsoft.XMLHTTP');      
      	} catch (e) {}
      }
    }	
          
    req.onreadystatechange = function () {  
        if (req.readyState == 4) {  
            if (req.status == 200){  
                wpanel.style.backgroundImage = 'none';  
                wpanel.innerHTML = req.responseText;
                if(onsuccess) {
                	onsuccess(event);
                }
            }  
            else{  
                wpanel.style.backgroundImage = 'none';  
                wpanel.innerHTML = 'Error';  
                if(onerror) {
                	onerror(event);
                }
            }  
        }  
    }  
    req.open('GET', URL, true);  
    req.send(null);  
}  



/* Used by the Classifieds Dock */
/*
function init_bg_switch(id) {
	var x = (document.getElementById(id)).getElementsByTagName('a');
	for(var i=0; i<x.length; i++) {
		x[i].onmouseover = show_bg_image;
		x[i].onmouseout = hide_bg_image;
	}
}
function show_bg_image() {
	this.firstChild.style.display = 'none';
	this.style.backgroundPosition = 'center bottom';
}
function hide_bg_image() {
	this.style.backgroundPosition = '500% bottom';
	this.firstChild.style.display = '';
}
*/

