var myImage = new Image();
var myDestination;
var imgArray = new Array();

function executeAction(actiontype,parameter)
{
	var form_name = "itemlist_form";
   document.getElementById(form_name).elements["action"].value=actiontype;
   document.getElementById(form_name).elements["action_parameter"].value=parameter;
   document.getElementById(form_name).submit();
}

function displayMessage(msg)
{
	document.getElementById("messagelayer").style.visibility = "visible";
	document.getElementById("message").innerHTML = msg;
}
function hideMessage() {document.getElementById("messagelayer").style.visibility = "hidden";}

function loadPicture(dest, path)
{
	myImage.src		= path;
	myDestination	= dest;
	displayMessage("Trwa ładowanie...");
	waitForLoading();
	//this.timerid = setInterval(this.waitForLoading,500);
}
/*
function waitForLoading_func()
{
	if(this.img.complete)
	{
		clearInteval(this.timerid);
		this.destination.src = this.img.src;
	}
	else {}
}*/
function waitForLoading()
{
	if(typeof(myImage) == "undefined")
	{
		displayMessage("Wystąpił błąd!");
		return;
	}
	if(!myImage.complete) setTimeout("waitForLoading()", 500);
	else
	{
	  	hideMessage();
		myDestination.src = myImage.src;
	}
}

function swapImg(obj,path)
{
	obj.style.backgroundImage = "url("+path+")";
}

function preloadImg(src)
{
  var img = new Image();
  img.src = src;
  imgArray.push(img);  
}

function highlight(obj)
{
  obj.style.borderColor = "#555555";
  obj.style.borderWidth = "1px";
  obj.style.borderStyle = "solid";
}

function unhighlight(obj)
{
  obj.style.borderColor = "white";
}

function swapOverImg(obj)
{
  obj.src = obj["altImg"].src;
}

function swapOutImg(obj)
{
  obj.src = obj["orgImg"].src;
}

function setAltImg(obj, src)
{
  obj["altImg"] = new Image;
  obj["altImg"].src = src;
  obj["orgImg"] = new Image;
  obj["orgImg"].src = obj.src;
  obj.onmouseover = function(){swapOverImg(this)};
  obj.onmouseout  = function(){swapOutImg(this)};
}
