var prej = {};
var priGarazah = {"f3":"f4","e4":"e3","f1":"f2","e2":"e1"};
var posebej = {"f4":"f3","e3":"e4","f2":"f1","e1":"e2"};
var izbran = null;

function oznaci(tip) {
	var hise = $(".bajta");
	var x;
	for (var i = 0; i < hise.length; i++) {
		x = hise[i].id.substring(0,1)
		if (x == izbran) {
			hise[i].src = hise[i].src.replace("tloris/on","tloris/off").replace("tloris/-offon","tloris/off").replace("tloris/-onon","tloris/off");
			//off(hise[i]);
		} else if (x == tip) {
			switch (hise[i].id) {
			 case "e4" : 
			 case "f3" :
			 case "e2" : 
			 case "f1" :
			 	hise[i].src = hise[i].src.replace("tloris/off","tloris/-onon"); break;
			 default : 
				hise[i].src = hise[i].src.replace("tloris/off","tloris/on"); break;
			}
			//on(hise[i]);
			
		}
	}
	izbran = tip;
}


function triggerHisa(img) {
	if (img.id != null && !prodano[img.id]) {
		if (img.src.match("tloris/off") != null) {
			on(img);
		} else if(prej[img.id] != null) {
			off(img);
		}
	}
}

function on(img) {
	var id = img.id;
	var src = img.src;
	var sosedId = posebej[id];
	prej[id] = img.src;
	img.src = src.substring(0, src.lastIndexOf("/")).replace("tloris/off","tloris/on") + "/"+id + ".png";
	// prizgi se soseda, ce je treba
	if (sosedId != null) {
		var sosed = $("img#"+sosedId)[0];
		var sosedSrc = sosed.src;
		prej[sosedId] = sosedSrc;
		sosed.src = sosedSrc.substring(0, sosedSrc.lastIndexOf("/")).replace("tloris/off","tloris/-offon") + "/"+sosedId + ".png";
	} 
}

function off(img) {
	var id = img.id;
	var src = img.src;
	var sosedId = posebej[id];
	img.src = prej[id];
	if (sosedId != null) {
		$("img#"+sosedId)[0].src = prej[sosedId];
	}
}

var tipi = ["a","b","c","d","e","f"];
var tipCount = {"a":10, "b":12, "c":2, "d":2, "e":4, "f":4};
var nodes = {"a":"node/18", "b":"node/19", "c":"node/20", "d":"node/21", "e":"node/22", "f":"node/23"};
function init(prodano) {
	var img = null;
	for (var i = 0; i < prodano.length; i++) {
		img = $("img#"+prodano[i])[0];
		prodaj(prodano[i]);
		tipCount[prodano[i].charAt(0)]--;
	}
	var hise = $("#tloris img");
	for (var i = 0; i < hise.length; i++) {
		if (hise[i].id) {
			hise[i].onmouseover = function() { if (triggerHisa) triggerHisa(this) };
			hise[i].onmouseout = function() { if (triggerHisa) triggerHisa(this) };
			hise[i].onclick = function() {
				window.location = "?q="+nodes[this.id.substring(0,1)];
			}
		}
	}
}

function prodaj(id) {
	var	img = $("img#"+id)[0];
	/*var object = img.style;
	object.opacity = (0.8);
    object.MozOpacity = (0.8);
    object.KhtmlOpacity = (0.3);
    object.filter = "alpha(opacity=30)";*/
	
	img.src = img.src.replace("tloris/off", "tloris/prodano");

}





