function mainmenu(){
$("#menu ul ul").css({display: "none"}); // Opera Fix
$("#menu ul li").hover(function(){
		var w=$("#menu").position().left+$("#menu").width()-$(this).position().left;
		$(this).find('ul:first').width(w).fadeIn(400);
		},function(){
		$(this).find('ul:first').hide();
		});
};

$(document).ready(function(){
	mainmenu();
});

function SendLogin()
{
	if (document.loginform.name.value&&document.loginform.pass.value) {document.loginform.act.value="login"; document.loginform.submit();}
	else alert("Vyplňte prosím jméno a heslo.");
};

function SaveArticle()
{
	document.artform.act.value="save"; document.artform.submit();
};

function SaveArticleAs()
{
	newfile=prompt("Uložit jako:",document.artform.file.value);
	if (newfile!=null) {
    newfolder=prompt("Uložit do složky:",document.artform.folder.value);
  	if (newfolder!=null) {
      document.artform.file.value=newfile;
      document.artform.folder.value=newfolder;
      document.artform.act.value="save";
      document.artform.submit();
    };
  };

};

function Reply(booknr,postnr)
{
  document.forms["bookform"+booknr].act.value="new_post";
  document.forms["bookform"+booknr].chpost.value=postnr; 
  document.forms["bookform"+booknr].submitbutton.value="Odeslat odpověď";
  document.forms["bookform"+booknr].postheader.value="Re: "+document.getElementById("hd"+booknr+"_"+postnr).innerHTML; //getelement
	document.forms["bookform"+booknr]["posttext"+booknr].value="";
  if (typeof tinyMCE!="undefined") {
    var id=tinyMCE.getEditorId("posttext"+booknr);
    tinyMCE.getInstanceById(id).setHTML("");
  };
  return false;
};

function ReplyCite(booknr,postnr)
{
  document.forms["bookform"+booknr].act.value="new_post"; 
  document.forms["bookform"+booknr].chpost.value=postnr; 
  document.forms["bookform"+booknr].submitbutton.value="Odeslat odpověď";
  document.forms["bookform"+booknr].postheader.value="Re: "+document.getElementById("hd"+booknr+"_"+postnr).innerHTML; //getelement
  document.forms["bookform"+booknr]["posttext"+booknr].value=document.getElementById("ps"+booknr+"_"+postnr).innerHTML;
  if (typeof tinyMCE!="undefined") {
    var id=tinyMCE.getEditorId("posttext"+booknr);
    tinyMCE.getInstanceById(id).setHTML(document.getElementById("ps"+booknr+"_"+postnr).innerHTML);
  };
  return false;
};

function EditPost(booknr,postnr)
{
  document.forms["bookform"+booknr].act.value="edit_post";
  document.forms["bookform"+booknr].chpost.value=postnr;
  document.forms["bookform"+booknr].submitbutton.value="Odeslat upravený příspěvek";
  document.forms["bookform"+booknr].postheader.value=document.getElementById("hd"+booknr+"_"+postnr).innerHTML;
  document.forms["bookform"+booknr]["posttext"+booknr].value=document.getElementById("ps"+booknr+"_"+postnr).innerHTML;
  if (typeof tinyMCE!="undefined") {
    var id=tinyMCE.getEditorId("posttext"+booknr);
    tinyMCE.getInstanceById(id).setHTML(document.getElementById("ps"+booknr+"_"+postnr).innerHTML);
  };
  return false;
};

function NewPost(booknr)
{
  document.forms["bookform"+booknr].act.value="new_post";
  document.forms["bookform"+booknr].chpost.value="";
  document.forms["bookform"+booknr].submitbutton.value="Odeslat příspěvek";
  document.forms["bookform"+booknr].postheader.value="";
  document.forms["bookform"+booknr]["posttext"+booknr].value="";
  if (typeof tinyMCE!="undefined") {
    var id=tinyMCE.getEditorId("posttext"+booknr);
    tinyMCE.getInstanceById(id).setHTML("");
  };
  return false;
};

function SendMessage(booknr,name)
{
  document.forms["bookform"+booknr].act.value="send_message";
  document.forms["bookform"+booknr].chpost.value=name;
  document.forms["bookform"+booknr].submitbutton.value="Odeslat soukromou zprávu uživateli "+name;
  document.forms["bookform"+booknr].postheader.value="";
  document.forms["bookform"+booknr]["posttext"+booknr].value="";
  if (typeof tinyMCE!="undefined") {
    var id=tinyMCE.getEditorId("posttext"+booknr);
    tinyMCE.getInstanceById(id).setHTML("");
  };
  return false;
};

function HidePost(booknr,postnr)
{
  if (confirm("Opravdu skrýt tento příspěvek?")) {
    document.forms["bookform"+booknr].act.value="hide_post"; 
    document.forms["bookform"+booknr].chpost.value=postnr; 
    document.forms["bookform"+booknr].submit();
  };
  return false;
};

function UnhidePost(booknr,postnr)
{
  if (confirm("Opravdu odkrýt tento příspěvek?")) {
    document.forms["bookform"+booknr].act.value="unhide_post"; 
    document.forms["bookform"+booknr].chpost.value=postnr; 
    document.forms["bookform"+booknr].submit();
  };
  return false;
};

function DelPost(booknr,postnr)
{
  if (confirm("Opravdu navždy smazat tento příspěvek?")) {
    document.forms["bookform"+booknr].act.value="del_post"; 
    document.forms["bookform"+booknr].chpost.value=postnr; 
    document.forms["bookform"+booknr].submit();
  };
  return false;
};

function SendBook(booknr)
{
  if (document.forms["bookform"+booknr].act.value=="no") {
    document.forms["bookform"+booknr].act.value="new_post";
    document.forms["bookform"+booknr].chpost.value="";
  };
  var textOK=false;
  if (typeof tinyMCE!="undefined") {
    var id=tinyMCE.getEditorId("posttext"+booknr);
    textOK=tinyMCE.getInstanceById(id).getHTML();
  } else {textOK=document.forms["bookform"+booknr]["posttext"+booknr].value};
  if (document.forms["bookform"+booknr].postheader.value&&textOK) {
	  document.forms["bookform"+booknr]["posttext"+booknr].name="posttext";
    document.forms["bookform"+booknr].submit();
  } else alert("Vyplňte prosím nadpis a text.");
  return false;
};

function SubscrBook(booknr)
{
  document.forms["bookform"+booknr].act.value="subscribe"; 
  document.forms["bookform"+booknr].submit();
  return false;
};

function NewBook(folder)
{
	newfile=prompt("Nová diskuse:","");
	if (newfile!=null) {
    window.location.href="?"+folder+"="+newfile+".book";
  };
  return false;
};

function SubmitUser(actn)
{
	if ((actn!='del_user')||(confirm('Opravdu smazat uživatelský účet?'))) {
		document.userform.act.value=actn;
		document.userform.ch_name.disabled=false;
		document.userform.submit();
	};
	return false;
};

function DelUser(name)
{
	ret=(confirm('Opravdu smazat účet uživatele '+name+'?'));
	return ret;
};

function loadFile(obj) {
  movieName="mpl";
  if(navigator.appName.indexOf("Microsoft") != -1) {
    window[movieName].loadFile({file:obj});
    window[movieName].sendEvent("playpause");
  } else {
    document[movieName].loadFile({file:obj});
    document[movieName].sendEvent("playpause");
  }
};

var prev_pict='none';
var next_pict='none';
var gallery=0;
var closeOK='yes';
var winH=0;
var winW=0;
var noScroll=((navigator.appName.indexOf("Microsoft")!=-1)&&(navigator.appVersion.indexOf("MSIE 7")==-1)&&(navigator.appVersion.indexOf("MSIE 8")==-1));


function ShowImage(gal,pict) {
  winH=$(window).height();
  winW=$(window).width();
  gallery=gal;
  id='#img'+gal+'_'+pict;
  if ($(id)!=null) {
    prev_pict='none';
    next_pict='none';
    HideNav();
    $('#lightbox').css("display","none");
    $('#overlay').css("display","block");
    $('#overlay').css("width",winW);
    $('#overlay').css("height",winH);
    $('#lightboxCaption').html($(id).attr('title'));
    $('#lightboxImage').css("width","auto");
    $('#lightboxImage').css("height","auto");
    prev_pict=pict-1;
    if ((gal==0)||($('#img'+gal+'_'+prev_pict))==null) {prev_pict='none';};
    next_pict=pict+1;
    if ((gal==0)||($('#img'+gal+'_'+next_pict))==null) {next_pict='none';};
  	if(navigator.appName.indexOf("Microsoft") != -1) {
  		var re=/%3A/g;
  		$('#lightboxImage').attr('src',escape(unescape($(id).attr('href'))).replace(re,':'));
  	} else {
  		$('#lightboxImage').attr('src',$(id).attr('href'));
  	};
  };
  return false;
};

function ShowPrev() {
  closeOK='no';
  ShowImage(gallery,prev_pict);
};

function ShowNext() {
  closeOK='no';
  ShowImage(gallery,next_pict);
};

function ShowNav() {
  $('#prevLink').css("display",prev_pict=='none'?"none":"block");
  $('#nextLink').css("display",next_pict=='none'?"none":"block");
};

function HideNav() {
  $('#prevLink').css("display","none");
  $('#nextLink').css("display","none");
};

function ImageLoaded() {
  if ($('#overlay').css("display")=="block") {
	  $('#lightbox').css("display","block");
	  $('#lightbox').css("visibility","hidden");
	  pictH=$('#lightboxImage').height();
	  pictW=$('#lightboxImage').width();
	  r=Math.max(pictH/(winH-50),pictW/(winW-30));
	  if ((r>1)&&(pictW!=0)&&(pictH!=0)) {
		pictH=Math.round(pictH/r);
		pictW=Math.round(pictW/r);
	  };
	  $('#lightboxImage').css("width",pictW);
	  $('#lightboxImage').css("height",pictH);
	  posH=Math.round((winH-50-pictH)/2+5);
	  posW=Math.round((winW-30-pictW)/2+5);
	  if(noScroll) {
		  posW=posW+($(window).scrollLeft());
		  posH=posH+($(window).scrollTop());
	  };
	  $('#lightbox').css("top",posH);
	  $('#lightbox').css("left",posW);
	  $('#lightbox').css("visibility","visible");
  };
  return false;
};

function CloseImage() {
  if (closeOK=='yes') {
    HideNav();
    $('#overlay').hide();
    $('#lightbox').hide();
  } else {closeOK='yes';};
};

