var thisX = 0;
var thisY = 0;

window.onload = externalLinks;

// externi linky v novem okne
function externalLinks() { 
	if (!document.getElementsByTagName) return; 
	var anchors = document.getElementsByTagName("a"); 
	for (var i = 0; i < anchors.length; i++) {
		var anchor = anchors[i]; 
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") {
			anchor.target = "_blank"; 
		}
	} 
}

// 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 ('195ea5', '15508c', '0f3a66', '09233e', '040e19');
	
		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 = '';
	}
}

// obnovení stránky
function _refresh (uri) {
	var timeout = setTimeout("document.location='" + uri + "'", 180000);
}

// hlasování do ankety
function anketa (id) {
	var thisForm = myGet('anketaForm');
	var thisInput = myGet('anketaHlas');
	
	if (thisForm && thisInput) {
		thisInput.value = id;
		thisForm.submit();
	} else {
		document.location = '/anketa/odpoved-' + id + '.html';
	}
}

// on-line odpovìdi
function odpovedet (id) {
	var thisItem;
	var thisLink;
	
	if (answers.length > 0) {
		if (id == 0) {
			for (x = 0; x < answers.length; x++) {
				thisItem = myGet('odpoved_' + answers[x]);
				thisLink = myGet('link_' + answers[x]);
				if (thisItem && thisLink) {
					thisItem.style.display = "none";
					thisLink.style.display = "block";
				}
			}
		} else {
			thisItem = myGet('odpoved_' + id);
			thisLink = myGet('link_' + id);
			if (thisItem) {
				thisItem.style.display = "block";
				thisLink.style.display = "none";
			}
		}
	}
}

// login
function loginForm () {
	var thisItem = myGet('login-form');
	
	if (thisItem) {
		if (thisItem.style.display == "") {
			thisItem.style.display = 'block';
		} else {
			thisItem.style.display = '';
		}
	}
}

// náhled èlánku z adminu
function nahled () {
	var thisItem = myGet('nahled');
	var thisParentText = window.opener.myGet('dhtml');
	var thisParentTitle = window.opener.myGet('titulek');
	var thisParentPhoto = window.opener.myGet('photo');
	
	if (thisItem && thisParentText) {
		thisItem.innerHTML = '';

		if (thisParentPhoto) {
			thisItem.innerHTML += '<div class="novinka"><img src="' + thisParentPhoto.value + '" alt="" /><div class="ramecek"></div></div>';
		}
		if (thisParentTitle) {
			thisItem.innerHTML += '<p class="nadpis">' + thisParentTitle.value + '</p>';
		}
		thisItem.innerHTML += thisParentText.value;
	}
}

// hudba
function play_stop () {
	var thisItem = myGet('play_button');
	var thisPlayer =myGet('player');
	
	if (thisItem && thisPlayer) {
		if (playing) {
			thisItem.className = 'stop';
		} else {
			thisItem.className = 'play';
		}

		thisPlayer.sendEvent('PLAY');
		playing = !playing;
	}
}

// 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;
}