// borrowed from http://www.webreference.com/js/column33/image.html
function docjslib_getRealLeft(imgElem) {
	xPos = eval(imgElem).offsetLeft;
	tempEl = eval(imgElem).offsetParent;
  	while (tempEl != null) {
  		xPos += tempEl.offsetLeft;
  		tempEl = tempEl.offsetParent;
  	}
	return xPos;
}

function docjslib_getRealTop(imgElem) {
	yPos = eval(imgElem).offsetTop;
	tempEl = eval(imgElem).offsetParent;
	while (tempEl != null) {
  		yPos += tempEl.offsetTop;
  		tempEl = tempEl.offsetParent;
  	}
	return yPos;
}

//http://www.somacon.com/p355.php
function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

// done borrowing

// generate the gallery menu using YUI
/*
         Initialize and render the Menu when the element it is to be 
         rendered into is ready to be scripted.
    */
    YAHOO.util.Event.onAvailable("galleryMenuDiv", function () {
		var galleryNavImage = document.getElementById('imgGalleryLink');
		var galleryMenuDiv = document.getElementById('galleryMenuDiv')
		var urlTemplate = 'http://www.chapmansphoto.com/v4/index.php?page=gallery&id=';
        /*
             Instantiate a Menu:  The first argument passed to the 
             constructor is the id of the element in the page 
             representing the Menu; the second is an object literal 
             of configuration properties.
        */

        var oMenu = new YAHOO.widget.Menu("galleryMenuDiv1",
			{
				zindex: 500,
				iframe: true,
				x: parseInt(docjslib_getRealLeft(galleryNavImage))-12,
				y: (parseInt(docjslib_getRealTop(galleryNavImage))-108),
				effect: {
					effect: YAHOO.widget.ContainerEffect.FADE,
                    duration: 0.50
				}
			}
		);


        /*
            Add items to the Menu instance by passing an array of object literals 
            (each of which represents a set of YAHOO.widget.MenuItem 
            configuration properties) to the "addItems" method.
        */

        oMenu.addItems([

                { text: "Babies &amp; Bellies", url: urlTemplate + '1' },
                { text: "Toddlers", url: urlTemplate + '2' },
                { text: "Older Kids &amp; Teens",  url: urlTemplate + '4' },
                { text: "Couples &amp; Families", url: urlTemplate + '8' }

            ]);


        /*
            Since this Menu instance is built completely from script, call the 
            "render" method passing in the DOM element that it should be 
            appended to.
        */

        oMenu.render('galleryMenuDiv');


        // Set focus to the Menu when it is made visible

        oMenu.subscribe("show", oMenu.focus);


        if ( ! YAHOO.util.Event.addListener("imgGalleryLink", "click", oMenu.show, null, oMenu))
        {
			alert('Could not add event listener');
        }

	
    
    });
// end gallery menu

function swapImg(img, strImg)
{

	img.src = "images/" + strImg + ".jpg";
}

function body_load()
{
	preload_images();
}

function preload_images()
{
	var imgsOver = ["home","aboutme","galleries","clients","prices","testimonials","contact"];
	
	for(var i=0; i < imgsOver.length; i++)
	{
		var img = new Image();
		img.src = "images/link_"+imgsOver[i]+"_over.jpg";
	}
}