// JScript File

//$(document).ready   (

	    function candyGallery()
	    {
	    	$('#Gallery a').fancybox();
	    }

                        function ajaxGallery()
                        {
                            $contentLoadTriggered = false;
                            $("#photoGallery").scroll    (
                                                        function()
                                                        {
                                                            if($("#photoGallery").scrollTop() >= ($("#Gallery").height() - $("#photoGallery").height()) && $contentLoadTriggered == false)
                                                            {
                                                                $contentLoadTriggered = true;
								
								var v = $("#Gallery a").last().attr('class');

								 $.ajax  (
                                                                            {
                                                                                type: "GET",
                                                                                url: "ajax/gallery.php?gallery=begin,"+(parseInt(v)+1)+",end,"+ ( parseInt(v) + 9 )+",load,1",
                                                                                async: true,
                                                                                cache: false,
                                                                                success:    function (msg) 
                                                                                            {
                                                                                                $("#Gallery").append(msg);
                                                                                                $contentLoadTriggered = false;
												candyGallery();
												
                                                                                            },
                                                                                error:  function (x, e)
                                                                                        {
                                                                                            alert("The call to the server side failed. " + x.responseText);
                                                                                        }
                                                                            }
                                                                        );
                                                            }
                                                        }
                                                    );
                        }
                    //);                    

  $(document).ready(function()
  {
    $.ajax({
      url: "ajax/gallery.php?gallery=begin,0,end,9",
      cache: false,
      success: function(html)
      {
	$("#photoGallery").append(html);
	ajaxGallery();
	candyGallery();
      }
    });
  });


