        function rotate_images()
        {
            var rotation = document.getElementById(CONTAINER_ID);
            var image_list = rotation.getElementsByTagName("IMG");
            prev_index = current_index;
            current_index = (current_index + 1) % image_list.length;
            var prev_image = image_list[prev_index];
            var current_image = image_list[current_index];
            current_image.style.display = '';
            opacity = 100;
            fade_time_id = window.setInterval
            (
                function()
                {
                    fade_image()
                },
                FADE_DELAY_TIME
            );
        }

        function fade_image()
        {
            var rotation = document.getElementById(CONTAINER_ID);
            var image_list = rotation.getElementsByTagName("IMG");
            var prev_image = image_list[prev_index];
            var current_image = image_list[current_index];
            opacity -= FADE_SPEED;
            prev_image.style.opacity = opacity / 100;
            prev_image.style.filter = 'alpha(opacity=' + (opacity) + ')';
            current_image.style.opacity = (100 - opacity) / 100;
            current_image.style.filter = 'alpha(opacity=' + (100 - opacity) + ')';
            if (opacity <= 0)
            {
                prev_image.style.display = 'none';
                window.setTimeout("rotate_images()", ROTATE_DELAY_TIME);
                window.clearTimeout(fade_time_id);
            }
        }

        addLoadEvent(
            function()
            {
                var rotation = document.getElementById(CONTAINER_ID);
                var image_list = rotation.getElementsByTagName("IMG");
                window.setTimeout("rotate_images()", ROTATE_DELAY_TIME);
            }
        ); 

function getStyleVal(elem, IEStyleName, CSSStyleName) {
    var target = "";

    if (elem.currentStyle) {
        target = elem.currentStyle[IEStyleName];
    } else if (window.getComputedStyle) {
        var compStyle = window.getComputedStyle(elem, "");
        target = compStyle.getPropertyValue(CSSStyleName);
    } else {
        target = 0;
    }
    target = target.replace(/px/g, '\r\n');
    
    if (target == 'auto')
        target = 0;
    return target;
}

function getWidth(obj)
{
    var width = obj.offsetWidth;
    if (width > 0)
        return width;
    if (!obj.firstChild)
        return 0;
    //return obj.parentNode.parentNode.offsetWidth;

    // use the left and right child instead
    return obj.lastChild.offsetLeft - obj.firstChild.offsetLeft + getWidth (obj.lastChild);
}

function getHeight(obj)
{
    var height = obj.offsetHeight;
    if (height > 0)
        return height;
    if (!obj.firstChild)
        return 0;
    // use the first child's height
    return obj.firstChild.offsetHeight;
}

function getXY(el)
{
    
    if (el.offsetParent == null) {
       return false;
    }
    
    var parentNode = null;
    var pos = [];
    var box;
    
    if (el.getBoundingClientRect) { // IE
       box = el.getBoundingClientRect();
       var doc = document;
       /*if ( !this.inDocument(el) && parent.document != document) {// might be in a frame, need to get its scroll
          doc = parent.document;
    
          if ( !this.isAncestor(doc.documentElement, el) ) {
             return false;
          }
    
       }*/
    
       var scrollTop = Math.max(doc.documentElement.scrollTop, doc.body.scrollTop);
       var scrollLeft = Math.max(doc.documentElement.scrollLeft, doc.body.scrollLeft);
    
       return [box.left + scrollLeft, box.top + scrollTop];
    }
    else { // safari, opera, & gecko
       pos = [el.offsetLeft, el.offsetTop];
       parentNode = el.offsetParent;
       if (parentNode != el) {
          while (parentNode) {
             pos[0] += parentNode.offsetLeft;
             pos[1] += parentNode.offsetTop;
             parentNode = parentNode.offsetParent;
          }
       }
       /*if (isSafari && el.style.position == 'absolute' ) { // safari doubles in some cases
          pos[0] -= document.body.offsetLeft;
          pos[1] -= document.body.offsetTop;
       }*/
    }
    
    if (el.parentNode) { parentNode = el.parentNode; }
    else { parentNode = null; }
    
    while (parentNode && parentNode.tagName.toUpperCase() != 'BODY' && parentNode.tagName.toUpperCase() != 'HTML')
    { // account for any scrolled ancestors
       if (parentNode.style.display != 'inline') { // work around opera inline scrollLeft/Top bug
          pos[0] -= parentNode.scrollLeft;
          pos[1] -= parentNode.scrollTop;
       }
    
       if (parentNode.parentNode) { parentNode = parentNode.parentNode; }
       else { parentNode = null; }
    }
    
    
    return pos;
}
function getDocHeight()
{

     var scrollHeight=-1, windowHeight=-1, bodyHeight=-1;

     var marginTop = 0;//parseInt(util.Dom.getStyle(document.body, 'marginTop'), 10);

     var marginBottom = 0;//parseInt(util.Dom.getStyle(document.body, 'marginBottom'), 10);



     var mode = document.compatMode;



     if ( (mode || getBrowser() == 'IE' || getBrowser() == 'IE7') && getBrowser() != 'opera' ) { // (IE, Gecko)

        switch (mode) {

           case 'CSS1Compat': // Standards mode

              scrollHeight = ((window.innerHeight && window.scrollMaxY) ?  window.innerHeight+window.scrollMaxY : - 1);

              windowHeight = [document.documentElement.clientHeight,self.innerHeight||-1].sort(function(a, b){return(a-b);})[1];

              bodyHeight = document.body.offsetHeight + marginTop + marginBottom;

              break;



           default: // Quirks

              scrollHeight = document.body.scrollHeight;

              bodyHeight = document.body.clientHeight;

        }

     } else { // Safari & Opera

        scrollHeight = document.documentElement.scrollHeight;

        windowHeight = self.innerHeight;

        bodyHeight = document.documentElement.clientHeight;

     }



     var h = [scrollHeight,windowHeight,bodyHeight].sort(function(a, b){return(a-b);});

     return h[2];

}

function getViewHeight()
{
    var height = -1;
    var mode = document.compatMode;

    if ( (mode || getBrowser() == 'IE' || getBrowser() == 'IE7') && getBrowser() != 'opera' ) 
    {
        switch (mode) 
        { // (IE, Gecko)
        case 'CSS1Compat': // Standards mode
            height = document.documentElement.clientHeight;
            break;
        default: // Quirks
            height = document.body.clientHeight;
        }
    } 
    else 
    { // Safari, Opera
        height = self.innerHeight;
    }

    return height;
}

function getViewWidth()
{
     var width = -1;
     var mode = document.compatMode;

     if (mode || getBrowser() == 'IE') { // (IE, Gecko, Opera)
        switch (mode) {
        case 'CSS1Compat': // Standards mode
           width = document.documentElement.clientWidth;
           break;

        default: // Quirks
           width = document.body.clientWidth;
        }
     } else { // Safari
        width = self.innerWidth;
     }
     return width;
  }

function getBrowser()
{
    var ua = navigator.userAgent.toLowerCase();
    
    if (ua.indexOf('msie 7')>-1)
    {
        return 'IE7';
    }
    
    if (ua.indexOf('opera')>-1)
    {
        return 'opera';
    }
    
    if (ua.indexOf('webkit')>-1)
    {
        return 'safari';
    }
    
    if (window.ActiveXObject)
    {
        return 'IE';
    }
    
    if (ua.indexOf('firefox')>-1)
    {
        return 'Firefox';
    }
    return false;
}

var current_index = -1;

function showPopup(obj, src, index)
{
    if (index == null)
        current_index = -1;
    else
        current_index = index;

    var popupContainer = document.getElementById('popup_container');
    var imageObj = document.getElementById('large_image');
    
    var left = getXY(obj)[0];
    var top = getXY(obj)[1];
    
    imageObj.src = src;
    
    var imgWidth = 355;
    var imgHeight = 312;
    
    var wndWidth = imgWidth;
    var wndHeight = imgHeight;
    
    var zIndex = 2000;

    popupContainer.style.left = (left - (imgWidth - obj.width) / 2) + 'px';//getViewWidth() / 2 - wndWidth / 2 + 'px';
    popupContainer.style.top = (top - (imgHeight - obj.height) / 2) + 'px';//getViewHeight() / 2 - wndHeight / 2 + 'px';
    popupContainer.style.width = wndWidth + 'px';
    popupContainer.style.height = wndHeight + 'px';
    popupContainer.style.zIndex = zIndex + 1;
    popupContainer.style.display = '';
    
    var popup_overlay = document.getElementById('popup_overlay');
    var opacity = 0;
    
    popup_overlay.style.display = '';
    popup_overlay.style.left = 0 + 'px';
    popup_overlay.style.top = 0 + 'px';
    popup_overlay.style.width = getViewWidth() - 1 + 'px';
    popup_overlay.style.height = getDocHeight() - 1 + 'px';
    popup_overlay.style.zIndex = zIndex;
    popup_overlay.style.opacity = opacity;
    popup_overlay.style.filter = 'alpha(opacity=' + (opacity * 100) + ')';
}

function hidePopup(eventName)
{
    if (typeof eventName != 'undefined' && eventName == 'onmouseout' && current_index != -1)
        return;

    var popupContainer = document.getElementById('popup_container');
    var popup_overlay = document.getElementById('popup_overlay');
    
    var imageObj = document.getElementById('large_image');
    imageObj.src= '';
    
    popupContainer.style.display = 'none';
    popup_overlay.style.display = 'none';
    
    current_index = -1;
}

function popUpWindow(mypage, myname, w, h, scroll, titlebar) 
{
    var winl = (screen.width - w) / 2;
    var wint = (screen.height - h) / 2;
    winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
    win = window.open(mypage, myname, winprops)
    if (parseInt(navigator.appVersion) >= 4) 
    {
        win.window.focus();
    }
}


function getMouseXY(event)
{
  if (window.event) 
  { // grab the x-y pos.s if browser is IE
    var scroll = getScroll();
    tempX = event.clientX + scroll['left'];
    tempY = event.clientY + scroll['top'];
  } 
  else 
  {  // grab the x-y pos.s if browser is NS
    tempX = event.pageX;
    tempY = event.pageY;
  }  
  
  // catch possible negative values in NS4
  /*if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}  */
  
  return [tempX, tempY];
}

function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            func();
            if (oldonload) {
                oldonload();
            }
        }
    }
}

window.onkeyup = function(event)
{
    if (!event)
        event = window.event;
    
    if (current_index == -1) 
        return true;
    //right arrow 
    if (event.keyCode == 39 || event.keyCode == 37)
    {
        if (event.keyCode == 39)
            current_index = (++current_index == 14?5:current_index);
        else
            current_index = (--current_index == 4?13:current_index);
        
        var obj = $('photogallery_img_' + current_index);
        var largeImgObj = $('photogallery_large_img_' + current_index) 
        var src = $('photogallery_img_' + current_index);
        
        showPopup(obj, largeImgObj.src, current_index);
    }
}