/**
 * Unobtrusive Image Rollovers
 * By: Paul McLanahan <paul dot mclanahan at digital insight>
 */
var Roll = {
    
    imgObjects: [],
    
    init: function(){
		
	    // 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);
		
        if(!document.getElementsByTagName)return;
        all_links = document.getElementsByTagName('a');
        for(var i = 0; i < all_links.length; i++){
            var linkObj = all_links[i]; 
            if (linkObj.className && (' ' + linkObj.className + ' ').indexOf(' rollover ') != -1){
                if (linkObj.childNodes && 
                    linkObj.childNodes.length == 1 && 
                    linkObj.firstChild.nodeName.toLowerCase() == 'img' &&
                    /_off\.[a-z]{3}$/.test(linkObj.firstChild.src)){
                    // preload rollover images
                    Roll.imgObjects[Roll.imgObjects.length] = new Image();
                    Roll.imgObjects[Roll.imgObjects.length-1].src = linkObj.firstChild.src.replace(/_off(\.[^.]{3})$/,"_on$1");
                    
                    // add mouseover and mouseout event handlers to links
                    libDI.addEvent(linkObj,'mouseover',Roll.imgOn,false);
                    libDI.addEvent(linkObj,'mouseout',Roll.imgOff,false);
                }
            }
        }
    },
    
    imgOn: function(e){
        linkObj = libDI.getTarget(e,'a');
        if(!linkObj)return;
        linkObj.firstChild.src = linkObj.firstChild.src.replace(/_off(\.[a-z]{3})$/,"_on$1");
    },
    
    imgOff: function(e){
        linkObj = libDI.getTarget(e,'a');
        if(!linkObj)return;
        linkObj.firstChild.src = linkObj.firstChild.src.replace(/_on(\.[a-z]{3})$/,"_off$1");
    }
    
}
    
// Dean Edwards/Matthias Miller/John Resig
// Faster initialization than window.onload

/*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
};*/

/* for Mozilla/Opera9 */
if (document.addEventListener) {
    document.addEventListener("DOMContentLoaded", Roll.init, false);
}

/* for Internet Explorer */
/*@cc_on @*/
/*@if (@_win32)
    document.write("<script defer src=diFiles/skins/default/js/ie_onload.js><"+"/script>");
/*@end @*/

/* for Safari */
if (/WebKit/i.test(navigator.userAgent)) { // sniff
    var _timer = setInterval(function() {
        if (/loaded|complete/.test(document.readyState)) {
            Roll.init(); // call the onload handler
        }
    }, 10);
}

/* for other browsers */
libDI.addEvent(window,'load',Roll.init,false);