var thisX = 0;
var thisY = 0;

// fotogalerie
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 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;
			}
	
			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');
	
	if (thisItem) {
		thisItem.innerHTML = '';
		thisShadow.innerHTML = '';
		thisItem.style.display = '';
		thisShadow.style.display = '';
	}
}

// kontrola sestavy
function _sestava (form) {
	var str = '';

	if (form.jmeno.value == "") {
		str += '- nezadali jste vaÅ¡e jmÃ©no\n';
	}
	if (form.telefon.value == "") {
		str += '- nezadali jste vÃ¡Å¡ telefon\n';
	}
	if (form.email.value == "") {
		str += '- nezadali jste vÃ¡Å¡ e-mail\n';
	}
	
	if (str == "") {
		return true;
	} else {
		alert('Nelze odeslat sestavu vaÅ¡eho kola z tÄ›chto dÅ¯vodÅ¯:\n' + str);
		return false;
	}
}

// cena sestavy
function _count (id, price) {
	var price_total = 0;
	var thisItem = myGet('cena_celkem');
	
	if (typeof(_item) != "undefined" && _item.length > 0 && thisItem) {
		_item[parseInt(id)] = parseInt(price);
		
		for (x = 0; x < _item.length; x++) {
			price_total += _item[x];
		}
		
		thisItem.innerHTML = price_total;
	}
}

function vyrobce (id) {
	var thisItem;
	
	if (id == "init") {
		for (x = 1; x<= firem; x++) {
			thisItem = myGet('firma' + x);
			if (thisItem) {
				thisItem.style.display = "none";
			}
		}
	} else {
		vyrobce('init');
		thisItem = myGet('firma' + id);
		if (thisItem) {
				thisItem.style.display = "block";
			}
	}
}

// delete
function DeleteItem (thisItem) {
	var question = 'Opravdu chcete smazat tento servis?';
	
	if (confirm(question)) {
		document.location = thisItem.href;
	}

	return false;
}

// získání elementu
function myGet (name) {
	if (document.getElementById)
		return document.getElementById(name);
	else if (document.all)
		return document.all(name);
	else
		return null;
}
