﻿function repositionDiv() {
	var divWidth = $("#frameDisplayDiv").width();
	var divHeight = $("#frameDisplayDiv").height();
	var wd = $(document).width() / 2;
	var newLeftPos = wd - (divWidth / 2);
	var newTopPos = ($(window).height() / 2 - (divHeight / 2)) + $(document).scrollTop();
	$("#frameDisplayDiv").css("left",newLeftPos + "px").css("top",newTopPos + "px");
}

function handleMinClick(source, border) {
	repositionDiv();
	reSizeBgBlocker();
	showBlocker();

	$("#frameDisplayDiv").addClass("loading");
	$("#frameDisplayDiv").empty();
	$("#frameDisplayDiv img").remove; // mimo empty() , dodatkowe usuwanie img -> internet explorer bug
	
	loadImg(source, border);
	
	$("#frameDisplayDiv").show();
	
}

function handleDivClose() {
	$("#frameDisplayDiv").fadeOut("slow", function() { hideBlocker(); $("#frameDisplayDiv").width(200).height(200); } );
}

function loadImg(source, border) {
	if ((border == null) || (border == ""))
		border = 0;
	var img = new Image();
	$(img).load(function() {
		$(this).hide();
		$("#frameDisplayDiv").empty();
		$("#frameDisplayDiv img").remove; // mimo empty() , dodatkowe usuwanie img -> internet explorer bug
		$("#frameDisplayDiv").removeClass("loading").append(this);
		
		var w = $(this).width() + border*2;
		var h = $(this).height() + border*2;
		
		var maxwidth = 960 + border*2;
		var maxheight = 1024 + border*2;
		
		if (w > maxwidth) {
			w = maxwidth;
		}
		
		if (h > maxheight) {
			h = maxheight;
		}
		
		$("#frameDisplayDiv").width(w);
		$("#frameDisplayDiv").height(h);
		
		repositionDiv();
		
		if (border > 0) {
			$(this).addClass("bordered").css("border-width", border + "px");
		}
			
		$(this).fadeIn("slow");
	}).attr("src",source);
}

// ---- BG BLOCKER
		
function reSizeBgBlocker() {
	$("#bgBlocker").width($(window).width());
	$("#bgBlocker").height($(document).height());
}
		
function showBlocker() {
	$("#bgBlocker").show();
}
		
function hideBlocker() {
	$("#bgBlocker").hide();
}
