/*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

	WebCore: Image control scripts
	Abyss Studios Ltd. (c) 2004-2007

	history:
		060318 - creation -=AGi=-

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/


function imageControl_GetEventTarget(e)
{
	if (!e) e = event;
	if (e) {
		if (e.srcElement) return e.srcElement;
		if (e.target) return e.target;
		//if (e.nodeType == 3) 	targ = targ.parentNode; // defeat Safari bug
	}
	return null;
}

//---------------------------------------------------------------

function imageControl_HotCoolHoverSequence_OnOver(e)
{
	e = imageControl_GetEventTarget(e);
	if (e==null) return;
	if (e.src) {
		e.src = e.src.replace('cool', 'hot');
	}
	else if (e.style) {
		e.style.backgroundImage = e.style.backgroundImage.replace('cool', 'hot');
    }
	else if (e.currentStyle) {
		s = e.currentStyle.backgroundImage.replace('cool', 'hot');
		e.currentStyle.backgroundImage = s;
    }	    
}


function imageControl_HotCoolHoverSequence_OnOut(e)
{
	e = imageControl_GetEventTarget(e);
    if (e==null) return;
    if (e.src) {
        e.src = e.src.replace('hot', 'cool');
    }
    else if (e.style) {
		e.style.backgroundImage = e.style.backgroundImage.replace('hot', 'cool');
    }
	else if (e.currentStyle) {
		s = e.currentStyle.backgroundImage.replace('cool', 'hot');
		e.currentStyle.backgroundImage = s;
    }
}

function imageControl_HotCoolHoverSequence_OnMouseDown(e)
{
	e = imageControl_GetEventTarget(e);
	if (e==null) return;

	navurl = e.getAttribute('navigateurl');
	if (navurl) {
		document.location.href = navurl;
	}
}

function imageControl_HotCoolHoverSequence_Install(e, img)
{
    if (typeof(e)=='string') e = document.getElementById(e);
	e.onmouseover = imageControl_HotCoolHoverSequence_OnOver;
	e.onmouseout = imageControl_HotCoolHoverSequence_OnOut;
	if (img!=null) {
		if (e.src) {
			e.src = img;
		}
		else if (e.style && e.style.backgroundImage) {
			e.style.backgroundImage = img;
		}		
		e.onmouseout(e);
	};

	navurl = e.getAttribute('navigateurl');
	if (navurl) {
		e.onmousedown = imageControl_HotCoolHoverSequence_OnMouseDown;
	}
}

function imageControl_HotCoolHoverSequence_InstallList(list, img)
{
    for(i = 0; i < list.length; i++) {
        imageControl_HotCoolHoverSequence_Install(list[i]);
    }
}

function imageControl_HotCoolHoverSequence_InstallTagClass(tag, _class, img)
{
    elementList = document.getElementsByTagName(tag);
    for(i = 0; i < elementList.length; i++) {
        if (_class==null || elementList[i].className==_class) {
            imageControl_HotCoolHoverSequence_Install(elementList[i]);
        }
    }
}

