﻿/// <reference path="jquery-vsdoc.js" />
var old_photo = 0;
var current_photo = 0;
var index_photo;
var selected_photo = 0;
$(document).ready(function () {
    //$("div.mosaic:eq(" + current_photo + ")").css('background-color', 'yellow');
    //http://localhost/imagebank/images/Riverbank.jpg?w=138&h=93
    $("div.mosaic").each(function (intIndex) {
        //var randomindexphoto= Math.floor(Math.random() * $('*[id$="totphotos"]')[0].value);
        //"<img src='images/spacer.gif?ib=" + CStr(GetPhoto()) + "&w=138&h=93' width='138' height='93'/>" dummy: new Date().getTime(),
        $.get('mosaic2.aspx', { getid: intIndex }, function (data) {
            var _photo = data.split("_");
            $("div.mosaic:eq(" + intIndex + ")").append('<img src="images/' + _photo[1] + '.jpg?w=138&h=93&t=1" width="138" height="93" border="0" onclick="gotophoto(' + _photo[0] + ')" onmouseover="this.style.cursor=\'pointer\'"  onmouseout="this.style.cursor=\'default\'" />')
            //$("div.mosaic:eq(" + intIndex + ")").append('<img src="images/spacer.gif?ib=' + data + '&w=138&h=93" width="138" height="93" border="0" onclick="gotophoto(' + data + ')" onmouseover="this.style.cursor=\'pointer\'"  onmouseout="this.style.cursor=\'default\'" />')
        });

    })
   var changephoto_interval = setInterval(runIt, 35000);
});

function gotophoto(photoid) {
    window.location.href = 'FindDetails.aspx?id=' + photoid

}

$.fn.wait = function (time, type) {
    time = time || 1000;
    type = type || "fx";
    return this.queue(type, function () {
        var self = this;
        setTimeout(function () {
            $(self).dequeue();
        }, time);
    });
};



function runIt() {
    photos_count = $("div.mosaic").size();
    current_photo = Math.floor(Math.random() * photos_count);
    old_photo = current_photo;
    var $img = $("div.mosaic:eq(" + current_photo + ") > img");
    // $img.clone().appendTo($("div.mosaic:eq(" + current_photo + ")"));dummy: new Date().getTime(), 
    $.get('mosaic2.aspx', { getid: current_photo }, function (data) {
        var _photo = data.split("_");
        //$("div.mosaic:eq(" + current_photo  + ")").append("<img src='images/spacer.gif?ib=" + data + "&w=138&h=93' width='138' height='93'/>");
        $img.fadeOut("slow").queue(function () { $img.attr("src", "images/" + _photo[1] + ".jpg?w=138&h=93&t=1").dequeue() }).wait();

        // $img.fadeOut("slow").wait(900);
        var performAction = function () {
            $img
            .fadeIn("slow");
            //$img.remove();
        };
        if ($img[0].complete) {
            performAction();
        }
        else {
            // $img.bind("load", performAction);
        }
    });

}
   



