
var galleryLoader;
var selectedGallery = 0;
var showGallery = false;
var requestUri = location.href;
var re = /[\?&](ghash=(.*))/gi;
requestUri = requestUri.replace(re, '');
if(requestUri.indexOf('?') < 0) {
    requestUri = requestUri + '?';
} else {
    requestUri = requestUri + '&';
}
if (galleryLoader == undefined || selectedGallery == 1) {
    showGallery = true;
}
 showGallery = true;
var imageGalleryLeftPos       = 31;
var previewImgContainerHeight = 327;
var imageGalleryWidth         = 469;
var maxGalleryXPos            = 31;
var minGalleryXPos            = -1099;
var thumbnailsPosition        = 'H';
var scrollingSpeed            = 60;
var slideShowDelay            = 5000;
var ihost                     = 'http://www.missionbeachrentalsnetwork.com/rbo_common/images/gallery/';
var ipath                     = 'http://www.missionbeachrentalsnetwork.com';
var Photos                    = new Array();
Photos[0] = new Array( ipath + '/rbo_common/d_images/listings_gallery_image_11973.jpeg', ipath + '/rbo_common/d_images/listings_gallery_thumbnail_11973.jpeg', "Front of house", "Front of house", "Front of house", "240", "320");
Photos[1] = new Array( ipath + '/rbo_common/d_images/listings_gallery_image_11982.jpeg', ipath + '/rbo_common/d_images/listings_gallery_thumbnail_11982.jpeg', "100 feet from the bay ", "100 feet from the bay ", "100 feet from the bay ", "426", "320");
Photos[2] = new Array( ipath + '/rbo_common/d_images/listings_gallery_image_11983.jpeg', ipath + '/rbo_common/d_images/listings_gallery_thumbnail_11983.jpeg', "1 block to Mission Beach", "1 block to Mission Beach", "1 block to Mission Beach", "426", "320");
Photos[3] = new Array( ipath + '/rbo_common/d_images/listings_gallery_image_11974.jpeg', ipath + '/rbo_common/d_images/listings_gallery_thumbnail_11974.jpeg', "1st level private patio", "1st level private patio", "1st level private patio", "240", "320");
Photos[4] = new Array( ipath + '/rbo_common/d_images/listings_gallery_image_11975.jpeg', ipath + '/rbo_common/d_images/listings_gallery_thumbnail_11975.jpeg', "1st level den sleeping quarters", "1st level den sleeping quarters", "1st level den sleeping quarters", "240", "320");
Photos[5] = new Array( ipath + '/rbo_common/d_images/listings_gallery_image_11976.jpeg', ipath + '/rbo_common/d_images/listings_gallery_thumbnail_11976.jpeg', "1st level trundel bed", "1st level trundel bed", "1st level trundel bed", "426", "320");
Photos[6] = new Array( ipath + '/rbo_common/d_images/listings_gallery_image_11977.jpeg', ipath + '/rbo_common/d_images/listings_gallery_thumbnail_11977.jpeg', "1st level den across toward private patio", "1st level den across toward private patio", "1st level den across toward private patio", "426", "320");
Photos[7] = new Array( ipath + '/rbo_common/d_images/listings_gallery_image_11985.jpeg', ipath + '/rbo_common/d_images/listings_gallery_thumbnail_11985.jpeg', "looking across living area to dining room on 2nd level", "looking across living area to dining room on 2nd level", "looking across living area to dining room on 2nd level", "240", "320");
Photos[8] = new Array( ipath + '/rbo_common/d_images/listings_gallery_image_11986.jpeg', ipath + '/rbo_common/d_images/listings_gallery_thumbnail_11986.jpeg', "Level 2 Living area", "Level 2 Living area", "Level 2 Living area", "426", "320");
Photos[9] = new Array( ipath + '/rbo_common/d_images/listings_gallery_image_11987.jpeg', ipath + '/rbo_common/d_images/listings_gallery_thumbnail_11987.jpeg', "Level 2 modern, fully-equipped kitchen", "Level 2 modern, fully-equipped kitchen", "Level 2 modern, fully-equipped kitchen", "426", "320");
Photos[10] = new Array( ipath + '/rbo_common/d_images/listings_gallery_image_11989.jpeg', ipath + '/rbo_common/d_images/listings_gallery_thumbnail_11989.jpeg', "2nd level bathroom", "2nd level bathroom", "2nd level bathroom", "240", "320");
Photos[11] = new Array( ipath + '/rbo_common/d_images/listings_gallery_image_11988.jpeg', ipath + '/rbo_common/d_images/listings_gallery_thumbnail_11988.jpeg', "Level 2 bedroom", "Level 2 bedroom", "Level 2 bedroom", "240", "320");
Photos[12] = new Array( ipath + '/rbo_common/d_images/listings_gallery_image_11990.jpeg', ipath + '/rbo_common/d_images/listings_gallery_thumbnail_11990.jpeg', "3rd level master bedroom", "3rd level master bedroom", "3rd level master bedroom", "426", "320");
Photos[13] = new Array( ipath + '/rbo_common/d_images/listings_gallery_image_11991.jpeg', ipath + '/rbo_common/d_images/listings_gallery_thumbnail_11991.jpeg', "Level 3 master bedroom--wood burning stove and stained glass", "Level 3 master bedroom--wood burning stove and stained glass", "Level 3 master bedroom--wood burning stove and stained glass", "426", "320");
Photos[14] = new Array( ipath + '/rbo_common/d_images/listings_gallery_image_11992.jpeg', ipath + '/rbo_common/d_images/listings_gallery_thumbnail_11992.jpeg', "3rd level master bedroom--looking out to private patio", "3rd level master bedroom--looking out to private patio", "3rd level master bedroom--looking out to private patio", "426", "320");
Photos[15] = new Array( ipath + '/rbo_common/d_images/listings_gallery_image_11993.jpeg', ipath + '/rbo_common/d_images/listings_gallery_thumbnail_11993.jpeg', "3rd level master bathroom", "3rd level master bathroom", "3rd level master bathroom", "240", "320");
Photos[16] = new Array( ipath + '/rbo_common/d_images/listings_gallery_image_11994.jpeg', ipath + '/rbo_common/d_images/listings_gallery_thumbnail_11994.jpeg', "3rd level master bathroom", "3rd level master bathroom", "3rd level master bathroom", "426", "320");
Photos[17] = new Array( ipath + '/rbo_common/d_images/listings_gallery_image_11996.jpeg', ipath + '/rbo_common/d_images/listings_gallery_thumbnail_11996.jpeg', "3rd level private patio", "3rd level private patio", "3rd level private patio", "240", "320");
Photos[18] = new Array( ipath + '/rbo_common/d_images/listings_gallery_image_11995.jpeg', ipath + '/rbo_common/d_images/listings_gallery_thumbnail_11995.jpeg', "Belmont Park famous roller coaster", "Belmont Park famous roller coaster", "Belmont Park famous roller coaster", "426", "320");
Photos[19] = new Array( ipath + '/rbo_common/d_images/listings_gallery_image_11984.jpeg', ipath + '/rbo_common/d_images/listings_gallery_thumbnail_11984.jpeg', "cycling on the beach boardwalk", "cycling on the beach boardwalk", "cycling on the beach boardwalk", "240", "320");
Photos[20] = new Array( ipath + '/rbo_common/d_images/listings_gallery_image_11981.jpeg', ipath + '/rbo_common/d_images/listings_gallery_thumbnail_11981.jpeg', "parking space 2 for economy car--back of house", "parking space 2 for economy car--back of house", "parking space 2 for economy car--back of house", "426", "320");
Photos[21] = new Array( ipath + '/rbo_common/d_images/listings_gallery_image_11980.jpeg', ipath + '/rbo_common/d_images/listings_gallery_thumbnail_11980.jpeg', "parking space 1 for suv--back of house", "parking space 1 for suv--back of house", "parking space 1 for suv--back of house", "240", "320");
Photos[22] = new Array( ipath + '/rbo_common/d_images/listings_gallery_image_11979.jpeg', ipath + '/rbo_common/d_images/listings_gallery_thumbnail_11979.jpeg', "1st level private patio garden ", "1st level private patio garden ", "1st level private patio garden ", "426", "320");
Photos[23] = new Array( ipath + '/rbo_common/d_images/listings_gallery_image_11978.jpeg', ipath + '/rbo_common/d_images/listings_gallery_thumbnail_11978.jpeg', "1st level washer and dryer", "1st level washer and dryer", "1st level washer and dryer", "240", "320");
var style_link = document.getElementById('gallery_css_111496');
if (style_link) {
    style_link.parentNode.removeChild(style_link);
}
style_link = document.createElement('link');
style_link.id = 'gallery_css_111496';
style_link.href = 'http://www.missionbeachrentalsnetwork.com/rbo_common/gallery/111496.css';
style_link.type = 'text/css';
style_link.rel = 'stylesheet';
var head = document.getElementsByTagName('HEAD')[0];
if (head) {
    head.appendChild(style_link);
} else {
    document.write('<link href="http://www.missionbeachrentalsnetwork.com/rbo_common/gallery/111496.css" type="text/css" rel="stylesheet" />');
}
if (showGallery) {
    var preloadPhotos = new Array('' + ihost + 'b_next.gif', '' + ihost + 'b_next_over.gif', '' + ihost + 'b_pause.gif', '' + ihost + 'b_pause_over.gif', '' + ihost + 'b_play.gif', '' + ihost + 'b_play_over.gif', '' + ihost + 'b_previous.gif', '' + ihost + 'b_previous_over.gif', '' + ihost + 'b_scroll_down.gif', '' + ihost + 'b_scroll_down_over.gif', '' + ihost + 'b_scroll_up.gif', '' + ihost + 'b_scroll_up_over.gif', '' + ihost + 'b_scroll_left_over.gif', '' + ihost + 'b_scroll_right_over.gif', '' + ihost + 'title_bg.gif', '' + ipath + '/rbo_common/d_images/listings_gallery_image_11973.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_thumbnail_11973.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_thumbnail_11982.jpeg');
    var preloadPhotosAfter = new Array('' + ipath + '/rbo_common/d_images/listings_gallery_image_11982.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_image_11983.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_thumbnail_11983.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_image_11974.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_thumbnail_11974.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_image_11975.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_thumbnail_11975.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_image_11976.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_thumbnail_11976.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_image_11977.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_thumbnail_11977.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_image_11985.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_thumbnail_11985.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_image_11986.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_thumbnail_11986.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_image_11987.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_thumbnail_11987.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_image_11989.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_thumbnail_11989.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_image_11988.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_thumbnail_11988.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_image_11990.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_thumbnail_11990.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_image_11991.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_thumbnail_11991.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_image_11992.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_thumbnail_11992.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_image_11993.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_thumbnail_11993.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_image_11994.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_thumbnail_11994.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_image_11996.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_thumbnail_11996.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_image_11995.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_thumbnail_11995.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_image_11984.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_thumbnail_11984.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_image_11981.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_thumbnail_11981.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_image_11980.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_thumbnail_11980.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_image_11979.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_thumbnail_11979.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_image_11978.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_thumbnail_11978.jpeg');
} else {
    var preloadPhotos = new Array(ihost + 'title_bg.gif');
}
function drawGallery()
{
    igallery = document.getElementById("gallery_slideshow");
    if (showGallery) {
    preview_pane = document.createElement('div');
    preview_pane.setAttribute('id', "previewPane");
    gncontainer = document.createElement('div');
    gncontainer.setAttribute('id', "galleryTitle");
    gnscontainer = document.createElement('div');
    gnTitle = document.createTextNode( "Mission Bay - Beach and Bay Getaway" );
    gnscontainer.appendChild(gnTitle);
    gncontainer.appendChild(gnscontainer);
    preview_pane.appendChild(gncontainer);
    preview_pane_img_div = document.createElement('div');
    preview_pane_img_div.setAttribute('id', 'gPreviewImgContainer');
    preview_pane_img = document.createElement('img');
    preview_pane_img.setAttribute('id', 'gPreviewImg');
    if (Photos.length > 0) {
        var margin_top = roundnumber( (previewImgContainerHeight/2 - 4) - (Photos[0][6]/2), 0);
        preview_pane_img.setAttribute('src', Photos[0][0]);
        preview_pane_img.setAttribute('width', Photos[0][5]);
        preview_pane_img.setAttribute('height', Photos[0][6]);
        preview_pane_img.setAttribute('style', 'margin-top: ' + margin_top + 'px;');
    }
    preview_pane_img_div.appendChild(preview_pane_img);
    preview_pane.appendChild(preview_pane_img_div);
    itext = document.createElement('div');
    itext.setAttribute('id', "imgTextContainer");
    if (Photos.length > 0 && Photos[0][3] != '') {
        var txt = document.createTextNode(Photos[0][3]);
        itext.appendChild(txt);
    }
    preview_pane.appendChild(itext);
    sscontainer = document.createElement('div');
    sscontainer.setAttribute('id', "slideShowContainer");
    prev_img_a = document.createElement('a');
    prev_img_a.setAttribute('onclick', "prevPhoto();return false");
    prev_img_a.setAttribute('href', "javascript:prevPhoto();");
    prev_img_a.setAttribute('onfocus', "this.blur()");
    prev_img = document.createElement('img');
    prev_img.setAttribute('id', 'prevSlideCtrl');
    prev_img.setAttribute('src', ihost + 'b_previous.gif');
    prev_img.setAttribute('alt', 'Previous');
    prev_img.setAttribute('title', 'Previous');
    prev_img_a.appendChild(prev_img);
    sscontainer.appendChild(prev_img_a);
    stop_img_a = document.createElement('a');
    stop_img_a.setAttribute('onclick', "stopSlideShow();return false");
    stop_img_a.setAttribute('href', "javascript:stopSlideShow();");
    stop_img_a.setAttribute('id', "stopSlideCtrlA");
    stop_img_a.setAttribute('onfocus', "this.blur()");
    stop_img = document.createElement('img');
    stop_img.setAttribute('id', 'stopSlideCtrl');
    stop_img.setAttribute('src', ihost + 'b_pause.gif');
    stop_img.setAttribute('alt', 'Pause');
    stop_img.setAttribute('title', 'Pause');
    stop_img_a.appendChild(stop_img);
    sscontainer.appendChild(stop_img_a);
    start_img_a = document.createElement('a');
    start_img_a.setAttribute('onclick', "startSlideShow();return false");
    start_img_a.setAttribute('href', "javascript:startSlideShow();");
    start_img_a.setAttribute('id', "startSlideCtrlA");
    start_img_a.setAttribute('onfocus', "this.blur()");
    start_img = document.createElement('img');
    start_img.setAttribute('id', 'startSlideCtrl');
    start_img.setAttribute('src', ihost + 'b_play.gif');
    start_img.setAttribute('alt', 'Play');
    start_img.setAttribute('title', 'Play');
    start_img_a.appendChild(start_img);
    sscontainer.appendChild(start_img_a);
    next_img_a = document.createElement('a');
    next_img_a.setAttribute('onclick', "nextPhoto();return false");
    next_img_a.setAttribute('href', "javascript:nextPhoto();");
    next_img_a.setAttribute('onfocus', "this.blur()");
    next_img_a.setAttribute('class', "none");
    next_img_a.setAttribute('className', "none");
    next_img = document.createElement('img');
    next_img.setAttribute('id', 'nextSlideCtrl');
    next_img.setAttribute('src', ihost + 'b_next.gif');
    next_img.setAttribute('alt', 'Next');
    next_img.setAttribute('title', 'Next');
    next_img_a.appendChild(next_img);
    sscontainer.appendChild(next_img_a);
    preview_pane.appendChild(sscontainer);
    icontainer = document.createElement('div');
    icontainer.setAttribute('id', "galleryContainer");
    arr_left_img_div = document.createElement('div');
    arr_left_img_div.setAttribute('id', "arrow_left");
    arr_left_img = document.createElement('img');
    arr_left_img.setAttribute('src', ihost + "b_scroll_left.gif");
    arr_left_img.setAttribute('id', "arrow_left_image");
    arr_left_img.setAttribute('width', "31");
    arr_left_img.setAttribute('height', "58");
    arr_left_img_div.appendChild(arr_left_img);
    icontainer.appendChild(arr_left_img_div);
    arr_right_img_div = document.createElement('div');
    arr_right_img_div.setAttribute('id', "arrow_right");
    arr_right_img = document.createElement('img');
    arr_right_img.setAttribute('src', ihost + "b_scroll_right.gif");
    arr_right_img.setAttribute('id', "arrow_right_image");
    arr_right_img.setAttribute('width', "33");
    arr_right_img.setAttribute('height', "58");
    arr_right_img_div.appendChild(arr_right_img);
    icontainer.appendChild(arr_right_img_div);
    the_img_div = document.createElement('div');
    the_img_div.setAttribute('id', "theImages");
    the_img_div_container = document.createElement('div');
    the_img_div_container.setAttribute('style', "left: 31px;");
    for (i=0; i<Photos.length; i++) {
        prev_img_a = document.createElement('a');
        prev_img_a.setAttribute('onclick', "showPreview(Photos[" + i + "][0], " + i +", Photos[" + i + "][3], Photos[" + i + "][5], Photos[" + i + "][6]);return false");
        prev_img_a.setAttribute('href', "javascript:showPreview(Photos[" + i + "][0], " + i +", Photos[" + i + "][3], Photos[" + i + "][5], Photos[" + i + "][6]);");
        prev_img = document.createElement('img');
        prev_img.setAttribute('src', Photos[i][1]);
        prev_img.setAttribute('alt', Photos[i][4]);
        if (i == Photos.length) {
            prev_img.setAttribute('style', 'margin: 0px;');
        }
        prev_img_a.appendChild(prev_img);
        the_img_div_container.appendChild(prev_img_a);
    }
    slide_end_div = document.createElement('div');
    slide_end_div.setAttribute('id', "slideEnd");
    the_img_div_container.appendChild(slide_end_div);
    the_img_div.appendChild(the_img_div_container);
    icontainer.appendChild(the_img_div);
    igallery.appendChild(preview_pane);
    igallery.appendChild(icontainer);
}
}
window.ua = navigator.userAgent.toLowerCase();
var Safari = (ua.indexOf('safari') != -1)?true:false;

var slideShowInterval;
var currentPhoto           = 0;
var arrowImageHeight       = 31;	// Height of arrow image in pixels;
var previewImage           = false;
var previewImageParent     = false;
var slideSpeed             = 0;
var previewImagePane       = false;
var slideEndMarker         = false;
var galleryContainer       = false;
var disablePlay            = false;

function getTopPos(inputObj)
{
    var returnValue = inputObj.offsetTop;
    while((inputObj = inputObj.offsetParent) != null) {
        returnValue += inputObj.offsetTop;
    }
    return returnValue;
}

function getLeftPos(inputObj)
{
    var returnValue = inputObj.offsetLeft;
    while((inputObj = inputObj.offsetParent) != null) {
        returnValue += inputObj.offsetLeft;
    }
    return returnValue;
}

function roundnumber(n, d)
{
    n = n - 0;
    if (d == null) d = 2;
    var f = Math.pow(10, d);
    n += Math.pow(10, - (d + 1));
    n = Math.round(n * f) / f;
    n += Math.pow(10, - (d + 1));
    n += '';
    return d == 0 ? n.substring(0, n.indexOf('.')) :  n.substring(0, n.indexOf('.') + d + 1);
}

function showPreview(newSrc, idx, imageText, width, height)
{
    currentPhoto = idx;
    var previewImage = document.getElementById('gPreviewImg');
    var margin_top = roundnumber( (previewImgContainerHeight/2 - 4) - (height/2), 0);
    previewImage.src = newSrc;
    previewImage.width = width;
    previewImage.height = height;
    previewImage.setAttribute('style', 'margin-top: ' + margin_top + 'px;');
    if (imageText == 'undefined') {
        imageText = '';
    }
    var imgTextContainer = document.getElementById('imgTextContainer');
    if (imageText != '') {

    }
    imgTextContainer.innerHTML = imageText;
}

function initSlide(e)
{
    if(document.all) {
        e = event;
    }
    var id = this.id;

    if(this.src.indexOf('over') < 0) {
        this.src = this.src.replace('.gif','_over.gif');
    }

    if (Safari) {
      slideSpeed = 10;
    } else {
        if (thumbnailsPosition == 'V') {
            slideSpeed = e.clientY + Math.max(document.body.scrollTop,document.documentElement.scrollTop) - getTopPos(this);
            if(this.src.indexOf('down')>=0) {
                slideSpeed = (slideSpeed)*-1;
            } else {
                slideSpeed = arrowImageHeight - slideSpeed;
            }
            slideSpeed = Math.round(slideSpeed * 15 / arrowImageHeight);
        } else {
            if(this.id=='arrow_right_image') {
                slideSpeedMultiply = Math.floor((e.clientX - this.offsetLeft) / 5);
                slideSpeed = -1*slideSpeedMultiply;
                slideSpeed = Math.max(-10,slideSpeed);
            } else {
                slideSpeedMultiply = 10 - Math.floor((e.clientX - this.offsetLeft) / 5);
                slideSpeed = 1*slideSpeedMultiply;
                slideSpeed = Math.min(10,slideSpeed);
                if(slideSpeed<0) slideSpeed=10;
            }
        }
    }
}

function stopSlide()
{
    slideSpeed = 0;
    this.src = this.src.replace('_over', '');
}

function slidePreviewPane()
{
    if(slideSpeed != 0) {
        if (thumbnailsPosition == 'V') {
            var topPos = previewImagePane.style.top.replace(/[^\-0-9]/g,'')/1;

            if(slideSpeed<0 && slideEndMarker.offsetTop<(previewImageParent.offsetHeight - topPos)) {
                slideSpeed = 0;
            }
            topPos = topPos + slideSpeed;
            if(topPos>0) {
                topPos = 0;
            }
            previewImagePane.style.top = topPos + 'px';
        } else {
            var leftPos = previewImageParent.offsetLeft;
            leftPos = leftPos/1 + slideSpeed;
            if(leftPos > maxGalleryXPos){
                leftPos = maxGalleryXPos;
                slideSpeed = 0;
            }
            if(leftPos < minGalleryXPos){
                leftPos = minGalleryXPos;
                slideSpeed = 0;
            }
			previewImageParent.style.left = leftPos + 'px';
        }
    }
    setTimeout('slidePreviewPane()', scrollingSpeed);
}

function revealThumbnail()
{
    this.style.filter = 'alpha(opacity=100)';
    this.style.opacity = 1;
}

function hideThumbnail()
{
    this.style.filter = 'alpha(opacity=50)';
    this.style.opacity = 0.5;
}

function initGalleryScript()
{
    drawGallery();

    previewImageParent = document.getElementById('theImages');
    if( previewImageParent != null ) {
        galleryContainer  = document.getElementById('galleryContainer');

        previewImagePane = document.getElementById('theImages').getElementsByTagName('DIV')[0];
        previewImagePane.style.top = '0px';

        var images = previewImagePane.getElementsByTagName('IMG');
        for(var no=0;no<images.length;no++){
            images[no].onmouseover = revealThumbnail;
            images[no].onmouseout = hideThumbnail;
        }
        slideEndMarker = document.getElementById('slideEnd');

        if (thumbnailsPosition == 'V') {
            document.getElementById('arrow_up_image').onmousemove = initSlide;
            document.getElementById('arrow_up_image').onmouseout = stopSlide;

            document.getElementById('arrow_down_image').onmousemove = initSlide;
            document.getElementById('arrow_down_image').onmouseout = stopSlide;
        } else {
            document.getElementById('arrow_left_image').onmousemove = initSlide;
            document.getElementById('arrow_left_image').onmouseout = stopSlide;

            document.getElementById('arrow_right_image').onmousemove = initSlide;
            document.getElementById('arrow_right_image').onmouseout = stopSlide;
        }

        document.getElementById('prevSlideCtrl').onmousemove = initCtrlBtn;
        document.getElementById('prevSlideCtrl').onmouseout = stopCtrlBtn;

        document.getElementById('startSlideCtrl').onmousemove = initCtrlBtn;
        document.getElementById('startSlideCtrl').onmouseout = stopCtrlBtn;

        document.getElementById('stopSlideCtrl').onmousemove = initCtrlBtn;
        document.getElementById('stopSlideCtrl').onmouseout = stopCtrlBtn;

        document.getElementById('nextSlideCtrl').onmousemove = initCtrlBtn;
        document.getElementById('nextSlideCtrl').onmouseout = stopCtrlBtn;

        slidePreviewPane();
    }
}

/*** Slide show functions ***/
function initCtrlBtn()
{
    if (this.id != 'startSlideCtrl' || disablePlay == false) {
        if(this.src.indexOf('over') < 0) {
            this.src = this.src.replace('.gif', '_over.gif');
        }
    }
}
function stopCtrlBtn()
{
    if (this.id != 'startSlideCtrl' || disablePlay == false) {
        if(this.src.indexOf('over') >= 0) {
            this.src = this.src.replace('_over', '');
        }
    }
}
function nextPhoto()
{
    currentPhoto++;
    if (currentPhoto >= Photos.length) { currentPhoto = 0; }
    showPreview(Photos[currentPhoto][0], currentPhoto, Photos[currentPhoto][3], Photos[currentPhoto][5], Photos[currentPhoto][6]);
}

function prevPhoto()
{
    currentPhoto--;
    if (currentPhoto >= Photos.length || currentPhoto < 0) { currentPhoto = Photos.length-1; }
    showPreview(Photos[currentPhoto][0], currentPhoto, Photos[currentPhoto][3], Photos[currentPhoto][5], Photos[currentPhoto][6]);
}

function doSlideshow()
{
    nextPhoto( );
    slideShowInterval = setTimeout("doSlideshow()", slideShowDelay);
}

function startSlideShow(initpic)
{
    slideShowInterval = setTimeout("doSlideshow()", slideShowDelay);
    var elm = document.getElementById('startSlideCtrl');
    var elm_ctrl = document.getElementById('startSlideCtrlA');
    disablePlay = true;
    if(elm.src.indexOf('over') < 0) {
        elm.src = elm.src.replace('.gif', '_over.gif');
    }
}

function stopSlideShow()
{
    clearTimeout(slideShowInterval);
    var elm = document.getElementById('startSlideCtrl');
    var elm_ctrl = document.getElementById('startSlideCtrlA');
    disablePlay = false;
    if(elm.src.indexOf('over') >= 0) {
        elm.src = elm.src.replace('_over', '');
    }
}

function viodAction()
{

}

// Image Preloader
function ImagePreloader(images,callback)
{
	// store the callback
	this.callback = callback;

	// initialize internal state.
	this.nLoaded = 0;
	this.nProcessed = 0;
	this.aImages = new Array;

	// record the number of images.
	this.nImages = images.length;

	// for each image, call preload()
	for ( var i = 0; i < images.length; i++ )
		this.preload(images[i]);
}
ImagePreloader.prototype.preload = function(image)
{
	// create new Image object and add to array
	var oImage = new Image;
	this.aImages.push(oImage);

	// set up event handlers for the Image object
	oImage.onload = ImagePreloader.prototype.onload;
	oImage.onerror = ImagePreloader.prototype.onerror;
	oImage.onabort = ImagePreloader.prototype.onabort;

	// assign pointer back to this.
	oImage.oImagePreloader = this;
	oImage.bLoaded = false;
	oImage.source = image;

	// assign the .src property of the Image object
	oImage.src = image;
}
ImagePreloader.prototype.onComplete = function()
{
	this.nProcessed++;
	if ( this.nProcessed == this.nImages )
		this.callback(this.aImages);
}
ImagePreloader.prototype.onload = function()
{
	this.bLoaded = true;
	this.oImagePreloader.nLoaded++;
	this.oImagePreloader.onComplete();
}
ImagePreloader.prototype.onerror = function()
{
	this.bError = true;
	this.oImagePreloader.onComplete();
}
ImagePreloader.prototype.onabort = function()
{
	this.bAbort = true;
	this.oImagePreloader.onComplete();
}

if (galleryLoader == undefined) {
    document.write('<div id="gallery_slideshow"><\/div>');
    var giv = new ImagePreloader(preloadPhotos, initGalleryScript);
    var aiv = new ImagePreloader(preloadPhotosAfter, viodAction);
}
