var isFF = (navigator.userAgent.indexOf("Firefox") != -1) ? true : false;
var isCH = (navigator.userAgent.indexOf("Chrome") != -1) ? true : false;
var isSF = (navigator.userAgent.indexOf("Safari") != -1) ? true : false;
/* FLASH detection B */
var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
// Flash Player Version Detection - Rev 1.6
// Detect Client Browser type
// Copyright(c) 2005-2006 Adobe Macromedia Software, LLC. All rights reserved.
function ControlVersion(){
	var version;
	var axo;
	var e;
	
	// NOTE : new ActiveXObject(strFoo) throws an exception if strFoo isn't in the registry
	try {
		// version will be set for 7.X or greater players
		axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
		version = axo.GetVariable("$version");
	} catch (e) {}
	
	if (!version){
		try {
			// version will be set for 6.X players only
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
			
			// installed player is some revision of 6.0
			// GetVariable("$version") crashes for versions 6.0.22 through 6.0.29,
			// so we have to be careful. 
			
			// default to the first public version
			version = "WIN 6,0,21,0";
			
			// throws if AllowScripAccess does not exist (introduced in 6.0r47)
			axo.AllowScriptAccess = "always";
			
			// safe to call for 6.0r47 or greater
			version = axo.GetVariable("$version");
			
		} catch (e) {}
	}
	
	if (!version){
		try {
			// version will be set for 4.X or 5.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = axo.GetVariable("$version");
		} catch (e) {}
	}
	
	if (!version){
		try {
			// version will be set for 3.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = "WIN 3,0,18,0";
		} catch (e) {}
	}
	
	if (!version){
		try {
			// version will be set for 2.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			version = "WIN 2,0,0,11";
		} catch (e) {
			version = -1;
		}
	}
	
	return version;
}

// 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;
}

// When called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available
function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision){
	versionStr = GetSwfVer();
	if (versionStr == -1 ) {
		return false;
	} else if (versionStr != 0) {
		if(isIE && isWin && !isOpera) {
			// Given "WIN 2,0,0,11"
			tempArray         = versionStr.split(" "); 	// ["WIN", "2,0,0,11"]
			tempString        = tempArray[1];			// "2,0,0,11"
			versionArray      = tempString.split(",");	// ['2', '0', '0', '11']
		} else {
			versionArray      = versionStr.split(".");
		}
		var versionMajor      = versionArray[0];
		var versionMinor      = versionArray[1];
		var versionRevision   = versionArray[2];
		
		// is the major.revision >= requested major.revision AND the minor version >= requested minor
		if (versionMajor > parseFloat(reqMajorVer)) {
			return true;
		} else if (versionMajor == parseFloat(reqMajorVer)) {
			if (versionMinor > parseFloat(reqMinorVer))
				return true;
			else if (versionMinor == parseFloat(reqMinorVer)) {
				if (versionRevision >= parseFloat(reqRevision))
					return true;
			}
		}
		return false;
	}
}
/* FLASH detection E */


/* 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 */

/* 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.STOPonPAUSE = false;
	this.AX = new Array(this.COUNT);
	this.AY = new Array(this.COUNT);
	
	this.on = rotator_on;
	this.off = rotator_off;
	this.rotuj = rotator_rotuj;
	this.setdirection = rotator_setdirection;
	this.stoponpause = rotator_stoponpause;
	this.prev = rotator_prev;
	this.next = rotator_next;
	
	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.AX1 = this.DX * this.WIDTH;
	this.AY1 = this.DY * this.HEIGHT;
	
	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);
	}
	
	if (((w==x)&&(this.DX)) || ((h==y)&&(this.DY))) {
		this.TimerID = setTimeout(this.NAME + ".rotuj()", 1);
	} else {
		this.TimerID = setTimeout(this.NAME + ".rotuj()", this.PAUSE);
	}
}

function rotator_on() {
	this.STOPonPAUSE = false;
	clearTimeout(this.TimerID);
	this.TimerID = setTimeout(this.NAME + ".rotuj()", this.SPEED);
}

function rotator_off() {
	clearTimeout(this.TimerID);
}

function rotator_stoponpause() {
	this.STOPonPAUSE = true;
}

function rotator_setdirection(d) {
	if (this.DIRECTION != d) {
		this.DIRECTION = d;
		this.DX = 0;
		this.DY = 0;
		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.AX1 += (this.DX * this.WIDTH * this.COUNT);
		this.AY1 += (this.DY * this.HEIGHT * this.COUNT);
		clearTimeout(this.TimerID);
	}
}

function rotator_prev() {
	for (i=0; i < this.COUNT; i++) {
		if (this.DX) {
			this.AX[i] -= (this.DX * this.WIDTH);
			if ( ( (this.AX[i] >= (-this.DX * this.WIDTH * this.COUNT))&&(this.DX < 0) ) || ( (this.AX[i] <= (-this.DX * this.WIDTH * this.COUNT))&&(this.DX > 0) ) ) {
				if (this.AX[i] != this.AX1) this.AX[i] = this.AX1;
				this.AX[i] -= (this.DX * this.WIDTH);
			}
			document.getElementById(this.OBJ_ID + i).style.left = this.AX[i]+"px";
		}
		if (this.DY) {
			this.AY[i] -= (this.DY * this.HEIGHT);
			if ( ( (this.AY[i] >= (-this.DY * this.HEIGHT * this.COUNT))&&(this.DY < 0) ) || ( (this.AY[i] <= (-this.DY * this.HEIGHT * this.COUNT))&&(this.DY > 0) ) ) {
				if (this.AY[i] != this.AY1) this.AY[i] = this.AY1;
				this.AY[i] -= (this.DY * this.HEIGHT);
			}
			document.getElementById(this.OBJ_ID + i).style.top = this.AY[i]+"px";
		}
	}
}

function rotator_next() {
	for (i=0; i < this.COUNT; i++) {
		if (this.DX) {
			this.AX[i] += (this.DX * this.WIDTH);
			if ( ( (this.AX[i] <= this.AX1)&&(this.DX < 0) ) || ( (this.AX[i] >= this.AX1)&&(this.DX > 0) ) ) {
				if (this.AX[i] != this.AX1) this.AX[i] = this.AX1;
				this.AX[i] -= (this.DX * this.WIDTH * this.COUNT);
			}
			document.getElementById(this.OBJ_ID + i).style.left = this.AX[i]+"px";
		}
		if (this.DY) {
			this.AY[i] += (this.DY * this.HEIGHT);
			if ( ( (this.AY[i] <= this.AY1)&&(this.DY < 0) ) || ( (this.AY[i] >= this.AY1)&&(this.DY > 0) ) ) {
				if (this.AY[i] != this.AY1) this.AY[i] = this.AY1;
				this.AY[i] -= (this.DY * this.HEIGHT * this.COUNT);
			}
			document.getElementById(this.OBJ_ID + i).style.top = this.AY[i]+"px";
		}
	}
}

function rotator_rotuj() {
	var next = this.SPEED;
	var paus = false;
	
	for (var i=0; i < this.COUNT; i++) {
		if (this.DX) {
			if ( ( (this.AX[i] <= this.AX1)&&(this.DX < 0) ) || ( (this.AX[i] >= this.AX1)&&(this.DX > 0) ) ) {
				if (this.AX[i] != this.AX1) this.AX[i] = this.AX1;
				this.AX[i] += (this.DX * this.WIDTH * (-1) * this.COUNT); next = this.PAUSE; paus = true;
			}
		}
		if (this.DY) {
			if ( ( (this.AY[i] <= this.AY1)&&(this.DY < 0) ) || ( (this.AY[i] >= this.AY1)&&(this.DY > 0) ) ) {
				if (this.AY[i] != this.AY1) this.AY[i] = this.AY1;
				this.AY[i] += (this.DY * this.HEIGHT * (-1) * this.COUNT); next = this.PAUSE; paus = true;
			}
		}
	}
	if (!paus) {
		for (i=0; i < this.COUNT; i++) {
			if (this.DX) {
				this.AX[i] += (this.DX * this.X);
				document.getElementById(this.OBJ_ID + i).style.left = this.AX[i]+"px";
			}
			if (this.DY) {
				this.AY[i] += (this.DY * this.Y);
				document.getElementById(this.OBJ_ID + i).style.top = this.AY[i]+"px";
			}
		}
	}
	
	this.TimerID = setTimeout(this.NAME + ".rotuj()", next);
	
	if (this.STOPonPAUSE && paus) clearTimeout(this.TimerID);
}
/* 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 */


var articleCategory = {
	zpravy : {
		category : "zpravy",
		categoryTitle : "Zpr&aacute;vy",
		moreURL : "http://zpravy.ihned.cz/",
		moreTitle : "zpr&aacute;v"},
	byznys : {
		category : "byznys",
		categoryTitle : "Byznys",
		moreURL : "http://byznys.ihned.cz/",
		moreTitle : "byznysu"},
	life : {
		category : "life",
		categoryTitle : "Life",
		moreURL : "http://life.ihned.cz/",
		moreTitle : "ze &#382;ivota"},
	art : {
		category : "art",
		categoryTitle : "Art",
		moreURL : "http://art.ihned.cz/",
		moreTitle : "kultury"},
	tech : {
		category : "tech",
		categoryTitle : "Tech",
		moreURL : "http://tech.ihned.cz/",
		moreTitle : "IT &amp; v&#283;dy"},
	sport : {
		category : "sport",
		categoryTitle : "Sport",
		moreURL : "http://sport.ihned.cz/",
		moreTitle : " sportu"},
	dialog : {
		category : "dialog",
		categoryTitle : "Dialog",
		moreURL : "http://dialog.ihned.cz/",
		moreTitle : "n&aacute;zor&#367;"}
};


var page_ay = 0;

$(window).scroll(function(){ page_ay = $(this).scrollTop(); });

window.onresize = function() { setTimeout('set_xPos("ihned","r-sky", 1000); set_xPos("ihned","r-sky-l", -130)', 200); }

$(document).ready(function(){
	$("A.more").each(function(){
		var href = $(this).attr('href'); 
		var toSet = ''; 
		$.each(articleCategory, function(key, val){
			if (val.moreURL == href) {
				toSet = 'v&iacute;ce ' + val.moreTitle;
				return false;
			}
		});
		if (toSet) $(this).html(toSet);
	});
});


var dTitle = document.title;

$(window).load(function () {
	var isSport = $('#ihned').parent().attr('id') == 'bg';
	var mf = function() {
		if ($('#r-sky').is(':visible')){
			var fn = function() {
				if ($(document).width()<1240){
					oldScrollTop = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop;
					var sf = function(e) {
						var rightEdge = get_xPos('ihned') + 1000;

						var sc = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop;
						var scrollLeft = $(window).scrollLeft(); 
						if (oldScrollTop != sc){
							oldScrollTop = sc;
							return;
						}
						$('#r-sky').css({left: (rightEdge - scrollLeft)});
						oldScrollTop = sc;
					}
					
					sf();
					
					if (isSport){
						$('#bg, #r-leader').css({margin: 0});
					} else {
						$('#ihned, #r-leader').css({margin: 0});
					}
					$('html, body').css({minWidth: '1135px'});
					$('body').css({backgroundPosition: 'left top'});
					$(window).unbind('scroll').bind('scroll', sf);
					///$('#r-sky').css({position: 'absolute'});
				} else {
					if (isSport){
						$('#bg, #r-leader').css({margin: '0 auto'});
					} else {
						$('#ihned, #r-leader').css({margin: '0 auto'});
					}
					$('html, body').css({minWidth: '0'});
					$('body').css({backgroundPosition: 'center top'});
					//$('#r-sky').css({position: 'fixed'});
					$(window).unbind('scroll', sf);
				}
			}
			
			fn();
		}
	}
	
	/*
		$(window).resize(function(){
			mf();
		});
	
		if ($.browser.msie == true)
		{
			setTimeout(mf, 3500);
		} else
		{
			mf();
		}
	*/
	
	document.title = dTitle;
	set_xPos("ihned","r-sky-l", -130);
	set_xPos("ihned","r-sky", 1000);
});

