var pics;
var thisX = 0;
var thisY = 0;

// move rows in table
function MoveRow (thisPosition, id, direction) {
	var thisForm = myGet('position');
	var thisItem;
	var nextItem;
	var tempItem;
	var thisInput = myGet('pos_' + id + '_'  + thisPosition);
	var nextInput;
	var tempInput;
	var i;
	var move = false;
	
	if (direction == "up") {
		i = -1;
	} else if (direction == "down") {
		i = 1;
	}

	if (thisPosition == 0 && i == 1) {
		move = true;
	} else if (thisPosition > 0 && thisPosition < count[id]) {
		move = true;
	}
	if (thisPosition + 1 == count[id] && i == 1) {
		move = false;
	}
	
	if (move) {
		for (x = 0; x < items[id].length; x++) {
			thisItem = myGet(items[id][x] + '_' + id + '_' + thisPosition);
			nextItem = myGet(items[id][x] + '_' + id + '_' + (thisPosition + i));

			tempItem = nextItem.innerHTML;
			nextItem.innerHTML = thisItem.innerHTML;
			thisItem.innerHTML = tempItem;
		}
		
		nextInput = myGet('pos_' + id + '_' + (thisPosition + i));

		tempInput = nextInput.value;
		nextInput.value = thisInput.value;
		thisInput.value = tempInput;
	}
}

// video ukazka
function _video (hash, name) {
	var HTML = '';
	var thisItem = myGet('dhtml');
	var s0 = new SWFObject('/flash/flvplayer.swf','player','240','135','9');
	s0.addParam('allowfullscreen', 'true');
	s0.addParam('allowscriptaccess', 'always');
	s0.addParam('wmode', 'transparent');
	s0.addParam('flashvars', 'file=' + hash + '&autostart=true&controlbar=none&displayheight=135title=' + name);
	
	if (thisItem) {
		HTML += '<h3 title="' + name + '">' + name + '</h3><p id="player"><a href="http://www.macromedia.com/go/getflashplayer">StÃ¡hnÄ›te si Flash player</a>, abyste si mohli prohlÃ©dnout toto video.</p>';
		thisItem.innerHTML = HTML;
		
		s0.write('player');
	}
}

// MP3 ukazka
function _mp3 (hash, name, play) {
	var HTML = '';
	var thisItem = myGet('dhtml');
	
	if (thisItem) {
		if (play) {
			HTML += '<h3 title="' + name + '">' + name + '</h3><p>PÅ™ehrÃ¡vÃ¡nÃ­ MP3 ukÃ¡zky.</p>';
			HTML += '<div class="vice float_l"><span><a href="#" onclick="_mp3(\'\', \'\', false); return false;">Zastavit pÅ™ehrÃ¡vÃ¡nÃ­ ...</a></span></div>';
			HTML += '<object id="mp3" type="application/x-shockwave-flash" data="/flash/musicplayer.swf?playlist_url=/' + hash + '.xspf&autoload=true&autoplay=true&b_fgcolor=b50214" width="17" height="17">';
			HTML += '<param name="movie" value="/flash/musicplayer.swf?playlist_url=/' + hash + '.xspf&autoload=true&autoplay=true&b_fgcolor=b50214" />';
			HTML += '<param name="bgcolor" value="000000" />';
			HTML += '</object>';
		}
		thisItem.innerHTML = HTML;
	}
}

// JPEG fotky 
function _jpeg (data) {
	pics = data;
	_pic(true, 0);
}

// fotogalerie
function _pic (e, i) {
	var o_width, o_height, w_width, w_height, w_offset_x, w_offset_y, picsLength, max_height;

	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);
			max_height = parseInt(self.scrollHeight);
		} 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);
			max_height = parseInt(document.documentElement.scrollHeight);
		} 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);
			max_height = parseInt(document.body.scrollHeight);
		}
		max_height = parseInt(document.body.scrollHeight);

		var thisItem = myGet('photo');
		var this0verlay = myGet('overlay');
		var thisInnerHTML = '';
	
		if (thisItem && this0verlay) {
			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;
			}
	
			this0verlay.style.height = max_height + 'px';
			this0verlay.style.display = 'block';
			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 this0verlay = myGet('overlay');
	
	if (thisItem) {
		thisItem.innerHTML = '';
		thisItem.style.display = '';
		this0verlay.style.height = '100%';
		this0verlay.style.display = '';
	}
}

// smazani
function _delete (object) {
	if (confirm('Opravdu chcete smazat tuto poloÅ¾ku?')) {
		document.location = object.href;
	}
}

// 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;
}
