$(function(){
	/**
	 * New swapper script. Hooks old Dreamweaver code, but old code is depreciated
	 * in favor of class "swapme" on images. Comples with Kapelle naming
	 * conventions. Someday should be expired in favor of CSS rollovers.
	 */
	Swapper = {

		bind:function() {
			/*
			this.imgs = [];
			var elem= $('a');
			var arr = new Array();
			for(i = 0, iarr = 0; i < elem.size(); i++) {
					var att = elem[i].getAttribute("onmouseover");
					if(typeof(att) == 'function') att = att.toString();
					if(att && att.indexOf("MM_")) {
						 $(elem[i]).find('img').addClass('swapme');
					}
			}
			*/
			if($(".swapme")) $(".swapme").each(function() {
				var el = $(this);
				el.removeAttr('onmouseover');
				el.removeAttr('onMouseOver');
				el.removeAttr('onmouseout');
				el.removeAttr('onMouseOut');
				var src = el.src;
				// Let's get both the default and highlight versions
				if(src) {
					Swapper.imgs.push($("<img src="+src+" />"));
					Swapper.imgs.push($("<img src="+src.replace(/(.*)\.(.*?)$/, '$1roll.$2')+" />"));
				}
				el.unbind('mouseover');
				el.bind('mouseover', function(ev) {ev.preventDefault(); Swapper.over(this)});
				el.unbind('mouseout');
				el.bind('mouseout', function(ev) {ev.preventDefault(); Swapper.out(this)});
			});
		},




		over:function(el) {
			el = $(el)[0];
			if(el.tagName && (el.tagName.toUpperCase() != 'IMG' && el.tagName.toUpperCase() != 'INPUT')) {
				el = el.getElement('img');
				if(!el) return;
			}
			if(el.src) {
				el.src = (el.src.indexOf('roll') < 0)?el.src.replace(/(.*)\.(.*?)$/, '$1roll.$2'):el.src.replace(/(.*)roll(.*)$/, '$1$2');
			}
		},




		out:function(el) {
			el = $(el)[0];
			if(el.tagName && (el.tagName.toUpperCase() != 'IMG' && el.tagName.toUpperCase() != 'INPUT')) {
				el = el.getElement('img');
				if(!el) return;
			}
			if(el.src) {
				el.src = (el.src.indexOf('roll') < 0)?el.src.replace(/(.*)\.(.*?)$/, '$1roll.$2'):el.src.replace(/(.*)roll(.*)$/, '$1$2');
			}
		},




		init:function() {
			this.bind();
		}
		
};

Swapper.init();
});
