﻿

/* image swapping code */

function imagedata(url, title, height, width) {
    this.url = url; 				// url of image
    this.title = title; 			// image title (alt text)
    this.height = height; 		// image height
    this.width = width; 			// image width
};

var currentimage = 0; 			// current displayed image
var imageresize = false; 		// if the main image will resize (PhotoAlbum sets in ASPX code)


// display image n (0-based) using image control ctl and optional label (title)
function DisplayImage(n, e) {
    var ctl = $(".defaultPhotoImage", '#PropertyGallery')[0];
    var labelctl = document.getElementById('labelMainPhoto');
    if (ctl != null)


    // is image within imagedata range
        if (n >= 0 && n < imagearray.length) {
        ctl.src = imagearray[n].url;
        ctl.title = imagearray[n].title;
        // optionally resize
        if (imageresize) {
            ctl.width = imagearray[n].width;
            ctl.height = imagearray[n].height;
        }
        // optional label control  
        if (labelctl != null)
            labelctl.innerHTML = imagearray[n].title;
        currentimage = n;
    };
    //UpdateNavigation();
    if (!e) {
        e = window.event;

    }
    if (e) {
        target = (e.target) ? e.target : e.srcElement;
        $(target).parents('li:eq(0)').addClass("selected").siblings().removeClass("selected");

    }
};

//

function DisplayPreviousImage() {
    if (currentimage == 0)
        currentimage = imagearray.length;

    DisplayImage(--currentimage);
}

function DisplayNextImage() {
    if (currentimage == imagearray.length - 1)
        currentimage = -1;

    DisplayImage(++currentimage);
}


/********************************************************************/


function thumbsCarousel_initCallback(carousel) {
    $('#NextPhoto').attr("href", "#1").click(function(e) {
        var i = parseInt(this.href.split('#')[1]);
        if (isNaN(i)) { return false };
        var x = (i + 1) - (i % 3);
        carousel.scroll($.jcarousel.intval(parseInt(x)));
        return ChangeImagePrevNext(i, e);

    });

    $('#PrevPhoto').click(function(e) {
        var i = parseInt(this.href.split('#')[1]);
        if (isNaN(i)) { return false };
        var x = (i + 1) - (i % 3);
        carousel.scroll($.jcarousel.intval(parseInt(x)));
        return ChangeImagePrevNext(i, e, carousel);
    });



}


function PrevNext(i) {
    var x = 0;
    if (i < (imagearray.length - 1)) {
        x = parseInt(i) + 1;
        $('#NextPhoto').attr("href", "#" + x).removeClass("next_disabled");
    } else {
        $('#NextPhoto').addClass("next_disabled").attr("href", "#");
    };

    if (i > 0) {
        x = parseInt(i) - 1;
        $('#PrevPhoto').attr("href", "#" + x).removeClass("prev_disabled");
    } else {
        $('#PrevPhoto').addClass("prev_disabled").attr("href", "#");

    };
}

function ShowLocalityToolTip() {
    var obj = $(this);
    if (obj.find('.tooltip').length == 0) {

        var tooltipContent = obj.prev(".tooltipTable:eq(0)"), toolTip = $('<div class="tooltip"><div class="closer"></div></div>');
        if (tooltipContent) {
            tooltipContent.appendTo(toolTip);
            toolTip.appendTo(obj);
        }

    }

    return window.FAP.UI.openToolTip(obj);
}
/**********************************************************************************************/

/* image swapping code */

var imagearray = new Array();
/* imagedata object should be added to this array. see PhotoAlbum as an example */


function imagedata(url, title, height, width) {
    this.url = url; 				// url of image
    this.title = title; 			// image title (alt text)
    this.height = height; 		// image height
    this.width = width; 			// image width
};

var currentimage = 0; 			// current displayed image
var imageresize = false; 		// if the main image will resize (PhotoAlbum sets in ASPX code)


// display image n (0-based) using image control ctl and optional label (title)
function DisplayImage(n) {

    var ctls = document.getElementsByName('imgMainPhoto');

    if (ctls.length > 0) {
        var ctl = ctls[0];
    }

    if (ctl != null) {

        // is image within imagedata range
        if (n >= 0 && n < imagearray.length) {

            ctl.src = imagearray[n].url;
            ctl.alt = imagearray[n].title;
            ctl.title = imagearray[n].title;

            // optionally resize
            if (imageresize) {
                ctl.width = imagearray[n].width;
                ctl.height = imagearray[n].height;
            }

            currentimage = n;
        }

    }
    UpdateNavigation();
}

function UpdateNavigation() {
    var pctl = document.getElementById('prevLink');
    var nctl = document.getElementById('nextLink');
    if (pctl != null) pctl.style.visibility = (imagearray.length > 0) ? 'visible' : 'hidden';
    if (nctl != null) nctl.style.visibility = (imagearray.length > 0) ? 'visible' : 'hidden';
}

function DisplayNextImage() {
    if (currentimage == 0)
        currentimage = imagearray.length;

    DisplayImage(--currentimage);
}

function DisplayPreviousImage() {
    if (currentimage == imagearray.length - 1)
        currentimage = -1;

    DisplayImage(++currentimage);
}

