var loader = new YAHOO.util.YUILoader({
    require: ['event'],
    filter: "DEBUG",
    onSuccess: function() {
        YAHOO.log("event successfully loaded");
        YAHOO.util.Event.addListener("thumbContainer", "click", onClickCallback); 
        YAHOO.util.Event.addListener("thumbContainer", "mousedown", onMouseDownCallback); 
        YAHOO.util.Event.addListener("nav", "click", onExposClickCallback);
        YAHOO.util.Event.addListener("displayimg", "load", onDisplayImgCallback);
        YAHOO.util.Event.addListener("DisplayLeft", "load", onDisplayLeftCallback);
        YAHOO.util.Event.addListener("DisplayRight", "load", onDisplayRightCallback);
        YAHOO.util.Event.addListener("email", "click", onEmailClickCallback);
    },
    onFailure: function(){
        alert("error: " + YAHOO.lang.dump(o));
    }
});
loader.insert();
function onMouseDownCallback(e){

    var elTarget = YAHOO.util.Event.getTarget(e);  
 	while (elTarget.id != "thumbContainer") {
		//are you an image?
		if((elTarget.tagName.toUpperCase() == "IMG") && (images[elTarget.id] != undefined) && (images[elTarget.id].large != undefined)) {
			//yes, an IMG and one we have data about 
			var imgObj = document.getElementById("displayimg");
			/*@cc_on @*/
            /*@if (@_win32)
 			//imgObj.style.visibility="hidden";
            /*@end @*/
            imgObj.setAttribute("alt", "Loading");
            imgObj.setAttribute("src", "blank.png");
			//and then stop looking:
			break;
		} else {
			//wasn't the container, but wasn't an image; so
			//let's step up the DOM and keep looking:
			elTarget = elTarget.parentNode;
		}
	}
  } 
  
function onClickCallback(e) {
    
    var elTarget = YAHOO.util.Event.getTarget(e);  
 	while (elTarget.id != "thumbContainer") {
		//are you an image?
		if((elTarget.tagName.toUpperCase() == "IMG") && (images[elTarget.id] != undefined) && (images[elTarget.id].large != undefined)) {
			//yes, an IMG and one we have data about 
			var imgObj = document.getElementById("displayimg");
			/*@cc_on @*/
            /*@if (@_win32)
 			//imgObj.style.visibility="hidden";
            /*@end @*/
            imgObj.setAttribute("alt", "Loading");
            imgObj.setAttribute("src", "blank.png");
			imgObj.setAttribute("src", images[elTarget.id].large);
			if(images[elTarget.id].width != undefined)
			    imgObj.setAttribute("width", images[elTarget.id].width);
			if(images[elTarget.id].height != undefined)
			    imgObj.setAttribute("height", images[elTarget.id].height);
			if(images[elTarget.id].title != undefined)
			    imgObj.setAttribute("alt", images[elTarget.id].title);
	        //alert("click on "+elTarget.id+" with "+images[elTarget.id].large);
			//and then stop looking:
			break;
		} else {
			//wasn't the container, but wasn't an image; so
			//let's step up the DOM and keep looking:
			elTarget = elTarget.parentNode;
		}
	}
  } 
function onExposClickCallback(e) {
    var elTarget = YAHOO.util.Event.getTarget(e);  
 	while (elTarget.id != "nav") {
	    //are you an image?
		if((elTarget.tagName.toUpperCase() == "IMG") && (elTarget.id == "prev") && (exposVar[ (index-1)<0 ? totalPages-1 : index-1 ] != undefined)) {
			    //yes, an IMG and one we have data about 
                
                index = (index-1)<0 ? totalPages-1 : index-1;
                var imgObj = document.getElementById("DisplayLeft");
                if(exposVar[index][0] != undefined)
                {
                    /*@cc_on @*/
                    /*@if (@_win32)
 			        imgObj.style.visibility="hidden";
                    /*@end @*/
                    imgObj.setAttribute("src", exposVar[index][0]);
                }
                if(exposVar[index][1] != undefined)
                    imgObj.setAttribute("alt", exposVar[index][1]);
                if(exposVar[index][2] != undefined)
                    imgObj.setAttribute("width", exposVar[index][2]);
                if(exposVar[index][3] != undefined)
                    imgObj.setAttribute("height", exposVar[index][3]);
                if(exposVar[index][4] != undefined)
                    imgObj.style.marginTop = exposVar[index][4];    
                var txtObj = document.getElementById("DisplayRight");
                if(exposVar[index][5] != undefined)
                {
                    /*@cc_on @*/
                    /*@if (@_win32)
 			        txtObj.style.visibility="hidden";
                    /*@end @*/
                    txtObj.setAttribute("src", exposVar[index][5]);
                }
                if(exposVar[index][6] != undefined)
                    txtObj.setAttribute("alt", exposVar[index][6]);
                if(exposVar[index][7] != undefined)
                    txtObj.setAttribute("width", exposVar[index][7]);
                if(exposVar[index][8] != undefined)
                    txtObj.setAttribute("height", exposVar[index][8]);
			    //and then stop looking:
			    break;
			    }
		else if((elTarget.tagName.toUpperCase() == "IMG") && (elTarget.id == "next") && (exposVar[(index+1) % totalPages] != undefined)) {
			    //yes, an IMG and one we have data about 
                index = (index+1) % totalPages;
                var imgObj = document.getElementById("DisplayLeft");
                if(exposVar[index][0] != undefined)
                {
                    /*@cc_on @*/
                    /*@if (@_win32)
 			        imgObj.style.visibility="hidden";
                    /*@end @*/
                    imgObj.setAttribute("src", exposVar[index][0]);
                }
                if(exposVar[index][1] != undefined)
                    imgObj.setAttribute("alt", exposVar[index][1]);
                if(exposVar[index][2] != undefined)
                    imgObj.setAttribute("width", exposVar[index][2]);
                if(exposVar[index][3] != undefined)
                    imgObj.setAttribute("height", exposVar[index][3]);
                if(exposVar[index][4] != undefined)
                    imgObj.style.marginTop = exposVar[index][4];   
                var txtObj = document.getElementById("DisplayRight");
                if(exposVar[index][5] != undefined)
                {
                    /*@cc_on @*/
                    /*@if (@_win32)
 			        txtObj.style.visibility="hidden";
                    /*@end @*/
                    txtObj.setAttribute("src", exposVar[index][5]);
                }
                if(exposVar[index][6] != undefined)
                    txtObj.setAttribute("alt", exposVar[index][6]);
			    if(exposVar[index][7] != undefined)
                    txtObj.setAttribute("width", exposVar[index][7]);
                if(exposVar[index][8] != undefined)
                    txtObj.setAttribute("height", exposVar[index][8]);
			    //and then stop looking:
			    break;
			    }
        else {
			//wasn't the container, but wasn't an image; so
			//let's step up the DOM and keep looking:
			elTarget = elTarget.parentNode;
		}
    }
}

function onDisplayImgCallback(e)
{
    var elTarget = YAHOO.util.Event.getTarget(e);  
    if(elTarget.id == "displayimg")
        elTarget.style.visibility="visible";
}
function onDisplayLeftCallback(e)
{
    var elTarget = YAHOO.util.Event.getTarget(e);  
    if(elTarget.id == "DisplayLeft")
        elTarget.style.visibility="visible";
}
function onDisplayRightCallback(e)
{
    var elTarget = YAHOO.util.Event.getTarget(e);  
    if(elTarget.id == "DisplayRight")
        elTarget.style.visibility="visible";
}

function onEmailClickCallback(e)
{
    var elTarget = YAHOO.util.Event.getTarget(e);
    if (elTarget.id == "email") {
        var toExec = "mailto:";
        toExec += "goldfish94102"
        toExec += "@";
        toExec += "gmail.com"
        window.location = toExec;
    }
}
