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",
		categoryClass: "",
		categoryTitle : "Zpr&aacute;vy",
		moreURL : "http://zpravy.ihned.cz/",
		moreTitle : "zpr&aacute;v"},
	byznys : {
		category : "byznys",
		categoryClass: "",
		categoryTitle : "Byznys",
		moreURL : "http://byznys.ihned.cz/",
		moreTitle : "byznysu"},
	life : {
		category : "life",
		categoryClass: "",
		categoryTitle : "Life",
		moreURL : "http://life.ihned.cz/",
		moreTitle : "ze &#382;ivota"},
	art : {
		category : "art",
		categoryClass: "",
		categoryTitle : "Art",
		moreURL : "http://art.ihned.cz/",
		moreTitle : "kultury"},
	tech : {
		category : "tech",
		categoryClass: "",
		categoryTitle : "Tech",
		moreURL : "http://tech.ihned.cz/",
		moreTitle : "IT &amp; v&#283;dy"},
	sport : {
		category : "sport",
		categoryClass: "",
		categoryTitle : "Sport",
		moreURL : "http://sport.ihned.cz/",
		moreTitle : " sportu"},
	dialog : {
		category : "dialog",
		categoryClass: "dialog-item",
		categoryTitle : "Dialog",
		moreURL : "http://dialog.ihned.cz/",
		moreTitle : "n&aacute;zor&#367;"},
	foto : {
		category : "foto",
		categoryClass: "",
		categoryTitle : "Foto",
		moreURL : "http://multimedia.ihned.cz/fotogalerie/",
		moreTitle : "fotogaleri&iacute;"},
	video : {
		category : "video",
		categoryClass: "",
		categoryTitle : "Video",
		moreURL : "http://multimedia.ihned.cz/",
		moreTitle : "vide&iacute;"},
	probyznysinfo : {
		category : "byznys",
		categoryClass: "probyznys",
		categoryTitle : "ProByznys.info",
		moreURL : "http://probyznysinfo.ihned.cz/",
		moreTitle : "pro podnikatele"}
};

var page_ay=0;
var sky_l_width=120;
var sky_r_width=120;
var primary_div='ihned';
var bbkeywords='';
var sklik_1_enabled = false;
var sklik_2_enabled = false;
var dTitle=document.title;

//ovládání skyscraperů
function sky(options){
	var default_options = {
		l_width:	120,
		l_height:	0,
		l_scroll:	true,
		l_label:	true,
		l_top:		0,
		
		r_width:	120,
		r_height:	0,
		r_scroll:	true,
		r_label:	true,
		r_top:		0,
		
		content_top:	0,
		content_border:	false,
		background:	'',
		brand_url:	''
	};
	var opt = $.extend(default_options, options);
	var page_height=0;
	sky_l_width=opt.l_width; $('#r-sky-l').css('width',opt.l_width+'px');
	sky_r_width=opt.r_width; $('#r-sky').css('width',opt.r_width+'px');
	
	if (opt.content_top)	$('#'+primary_div).css('margin-top',opt.content_top+'px');
	if (opt.l_top)		$('#r-sky-l').css('top',opt.l_top+'px');
	if (opt.r_top)		$('#r-sky').css('top',opt.r_top+'px');
	
	if (opt.background){//s pozadím
		$('BODY').css('background',opt.background);
		opt.content_border = true;
	}
	if (opt.content_border){
		sky_l_width-=10; page_height=10;
		$('#r-leader').css('background','transparent');
		$('#'+primary_div).css({'border':'10px solid white','border-bottom':'0'});
		$('#r-leader DIV.reklama').css('padding-bottom','0');
		$('#r-sky DIV.reklama').css('margin-left','10px');
	}
	
	//zbytek po onload
	$(function(){
		if (!opt.l_scroll)	$('#r-sky-l').css('position','absolute');
		if (!opt.r_scroll)	$('#r-sky').css('position','absolute');
		if (!opt.l_label)	$('#r-sky-l-ozn').css('visibility','hidden');
		if (!opt.r_label)	$('#r-sky-ozn').css('visibility','hidden');
		
		if (opt.l_height=='by_page' || opt.r_height=='by_page' || opt.brand_url){
					page_height += $('#'+primary_div).height()+opt.content_top+$('#r-leader').height()-10;
		}
		if (opt.l_height){
					if (opt.l_height=='by_page') { opt.l_height=page_height; $('#r-sky-l DIV.reklama').css('overflow','hidden'); }
					$('#r-sky-l DIV.reklama').css('height',opt.l_height+'px').css('width',opt.l_width+'px');
		}
		if (opt.r_height){
					if (opt.r_height=='by_page') { opt.r_height=page_height; $('#r-sky DIV.reklama').css('overflow','hidden'); }
					$('#r-sky DIV.reklama').css('height',opt.r_height+'px').css('width',opt.r_width+'px');
		}
		if (opt.brand_url && opt.background){
					$('#'+primary_div).css('position','relative').css('z-index','2');
					$('#r-leader,#r-sky-l,#r-sky').css('z-index','1');
					$('BODY').append('<a id="bg-branding-click" target="_new" style="position:absolute; top:0; left:0; cursor:pointer; z-index:0" href="'+opt.brand_url+'"></a>');
					$('#bg-branding-click').css('height',page_height+'px').css('width',$(window).width()+'px');
		}
	});
}



if(!String.prototype.trim) {
	String.prototype.trim = function () {
		return this.replace(/^\s+|\s+$/g,'');
	};
}

//chartbeat.com
function get_sections_for_chartbeat(){
	var dom=window.location.href;
	var idx=dom.indexOf('://'); dom = dom.substr(idx+3);
	idx=dom.indexOf('/'); dom = dom.substring(0,idx);
	return dom;
}
function get_authors_for_chartbeat(){
	var txt = $("#next-authors .l").text().trim();
	var idx = txt.indexOf('Autoři:');
	if (idx>=0) {
		return txt.substr(idx+8);
	} else {
		txt = $(".d-autor span:first").text().trim();
		idx = txt.indexOf('Autor/ři:');
		if (idx>=0) return txt.substr(idx+10);
	}
	return '';
}



$(window).scroll(function(){ page_ay = $(this).scrollTop(); });

window.onresize = function() {
	setTimeout(function() {
		var wrapper = document.getElementById('ihned') || document.getElementById('respekt');
		set_xPos(primary_div,"r-sky", wrapper.offsetWidth);
		set_xPos(primary_div,"r-sky-l", (-1*sky_l_width-30));
	}, 200);
	$('#bg-branding-click').css('width',$(window).width()+'px');
}

$(document).ready(function(){
	if (primary_div == 'ihned'){
		$("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);
		});
	}
	
	// eventy na tagy
	$('.tags a').click(function() {
		_gaq.push(['_trackEvent', 'TAG', $(this).text(), $('h1 a').text()]);
		datalayer.push(['_trackEvent', 'TAG', $(this).text(), $('h1 a').text()]);
	});
});

$(window).load(function () {
	var wrapper = document.getElementById('ihned') || document.getElementById('respekt');
	set_xPos(primary_div,"r-sky-l", (-1*sky_l_width-30));
	set_xPos(primary_div,"r-sky", wrapper.offsetWidth);
	if (document.title!=dTitle) document.title=dTitle;;
});

// vraci zvolenou cast domeny, pokud neni url, bere se aktualni
// cislo casti se pocita od 1 => cz=1, ihned=2, ....
function get_domain_part(num, url) {
	url = url || location.href;
	num = num || 1;
	
	var a = $('<a>',{href: url})[0];
	a = a.hostname.split('.').reverse();
	
	return a[num-1] ? a[num-1] : '';
}


//<SAS
//almost same code in 7/7.js
if (!Array.prototype.indexOf) {
	Array.prototype.indexOf = function (searchElement, fromIndex) {
		if ( this === undefined || this === null ) {
			throw new TypeError( '"this" is null or not defined' );
		}
		var length = this.length >>> 0; // Hack to convert object.length to a UInt32
		fromIndex = +fromIndex || 0;
		if (Math.abs(fromIndex) === Infinity) {
			fromIndex = 0;
		}
		if (fromIndex < 0) {
			fromIndex += length;
			if (fromIndex < 0) {
				fromIndex = 0;
			}
		}
		for (;fromIndex < length; fromIndex++) {
			if (this[fromIndex] === searchElement) {
				return fromIndex;
			}
		}
		return -1;
	};
}

function _SAS_ECO_PARAMS(){//objekt s parametry pro SAS
	this.site='';
	this.area='';
	this.keywords=[];
	this.targets={device:'u', template:'list'};//v detail.js se mění template
	
	// definice podle eventType
	this.callbacks = {
		cleanup: function(e) {
			var p = e.position.options.element.parentNode; // wrapper
			_saseco.removeClass(p,['ad-visible', p.id+'-visible']);
			if(e.position.options.size == 'commercial' && p.parentNode.id == 'r-ht') {
				p.parentNode.style.display = 'none';
			}
			// clear DOM elements
			while (e.position.options.element.firstChild) {
				e.position.options.element.removeChild(e.position.options.element.firstChild);
			}
		},
		insert: function(e) {
			var p = e.position.options.element.parentNode; // wrapper
			switch(e.position.options.size) {
				case 'commercial': {
					// zviditelneni wrapperu hypertextu
					if(!e.is_empty && p.parentNode.id == 'r-ht') p.parentNode.style.display = 'block';
				}
				default: {
					if(!e.is_empty) _saseco.addClass(p, ['ad-visible', p.id+'-visible']);
				}
			}
			// user callback
			_saseco.user_callback(e);
		}
	};
	
	// default callback
	this.callback = function(e) {
		if(typeof _saseco.callbacks[e.type] != 'function') return;
		return _saseco.callbacks[e.type](e);
	};
	
	this.user_callback = function(e) {
		var call_name = e.position.options.size + (e.position.options.pos != undefined ? '_'+e.position.options.pos : '') + '_call';
		if(typeof window[call_name] === 'function') return window[call_name].call(e.position.options.element,window.jQuery);
		return false;
	};
	
	// pridani css trid k DOM elementu
	// pro class_list povoleno string nebo array
	this.addClass = function(element, class_list) {
		if(typeof element != 'object' || class_list == undefined) return;
		
		var classes = element.className != undefined ? element.className.trim().split(' ') : [];
		if(!classes) {
			element.className = class_list;
			return;
		}
		if(typeof class_list == 'string') class_list = class_list.split(' ');
		for(var i in class_list) {
			if(typeof class_list[i] != 'string') continue;
			if(classes.indexOf(class_list[i]) == -1) classes.push(class_list[i]);
		}
		
		element.className = classes.join(' ');
	};
	
	// odebrani css trid z DOM elementu
	// pro class_list povoleno string nebo array
	this.removeClass = function(element, class_list) {
		if(typeof element != 'object' || class_list == undefined) return;
		if(element.className == undefined) return;
		class_list = (typeof class_list == 'string' ? class_list.split(' ') : class_list);
		if(!class_list) return;
		element.className = element.className.replace(new RegExp(class_list.join("|"), 'gi'), '');
	};
	
	// pomocna funkce pro sanitovani keywords
	this.parse = function(str) {
		
		// kontrola na obsah
		if(str === undefined) return undefined;
		str = str.trim().toLowerCase();
		if(str == '') return undefined;
		
		// odstraneni diakritiky
		var search  = "áäčçďéěëíňóöřúůüý _=+%'/&*()][{}!<>:?;,#$";
		var replace = "aaccdeeeinoorstuuuyz--_";
		
		var result = '';
		for(var i=0;i<str.length;i++) {
			var k = search.indexOf(str[i]);
			if(k == -1) {
				result += str.charAt(i);
				continue;
			}
			result += replace.charAt(k);
		}
		//odstraneni duplicitnich -
		result = result.replace(/([-]{2,})/g,'-');
		return result.replace('"','');
	};
	
	// nastaveni keywords s moznosti nahrazeni predchoziho
	this.push_keywords = function(keywords,replace) {
		replace = replace || false; //je-li true keywords se přepisují
		if(keywords == undefined) return;
		
		//string with keywords separated by ";"
		if (typeof keywords === 'string') {
			if(keywords.trim() == '' && !replace) return;
			keywords = keywords.split(';');
		}

		// aplikovano nahrazeni 
		if(replace) this.keywords = [];
		
		// zpracovani jednotlivych kw a pridani do pole
		for(var k=0;k<keywords.length;k++) {
			var $kw = this.parse(keywords[k]);
			if($kw === undefined || this.keywords.indexOf($kw) != -1) continue;
			this.keywords.push($kw);
		}
	};
	
	// nastaveni ciloveho webu (site)
	this.set_site = function(str) {
		if (str) this.site = str;//vdy se přepisuje
	};
	
	// nastaveni cilove oblasti (area)
	this.set_area = function(str) {
		//přepisuje se pouze pokud není vyplněno TODO: je to v pořádku?
		if (str && !this.area) this.area = str;
	};
	
	// ID clanku
	this.set_targets_id = function(str) {
		if (str) this.targets.id = str;
	};
	
	// ziskani aktualni site
	this.get_site = function() {
		if (!this.site) return 'ihned';
		return this.site;
	};
	
	// ziskani aktualni oblasti
	this.get_area = function() {
		if (!this.area) return 'default';
		return this.area;
	};
};

var _saseco = new _SAS_ECO_PARAMS();
//SAS>
