    function rand( min, max ) 
    {
      // *     example 1: rand(1, 1);
      // *     returns 1: 1
      var argc = arguments.length;
      if (argc == 0) 
      {
          min = 0;
          max = 2147483647;
      } 
      else if (argc == 1) 
      {
          throw new Error('Warning: rand() expects exactly 2 parameters, 1 given');
      }
      return Math.floor(Math.random() * (max - min + 1)) + min;
    }  
    
    
    $(function()
    {         
			 
      $(document).bind("contextmenu",function(e)
      {
      	return false;
      });
      
      
      
      var select_photo_thumbnail=function(id_photo)
      {        
        if(id_photo && !isNaN(id_photo))
        {
          $("#thumbnail_table td").each(function(){$(this).css("background-color","#2F2F2F")});
          $("#photo_"+id_photo).parent().parent().css("background-color","#979797");
          $("body").trigger("click");
        } 
      }
      
      if(gup("id"))
        select_photo_thumbnail(gup("id"));
         
         
      if(document.getElementById('slideshow_img') && document.getElementById('slideshow_img')!="")
      {
        var imgPath=$('#slideshow_img').val();
        imgPath=imgPath.split(";");
        
        var slideshow_image_nr=-1;
        var slideshow_image_path="";
        var slideshow=function()
        {          
          do
          {
            new_slideshow_image_nr=rand(1,3); 
            //alert(slideshow_image_nr);
          }
          while(new_slideshow_image_nr==slideshow_image_nr);
          slideshow_image_nr=new_slideshow_image_nr;
          
          do
          {
            rand_nr=rand(0,imgPath.length-1);
            new_slideshow_image_path=imgPath[rand_nr];            
            var image_id=$("#thumbnail_table img").eq(rand_nr).attr("id");
          }
          while(new_slideshow_image_path==slideshow_image_path);
          slideshow_image_path=new_slideshow_image_path;
              
          //alert(slideshow_image_path);
          $.preload([slideshow_image_path],
          {                            
    				onComplete:function(data)
            {
              $("#slideshow_images img").each(function()
              {
                $(this).fadeOut("show");
              });
              
              var id="#slideshow_image"+slideshow_image_nr;                         
              $(id).attr("src",slideshow_image_path);
              $(id).fadeIn("slow");
              $(id).click(function(){$("#"+image_id).trigger("click"); return false;});
            }
          });
        }           
        
        slideshow();
        setInterval(slideshow,3000);
      }
      
      
      
      

      $('#loading_bar').hide(); 
      $('.small_img').click(function()
      {
        var src=$(this).attr('src');        
        var aux=src.split('/');
        var filename=aux[2].split('.');
        var aux=$(this).attr('id');
        var id=aux.split('_');
        var href=$(this).parent().attr("href");
        
        $.ajax(
        {
					type:'GET',
					url:'/index.php?p=gallerie:image',
					data:'id='+id[1],
					success:function(data)
					{						
            //alert(data);
            var image=data.split(';');
            					   
            $.preload([image[0]],
            {                            
      				onComplete:function(data)
                {
                  var img = new Image();
                  img.src = data.image;
                  $('#loading_bar').hide();    				      
    				      $('#big_img_placeholder').html(image[2]);
    				      $('#language a').attr("href",image[3]);
    				          				                       
                  document.title=image[1];                                      
    				        
    				      $('#big_img_placeholder').show("slow");
    				      
    				      select_photo_thumbnail(id[1]);
    				      
    				      pageTracker._trackPageview(href);
                }  				
      			});
      		}
      	})
      	return false;
  		}); 
      
      $("#loading_bar").ajaxStart(function()
      {
        $('#big_img_placeholder').hide();
        $(this).show();
      }); 	                        	
    });