var timer = null;
var speed = [[500, 0],
	[300, 14],
	[200, 28],
	[100, 42],
	[70, 55],
	[50, 70],
	[10, 80]
];
var thisSpeed = 3;
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 && (typeof(picsSingle) == "undefined")) {
				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 = '';
	}
}
// 360° rotace modelu
function rotate (akce) {
	var thisButton = myGet('play');
	var thisSpeedLI = myGet('speed_img');

	if (thisButton && thisSpeedLI) {
		switch (akce) {
			case 'play': {
				thisButton.style.backgroundImage = "url('/images/_layout/bg-video-navigace-pause.gif')";
				thisButton.innerHTML = '<a href="#" onclick="rotate(\'stop\'); return false;"><span>zastav</span></a>';
				clearInterval(timer);
				timer = setInterval("rotateVisibility()", speed[thisSpeed][0]);
				break;
			}
			
			case 'stop': {
				thisButton.style.backgroundImage = "url('/images/_layout/bg-video-navigace-play.gif')";
				thisButton.innerHTML = '<a href="#" onclick="rotate(\'play\'); return false;"><span>pÅ™ehraj</span></a>';
				clearInterval(timer);
				timer = null;
				break;
			}
	
			case 'next': {
				thisButton.style.backgroundImage = "url('/images/_layout/bg-video-navigace-play.gif')";
				thisButton.innerHTML = '<a href="#" onclick="rotate(\'play\'); return false;"><span>pÅ™ehraj</span></a>';
				clearInterval(timer);
				timer = null;
				rotateVisibility();
				break;
			}
			
			case 'prev': {
				thisButton.style.backgroundImage = "url('/images/_layout/bg-video-navigace-play.gif')";
				thisButton.innerHTML = '<a href="#" onclick="rotate(\'play\'); return false;"><span>pÅ™ehraj</span></a>';
				clearInterval(timer);
				timer = null;
				thisFrame = thisFrame - 2;
				rotateVisibility();
				break;
			}

			case 'speed_plus': {
				clearInterval(timer);
				thisSpeed = thisSpeed + 1
				thisSpeed = thisSpeed >= speed.length ? speed.length - 1 : thisSpeed;
				thisSpeedLI.style.left = speed[thisSpeed][1] + 'px';
				if (timer != null) {
					timer = setInterval("rotateVisibility()", speed[thisSpeed][0]);
				}
				break;
			}
			
			case 'speed_minus': {
				clearInterval(timer);
				thisSpeed = thisSpeed - 1;
				thisSpeed = thisSpeed <= 0 ? 0 : thisSpeed;
				thisSpeedLI.style.left = speed[thisSpeed][1] + 'px';
				if (timer != null) {
					timer = setInterval("rotateVisibility()", speed[thisSpeed][0]);
				}
				break;
			}
		}
	}
}

function rotateVisibility () {
	var prevItem, thisItem, nextItem;
	var frame = myGet('current');
	
	thisFrame++;
	thisFrame = thisFrame > thisFrames ? 1 : thisFrame < 1 ? thisFrames : thisFrame;
	thisItem = myGet(thisCSSid + thisFrame);
	if (thisFrame == 1) {
		prevItem = myGet(thisCSSid + thisFrames)
		nextItem = myGet(thisCSSid + (thisFrame + 1))
	} else if (thisFrame == thisFrames) {
		prevItem = myGet(thisCSSid + (thisFrames - 1))
		nextItem = myGet(thisCSSid + 1)
	} else {
		prevItem = myGet(thisCSSid + (thisFrame - 1))
		nextItem = myGet(thisCSSid + (thisFrame + 1))
	}
	
	if (prevItem && thisItem && nextItem && frame) {
		prevItem.style.visibility = 'hidden';
		thisItem.style.visibility = 'visible';
		nextItem.style.visibility = 'hidden';
		frame.innerHTML = thisFrame + '/'+ thisFrames;
	}
}

// technické informace - tabulky
function techInfo (id) {
	var thisTable, thisButton;

	if (typeof(tech_info_tables) != "undefined" && tech_info_tables.length > 0) {
		for (x = 0; x < tech_info_tables.length; x++) {
			thisTable = myGet('tbl_' + tech_info_tables[x]);
			thisButton = myGet('btn_' + tech_info_tables[x]);
			if (thisTable && thisButton) {
				if (id == "") {
					thisButton.className = !x ? "selected" : "";
					thisTable.style.display = !x ? "block" : "none";
				} else {
					thisButton.className = id == tech_info_tables[x] ? "selected" : "";
					thisTable.style.display = id == tech_info_tables[x] ? "block" : "none";
				}
			}
		}
	}
	
	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;
}