if ($.browser.msie && $.browser.version < 7)
	var IE6 = true;
else
	var IE6 = false;

$(document).ready(function () {

	if (IE6) {
		$("#fixed > img.logo").attr("src",$("#fixed > img.logo").attr("src").replace("png","gif"));
	}

        $("#container div.block").each(function () {
                if ($(this).find("div.img img").size() > 1) $(this).find("div.img").css("cursor","pointer");
        });

        $("#fixed a.news").click(function (e) {
                e.preventDefault();
                $("div.popup").hide();
                $("#news").show();
        });

        $("#fixed a.popup").click(function (e) {
                e.preventDefault();
                $("div.popup").hide();
                $("#"+$(this).attr("rel")).show();
        });

        $("div.popup a.close").click(function (e) {
                e.preventDefault();
                $("div.popup").hide();
        });

        redimNews();
        redimPopup();
        $(window).resize(function () {
                redimNews();
                redimPopup();
        });

        $("div.popup div.new:last").css("border","none");

	$("div.block div.img > img:not(.active)").each(function () {
		$(this).attr("wait",$(this).attr("src"));
		$(this).attr("src","/images/loader.gif");
		$(this).addClass("wait");
		$(this).css("margin","0 auto");
	});

	if (IE6) set_more();

	$("div.block div.img img.gallery").click(function () {
		var self = this;
		var newimg = $(this).next();
		if (!newimg.is("img")) {
			newimg = $(this).parent().find("> img:first");
		}
		if (newimg.hasClass("wait")) {
			newimg.removeClass("wait");
			newimg.attr("src",newimg.attr("wait"));
			newimg.load(function () {
				newimg.addClass("active");
				$(self).removeClass("active");
				if (IE6) set_more();
			});
		}
		else {
			newimg.addClass("active");
			$(self).removeClass("active");
			if (IE6) set_more();
		}
	});

	$("div.block div.img").each(function () {
		var n = $(this).find("> img").size();
		if (n <= 1) {
			$(this).find("a").remove();
			$(this).find("img")
				.css("cursor","default")
				.attr("title","")
				.attr("alt","");
		}
	});

	$("div.block div.img a").click(function (e) {
		e.preventDefault();
		$(this).parent().find("img.active").click();
	});
});

function redimNews() {
        $("div#news.popup").height(parseInt($(window).height()) - 219);
        $("div#news.popup div.scroll").height($("div#news.popup").height());
}

function redimPopup() {
        $("div.popup:not(#news)").height(parseInt($(window).height()) - 79);
        $("div.popup:not(#news) div.scroll").height($("div.popup:not(#news)").height());
}

function set_more() {
	$("div.block div.img").each(function () {
		var img = $(this).find("> img.active");
		var more = $(this).find("> a");
		more.css({
			top: img.height() - 19,
			left: img.width() - 19,
			bottom: "auto",
			right: "auto"
		});
	});
}