
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            = -1461;
var thumbnailsPosition        = 'H';
var scrollingSpeed            = 60;
var slideShowDelay            = 5000;
var ihost                     = 'http://www.mexicorentalsnetwork.com/rbo_common/images/gallery/';
var ipath                     = 'http://www.mexicorentalsnetwork.com';
var Photos                    = new Array();
Photos[0] = new Array( ipath + '/rbo_common/d_images/listings_gallery_image_13133.jpeg', ipath + '/rbo_common/d_images/listings_gallery_thumbnail_13133.jpeg', "Front Entrance", "Front Entrance", "Front Entrance", "426", "320");
Photos[1] = new Array( ipath + '/rbo_common/d_images/listings_gallery_image_13110.jpeg', ipath + '/rbo_common/d_images/listings_gallery_thumbnail_13110.jpeg', "Lobby and Concierge upon entrance. Walk through into  interior.", "Lobby and Concierge upon entrance. Walk through into  interior.", "Lobby and Concierge upon entrance. Walk through into  interior.", "483", "320");
Photos[2] = new Array( ipath + '/rbo_common/d_images/listings_gallery_image_13134.jpeg', ipath + '/rbo_common/d_images/listings_gallery_thumbnail_13134.jpeg', "Private Parking Lot", "Private Parking Lot", "Private Parking Lot", "426", "320");
Photos[3] = new Array( ipath + '/rbo_common/d_images/listings_gallery_image_13136.jpeg', ipath + '/rbo_common/d_images/listings_gallery_thumbnail_13136.jpeg', "Grand Pool runs between 5 condo buildings", "Grand Pool runs between 5 condo buildings", "Grand Pool runs between 5 condo buildings", "426", "320");
Photos[4] = new Array( ipath + '/rbo_common/d_images/listings_gallery_image_13132.jpeg', ipath + '/rbo_common/d_images/listings_gallery_thumbnail_13132.jpeg', "poolside view of condo patio", "poolside view of condo patio", "poolside view of condo patio", "427", "320");
Photos[5] = new Array( ipath + '/rbo_common/d_images/listings_gallery_image_13135.jpeg', ipath + '/rbo_common/d_images/listings_gallery_thumbnail_13135.jpeg', "Pathways throughout Complex", "Pathways throughout Complex", "Pathways throughout Complex", "426", "320");
Photos[6] = new Array( ipath + '/rbo_common/d_images/listings_gallery_image_13131.jpeg', ipath + '/rbo_common/d_images/listings_gallery_thumbnail_13131.jpeg', "Mature Palm near pool", "Mature Palm near pool", "Mature Palm near pool", "426", "320");
Photos[7] = new Array( ipath + '/rbo_common/d_images/listings_gallery_image_13130.jpeg', ipath + '/rbo_common/d_images/listings_gallery_thumbnail_13130.jpeg', "Condo booklet and Maps", "Condo booklet and Maps", "Condo booklet and Maps", "426", "320");
Photos[8] = new Array( ipath + '/rbo_common/d_images/listings_gallery_image_13124.jpeg', ipath + '/rbo_common/d_images/listings_gallery_thumbnail_13124.jpeg', "Deluxe Kitchen. Purified Drinking Water system. Bring your favorite scented candles.", "Deluxe Kitchen. Purified Drinking Water system. Bring your favorite scented candles.", "Deluxe Kitchen. Purified Drinking Water system. Bring your favorite scented candles.", "426", "320");
Photos[9] = new Array( ipath + '/rbo_common/d_images/listings_gallery_image_13123.jpeg', ipath + '/rbo_common/d_images/listings_gallery_thumbnail_13123.jpeg', "Family Room comfort", "Family Room comfort", "Family Room comfort", "426", "320");
Photos[10] = new Array( ipath + '/rbo_common/d_images/listings_gallery_image_13121.jpeg', ipath + '/rbo_common/d_images/listings_gallery_thumbnail_13121.jpeg', "Open and Airy living and dining", "Open and Airy living and dining", "Open and Airy living and dining", "426", "320");
Photos[11] = new Array( ipath + '/rbo_common/d_images/listings_gallery_image_13122.jpeg', ipath + '/rbo_common/d_images/listings_gallery_thumbnail_13122.jpeg', "Entertainment Center, DVD player, Stereo, High-Speed Wireless Internet, DVD movie Library", "Entertainment Center, DVD player, Stereo, High-Speed Wireless Internet, DVD movie Library", "Entertainment Center, DVD player, Stereo, High-Speed Wireless Internet, DVD movie Library", "427", "320");
Photos[12] = new Array( ipath + '/rbo_common/d_images/listings_gallery_image_13129.jpeg', ipath + '/rbo_common/d_images/listings_gallery_thumbnail_13129.jpeg', "Patio Close-up", "Patio Close-up", "Patio Close-up", "427", "320");
Photos[13] = new Array( ipath + '/rbo_common/d_images/listings_gallery_image_13118.jpeg', ipath + '/rbo_common/d_images/listings_gallery_thumbnail_13118.jpeg', "Master Bedroom", "Master Bedroom", "Master Bedroom", "427", "320");
Photos[14] = new Array( ipath + '/rbo_common/d_images/listings_gallery_image_13119.jpeg', ipath + '/rbo_common/d_images/listings_gallery_thumbnail_13119.jpeg', "2nd Guest Bedroom", "2nd Guest Bedroom", "2nd Guest Bedroom", "426", "320");
Photos[15] = new Array( ipath + '/rbo_common/d_images/listings_gallery_image_13127.gif', ipath + '/rbo_common/d_images/listings_gallery_thumbnail_13127.gif', "Tiled bathrooms and shower with shower seating", "Tiled bathrooms and shower with shower seating", "Tiled bathrooms and shower with shower seating", "427", "320");
Photos[16] = new Array( ipath + '/rbo_common/d_images/listings_gallery_image_13120.jpeg', ipath + '/rbo_common/d_images/listings_gallery_thumbnail_13120.jpeg', "3rd Guest Bedroom", "3rd Guest Bedroom", "3rd Guest Bedroom", "426", "320");
Photos[17] = new Array( ipath + '/rbo_common/d_images/listings_gallery_image_13125.jpeg', ipath + '/rbo_common/d_images/listings_gallery_thumbnail_13125.jpeg', "Free beach club and facility access. There are other beautiful public beaches in Playa.", "Free beach club and facility access. There are other beautiful public beaches in Playa.", "Free beach club and facility access. There are other beautiful public beaches in Playa.", "426", "320");
Photos[18] = new Array( ipath + '/rbo_common/d_images/listings_gallery_image_13116.jpeg', ipath + '/rbo_common/d_images/listings_gallery_thumbnail_13116.jpeg', "Pro Tennis Court on site (rackets and balls). Championship Golf Course and Professional Spa Therapy Center next door. Discounts available to rental tenants.", "Pro Tennis Court on site (rackets and balls). Championship Golf Course and Professional Spa Therapy Center next door. Discounts available to rental tenants.", "Pro Tennis Court on site (rackets and balls). Championship Golf Course and Professional Spa Therapy Center next door. Discounts available to rental tenants.", "426", "320");
Photos[19] = new Array( ipath + '/rbo_common/d_images/listings_gallery_image_13117.jpeg', ipath + '/rbo_common/d_images/listings_gallery_thumbnail_13117.jpeg', "Gardens and Pathways throughout", "Gardens and Pathways throughout", "Gardens and Pathways throughout", "426", "320");
Photos[20] = new Array( ipath + '/rbo_common/d_images/listings_gallery_image_13112.jpeg', ipath + '/rbo_common/d_images/listings_gallery_thumbnail_13112.jpeg', "Our pool with bridge over crossing", "Our pool with bridge over crossing", "Our pool with bridge over crossing", "426", "320");
Photos[21] = new Array( ipath + '/rbo_common/d_images/listings_gallery_image_13115.jpeg', ipath + '/rbo_common/d_images/listings_gallery_thumbnail_13115.jpeg', "Pool shot east end (baby pool)", "Pool shot east end (baby pool)", "Pool shot east end (baby pool)", "426", "320");
Photos[22] = new Array( ipath + '/rbo_common/d_images/listings_gallery_image_13114.jpeg', ipath + '/rbo_common/d_images/listings_gallery_thumbnail_13114.jpeg', "Private Laundry room. Optional rental bikes (2)", "Private Laundry room. Optional rental bikes (2)", "Private Laundry room. Optional rental bikes (2)", "426", "320");
Photos[23] = new Array( ipath + '/rbo_common/d_images/listings_gallery_image_13126.jpeg', ipath + '/rbo_common/d_images/listings_gallery_thumbnail_13126.jpeg', "floor plan", "floor plan", "floor plan", "426", "320");
var style_link = document.getElementById('gallery_css_111841');
if (style_link) {
    style_link.parentNode.removeChild(style_link);
}
style_link = document.createElement('link');
style_link.id = 'gallery_css_111841';
style_link.href = 'http://www.mexicorentalsnetwork.com/rbo_common/gallery/111841.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.mexicorentalsnetwork.com/rbo_common/gallery/111841.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_13133.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_thumbnail_13133.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_thumbnail_13110.jpeg');
    var preloadPhotosAfter = new Array('' + ipath + '/rbo_common/d_images/listings_gallery_image_13110.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_image_13134.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_thumbnail_13134.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_image_13136.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_thumbnail_13136.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_image_13132.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_thumbnail_13132.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_image_13135.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_thumbnail_13135.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_image_13131.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_thumbnail_13131.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_image_13130.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_thumbnail_13130.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_image_13124.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_thumbnail_13124.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_image_13123.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_thumbnail_13123.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_image_13121.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_thumbnail_13121.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_image_13122.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_thumbnail_13122.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_image_13129.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_thumbnail_13129.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_image_13118.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_thumbnail_13118.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_image_13119.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_thumbnail_13119.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_image_13127.gif', '' + ipath + '/rbo_common/d_images/listings_gallery_thumbnail_13127.gif', '' + ipath + '/rbo_common/d_images/listings_gallery_image_13120.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_thumbnail_13120.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_image_13125.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_thumbnail_13125.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_image_13116.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_thumbnail_13116.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_image_13117.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_thumbnail_13117.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_image_13112.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_thumbnail_13112.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_image_13115.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_thumbnail_13115.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_image_13114.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_thumbnail_13114.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_image_13126.jpeg', '' + ipath + '/rbo_common/d_images/listings_gallery_thumbnail_13126.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( "Paseo del Sol - Opulent 3 Bedroom Condo in Playacar. Online Video..." );
    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);
}
