var page;
var scn = 0; 
var Z = new Array(
  "Who you are,<br/> will sound as unmistakable from you<br/>that I can not hear what you say.",
  "It Ain't Over Till It's Over.", 
  "Why so serious?",
  "Face it, girls, I'm older and I have more insurance.",
  "As far back as I can remember, I always wanted to be a gangster.",
  "I am a star. I'm a star, I'm a star, I'm a star.<br/>I am a big, bright, shining star. That's right.",
  "Machete don't text.",
  "If you're good at something, never do it for free.",
  "Fish are friends, not food.",
  "Gentlemen, you can't fight in here! This is the War Room."
);
var ZP = new Array(
  "Ralph Waldo Emerson",
  "Rocky Balboa", 
  "The Joker",
  "Fried Green Tomatoes",
  "GoodFellas",
  "Boogie Nights",
  "Machete",
  "The Joker",
  "Finding Nemo",
  "Dr. Strangelove: Or, How I Learned to Stop Worrying and Love the Bomb"
);   

(function($) {
  var imgList = [];
  $.extend({
    preload: function(imgArr, option) {
      var setting = $.extend({
        init: function(loaded, total) {},
        loaded: function(img, loaded, total) {},
        loaded_all: function(loaded, total) {}
      }, option);
      var total = imgArr.length;
      var loaded = 0;
      
      setting.init(0, total);
      for(var i in imgArr) {
        imgList.push($("<img />")
          .attr("src", imgArr[i])
          .load(function() {
            loaded++;
            setting.loaded(this, loaded, total);
            if(loaded == total) {
              setting.loaded_all(loaded, total);
            }
          })
        );
      }
      
    }
  });
})(jQuery);



$(document).ready(function() {
  page = $("body").attr("name");
  $(".galleryImg").live("click", function() {
	  scn = scrollY();
		if (scn != 0) {
		  $('html, body').animate({ scrollTop: 0 }, "slow");
		}
    $(".galleryImgBig").remove();
    $(".galleryImgBigImg").remove();
    var iurl = '/img/preview/500/' + $(this).attr("name");
    $.preload([
      iurl
    ], {
      init: function(loaded, total) {
        $("body").append('<div class="galleryImgBig"></div>');     
        $("body").append('<table class="galleryImgBigImg"><tr><td class="loading">loading...</td></tr></table>');        
      },
      loaded: function(img, loaded, total) {     
        $(".galleryImgBigImg").html('<tr><td class="galleryImgBigImgImg"></td></tr>');
        $(".galleryImgBigImgImg").append(img);
      }
    });    
		return(false);
  });
  $(".galleryImgBig").live("click", function() {
	  scrollBack();
    $(".galleryImgBig").remove();
    $(".galleryImgBigImg").remove();
  });
  $(".galleryImgBigImg").live("click", function() {
	  scrollBack();
    $(".galleryImgBig").remove();
    $(".galleryImgBigImg").remove();
  });  
});

function scrollBack() {
  var y = scrollY();
	if ((scn == 0) && (y == 0)) {
	} else {
	  $('html, body').animate({ scrollTop: scn }, "slow");
	}
}
function scrollY() {
	var h = $("html").scrollTop();
	var b = $("body").scrollTop();
	if (b > h) {
	  h = b;
	}
	return(h);
}



function zitat() {
  var n = Math.round(Math.random() * (Z.length-1));
  $("#zitat").html(Z[n] + '<div id="autor">' + ZP[n] + '</div>');
}


function siteStatus(message) {
  $("#siteStatusText").html(message);  
  $("#siteStatus").show();
  if (message.match(/^error.*/)) {
    $("#siteStatus").click(function() {
      $(this).fadeOut(1000);
    });
  } else {
    $("#siteStatus").fadeOut(1000);
  }
}

