//Art Dealers Front end javascript functions


// preload image
function imagespreload(imagestoLoad) {
    var mySplitResult = imagestoLoad.split(";");
    for (var i = 0; i < mySplitResult.length; i++) {
        var imagetoLoad = mySplitResult[i];
        if (document.images) {
            preload_image_object = new Image();
            preload_image_object.src = imagetoLoad;
        }
    }
}


function change(picurl, imageId) {

    // check to make syre we are changing image
    if (change.CurrentPic != picurl || change.LastimageId != imageId) {
        //set static function varibles currentpic and lastimageid
        change.CurrentPic = picurl;
        change.LastimageId = imageId;
        // find control
        image = document.getElementById(imageId);
        // set opacity to 0
        setOpacity(image, 0);
        // change image
        document.images.PreviewImage.src = picurl;
        image.style.visibility = "visible";
        //fade in image
        fadeIn(imageId, 0);
    }
}


function changewithzoom(picurl, zoomurl, pictitle, imageId) {

    // check to make syre we are changing image
    if (change.CurrentPic != picurl || change.LastimageId != imageId) {
        //set static function varibles currentpic and lastimageid
        change.CurrentPic = picurl;
        change.LastimageId = imageId;
        
        // find control
        image = document.getElementById(imageId);
        
        // set opacity to 0
        setOpacity(image, 0);
        
        // change image
        document.images.PreviewImage.src = picurl; 
        image.style.visibility = "visible";

        //set zoomable url
        if (document.getElementById('imagetitle') != null) {
            document.getElementById('imagetitle').href = zoomurl;
            document.getElementById('imagetitle').childNodes[0].nodeValue  = pictitle;
        } else if (document.getElementById('ctl00_MainContent_exhibitionDisplay1_FormView1_Imagepreview1_FormView1_zoomlink') != null) {
            document.getElementById('ctl00_MainContent_exhibitionDisplay1_FormView1_Imagepreview1_FormView1_zoomlink').href = zoomurl;
            document.getElementById('ctl00_MainContent_exhibitionDisplay1_FormView1_Imagepreview1_FormView1_zoomlink').title = pictitle;
        }
        
        
        //fade in image
        fadeIn(imageId, 0);
    }
}

function fadeIn(objId, opacity) {
// fade in image function
    if (document.getElementById) {
        obj = document.getElementById(objId);
        if (opacity <= 100) {
            setOpacity(obj, opacity);
            opacity += 10;
            window.setTimeout("fadeIn('" + objId + "'," + opacity + ")", 100);
        }
    }
}

function setOpacity(obj, opacity) {
//sets opasity of a control
    opacity = (opacity == 100) ? 99.999 : opacity;

    // IE/Win
    obj.style.filter = "alpha(opacity:" + opacity + ")";

    // Safari<1.2, Konqueror
    obj.style.KHTMLOpacity = opacity / 100;

    // Older Mozilla and Firefox
    obj.style.MozOpacity = opacity / 100;

    // Safari 1.2, newer Firefox and Mozilla, CSS3
    obj.style.opacity = opacity / 100;
}

timerDown = "";
timerUp = "";
timerLeft = "";
timerRight = "";

// stop the scroll timer running
function stopMe() {
    clearTimeout(timerDown);
    clearTimeout(timerUp);
    clearTimeout(timerRight);
    clearTimeout(timerLeft);
}

/********************************************
    image on mouse scrolling div functions

*********************************************/

//set scroll step
hscrollStep = 3;
vscrollStep = 3;

// for scrolling divs down 
function scrollDivDown(id) {
    clearTimeout(timerDown);
    document.getElementById(id).scrollTop += hscrollStep;
    timerDown = setTimeout("scrollDivDown('" + id + "')", 10);

}
// for scrolling divs left  
function scrollDivUp(id) {
    clearTimeout(timerUp);
    document.getElementById(id).scrollTop -= hscrollStep;
    timerUp = setTimeout("scrollDivUp('" + id + "')", 10);
}
// for scrolling divs left
function scrollDivLeft(id) {
    clearTimeout(timerRight);
    document.getElementById(id).scrollLeft -= hscrollStep;
    timerRight = setTimeout("scrollDivLeft('" + id + "')", 10);
}
// for scrolling divs right
function scrollDivRight(id) {
    clearTimeout(timerLeft);
    document.getElementById(id).scrollLeft += hscrollStep;
    timerLeft = setTimeout("scrollDivRight('" + id + "')", 10);
}


// for scrolling horizontal div set the width
function setDivWidth(id, widthpx) {
    document.getElementById(id).width = widthpx;
}
