function addEvent(elem, type, handle) {
        if ( elem.addEventListener ) {
                elem.addEventListener( type, handle, false );
        } else if ( elem.attachEvent ) {
                elem.attachEvent( "on" + type, handle );
        }
}
function addLoadEvent(handle) {
        addEvent(window, 'load', handle);
}

addLoadEvent(function() {
        var navLIs = document.getElementById("navWrap").getElementsByTagName("li");
        for (var i=0; i<navLIs.length; i++) {
                navLIs[i].onmouseover = function() {
                        if (this.className.match("parent") != null) {
                                this.className += " both";
                        }
                        this.className += " active";
                }
                navLIs[i].onmouseout = function() {
                        this.className = this.className.replace(/active/g,"");
                        this.className = this.className.replace(/both/g,"");
                }
        }
});

(function() {

var slidespeed = 1,
	imgSrc = "/static/img/clientLogos.gif",
	imgAlt = "iContact Clients",
	enabled = true,
	actualwidth,
	slider,
	slider2,
	loaded;

addEvent(window, 'load', function() {
	var wrapper = document.createElement('div');
	wrapper.style.position = 'absolute';
	wrapper.style.width = '2000px';
	addEvent(wrapper, 'mouseover', function() {
		enabled = false;
	});
	addEvent(wrapper, 'mouseout', function() {
		enabled = true;
	});

	slider = document.createElement('div');
	slider.style.position = 'absolute';
	slider.style.left = '0px';
	slider.style.top = '0px';
	wrapper.appendChild(slider);
	
	var img = document.createElement('img');
	slider.appendChild(img);
	
	addEvent(img, 'load', function() {
		// prevent this code from running when the second image is loaded
		if (!loaded) {
			loaded = true;
			document.getElementById('scroller').appendChild(wrapper, true);
			actualwidth = slider.offsetWidth + 10;
			slider.style.width = actualwidth + 'px';
			
			slider2 = slider.cloneNode(true);
			slider2.style.width = actualwidth + 'px';
			slider2.style.left = actualwidth + "px";
			wrapper.appendChild(slider2);
			
			setInterval(slideleft, 30);
		}
	});
	
	img.src = imgSrc;
	img.alt = imgAlt;
	
});

function slideleft() {
	if (!enabled) { return; }
	if (parseInt(slider.style.left) > (actualwidth*(-1)+8)) {
		slider.style.left=parseInt(slider.style.left)-slidespeed+"px"
	} else {
		slider.style.left=parseInt(slider2.style.left)+actualwidth+"px"
	}
	if (parseInt(slider2.style.left) > (actualwidth*(-1)+8)) {
		slider2.style.left=parseInt(slider2.style.left)-slidespeed+"px"
	} else {
		slider2.style.left=parseInt(slider.style.left)+actualwidth+"px"
	}
}

})();
