// Promenne

var page_ay = 0;
var rs_hp = false;
var liTimer;
var sma,smt;	//actual,timer submenu

// Funkce

// JavaScript helper required to detect Flash Player PlugIn version information
function GetSwfVer(){
	// NS/Opera version >= 3 check for Flash plugin in plugin array
	var flashVer = -1;
	
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
			var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
			var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
			var descArray = flashDescription.split(" ");
			var tempArrayMajor = descArray[2].split(".");
			var versionMajor = tempArrayMajor[0];
			var versionMinor = tempArrayMajor[1];
			var versionRevision = descArray[3];
			if (versionRevision == "") {
				versionRevision = descArray[4];
			}
			if (versionRevision[0] == "d") {
				versionRevision = versionRevision.substring(1);
			} else if (versionRevision[0] == "r") {
				versionRevision = versionRevision.substring(1);
				if (versionRevision.indexOf("d") > 0) {
					versionRevision = versionRevision.substring(0, versionRevision.indexOf("d"));
				}
			}
			var flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
			//alert("flashVer="+flashVer);
		}
	}
	// MSN/WebTV 2.6 supports Flash 4
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
	// WebTV 2.5 supports Flash 3
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
	// older WebTV supports Flash 2
	else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
	else if ( isIE && isWin && !isOpera ) {
		flashVer = ControlVersion();
	}
	return flashVer;
}

/* 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' && parElement.tagName != 'HTML') {
				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 toplogin() {
	$.post("http://respekt.ihned.cz/index.php?p=RRL000_a", $("#toploginform").serialize(), function(data){
		if (data == "1") {
			location.reload();
		} else {
			$("#logininfo").html(data);
			$("#logininfo").slideDown();
			clearTimeout(liTimer);
			liTimer = setTimeout('$("#logininfo").slideUp()',12000);
		}
	});
}

function loadwebmap() {
	if ($("#webmap").html()=='') {
		$("#webmap").ajaxStop(function(){
			$("#webmap").show();
		});
		$("#webmap").load('/index.php?p=ROWM00_a');
	} else {
		$("#webmap").toggle();
	}
}

function col3height() {
	var pom = get_yPos("main");
	var c3h = get_yPos("col3end") - pom;
	if (document.getElementById("readed-bottom") != null) {
		pom = get_yPos("readed-bottom") - pom;
	} else {
		pom = get_yPos("foot") - pom;
	}
	if ((c3h+75)>pom) { $(".col12").css("height",c3h); }
}

$(window).scroll(function(){
	page_ay = document.body.scrollTop;
});

window.onresize = function() { set_xPos("respekt","r-sky", 1001); set_xPos("respekt","r-sky-l", -129); }

function on_load2() {
	iload = true;
	
	sma = $("#menu-nl");
	$("#m-nl SPAN").mouseenter(function(){	var rsp = $("#respekt").position(); $("#menu-nl").css("top",(rsp.top+134)).css("left",(rsp.left+506));
						clearTimeout(smt); $(sma).hide(); $("#menu-nl").show(); sma=$("#menu-nl"); }).mouseleave(function(){ smt = setTimeout('$(sma).hide();',1000); });
	$("#m-ep SPAN").mouseenter(function(){	var rsp = $("#respekt").position(); $("#menu-ep").css("top",(rsp.top+134)).css("left",(rsp.left+649));
						clearTimeout(smt); $(sma).hide(); $("#menu-ep").show(); sma=$("#menu-ep"); }).mouseleave(function(){ smt = setTimeout('$(sma).hide();',1000); });
	$(".submenu").mouseenter(function(){ clearTimeout(smt); }).mouseleave(function(){ smt = setTimeout('$(sma).hide();',1000); });
	
	$("#login-box").click(function() {
		$("#login").slideToggle(500);
	});
	
}
