function imageSwitch(id)
{
  var obj = document.getElementById(id);
  var source = obj.src;
  var pieces = source.split("_");
  var act = pieces[pieces.length - 1].split(".jpg");
  
  act = parseInt(act);
  
  if(act == 5)
    act = 1;
  else
    act++;

  obj.src = pieces[0]+"_"+pieces[1]+"_"+act+".jpg";
  
  imgho = window.setTimeout('imageSwitch("' + id + '");', 1000);
}

function tryMe(obj)
{
  alert(obj);
}

function turnOffSwitching(obj, start)
{
  clearTimeout(imgho);
  var source = obj.src;
  var pieces = source.split("_");
  
  obj.src = pieces[0]+"_"+pieces[1]+"_"+start+".jpg";
}

function controlForm(frm)
{
  if(frm.videofile.value == "") { alert("Nahrajte Soubor"); return false; }
  if(frm.nazev.value == "") { alert("Vyplňte Název"); return false; }
  if(frm.popis.value == "") { alert("Vyplňte Popis"); return false; }
  if(frm.keywords.value == "") { alert("Vyplňte Klíčová slova"); return false; }

  return true;
}
function flashUp(file, original)
{
  document.getElementById("videofile").value = file;
  document.getElementById("originalfile").value = original;
}
function controlPhotoForm(frm)
{
	metoda = "exist";
	if(frm.metoda[1].checked == true)
		metoda = "new";

	if(frm.imagefiles.value == "") { alert("Vyberte fotky"); return false; }
	if(metoda == "new")
	{
		if(frm.nazev.value == "") { alert("Vyplňte Název"); return false; }
		if(frm.popis.value == "") { alert("Vyplňte Popis"); return false; }
		if(frm.keywords.value == "") { alert("Vyplňte Klíčová slova"); return false; }
	}
	
  startUploading();
  frm.submitbtn.disabled = "disabled";
  return false;
}
function selectedPhotos(files, originals)
{
	document.getElementById("imagefiles").value = files;
  document.getElementById("originalfiles").value = originals;
}
function getObj(objName)
{
	var isIE = navigator.appName.indexOf("Microsoft") != -1;
	return (isIE) ? window[objName] : document[objName];
}
function startUploading()
{
	getObj("single").letsGo();
}

function odebirat(obj, id)
{
  $.get("./engine/ajax/ajax.subscribe.php", { 'id': id },
  
  function(data)
  {
    if(data == "0")
      obj.innerHTML = "Odebírat obsah uživatele";
    else if(data == "1")
      obj.innerHTML = "Zrušit odběr uživatele";
    else
      alert(data);
  });
}

function rate(id, rate, type)
{
  $.get("./engine/ajax/ajax.vote.php", { 'id': id, 'rate': rate, 'type': type },
  
  function(data)
  {
    if(data == "404")
      alert("Hlasovat můžete jednou za 24 hodin");
    else
    {
			$("#rating").removeClass();
			$("#rating").addClass("rating rate"+data);
    }
  });
}

function albumMethod(obj)
{
	document.getElementById(obj.value + "album").style.display = "block";
	if(obj.value == "exist")
	{
		document.getElementById("newalbum").style.display = "none";
	}
	else
	{
		document.getElementById("existalbum").style.display = "none";
	}
}

function newAlbum(selectbox, overall)
{
	var val = selectbox[selectbox.selectedIndex].value;
	
	if(val == "0")
	{
		var name = prompt("Zadejte název nového alba", "");
		
		if(name != "")
		{
			$.get("engine/ajax/ajax.newalbum.php", { 'check': name },
      function(data){
				if(data == "0")
				{
					alert("Nejsi přihlášen");
				}
				else
				{
					name = data;
				}
      } );
      $.get("engine/ajax/ajax.newalbum.php", { 'add': name },
      function(data){
				if(data == "0")
				{
					alert("Nejsi přihlášen");
				}
				else
				{
					var selects = document.getElementById("overallphotos").getElementsByTagName("select");
					for(i = 0; i < selects.length; i++)
					{
						var item = selects[i].getElementsByTagName("option");
						item = item.length;
						selects[i].options[item - 1] = new Option(name, data);
						selects[i].options[item] = new Option("Vytvořit nové album", "0");
					}
				}
      } );
		}
	}
}

function nextPage(cpage)
{
	var nextPage = document.paging.p.value;
	
	if(cpage == nextPage)
		return true;
	else
		document.paging.submit();
	return false;
}

function setDefPict(no)
{
	document.getElementById("defpict").value = no;
      
	for(i = 1; i <= 5; i++)
	{
		if(i == no){
			document.getElementById("defpict" + i).className = "active";
		}else{
			document.getElementById("defpict" + i).className = "";
		}
	}
}

function keeploged()
{
	var nahoda = Math.random() * Math.random() * 2 * Math.random();
	$.get("engine/ajax/ajax.keeploged.php", { 'nahoda' : nahoda },
				function(data){ }
				);
}

var postacheck = false;

$(document).ready(function()
  {
    $('div.box-toggle:eq(0)> div.pad').hide();
    $('div.box-toggle:eq(0)> div.open').show();
    $('div.box-toggle:eq(0)> h2').click(function()
    {
      $(this).next().slideToggle('slow');
    });
  });
$(document).ready(function(){

	if(postacheck == true)
	{
		var obj = document.getElementById("postabohusu");
		var vys = obj.innerHTML.replace("abcdegh", "@");
		obj.innerHTML = vys;
	}

  $("div.box-toggle h2").click(function() {
    $(this).toggleClass("active");
  });

});

function checkFrame(uri)
{
	if(top!=self)
		top.location.replace(uri);
}