﻿/// <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');

    $("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'/>"
    $.get('mosaic.aspx', { dummy: new Date().getTime() , getid: intIndex}, function(data) {
    $("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, 5000);
});

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 + ")"));
        $.get('mosaic.aspx', { dummy: new Date().getTime(), getid: current_photo }, function(data) {
            //$("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/spacer.gif?ib=" + data + "&w=138&h=93").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);
            }
        });
        
    }
   


