
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 = 307;
var imageGalleryWidth         = 369;
var maxGalleryXPos            = 31;
var minGalleryXPos            = -2372;
var thumbnailsPosition        = 'H';
var scrollingSpeed            = 60;
var slideShowDelay            = 5000;
var ihost                     = '/pmt_common/images/gallery2/';
var ipath                     = '/pmt_common/d_images/unit_gallery/';
var Photos                    = new Array();
Photos[0] = new Array( ipath + 'image_7502.jpeg', ipath + 'thumbnail_7502.jpeg', "Electric Pontoon Boat Included", "Electric Pontoon Boat Included", "Electric Pontoon Boat Included", "400", "300");
Photos[1] = new Array( ipath + 'image_7636.jpeg', ipath + 'thumbnail_7636.jpeg', "Strawberry Lake is great for swimming and fishing", "Strawberry Lake is great for swimming and fishing", "Strawberry Lake is great for swimming and fishing", "400", "300");
Photos[2] = new Array( ipath + 'image_7504.jpeg', ipath + 'thumbnail_7504.jpeg', "Fully Furnished Kitchen", "Fully Furnished Kitchen", "Fully Furnished Kitchen", "400", "300");
Photos[3] = new Array( ipath + 'image_7505.jpeg', ipath + 'thumbnail_7505.jpeg', "Living Room with TV and Wood-Burning Fireplace", "Living Room with TV and Wood-Burning Fireplace", "Living Room with TV and Wood-Burning Fireplace", "400", "300");
Photos[4] = new Array( ipath + 'image_7507.jpeg', ipath + 'thumbnail_7507.jpeg', "Dock for Electric Pontoon and Paddle Boat (Included!)", "Dock for Electric Pontoon and Paddle Boat (Included!)", "Dock for Electric Pontoon and Paddle Boat (Included!)", "400", "300");
Photos[5] = new Array( ipath + 'image_7503.jpeg', ipath + 'thumbnail_7503.jpeg', "2 Story Cedar Home with Walk-Out Basement", "2 Story Cedar Home with Walk-Out Basement", "2 Story Cedar Home with Walk-Out Basement", "400", "300");
Photos[6] = new Array( ipath + 'image_7508.jpeg', ipath + 'thumbnail_7508.jpeg', "Master Bedroom has King Bed and Full Futon with Walk-Out Deck and Strawberry Lake View", "Master Bedroom has King Bed and Full Futon with Walk-Out Deck and Strawberry Lake View", "Master Bedroom has King Bed and Full Futon with Walk-Out Deck and Strawberry Lake View", "400", "300");
Photos[7] = new Array( ipath + 'image_7529.jpeg', ipath + 'thumbnail_7529.jpeg', "Master Bedroom Upstairs Deck", "Master Bedroom Upstairs Deck", "Master Bedroom Upstairs Deck", "400", "300");
Photos[8] = new Array( ipath + 'image_7509.jpeg', ipath + 'thumbnail_7509.jpeg', "Fire Ring and Picnic Table on Beach", "Fire Ring and Picnic Table on Beach", "Fire Ring and Picnic Table on Beach", "400", "300");
Photos[9] = new Array( ipath + 'image_8354.jpeg', ipath + 'thumbnail_8354.jpeg', "Main Level Queen Bedroom", "Main Level Queen Bedroom", "Main Level Queen Bedroom", "400", "300");
Photos[10] = new Array( ipath + 'image_7513.jpeg', ipath + 'thumbnail_7513.jpeg', "2nd Dining Area Seats an Additional 6", "2nd Dining Area Seats an Additional 6", "2nd Dining Area Seats an Additional 6", "400", "300");
Photos[11] = new Array( ipath + 'image_7514.jpeg', ipath + 'thumbnail_7514.jpeg', "Main Dining Seats 4", "Main Dining Seats 4", "Main Dining Seats 4", "400", "300");
Photos[12] = new Array( ipath + 'image_7512.jpeg', ipath + 'thumbnail_7512.jpeg', "Laundry Room with Sink and Counter", "Laundry Room with Sink and Counter", "Laundry Room with Sink and Counter", "400", "300");
Photos[13] = new Array( ipath + 'image_7515.jpeg', ipath + 'thumbnail_7515.jpeg', "Doors to Lakefront Main Deck", "Doors to Lakefront Main Deck", "Doors to Lakefront Main Deck", "400", "300");
Photos[14] = new Array( ipath + 'image_7516.jpeg', ipath + 'thumbnail_7516.jpeg', "View from Master Bedroom", "View from Master Bedroom", "View from Master Bedroom", "400", "300");
Photos[15] = new Array( ipath + 'image_7517.jpeg', ipath + 'thumbnail_7517.jpeg', "View from 2nd Dining Area", "View from 2nd Dining Area", "View from 2nd Dining Area", "400", "300");
Photos[16] = new Array( ipath + 'image_7520.jpeg', ipath + 'thumbnail_7520.jpeg', "Master Bath with Walk-In Glass Shower", "Master Bath with Walk-In Glass Shower", "Master Bath with Walk-In Glass Shower", "400", "300");
Photos[17] = new Array( ipath + 'image_7521.jpeg', ipath + 'thumbnail_7521.jpeg', "Master Bath Shower", "Master Bath Shower", "Master Bath Shower", "400", "300");
Photos[18] = new Array( ipath + 'image_8352.jpeg', ipath + 'thumbnail_8352.jpeg', "Bedroom 5 on Lower Level", "Bedroom 5 on Lower Level", "Bedroom 5 on Lower Level", "400", "298");
Photos[19] = new Array( ipath + 'image_8357.jpeg', ipath + 'thumbnail_8357.jpeg', "Bedroom 6 in Lower Level", "Bedroom 6 in Lower Level", "Bedroom 6 in Lower Level", "400", "300");
Photos[20] = new Array( ipath + 'image_8358.jpeg', ipath + 'thumbnail_8358.jpeg', "Bedroom 4 with Sofa Bed, Futon and TV", "Bedroom 4 with Sofa Bed, Futon and TV", "Bedroom 4 with Sofa Bed, Futon and TV", "400", "300");
Photos[21] = new Array( ipath + 'image_8500.jpeg', ipath + 'thumbnail_8500.jpeg', "Lower Level - Great Room for Meetings, Dining - Sliding Glass Door to Driveway", "Lower Level - Great Room for Meetings, Dining - Sliding Glass Door to Driveway", "Lower Level - Great Room for Meetings, Dining - Sliding Glass Door to Driveway", "400", "300");
Photos[22] = new Array( ipath + 'image_8356.jpeg', ipath + 'thumbnail_8356.jpeg', "Bunk House (Bedroom 7) with Bunk Beds and 2 Futons, TV", "Bunk House (Bedroom 7) with Bunk Beds and 2 Futons, TV", "Bunk House (Bedroom 7) with Bunk Beds and 2 Futons, TV", "400", "300");
Photos[23] = new Array( ipath + 'image_7518.jpeg', ipath + 'thumbnail_7518.jpeg', "View from Deer Blind on Property (10 Acres)", "View from Deer Blind on Property (10 Acres)", "View from Deer Blind on Property (10 Acres)", "400", "300");
Photos[24] = new Array( ipath + 'image_7519.jpeg', ipath + 'thumbnail_7519.jpeg', "Deer Blind on Property - Great for Turkey Hunting, Too!", "Deer Blind on Property - Great for Turkey Hunting, Too!", "Deer Blind on Property - Great for Turkey Hunting, Too!", "400", "300");
Photos[25] = new Array( ipath + 'image_7523.jpeg', ipath + 'thumbnail_7523.jpeg', "Deer right outside your window!", "Deer right outside your window!", "Deer right outside your window!", "400", "300");
Photos[26] = new Array( ipath + 'image_7524.jpeg', ipath + 'thumbnail_7524.jpeg', "Bunk House Sleeps Extra 6", "Bunk House Sleeps Extra 6", "Bunk House Sleeps Extra 6", "400", "300");
Photos[27] = new Array( ipath + 'image_7525.jpeg', ipath + 'thumbnail_7525.jpeg', "Electric Pontoon Boat and Paddle Boat", "Electric Pontoon Boat and Paddle Boat", "Electric Pontoon Boat and Paddle Boat", "400", "300");
Photos[28] = new Array( ipath + 'image_7526.jpeg', ipath + 'thumbnail_7526.jpeg', "View of House from Driveway", "View of House from Driveway", "View of House from Driveway", "400", "300");
Photos[29] = new Array( ipath + 'image_7528.jpeg', ipath + 'thumbnail_7528.jpeg', "Deck and Doors to Bedroom 4", "Deck and Doors to Bedroom 4", "Deck and Doors to Bedroom 4", "400", "300");
Photos[30] = new Array( ipath + 'image_7530.jpeg', ipath + 'thumbnail_7530.jpeg', "Tranquility on Strawberry Lake", "Tranquility on Strawberry Lake", "Tranquility on Strawberry Lake", "400", "300");
Photos[31] = new Array( ipath + 'image_7532.jpeg', ipath + 'thumbnail_7532.jpeg', "View from Main Deck", "View from Main Deck", "View from Main Deck", "400", "300");
Photos[32] = new Array( ipath + 'image_7533.jpeg', ipath + 'thumbnail_7533.jpeg', "Pere Marquette ORV Trail", "Pere Marquette ORV Trail", "Pere Marquette ORV Trail", "400", "300");
Photos[33] = new Array( ipath + 'image_8353.jpeg', ipath + 'thumbnail_8353.jpeg', "Driveway", "Driveway", "Driveway", "370", "300");
var style_link = document.getElementById('gallery_css_2628');
if (style_link) {
    style_link.parentNode.removeChild(style_link);
}
style_link = document.createElement('link');
style_link.id = 'gallery_css_2628';
style_link.href = '/pmt_common/gallery2/unit_2628.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="/pmt_common/gallery2/unit_2628.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 + 'image_7502.jpeg', '' + ipath + 'thumbnail_7502.jpeg', '' + ipath + 'thumbnail_7636.jpeg');
    var preloadPhotosAfter = new Array('' + ipath + 'image_7636.jpeg', '' + ipath + 'image_7504.jpeg', '' + ipath + 'thumbnail_7504.jpeg', '' + ipath + 'image_7505.jpeg', '' + ipath + 'thumbnail_7505.jpeg', '' + ipath + 'image_7507.jpeg', '' + ipath + 'thumbnail_7507.jpeg', '' + ipath + 'image_7503.jpeg', '' + ipath + 'thumbnail_7503.jpeg', '' + ipath + 'image_7508.jpeg', '' + ipath + 'thumbnail_7508.jpeg', '' + ipath + 'image_7529.jpeg', '' + ipath + 'thumbnail_7529.jpeg', '' + ipath + 'image_7509.jpeg', '' + ipath + 'thumbnail_7509.jpeg', '' + ipath + 'image_8354.jpeg', '' + ipath + 'thumbnail_8354.jpeg', '' + ipath + 'image_7513.jpeg', '' + ipath + 'thumbnail_7513.jpeg', '' + ipath + 'image_7514.jpeg', '' + ipath + 'thumbnail_7514.jpeg', '' + ipath + 'image_7512.jpeg', '' + ipath + 'thumbnail_7512.jpeg', '' + ipath + 'image_7515.jpeg', '' + ipath + 'thumbnail_7515.jpeg', '' + ipath + 'image_7516.jpeg', '' + ipath + 'thumbnail_7516.jpeg', '' + ipath + 'image_7517.jpeg', '' + ipath + 'thumbnail_7517.jpeg', '' + ipath + 'image_7520.jpeg', '' + ipath + 'thumbnail_7520.jpeg', '' + ipath + 'image_7521.jpeg', '' + ipath + 'thumbnail_7521.jpeg', '' + ipath + 'image_8352.jpeg', '' + ipath + 'thumbnail_8352.jpeg', '' + ipath + 'image_8357.jpeg', '' + ipath + 'thumbnail_8357.jpeg', '' + ipath + 'image_8358.jpeg', '' + ipath + 'thumbnail_8358.jpeg', '' + ipath + 'image_8500.jpeg', '' + ipath + 'thumbnail_8500.jpeg', '' + ipath + 'image_8356.jpeg', '' + ipath + 'thumbnail_8356.jpeg', '' + ipath + 'image_7518.jpeg', '' + ipath + 'thumbnail_7518.jpeg', '' + ipath + 'image_7519.jpeg', '' + ipath + 'thumbnail_7519.jpeg', '' + ipath + 'image_7523.jpeg', '' + ipath + 'thumbnail_7523.jpeg', '' + ipath + 'image_7524.jpeg', '' + ipath + 'thumbnail_7524.jpeg', '' + ipath + 'image_7525.jpeg', '' + ipath + 'thumbnail_7525.jpeg', '' + ipath + 'image_7526.jpeg', '' + ipath + 'thumbnail_7526.jpeg', '' + ipath + 'image_7528.jpeg', '' + ipath + 'thumbnail_7528.jpeg', '' + ipath + 'image_7530.jpeg', '' + ipath + 'thumbnail_7530.jpeg', '' + ipath + 'image_7532.jpeg', '' + ipath + 'thumbnail_7532.jpeg', '' + ipath + 'image_7533.jpeg', '' + ipath + 'thumbnail_7533.jpeg', '' + ipath + 'image_8353.jpeg', '' + ipath + 'thumbnail_8353.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( "Huge Lakefront Home South of Cadillac - Home" );
    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;text-align: center;');
    }
    preview_pane_img_div.appendChild(preview_pane_img);
    preview_pane_center = document.createElement('center');
    preview_pane_center.appendChild(preview_pane_img_div);
    preview_pane.appendChild(preview_pane_center);
    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);
}
