var image_popup_old_onload = window.onload;
var image_popup_window_reference = null;
window.onload = function()
{
    if (typeof image_popup_old_onload == 'function')
    {
         image_popup_old_onload();
    }

    var imagePopups = new imagePopupScript();
    imagePopups.init();
}

/* class definition */
function imagePopupScript()
{
    this.containerClassName = 'popup_thumbs';
}

imagePopupScript.prototype.init = function()
{
    // get all ULs in document, look for needed class name, attach handlers if found
    var lists = document.getElementsByTagName('span');
    var className = ' ' + this.containerClassName + ' ';
    for (var i = 0, item, position; item = lists[i]; i++) {
        if (!item.className)
        {
            continue;
        }

        position = ' ' + item.className + ' ';

        if (position.indexOf( className ) == -1)
        {
            continue;
        }

        this.attachHandlers( item );

    }
}

imagePopupScript.prototype.attachHandlers = function (element)
{
    // get all images in container element and attach onclick handlers
    var imgs = element.getElementsByTagName('img');
    var self = this;
    for (var i = 0, img, imgId; img = imgs[i]; i++) {
        img.onclick = function()
        {
            return self.popupImageFromClick(this);
        }
        img = null;

    }
    return;
}

imagePopupScript.prototype.popupImageFromClick = function (img)
{
    // the actual function that is called onclick

    var objectId = img.id.split('_')[1];

    return this.popupImage(objectId); // cancel click event
}

imagePopupScript.prototype.popupImage = function (objectId)
{
    return popupImage(objectId);
}

/*
    put this function in global namespace so that it can be called directly if needed
*/
function popupImage (objectId)
{

    var url = document.location.href;

    var delimiter = (url.indexOf('?') == -1) ? '?' : '&';

    url = url.concat(delimiter, 'popup_image=' + objectId );

    var winName = 'popup_img_' + objectId ;
	var W = 100;
	var H = 100;

	var left = 0;
	var top  = 0;


	// if this is uncommented, only one popup window is allowed
	if (
	   (image_popup_window_reference)
	   &&
	   (image_popup_window_reference.close)
	)
	{
	    image_popup_window_reference.close();
	}



	image_popup_window_reference = window.open(url, winName, "scrollbars=no,resizable=yes,width=" + W + ",height=" + H + " , top=" + top + ", left=" + left);

    return false;
}

jQuery(document).ready(function(){
    if(typeof(IE) != 'undefined')
    {
        jQuery('.homeMenuItem').bind('mouseenter', function() {
            if(jQuery(this).hasClass('item01'))
            {
                jQuery('.item02').css('z-index', 1);
                jQuery('.item01').css('z-index', 2);
            }
            else if(jQuery(this).hasClass('item02'))
            {
                jQuery('.item02').css('z-index', 2);
                jQuery('.item01').css('z-index', 1);
                jQuery('.item03').css('z-index', 1);
            }
            else if(jQuery(this).hasClass('item03'))
            {
                jQuery('.item02').css('z-index', 1);
                jQuery('.item03').css('z-index', 2);
            }
            
        });
        jQuery('.homeMenuItem').bind('click', function(){
            redirectUrl = jQuery(this).find('a').attr('href');
            location.href = redirectUrl;
        });
        jQuery('.homeMenuItem').bind('mouseenter', function(){
           jQuery(this).find('.hover').show(); 
          // alert(jQuery(this).find('.hover'));
           jQuery(this).find('.normal').hide(); 
        })
        .bind('mouseleave', function(){
           jQuery(this).find('.normal').show(); 
           jQuery(this).find('.hover').hide(); 
        });
    }
})



