//ą

$(document).ready(function(){
  if ($("#content p").height()>2) {
    setTimeout("$(\"#content\").append(\"<div class=\\\"shadow\\\"></div>\").find(\".shadow\").css(\"height\", (40+$(\"#content p\").height())+\"px\").css(\"opacity\", \"0.6\");",400);
  }
    $("#miniaturki a").css("opacity", "0.5").hover(
      function() {
        $(this).css("opacity", "1");
      }, function(){
        $(this).css("opacity","0.5");
      }).click(function(){
        $(this).parent().find("a").removeClass("selected");
        $(this).addClass("selected");
      });

    setInterval("watchIndex()", 100);
});

function getIndex() {
  return window.location.href.substr(window.location.href.lastIndexOf("#")+1);
}
var lastIndexState="";
function watchIndex() {
  var gottenIndex = getIndex();
	if (lastIndexState!=gottenIndex && gottenIndex!="" && gottenIndex!="top") {
		window.location.href=window.location.href.substring(0, window.location.href.lastIndexOf("#"))+"#";
		lastIndexState="";
		IndexChanged(gottenIndex);
	}
}

function IndexChanged(index) {
  if (index.substr(0,4)=="img:")
  {
    $("#content p, #content .shadow, #content h2").fadeOut(400,function(){$(this).remove();});
    if ($("#content img").length==0) $("#content").prepend("<img />");
    $("#content img").attr("src","images2.php?maxw=500&img="+index.substr(4)).unbind().click(function(){
      if ($("#miniaturki a.selected").next().length>0) {
      	window.location.href = $("#miniaturki a.selected").next().attr("href");
      	$("#miniaturki a.selected").next().click();
      }
    }).load(function(){
    	$("#content").slideDown();
    });
    $("#content").slideUp();
  }
}
