
// set the image for the banner
function setBanner() {
    img = $('banner');
    if (typeof img != 'undefined') {
        arr = window.location.pathname.split('/')
        // add test here for the image
        name = arr[arr.length-1];
        name = name.split('.')[0];
        if (name == '') {
            name = 'index';
        }
        img.setStyle({'background-image':'url(/images/banners/'+name+'.jpg)'});
    }
}

Event.observe(window, 'load', setBanner, false );

// set images for open window to enlargement
function imageExpand(el) {
    src = el.parent.src
    w = el.parent.width
    h = el.parent.height
    openWin(src, w, h, el.alt);
}

function imageInitialize() {
  imgs = $A(document.getElementsByClassName('expand'));
  imgs.each(function(img) {
    //Event.observe(img, 'mouseup', imageExpand, false);
    new Thumbnail(img);
    img.setStyle({'cursor':'pointer'});
  });
}

Event.observe(window, 'load', imageInitialize, false);

var Thumbnail = Class.create();
Thumbnail.prototype = {
    initialize: function(img) {
        this.obj = img;
        this.obj.parent = new Image()
        this.obj.parent.src = this.obj.src.replace('.jpg', '_fullsize.jpg');
        //alert(this.obj + ' ' + this.obj.parent);
        Event.observe(this.obj, "mouseup", this.mouseup);
    },
    mouseup: function(event) {
        obj = Event.element(event);
        imageExpand(obj);
    }
}

var newWin = null;
function openWin(src,w,h,name,size) {

	if (window.screen) {
		ah=screen.height - 80;
        if(ah > h) {
            ah = h;
        }
	} else {
		ah=h;
	}
    l=3;
    t=3;
	prefs = "left="+l+","
		+"top="+t+","
		+"screenX="+l+","
		+"screenY="+t+","
		+"width="+w+","
		+"height="+ah+","
		+"innerWidth="+w+","
		+"innerHeight="+ah+","
		+"toolbar=no,"
		+"location=no,"
		+"directories=no,"
		+"status=no,"
		+"menubar=no,"
		+"scrollbars=no,"
		+"resizable=no"
	newWin=window.open("",("image_"+w+"_"+h),prefs)

	newWin.document.open()
	newWin.document.clear()
	newWin.document.write(
	"<html><head>\n"
	+"<title>" + name + "</title>\n"
	+"<style><!-\n"
    +"html{height:100%;}\n"
	+"body{margin:0px;padding:0px;background:no-repeat url('" + src + "') top left;"
    +"cursor:pointer;height:100%;"
    +"}\n"
	+"img{margin:0px;padding:0px;border:0px;}\n"
	+"div.box{margin:0px;padding:0px;border:1px solid #333;"
    +"font-family:verdana, sans-serif;font-size:10px;"
    +"margin:3px;}\n"
	+"-></style>\n"
	+"</head>\n"
	+"<body bgcolor=#ffffff background="
    +src
    +" onclick='window.close()'"
    +">\n"
    +"<table height='100%' width='100%'><tr>"
    +"<td valign='bottom' height='100%' width='100%'>\n"
    +"<div class='box' style='background:#f8f1f2;float:right;'"
    +">Click on image to close window</div>"
    +"</td></tr></table>\n"
    +"</body>\n"
    +"</html>\n"
	)
	newWin.document.close()
	newWin.focus()
}

