var thisItem;
var thisX = 0;
var thisY = 0;

// delete
function DeleteItem (item) {
	var question;
	
	if (item.href.indexOf("undelete") != -1) {
		question = 'Opravdu chcete obnovit tuto poloÅ¾ku?';
	} else {
		question = 'Opravdu chcete smazat tuto poloÅ¾ku?'
	}
	
	if (confirm(question)) {
		document.location = item.href;
	}

	return false;
}

function pic (e, i) {
	var o_width, o_height, w_width, w_height, w_offset_x, w_offset_y, picsLength;

	if (typeof(pics) != "undefined" && pics.length > 0) {
		o_width = parseInt(pics[i][1]);
		o_height = parseInt(pics[i][2]);

		picsLength = pics.length;
		for (x = 0; x < picsLength; x++) {
			if (typeof(pics[x]) == "undefined") {
				picsLength--;
			} 
		}
	
		if (self.innerWidth) {															// all except Explorer
			w_width = parseInt(self.innerWidth);
			w_height = parseInt(self.innerHeight);
			w_offset_x = parseInt(self.pageXOffset);
			w_offset_y = parseInt(self.pageYOffset);
		} else if (document.documentElement && document.documentElement.clientHeight) {	// Explorer 6 Strict Mode
			w_width = parseInt(document.documentElement.clientWidth);
			w_height = parseInt(document.documentElement.clientHeight);
			w_offset_x = parseInt(document.documentElement.scrollLeft);
			w_offset_y = parseInt(document.documentElement.scrollTop);
		} else if (document.body) {														// other Explorers
			w_width = parseInt(document.body.clientWidth);
			w_height = parseInt(document.body.clientHeight);
			w_offset_x = parseInt(document.body.scrollLeft);
			w_offset_y = parseInt(document.body.scrollTop);
		}

		var thisItem = myGet('photo');
		var thisShadow = myGet('shadow');
		var thisOverlay = myGet('overlay');
		var thisInnerHTML = '';
		var thisShadowHTML = '';
		var thisBGcolor = new Array ('888', '777', '666', '555', '444');
	
		if (thisItem) {
			if (e) {
				thisX = w_width / 2 - o_width / 2 + w_offset_x;
				thisX = thisX < 0 ? 0 : thisX;
				thisY = w_height / 2 - o_height / 2 + w_offset_y;
				thisY = thisY < 0 ? 0 : thisY < w_offset_y ? w_offset_y : thisY;
			}
	
			thisOverlay.style.display = 'block';
			thisShadow.style.display = 'block';
			thisShadow.style.width = o_width + 20 + 'px';
			thisShadow.style.height = o_height + (pics[i][3] != "" ? 40 : 20) + 'px';
			thisShadow.style.top = thisY + thisBGcolor.length + (pics[i][3] != "" ? -20 : 0) + 'px';
			thisShadow.style.left = thisX + thisBGcolor.length + 'px';

			for (x = 0; x < thisBGcolor.length; x++) {
				thisShadowHTML += '<div style="background-color:#' + thisBGcolor[x] + '; position:absolute; top:-' + (x+1) + 'px; left:-' + (x+1) + 'px; width:' + (o_width + 20) + 'px; height:' + (o_height + (pics[i][3] != "" ? 40 : 20)) + 'px;"></div>';
			}
			thisShadow.innerHTML = thisShadowHTML;

			thisItem.style.display = 'block';
			thisItem.style.width = o_width + 20 + 'px';
			thisItem.style.height = o_height + (pics[i][3] != "" ? 40 : 20) + 'px';
			thisItem.style.top = thisY + (pics[i][3] != "" ? -20 : 0) + 'px';
			thisItem.style.left = thisX + 'px';

			thisInnerHTML = '<div class="margin">';
			thisInnerHTML += '<div class="close"><a href="javascript:pic_close(' + i + ');" title="zavÅ™i obrÃ¡zek">zavÅ™i obrÃ¡zek</a></div>';
			if (picsLength > 1 && i >= 0) {
				thisInnerHTML += '<ul class="nav">';
				thisInnerHTML += !i ? '<li class="first_off"><span>prvnÃ­ obrÃ¡zek</span></li>' : '<li class="first"><a href="#" onclick="pic(false, 0); return false;" title="prvnÃ­ obrÃ¡zek"><span>prvnÃ­ obrÃ¡zek</span></a></li>';
				thisInnerHTML += !i ? '<li class="prev_off"><span>pÅ™edchozÃ­ obrÃ¡zek</span></li>' : '<li class="prev"><a href="#" onclick="pic(false, ' + (i-1) + '); return false;" title="pÅ™edchozÃ­ obrÃ¡zek"><span>pÅ™edchozÃ­ obrÃ¡zek</span></a></li>';
				thisInnerHTML += i == (picsLength-1) ? '<li class="next_off"><span>dalÅ¡Ã­ obrÃ¡zek</span></li>' : '<li class="next"><a href="#" onclick="pic(false, ' + (i+1) + '); return false;" title="dalÅ¡Ã­ obrÃ¡zek"><span>dalÅ¡Ã­ obrÃ¡zek</span></a></li>';
				thisInnerHTML += i == (picsLength-1) ? '<li class="last_off"><span>poslednÃ­ obrÃ¡zek</span></li>' : '<li class="last"><a href="#" onclick="pic(false, ' + (picsLength-1) + '); return false;" title="poslednÃ­ obrÃ¡zek"><span>poslednÃ­ obrÃ¡zek</span></a></li>';
				thisInnerHTML += '</ul>';
			}
			thisInnerHTML += '<a href="javascript:pic_close(' + i + ');" title="zavÅ™i obrÃ¡zek"><img src="' + pics[i][0] + '" width="' + pics[i][1] + '" height="' + pics[i][2] + '" alt="' + pics[i][3] + '" /></a>';
			thisInnerHTML += (pics[i][3] != "" ? '<p>' + pics[i][3] + '</p>' : '');
			thisInnerHTML += '</div>';
			thisItem.innerHTML = thisInnerHTML;
		}
	}

	return false;
}

function pic_close (i) {
	var thisItem = myGet('photo');
	var thisShadow = myGet('shadow');
	var thisOverlay = myGet('overlay');
	//var thisImg = myGet('photo-' + i);
	
	if (thisItem) {
		thisItem.innerHTML = '';
		thisShadow.innerHTML = '';
		thisItem.style.display = '';
		thisShadow.style.display = '';
		thisOverlay.style.display = '';
		//try { thisImg.scrollIntoView(true); }
		//catch (e) {}
		//try { window.scrollBy(0, -20); }
		//catch (e) {}
	}
}

// viditelnost objektu
function _visibility (oID) {
	var thisItem = myGet(oID);
	
	if (thisItem) {
		if (thisItem.style.display == "none") {
			thisItem.style.display = '';
		} else {
			thisItem.style.display = 'none';
		}
	}
	
	return false;
}

//pracovní hodiny naèti dynamicky
function _work_hours (url) {
	if (_load_JS(url)) {
		return false;
	} else {
		return true;
	}
}

function _load_JS (url) {
	var script = document.createElement('script');
	var thisHead = document.getElementsByTagName('head')[0];

	script.id = 'scriptLoader';
	script.src = url;
	if (typeof(thisHead.appendChild(script)) != "undefined") {
		return true;
	} else {
		return false;
	}
}

// poèítání ceny z pracovních hodin
function _count_price (id) {
	var thisInput;
	var thisPrice;
	var price;
	var price_discount;
	var thisItem = myGet('price_from_hours');

	if (thisItem) {
		price = parseFloat(thisItem.innerHTML);
		price = isNaN(price) ? 0 : price;

		if (id == "prace") {
			thisInput = document.getElementsByTagName('input');
			for (x = 0; x < thisInput.length; x++) {
				if (thisInput[x].type == "checkbox") {
					if (thisInput[x].checked) {
						price = price + parseFloat(thisInput[x].value);
					}
				}
			}
		} else {
			thisInput = myGet('prace_' + id);
			thisPrice = parseFloat(thisInput.value);
			
			if (thisInput.checked) {
				price = price + thisPrice;
			} else {
				price = price - thisPrice;
			}
		}
		
		thisItem.innerHTML = price;
		_count_discount();
	}
}

function _count_discount (id) {
	var thisItem = myGet('price_from_hours');
	var thisPrice = myGet('price_from_hours_discount');
	var thisDiscount = myGet('price_discount');
	var price;
	var price_discount;

	if (thisItem && thisDiscount) {
		price = parseFloat(thisItem.innerHTML);
		price = isNaN(price) ? 0 : price;
		price_discount = parseInt(thisDiscount.value);
		
		if (price_discount > 0) {
			price = price - (price * price_discount / 100);

			thisPrice.innerHTML = price;
		}
	}
}

function _fakturacni_udaje (thisSelect) {
	for (x = 0; x < thisSelect.length; x++) {
		thisItem = myGet('udaje_' + thisSelect[x].value);
		if (thisItem) {
			if (thisSelect.value == thisSelect[x].value) {
				thisItem.className = 'visible';
			} else {
				thisItem.className = 'hidden';
			}
		}
	}
}

// nove vokno
function _new_window (object) {
	window.open(object.href);
	
	return false;
}

// získání elementu
function myGet (objectID) {
	var oRef = null;

  	if (document.getElementById && document.getElementById(objectID) != null)
		oRef = document.getElementById(objectID);
	else if (document.layers && document.layers[objectID] != null)
		oRef = document.layers[objectID];
	else if (document.all)
		oRef = document.all[objectID];

	return oRef;
}
