/**
 * vola se z homepage
 * zapne vsechny potrebne JS funkce po nacteni stranky
 */

function runHome() {
	linkLinks(this.document);
	activateFigure();
}

function runPage(mode) {
	linkLinks(this.document);

	if(document.getElementById('figure'))
	{
		activateFigure();
	}

	if(document.getElementById('chatWindow'))
	{
		getChatMessages();
		setInterval('getChatMessages()',15000);
	}
}

/**
* pridavani zalozek
*/

function addBookmark(title,url) {
    if (window.sidebar) {
        window.sidebar.addPanel(title, url,"");
    } else if( document.all ) {
        window.external.AddFavorite( url, title);
    } else if( window.opera && window.print ) {
        return true;
    }
}

//############### EXTERNI SKRIPTY

/**
* funkce pro manipulaci s cookies
*/

function setCookie(name, value, expire, path) {
    document.cookie = name + "=" + escape(value)
    + ((expire == null) ? "" : ("; expires=" + expire.toGMTString()))
    + ((path == null) ? "" : ("; path=" + escape(path)));
}

function getCookie(Name) {
    var search = Name + "="
    if (document.cookie.length > 0) { // if there are any cookies
        offset = document.cookie.indexOf(search)
        if (offset != -1) { // if cookie exists
            offset += search.length 
            // set index of beginning of value
            end = document.cookie.indexOf(";", offset)
            // set index of end of cookie value
            if (end == -1)
                end = document.cookie.length
            return unescape(document.cookie.substring(offset, end))
        }
    }
}

function registerCookie(name,value) {
    var today = new Date()
    var expires = new Date()
    expires.setTime(today.getTime() + 1000*60*60*24*365)
    setCookie(name,value, expires)
}

function htmlspecialchars (string, quote_style, charset, double_encode) {
    // Convert special characters to HTML entities
    //
    // version: 1004.2314
    // discuss at: http://phpjs.org/functions/htmlspecialchars
    // +   original by: Mirek Slugen
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: Nathan
    // +   bugfixed by: Arno
    // +    revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +    bugfixed by: Brett Zamir (http://brett-zamir.me)
    // +      input by: Ratheous
    // +      input by: Mailfaker (http://www.weedem.fr/)
    // +      reimplemented by: Brett Zamir (http://brett-zamir.me)
    // +      input by: felix
    // +    bugfixed by: Brett Zamir (http://brett-zamir.me)
    // %        note 1: charset argument not supported
    // *     example 1: htmlspecialchars("<a href='test'>Test</a>", 'ENT_QUOTES');
    // *     returns 1: '&lt;a href=&#039;test&#039;&gt;Test&lt;/a&gt;'
    // *     example 2: htmlspecialchars("ab\"c'd", ['ENT_NOQUOTES', 'ENT_QUOTES']);
    // *     returns 2: 'ab"c&#039;d'
    // *     example 3: htmlspecialchars("my "&entity;" is still here", null, null, false);
    // *     returns 3: 'my &quot;&entity;&quot; is still here'
    var optTemp = 0, i = 0, noquotes= false;
    if (typeof quote_style === 'undefined' || quote_style === null) {
        quote_style = 2;
    }
    string = string.toString();
    if (double_encode !== false) { // Put this first to avoid double-encoding
        string = string.replace(/&/g, '&amp;');
    }
    string = string.replace(/</g, '&lt;').replace(/>/g, '&gt;');

    var OPTS = {
        'ENT_NOQUOTES': 0,
        'ENT_HTML_QUOTE_SINGLE' : 1,
        'ENT_HTML_QUOTE_DOUBLE' : 2,
        'ENT_COMPAT': 2,
        'ENT_QUOTES': 3,
        'ENT_IGNORE' : 4
    };
    if (quote_style === 0) {
        noquotes = true;
    }
    if (typeof quote_style !== 'number') { // Allow for a single string or an array of string flags
        quote_style = [].concat(quote_style);
        for (i=0; i < quote_style.length; i++) {
            // Resolve string input to bitwise e.g. 'PATHINFO_EXTENSION' becomes 4
            if (OPTS[quote_style[i]] === 0) {
                noquotes = true;
            }
            else if (OPTS[quote_style[i]]) {
                optTemp = optTemp | OPTS[quote_style[i]];
            }
        }
        quote_style = optTemp;
    }
    if (quote_style & OPTS.ENT_HTML_QUOTE_SINGLE) {
        string = string.replace(/'/g, '&#039;');
    }
    if (!noquotes) {
        string = string.replace(/"/g, '&quot;');
    }

    return string;
}

function TextToXML (text) {
    var domXML;
    var parser;

    if (window.DOMParser) {

	parser=new DOMParser();
	domXML=parser.parseFromString(text,"text/xml");

    } else { // Internet Explorer

	domXML=new ActiveXObject("Microsoft.XMLDOM");
	domXML.async="false";
	domXML.loadXML(text);

    }

    return domXML;
}

/**
 * Check for valid XML data
 *
 * author: http://www.w3schools.com/dom/dom_validate.asp
 */
var xt="",h3OK=1

function checkErrorXML(x) {
    xt=""
    h3OK=1
    checkXML(x)
}

function checkXML(n) {
    var l,i,nam
    nam=n.nodeName

    if (nam=="h3") {
	if (h3OK==0) {
	    return;
	}
	h3OK=0
    }

    if (nam=="#text") {
	xt=xt + n.nodeValue + "\n"
    }

    l=n.childNodes.length

    for (i=0;i<l;i++) {
	checkXML(n.childNodes[i])
    }
}

function validateXML() {
    // code for IE
    if (window.ActiveXObject) {
	var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
	xmlDoc.async="false";
	xmlDoc.loadXML(document.all("validxml").value);

	if(xmlDoc.parseError.errorCode!=0) {
	    txt="Chybový kód: " + xmlDoc.parseError.errorCode + "\n";
	    txt=txt+"Důvod: " + xmlDoc.parseError.reason;
	    txt=txt+"Na řádku: " + xmlDoc.parseError.line;
	    alert(txt);
	} else {
	    alert("V dokumentu nebyla nalezena chyba.");
	}
    // code for Mozilla, Firefox, Opera, etc.
    } else if (document.implementation && document.implementation.createDocument) {
	var parser=new DOMParser();
	var text=document.getElementById("validxml").value;
	var xmlDoc=parser.parseFromString(text,"text/xml");
	if (xmlDoc.getElementsByTagName("parsererror").length>0) {
	    checkErrorXML(xmlDoc.getElementsByTagName("parsererror")[0]);
	    alert(xt)
	} else {
	    alert("V dokumentu nebyla nalezena chyba.");
	}
    } else {
	alert('Váš prohlížeč nepodporuje tento skript');
    }
}

/**
 * Tabs - jQuery plugin for accessible, unobtrusive tabs
 * @requires jQuery v1.1.1
 *
 * http://stilbuero.de/tabs/
 *
 * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 * Version: 2.7.4
 */
eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('(4($){$.2l({z:{2k:0}});$.1P.z=4(x,w){3(O x==\'2Y\')w=x;w=$.2l({K:(x&&O x==\'1Z\'&&x>0)?--x:0,12:C,J:$.1f?2h:T,18:T,1r:\'2X&#2Q;\',21:\'18-2F-\',1m:C,1u:C,1l:C,1F:C,1x:\'2u\',2r:C,2p:C,2m:T,2i:C,1d:C,1c:C,1j:\'z-1M\',H:\'z-2b\',14:\'z-12\',16:\'z-26\',1q:\'z-1H\',1L:\'z-2L\',2j:\'10\'},w||{});$.8.1D=$.8.U&&($.8.1Y&&$.8.1Y<7||/2A 6.0/.2y(2x.2w));4 1w(){1V(0,0)}F 5.Y(4(){2 p=5;2 r=$(\'13.\'+w.1j,p);r=r.V()&&r||$(\'>13:9(0)\',p);2 j=$(\'a\',r);3(w.18){j.Y(4(){2 c=w.21+(++$.z.2k),B=\'#\'+c,2f=5.1O;5.1O=B;$(\'<10 S="\'+c+\'" 34="\'+w.16+\'"></10>\').2c(p);$(5).19(\'1B\',4(e,a){2 b=$(5).I(w.1L),X=$(\'X\',5)[0],27=X.1J;3(w.1r){X.1J=\'<24>\'+w.1r+\'</24>\'}1p(4(){$(B).2T(2f,4(){3(w.1r){X.1J=27}b.17(w.1L);a&&a()})},0)})})}2 n=$(\'10.\'+w.16,p);n=n.V()&&n||$(\'>\'+w.2j,p);r.P(\'.\'+w.1j)||r.I(w.1j);n.Y(4(){2 a=$(5);a.P(\'.\'+w.16)||a.I(w.16)});2 s=$(\'A\',r).20($(\'A.\'+w.H,r)[0]);3(s>=0){w.K=s}3(1e.B){j.Y(4(i){3(5.B==1e.B){w.K=i;3(($.8.U||$.8.2E)&&!w.18){2 a=$(1e.B);2 b=a.15(\'S\');a.15(\'S\',\'\');1p(4(){a.15(\'S\',b)},2D)}1w();F T}})}3($.8.U){1w()}n.1a(\':9(\'+w.K+\')\').1C().1n().2C(\':9(\'+w.K+\')\').I(w.1q);$(\'A\',r).17(w.H).9(w.K).I(w.H);j.9(w.K).N(\'1B\').1n();3(w.2m){2 l=4(d){2 c=$.2B(n.1t(),4(a){2 h,1A=$(a);3(d){3($.8.1D){a.Z.2z(\'1X\');a.Z.G=\'\';a.1k=C}h=1A.L({\'1h-G\':\'\'}).G()}E{h=1A.G()}F h}).2v(4(a,b){F b-a});3($.8.1D){n.Y(4(){5.1k=c[0]+\'1W\';5.Z.2t(\'1X\',\'5.Z.G = 5.1k ? 5.1k : "2s"\')})}E{n.L({\'1h-G\':c[0]+\'1W\'})}};l();2 q=p.1U;2 m=p.1v;2 v=$(\'#z-2q-2o-V\').1t(0)||$(\'<X S="z-2q-2o-V">M</X>\').L({1T:\'2n\',3a:\'39\',38:\'37\'}).2c(Q.1S).1t(0);2 o=v.1v;36(4(){2 b=p.1U;2 a=p.1v;2 c=v.1v;3(a>m||b!=q||c!=o){l((b>q||c<o));q=b;m=a;o=c}},35)}2 u={},11={},1R=w.2r||w.1x,1Q=w.2p||w.1x;3(w.1u||w.1m){3(w.1u){u[\'G\']=\'1C\';11[\'G\']=\'1H\'}3(w.1m){u[\'W\']=\'1C\';11[\'W\']=\'1H\'}}E{3(w.1l){u=w.1l}E{u[\'1h-2g\']=0;1R=1}3(w.1F){11=w.1F}E{11[\'1h-2g\']=0;1Q=1}}2 t=w.2i,1d=w.1d,1c=w.1c;j.19(\'2e\',4(){2 c=$(5).1g(\'A:9(0)\');3(p.1i||c.P(\'.\'+w.H)||c.P(\'.\'+w.14)){F T}2 a=5.B;3($.8.U){$(5).N(\'1b\');3(w.J){$.1f.1N(a);1e.B=a.1z(\'#\',\'\')}}E 3($.8.1y){2 b=$(\'<2d 33="\'+a+\'"><10><32 31="2a" 30="h" /></10></2d>\').1t(0);b.2a();$(5).N(\'1b\');3(w.J){$.1f.1N(a)}}E{3(w.J){1e.B=a.1z(\'#\',\'\')}E{$(5).N(\'1b\')}}});j.19(\'1E\',4(){2 a=$(5).1g(\'A:9(0)\');3($.8.1y){a.1o({W:0},1,4(){a.L({W:\'\'})})}a.I(w.14)});3(w.12&&w.12.1K){29(2 i=0,k=w.12.1K;i<k;i++){j.9(--w.12[i]).N(\'1E\').1n()}};j.19(\'28\',4(){2 a=$(5).1g(\'A:9(0)\');a.17(w.14);3($.8.1y){a.1o({W:1},1,4(){a.L({W:\'\'})})}});j.19(\'1b\',4(e){2 g=e.2Z;2 d=5,A=$(5).1g(\'A:9(0)\'),D=$(5.B),R=n.1a(\':2W\');3(p[\'1i\']||A.P(\'.\'+w.H)||A.P(\'.\'+w.14)||O t==\'4\'&&t(5,D[0],R[0])===T){5.25();F T}p[\'1i\']=2h;3(D.V()){3($.8.U&&w.J){2 c=5.B.1z(\'#\',\'\');D.15(\'S\',\'\');1p(4(){D.15(\'S\',c)},0)}2 f={1T:\'\',2V:\'\',G:\'\'};3(!$.8.U){f[\'W\']=\'\'}4 1I(){3(w.J&&g){$.1f.1N(d.B)}R.1o(11,1Q,4(){$(d).1g(\'A:9(0)\').I(w.H).2U().17(w.H);R.I(w.1q).L(f);3(O 1d==\'4\'){1d(d,D[0],R[0])}3(!(w.1u||w.1m||w.1l)){D.L(\'1T\',\'2n\')}D.1o(u,1R,4(){D.17(w.1q).L(f);3($.8.U){R[0].Z.1a=\'\';D[0].Z.1a=\'\'}3(O 1c==\'4\'){1c(d,D[0],R[0])}p[\'1i\']=C})})}3(!w.18){1I()}E{$(d).N(\'1B\',[1I])}}E{2S(\'2R P 2P 2O 26.\')}2 a=1G.2N||Q.1s&&Q.1s.23||Q.1S.23||0;2 b=1G.2M||Q.1s&&Q.1s.22||Q.1S.22||0;1p(4(){1G.1V(a,b)},0);5.25();F w.J&&!!g});3(w.J){$.1f.2K(4(){j.9(w.K).N(\'1b\').1n()})}})};2 y=[\'2e\',\'1E\',\'28\'];29(2 i=0;i<y.1K;i++){$.1P[y[i]]=(4(d){F 4(c){F 5.Y(4(){2 b=$(\'13.z-1M\',5);b=b.V()&&b||$(\'>13:9(0)\',5);2 a;3(!c||O c==\'1Z\'){a=$(\'A a\',b).9((c&&c>0&&c-1||0))}E 3(O c==\'2J\'){a=$(\'A a[@1O$="#\'+c+\'"]\',b)}a.N(d)})}})(y[i])}$.1P.2I=4(){2 c=[];5.Y(4(){2 a=$(\'13.z-1M\',5);a=a.V()&&a||$(\'>13:9(0)\',5);2 b=$(\'A\',a);c.2H(b.20(b.1a(\'.z-2b\')[0])+1)});F c[0]}})(2G);',62,197,'||var|if|function|this|||browser|eq||||||||||||||||||||||||||tabs|li|hash|null|toShow|else|return|height|selectedClass|addClass|bookmarkable|initial|css||trigger|typeof|is|document|toHide|id|false|msie|size|opacity|span|each|style|div|hideAnim|disabled|ul|disabledClass|attr|containerClass|removeClass|remote|bind|filter|click|onShow|onHide|location|ajaxHistory|parents|min|locked|navClass|minHeight|fxShow|fxFade|end|animate|setTimeout|hideClass|spinner|documentElement|get|fxSlide|offsetHeight|unFocus|fxSpeed|safari|replace|jq|loadRemoteTab|show|msie6|disableTab|fxHide|window|hide|switchTab|innerHTML|length|loadingClass|nav|update|href|fn|hideSpeed|showSpeed|body|display|offsetWidth|scrollTo|px|behaviour|version|number|index|hashPrefix|scrollTop|scrollLeft|em|blur|container|tabTitle|enableTab|for|submit|selected|appendTo|form|triggerTab|url|width|true|onClick|tabStruct|remoteCount|extend|fxAutoHeight|block|font|fxHideSpeed|watch|fxShowSpeed|1px|setExpression|normal|sort|userAgent|navigator|test|removeExpression|MSIE|map|not|500|opera|tab|jQuery|push|activeTab|string|initialize|loading|pageYOffset|pageXOffset|such|no|8230|There|alert|load|siblings|overflow|visible|Loading|object|clientX|value|type|input|action|class|50|setInterval|hidden|visibility|absolute|position'.split('|'),0,{}));

/*
 * Copyright (c) 2007 Josh Bush (digitalbush.com)
 * 
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use,
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following
 * conditions:

 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE. 
 */
 
/*
 * Version: Beta 1
 * Release: 2007-06-01
 */ 
(function($) {
	var map=new Array();
	$.Watermark = {
		ShowAll:function(){
			for (var i=0;i<map.length;i++){
				if(map[i].obj.val()==""){
					map[i].obj.val(map[i].text);					
					map[i].obj.css("color",map[i].WatermarkColor);
				}else{
				    map[i].obj.css("color",map[i].DefaultColor);
				}
			}
		},
		HideAll:function(){
			for (var i=0;i<map.length;i++){
				if(map[i].obj.val()==map[i].text)
					map[i].obj.val("");					
			}
		}
	}
	
	$.fn.Watermark = function(text,color) {
		if(!color)
			color="#aaa";
		return this.each(
			function(){		
				var input=$(this);
				var defaultColor=input.css("color");
				map[map.length]={text:text,obj:input,DefaultColor:defaultColor,WatermarkColor:color};
				function clearMessage(){
					if(input.val()==text)
						input.val("");
					input.css("color",defaultColor);
				}

				function insertMessage(){
					if(input.val().length==0 || input.val()==text){
						input.val(text);
						input.css("color",color);	
					}else
						input.css("color",defaultColor);				
				}

				input.focus(clearMessage);
				input.blur(insertMessage);								
				input.change(insertMessage);
				
				insertMessage();
			}
		);
	};
})(jQuery);

var replyCollection = {
	view: 3,
	replies: new Array(),
	append: function(id) {
		var rid = id.match(new RegExp('\\d+$'));
		this.replies[rid] = new Reply(document.getElementById(id));
	},
	get: function(id) {
		return this.replies[id];
	},
	expandAll: function(mode) {
		this.view = (mode == 'expand' ? 6 : 1);
		for(var key in this.replies)
		{
			this.expand(key,mode);
		}
	},
	expandChecked: function(mode,recursive) {
		this.view = (mode == 'expand' ? 6 : 1);
		var e = document.showReply.elements;
		for(var i=0;i<e.length;i++)
		{
			if (e.item(i).checked)
			{
				this.expand(e.item(i).value,mode,recursive);
			}
		}
	},
	expand: function(id,mode,recursive) {
		this.replies[id].expand(mode,recursive);
	},
	increaseView: function() {
		if(this.view > 1)
			this.view--;
		this.refreshView();
	},
	decreaseView: function() {
		if(this.view < 6)
			this.view++;
		this.refreshView();
	},
	refreshView: function() {
		var a = new Array();
		var e = document.showReply.elements;
		var fm = false;

		for(var i=0;i<e.length;i++)
		{
			if (!fm) {a.push(e.item(i).value);}
			if (e.item(i).checked)
			{
				if (!fm)
				{
					a = new Array();
					fm = true;
				}
				a.push(e.item(i).value);
			}
		}
		
		for(var i=0;i<e.length;i++) {this.replies[a[i]].setView(this.view);}
	}
};

function Reply(obj) {
	//settery a hlavni iniciacni funkce
	this.initId = function() {this.setCnt('id',this.myself.id.match(new RegExp('\\d+$')));}
	this.initLvl = function() {this.setCnt('lvl',this.myself.className.match(new RegExp('lvl-([\\d]+)'))[1]);}
	//inicializuje "div class=packer"
	this.initPacker = function() {
		if (this.getObj('packer')) {
			this.setObj(this.getObj('packer').getElementsByTagName('a').item(0),'expander');
			this.setObj(this.getObj('packer').getElementsByTagName('input').item(0),'checker');
		}
	}
	// inicializuje "div class=title"
	this.initTitle = function() {
		if (this.getObj('title')) {
			this.setCnt('subject',this.getObj('title').getElementsByTagName('h3').item(0).innerHTML);
			this.setObj(this.getObj('title').getElementsByTagName('span')[1],'thankYou');
		}
	}
	// inicializuje "div class=cnt"
	this.initCnt = function() {
		if (this.getObj('cnt')) {
			this.setObj(this.getObj('cnt').getElementsByTagName('p').item(0),'msg');
			this.setCnt('msg',this.getObj('msg').innerHTML);
		}
	}	
	// nastavi, nebo prepise objekt odpovedi
	this.setObj = function(object,defName) {
		//inicializace promennych
		var name = null;
		//definuju jmeno objektu v poli
		if (defName) 					name = defName;
		else if (object.id) 			name = object.id;
		else if (object.className)	name = object.className
		//objektu, ktere nemaji id ani jmeno si nevsimam
		if (name)						this.objects[name] = object;
	}
	// nastavy novy, nebo prepise stary obsah odpovedi
	this.setCnt = function(param,value) {
		this.contents[param] = value;
	}
	// ziska objekt odpovedi
	this.getObj = function(objName) {
		if (this.objects[objName]) {
			return this.objects[objName];
		} else {
			return false;
		}
	}
	// ziska obsah odpovedi
	this.getCnt = function(cntName) {
		if (this.contents[cntName]) {
			return this.contents[cntName];
		} else {
			return false;
		}
	}
	//pak se definuji funkce, ktere pracuji nad prispevky
	this.getId = function() {
		return this.getCnt('id');
	}
	//ziska predmet zpravy
	this.getSubject = function() {
		return this.getCnt('subject');
	}
	//nastavi pocet podekovani
	this.setThanks = function(count) {
		this.getObj('thankYou').style.visibility = count > 0 ? 'visible' : 'hidden';
		this.getObj('thankYou').innerHTML = this.getObj('thankYou').innerHTML.replace(new RegExp('\\d+$'),count);
	}
	
	//nastavi text prispevku v urcitem rezimu
	this.setTextNormal = function() {this.getObj('msg').innerHTML = this.getCnt('msg');}
	this.setTextPreview = function() {this.getObj('msg').innerHTML = this.getCnt('msg').length > 50 ? this.getCnt('msg').substr(0,47) + '&hellip;' : this.getCnt('msg')}
	//nastavi plusy a minusy
	this.setPlus = function() {this.getObj('expander').style.backgroundPosition = '0 0';}
	this.setMinus = function() {this.getObj('expander').style.backgroundPosition = '0 -10px';}
	//prace s obsahem prispevku	
	this.hideCnt = function() {this.getObj('cnt').style.display = 'none';}
	this.showCnt = function() {this.getObj('cnt').style.display = 'block';}
	//prace s odpovedmi
	this.hideReplies = function() {for(var i=0;i<this.getObj('replies').length;i++) this.getObj('replies')[i].style.display = 'none';}
	this.showReplies = function() {for(var i=0;i<this.getObj('replies').length;i++) this.getObj('replies')[i].style.display = 'block';}
	//nastavi mod zobrazeni
	this.setView = function(view) {
		switch(view)
		{
			case 1:
				this.setTextNormal();
				this.setMinus();
				this.showCnt();
				this.showReplies();
			break;
			case 2:
				if (this.getCnt('lvl') == 0)
					this.setTextNormal();
				else this.setTextPreview();
				this.setMinus();
				this.showCnt();
				this.showReplies();
			break;
			case 3:
				if (this.getCnt('lvl') == 0) {
					this.setMinus();
					this.showCnt();
					this.showReplies();
				} else {
					this.setPlus();
					this.hideCnt();
					this.hideReplies();
				}
				this.setTextNormal();
			break;
			case 4:
				if (this.getCnt('lvl') == 0) {
					this.setMinus();
					this.showCnt();
					this.showReplies();
				} else {
					this.setPlus();
					this.hideCnt();
					this.hideReplies();
				}
				this.setTextPreview();
			break;
			case 5:
				if (this.getCnt('lvl') == 0) {
					this.showReplies();
				} else {
					this.hideReplies();
				}
				this.setPlus();
				this.hideCnt();
			break;
			case 6:
				this.setPlus();
				this.hideCnt();
				this.hideReplies();
			break;
		}

		for(var i=0;i<this.getObj('replies').length;i++)
			replyCollection.get(this.getObj('replies')[i].id.match(new RegExp('\\d+$'))).setView(view);
	}
	//rozbalit prispevky
	this.expand = function(mode,recursive) {
		if ((this.getObj('cnt').style.display == 'block' && !mode) || mode == 'contract') {
			this.setPlus();
			this.hideCnt();
			this.hideReplies();
		} else if ((this.getObj('cnt').style.display == 'none' && !mode) || mode == 'expand') {
			this.setMinus();
			this.showCnt();
			this.setTextNormal();
			this.showReplies();
		}
		
		if (recursive)
			for(var i=0;i<this.getObj('replies').length;i++)
				replyCollection.get(this.getObj('replies')[i].id.match(new RegExp('\\d+$'))).expand(mode,recursive);
	}
	
	//zakladni objekty
	this.myself = obj;
	this.objects = new Array();
	//pole, kde se uklada veskery obsah
	this.contents = new Array();
	//inicializace zakladnich parametru
	this.objects['replies'] = new Array();		
	//selfScan -> nacte vsechny korenove classy
	var d = this.myself.children;
	for(var i=0;i<d.length;i++)
	{
		if (d.item(i).className.match(new RegExp('reply')))
		{
			this.getObj('replies').push(d.item(i));
		}
		else
		{
			this.setObj(d.item(i));
		}
	}
	//
	this.initId();
	this.initLvl();
	this.initPacker();
	this.initTitle();
	this.initCnt();
}

function setReply(r)
{
	var f = document.getElementById('post-reply');
	var e = f.elements;

	for(var i=0;i<e.length;i++)
	{
		if (e.item(i).name == 'id_parent') {
			e.item(i).value = r.getId();
		} else if (e.item(i).name == 'subject') {
			e.item(i).value = 'RE: ' + r.getSubject();
			e.item(i).setAttribute('readOnly','readonly');
		} else if (e.item(i).type == 'reset') {
			e.item(i).style.visibility = 'visible';
		}
	}
}

function clearReply()
{
	var f = document.getElementById('post-reply');
	var e = f.elements;

	for(var i=0;i<e.length;i++)
	{
		if (e.item(i).name == 'id_parent') {
			e.item(i).value = 0;
		} else if (e.item(i).name == 'subject') {
			e.item(i).value = '';
			e.item(i).removeAttribute('readOnly');
		} else if (e.item(i).type == 'reset') {
			e.item(i).style.visibility = 'hidden';
		}
	}
}

/**
 * Zobrazi okno pro nahlaseni prispevku v diskusich
 */
function showReportReplyForm(e,h,reply)
{
    	var frm = '<div class="std-form">\n\
	    <form method="post" name="BubbleForm" onsubmit="(function() {\n\
								var cptcha = document.forms[\'BubbleForm\'].elements[\'BubbleCaptcha\'].value;\n\
								reportReply(' + reply + ',\'\' + cptcha + \'\');\n\
							    })(); return false;">\n\
		<div class="mandatory">\n\
		    <p style="margin-bottom:5px;">Myslíte si, že příspěvek je nevhodný a do této diskuse nepatří? Pošlete informaci správci diskusí Ordinace.cz.</p>\n\
		    <fieldset><legend style="font-size:145%;">Opište kód a stiskněte enter</legend>\n\
			<input style="margin-bottom:10px;float:left;" type="text" name="BubbleCaptcha" value="" />\n\
			<a href="javascript:void(0);" title="Kliknutím získáte nový kontrolní obrázek"><img onclick="changeCaptcha(event,\'BubbleCaptcha\');" src="/img/captcha.png?session=BubbleCaptcha" id="captcha" alt="Captcha" /></a>\n\
		    </fieldset>\n\
		</div>\n\
		<div class="cistic"></div>\n\
	    </form>\n\
	</div>';

	h . setHeader('Nahlásit příspěvek');
	h . setContent(frm);
	return h . display(e,null,'click');
}

/**
 * Vymeni obrazek captcha (event se predpoklada kliknuti na obrazek captcha)
 * @param event
 */
function changeCaptcha(e,session)
{
	var self = e . currentTarget;

	if (!self || self == 'undefined') {
	    self = e . srcElement;
	}

	self.src='/img/captcha.png?' + Math.random() + (session && session != '' && session != 'undefined' ? '&session=' + session : '');
	
	return true;
}

/*
* Ziska absolutni pozici objektu na strance
*
* @param event
*/

function getPosition(e) { 
	var curtop = 0, curleft = 0; 
	var tgt = e.currentTarget; 

	if (!tgt || tgt == "undefined") { 
		tgt = e.srcElement; 
	} 

	while(tgt!= document.body && !(tgt===null)) { 
		curtop += tgt.offsetTop; 
		curleft += tgt.offsetLeft; 
		tgt = tgt.offsetParent; 
	}

  return {x: curleft, y: curtop}
}

/*
* Ziska vnitrni velikost okna
*
* http://www.howtocreate.co.uk/tutorials/javascript/browserwindow
*/

function getWindowXY() {
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}

	return {x: myWidth,y: myHeight};
}

/*
* Ziska vzdalenost scrollu
*
* http://www.howtocreate.co.uk/tutorials/javascript/browserwindow
*/

function getScrollXY() {
	var scrOfX = 0, scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
		//Netscape compliant
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		//DOM compliant
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	}

	return {x: scrOfX,y: scrOfY};
}

/*
* Tooltip funkce.
*/

var BubbleTooltip = (function(){

    function _class() {

	// nastaveni zobrazeni tooltipu
	// zatim v podstate k nicemu :)
	var e;
	var scheme;
	// automaticka nastaveni
	var quadrant;
	// ziskani objektu tooltipu
	var header;
	var content;
	var footer;
	var arrow;
	var container;
	var errMsg;
	var succMsg;
	//obcas nam ukazatel 'this' nestaci...
	var _self = this;

	this . setDefaults = function () {
	    this . e = null;
	    this . scheme = 'default';
	    this . quadrant = 1;
	    this . header = document.getElementById('tooltip-t');
	    this . content = document.getElementById('tooltip-m');
	    this . footer = document.getElementById('tooltip-b');
	    this . arrow  = document.getElementById('tooltip-arrow');
	    this . container = document.getElementById('bubble_tooltip');
	    this . errMsg = new Array();
	    this . succMsg = new Array();
	};
	
	// settery
	this . setScheme = function(s) {this.scheme = s ? s : 'default';};
	this . setHeader = function(h) {this.header.innerHTML = '<h4>' + h + '</h4>';};
	this . setContent = function(c) {this.content.innerHTML = c;};
	this . setFooter = function(f) {this.footer.innerHTML = f;};
	this . assignTimeout = function(t) {this.timeout = t;};

	this . guessQuadrant = function() {
		var o = this.e.target ? this.e.target : this.e.srcElement;
		var p = getPosition(this.e);
		var scrollXY = getScrollXY(); 
		var windowXY = getWindowXY();
		
		if (p.x - scrollXY.x + o.offsetWidth + this.getQuadrantSize(1).x < windowXY.x && p.y - scrollXY.y - this.getQuadrantSize(1).y > 0) {
			this.quadrant = 1;
		} else if (p.x - scrollXY.x - this.getQuadrantSize(2).x > 0 && p.y - scrollXY.y - this.getQuadrantSize(2).y > 0) {
			this.quadrant = 2;
		} else if (p.x - scrollXY.x + o.offsetWidth + this.getQuadrantSize(3).x < windowXY.x && p.y - scrollXY.y + this.getQuadrantSize(3).y < windowXY.y) {
			this.quadrant = 3;
		} else if (p.x - scrollXY.x - this.getQuadrantSize(4).x > 0 && p.y - scrollXY.y + this.getQuadrantSize(4).y < windowXY.y) {
			this.quadrant = 4;
		} else if (p.x - scrollXY.x + o.offsetWidth + this.getQuadrantSize(5).x < windowXY.x) {
			this.quadrant = 5;
		} else {
			this.quadrant = 6;
		}
	};
	
	this . getQuadrantSize = function(q) {
		var c = this.container;		
		switch(q) {
			case 1:
			case 2:
			case 3:
			case 4:return {x: c.offsetWidth, y: c.offsetHeight + this.getArrowSize(q).y};reak;
			default:return {x: c.offsetWidth + this.getArrowSize(q).x, y: c.offsetHeight};reak;
		}
	};
	
	this . getArrowSize = function(q) {
		switch(q) {
			case 1:
			case 2:
			case 3:
			case 4:return {x: 25, y: 20};reak;
			default:return {x: 9, y: 35};reak;
		}
	};
	
	this . setupArrow = function() {
		var as = this.arrow.style;	
	
		as.width = (this.getArrowSize(this.quadrant).x) + 'px';
		as.height = (this.getArrowSize(this.quadrant).y) + 'px';

		switch(this.quadrant) {
			case 1:
				as.left = '9px';
				as.top = (this.container.offsetHeight - 5) + 'px';
				as.backgroundPosition = '-40px -100px';
			break;
			case 2:
				as.right = '9px';
				as.top = (this.container.offsetHeight - 5) + 'px';
				as.backgroundPosition = '-140px -100px';
			break;
			case 3:
				as.left = '9px';
				as.top = (-(1 + this.getArrowSize(this.quadrant).y) + 5) + 'px';
				as.backgroundPosition = '-180px -100px';
			break;
			case 4:
			
			break;
		}
	};
	
	this . recalcPosition = function() {
		var c = this.container;
		var o = this.e.target ? this.e.target : this.e.srcElement;
		var p = getPosition(this.e);	

		switch(this.quadrant) {
			case 1:
				c.style.top = (p.y - c.offsetHeight - (this.arrow.offsetHeight - 9)) + 'px';
				c.style.left = (p.x + o.offsetWidth - 15) + 'px';
			break;
			case 2:
				c.style.top = (p.y - c.offsetHeight - (this.arrow.offsetHeight - 9)) + 'px';
				c.style.left = (p.x - o.offsetWidth + 15) + 'px';
			break;
			case 3:
				c.style.top = (p.y + o.offsetHeight + (this.arrow.offsetHeight - 12)) + 'px';
				c.style.left = (p.x + o.offsetWidth - 15) + 'px';
			break;
			case 4:
			
			break;
			case 5:
				var offset = getScrollXY().y;
				if (offset + c.offsetHeight < p.y)
					offset = p.y - c.offsetHeight + this.arrow.offsetHeight + 9;
								
				c.style.top = (offset) + 'px';
				c.style.left = (p.x + o.offsetWidth + (this.arrow.offsetWidth) - 11) + 'px';

				this.arrow.style.left = '-16px';
				if (c.offsetHeight / 2 < p.y - offset) {
					this.arrow.style.top = (p.y - offset - 29) + 'px';
					this.arrow.style.backgroundPosition = '-225px -100px';
				} else {
					this.arrow.style.top = (p.y - offset) + 'px';
					this.arrow.style.backgroundPosition = '-80px -100px';
				}
			break;
			case 6:

			break;
		}
	};

	this . setPosition = function() {
		var c = this . container;
		var avail = getWindowXY();
		var offset = getScrollXY();

		c.style.left = offset.x + ((avail.x - c.offsetWidth - 100) / 2) + "px";
		c.style.top = offset.y + ((avail.y - c.offsetHeight) / 2) + "px";
	};
	
	this . applyScheme = function() {
		this.container.className = 'bubble_' + this.scheme;
	};

	this . enableArrow = function() {
		this.arrow.style.display = 'block';
	};

	this . disableArrow = function() {
		this.arrow.style.display = 'none';
	};

	this . addError = function(m) {
		this . errMsg . push(m);
	};

	this . addSuccess = function(m) {
		this . succMsg . push(m);
	};

	this . buildMessages = function() {
		var msg = '';
		var html = '';

		// vypis chybovych hlaseni
		if (this . errMsg . length > 0) {
		    html = '<ul class="list">';
		    for (msg in this . errMsg) {html += '<li>' + this . errMsg[msg] + '</li>';}
		    html += '</ul>';
		}
		// vypis oznameni o uspesnem provedeni
		if (this . succMsg . length > 0) {
		    html = '<ul class="list-green">';
		    for (msg in this . succMsg) {html += '<li>' + this . succMsg[msg] + '</li>';}
		    html += '</ul>';
		}

		this . setContent(html);
	};

	this . displayMessages = function (e,s,cond,t) {

		this . buildMessages();
		this . setHeader('Oznámení - kliknutím zavřete');

		this . errMsg = new Array;
		this . succMsg = new Array();
		
		this . display(e,s,cond,t);
	};

	this . display = function(e,s,cond,t) {
		this.e = e;
		this.setScheme(s != null ? s : 'default');
		//this.setFooter(f);

		if (e != null) {
		    this.enableArrow();
		    this.guessQuadrant();
		    this.setupArrow();
		    this.recalcPosition();
		} else {
		    this.disableArrow();
		    this.setPosition();
		}

		this.applyScheme();
		this.container.style.visibility = 'visible';

		switch (cond) {
		    case 'timeout':
			this.startClock(t);
		    case 'click':
			this.header.onclick = function() {_self . hide();return false;};
		    break;
		    default:
			this.e.currentTarget.onmouseout = function() {_self . hide();return false;};
		    break;
		}
	};

	this . startClock = function(t) {
	    t = parseInt(t);

	    if (t <= 0) {
		_self . hide();
	    } else {
		setTimeout(_self . startClock,1000,[--t]);
	    }
	};
	
	this . hide = function() {
	    this.container.style.visibility = 'hidden';
	};

    };

    return _class;

})();

bubbleTooltip = new BubbleTooltip();
bubbleTooltip . setDefaults();

