// Funkce

/* Get/Set x/y position from/to element B */
	function get_xPos(elm) {
		var xPos = 0;
		if (document.getElementById(elm) != null) {
			xPos = document.getElementById(elm).offsetLeft;
		}
		return xPos;
	}

	function set_xPos(from,to,dx) {
		if ((document.getElementById(from) != null)&&(document.getElementById(to) != null)) {
			dx += get_xPos(from);
			document.getElementById(to).style.left = dx + "px";
		}
	}

	function get_yPos(elm) {
		var yPos = 0;
		if (document.getElementById(elm) != null) {
			var parElement = document.getElementById(elm);
			while (typeof parElement == 'object' && parElement.tagName != 'BODY') {
				yPos += parElement.offsetTop;
				parElement = parElement.offsetParent;
			}
		}
		return yPos;
	}

	function set_yPos(from,to,dy) {
		if ((document.getElementById(from) != null)&&(document.getElementById(to) != null)) {
			dy += get_yPos(from);
			document.getElementById(to).style.top = dy + "px";
		}
	}
/* Get/Set x/y position from/to element E */

/* Cookies B */
	var cookieArray = new Array();
	
	function parseCookie() {
		var cookieList=document.cookie.split("; ");
		for (var i=0; i < cookieList.length; i++) {
			var spl = cookieList[i].split("=");
			cookieArray[unescape(spl[0])] = unescape(spl[1]);
			//alert(spl[0] + " = " + cookieArray[unescape(spl[0])]);
		}
	}
	
	function getCookie(name) {
		if (cookieArray[name]) { return cookieArray[name]; } else { return ""; }
	}
	
	function setCookie(name, value, expire) {
		var cookielife = new Date();
		cookielife.setDate(cookielife.getDate() + expire);
		document.cookie = name + "=" + escape(value) + ((expire) ? "; expires=" + cookielife.toGMTString() : "");
	}
	
	//parseCookie();
/* Cookies E */


/* Rotator B */
function Rotator (name, w, h, d, x, y, c, s, p, obj) {
	this.NAME = name;
	this.WIDTH = w;
	this.HEIGHT= h;
	this.DIRECTION = d;
	this.X = x;
	this.Y = y;
	this.COUNT = c;
	this.SPEED = s;
	this.PAUSE = p;
	this.OBJ_ID = obj;
	
	this.DX = 0;
	this.DY = 0;
	this.TimerID = 0;
	this.AX = new Array(this.COUNT);
	this.AY = new Array(this.COUNT);
	
	this.on = rotator_on;
	this.off = rotator_off;
	this.rotuj = rotator_rotuj;
	
	if (this.DIRECTION=="up") { this.DY = -1; }
	if (this.DIRECTION=="down") { this.DY = 1; }
	if (this.DIRECTION=="left") { this.DX = -1; }
	if (this.DIRECTION=="right") { this.DX = 1; }
	
	for (var i=0; i < this.COUNT; i++) {
		this.AX[i] = this.DX*i*this.WIDTH*(-1);
		this.AY[i] = this.DY*i*this.HEIGHT*(-1);
	}
	
	this.AX1 = this.DX * this.WIDTH;
	this.AY1 = this.DY * this.HEIGHT;
	
	if (((w==x)&&(this.DX)) || ((h==y)&&(this.DY))) {
		this.TimerID = setTimeout(this.NAME + ".rotuj()", this.SPEED);
	} else {
		this.TimerID = setTimeout(this.NAME + ".rotuj()", this.PAUSE);
	}
}

function rotator_on() {
	clearTimeout(this.TimerID);
	this.TimerID = setTimeout(this.NAME + ".rotuj()", this.SPEED);
}

function rotator_off() {
	clearTimeout(this.TimerID);
}

function rotator_rotuj() {
	var next = this.SPEED;
	for (var i=0; i < this.COUNT; i++) {
		if (this.DX) {
			this.AX[i] = this.AX[i] + (this.DX * this.X);
			document.getElementById(this.OBJ_ID + i).style.left = this.AX[i]+"px";
			if ( ( (this.AX[i] <= this.AX1)&&(this.DX < 0) ) || ( (this.AX[i] >= this.AX1)&&(this.DX > 0) ) ) {
				this.AX[i] = this.AX1*(-1)*(this.COUNT-1); next = this.PAUSE;
			}
		}
		if (this.DY) {
			this.AY[i] = this.AY[i] + (this.DY * this.Y);
			document.getElementById(this.OBJ_ID + i).style.top = this.AY[i]+"px";
			if ( ( (this.AY[i] <= this.AY1)&&(this.DY < 0) ) || ( (this.AY[i] >= this.AY1)&&(this.DY > 0) ) ) {
				this.AY[i] = this.AY1*(-1)*(this.COUNT-1); next = this.PAUSE;
			}
		}
	}
	this.TimerID = setTimeout(this.NAME + ".rotuj()", next);
}
/* Rotator E */

/* Mover B */
function Mover (name, l, t, w, h, d, x, y, s, am, b, as, obj) {
	this.NAME = name;
	this.WIDTH = w;
	this.HEIGHT= h;
	this.DIRECTION = d;
	this.X = x;
	this.Y = y;
	this.SPEED = s;
	this.AUTOMOVE = am;
	this.BACKTOZERO = b;
	this.AUTOSTART = as;
	this.OBJ_ID = obj;
	
	this.DX = 0;
	this.DY = 0;
	this.TimerID = 0;
	
	this.on = mover_on;
	this.off = mover_off;
	this.move = mover_move;
	
	if (this.DIRECTION=="up") { this.DY = -1; }
	if (this.DIRECTION=="down") { this.DY = 1; }
	if (this.DIRECTION=="left") { this.DX = -1; }
	if (this.DIRECTION=="right") { this.DX = 1; }
	
	this.AX = l;
	this.AY = t;
	
	this.AX0 = l;
	this.AY0 = t;
	
	this.AX1 = this.DX * this.WIDTH;
	this.AY1 = this.DY * this.HEIGHT;
	
	if (this.AUTOSTART) {
		this.TimerID = setTimeout(this.NAME + ".move()", this.AUTOSTART);
	}
}

function mover_on() {
	clearTimeout(this.TimerID);
	this.TimerID = setTimeout(this.NAME + ".move()", 1);
}

function mover_off() {
	clearTimeout(this.TimerID);
}

function mover_move() {
	if (this.DX) {
		if ( ( (this.AX <= this.AX1)&&(this.DX < 0) ) || ( (this.AX >= this.AX0)&&(this.DX > 0) ) ) {
			if (this.BACKTOZERO) {
				this.DX = this.DX*(-1);
				if (this.AUTOMOVE) this.TimerID = setTimeout(this.NAME + ".move()", this.SPEED);
			}
		} else {
			this.AX = this.AX + (this.DX * this.X);
			document.getElementById(this.OBJ_ID).style.left = this.AX+"px";
			if (this.AUTOMOVE) this.TimerID = setTimeout(this.NAME + ".move()", this.SPEED);
		}
	}
	if (this.DY) {
		if ( ( (this.AY <= this.AY1)&&(this.DY < 0) ) || ( (this.AY >= this.AY0)&&(this.DY > 0) ) ) {
			if (this.BACKTOZERO) {
				this.DY = this.DY*(-1);
				if (this.AUTOMOVE) this.TimerID = setTimeout(this.NAME + ".move()", this.SPEED);
			}
		} else {
			this.AY = this.AY + (this.DY * this.Y);
			document.getElementById(this.OBJ_ID).style.top = this.AY+"px";
			if (this.AUTOMOVE) this.TimerID = setTimeout(this.NAME + ".move()", this.SPEED);
		}
	}
}
/* Mover E */


function col3height() {
	var pom = get_yPos("main");
	var c3h = get_yPos("col3end") - pom;
	var pom = get_yPos("readed-bottom") - pom;
	if ((c3h+75)>pom) { $(".col12").css("height",c3h); }
}




// ON LOAD
$(document).ready(function(){

	setTimeout("col3height()", 500);

	if ($("#l-nm").val()=='') { $("#l-nm").val('UŽIVATELSKÉ JMÉNO'); }
	$("#l-nm").focus(function(){
		if($(this).val()=='UŽIVATELSKÉ JMÉNO'){ $(this).val(''); }
	});
	
	if (rs_hp) {
		$("#hp-reader").html(rrfc);
	}
	
	if ($("#l-pw-p").val()=='') { $("#l-pw-p").css("display","none"); $("#l-pw-t").css("display","inline"); }
	$("#l-pw-t").focus(function(){
		$("#l-pw-t").css("display","none"); $("#l-pw-p").css("display","inline").focus();
	});
	
	$("#readed-bottom DIV.ow:last").css("border-right","0");
	
	
	$("#z-readed").click(function(){
		$("#z-commen").removeClass().addClass("unact").css("border-left","0").css("border-right","1px solid white");
		$("#z-middle").removeClass().addClass("re-act");
		$(this).removeClass().addClass("active").css("border-right","0").css("border-left","1px solid #C5C7C8").blur();
		$("#readed2, #commen1, #commen2").css("display","none"); $("#readed1").css("display","block");
		return false;
	});
	$("#z-commen").click(function(){
		$("#z-readed").removeClass().addClass("unact").css("border-right","0").css("border-left","1px solid white");
		$("#z-middle").removeClass().addClass("co-act");
		$(this).removeClass().addClass("active").css("border-left","0").css("border-right","1px solid #C5C7C8").blur();
		$("#readed1, #readed2, #commen2").css("display","none"); $("#commen1").css("display","block");
		return false;
	});
	
	var d_big_img = $("#big-img-src").html();
	if (d_big_img!="") {
		$("#big-img").html(d_big_img);
		var d_dx = get_xPos("respekt")+1;
		var bi_h = $("#big-img IMG").attr("height");
		$("#big-img-bg").css("left",d_dx+"px");
		$("#big-img").css("left",d_dx+"px");
		$("#big-img IMG").attr("title", "Kliknutím zavřete");
		
		$("#big-img").click(function(){
			$("#big-img-bg").hide("normal");
			$("#big-img").hide("normal");
			return false;
		});
	}
	$("#big-img-a").click(function(){
		if (d_big_img!="") {
			$("#big-img-bg").css("top",(page_ay+5)+"px").css("height",(bi_h+40)+"px").fadeTo(0, 0.95).show("fast");
			$("#big-img").css("top",(page_ay+25)+"px");
			$("#big-img").show("normal");
		}
		return false;
	});
	
	
	if (document.getElementById("comm-count-to")==null) { $("#comm").css("display","none"); } else { $("#comm-count-to").append($("#comm-count-from").html()); }
	
});