/*
 * � 2008 Martin Veverka <martin@veverka.eu>
 * Hotel Karlov
 */

var keys=new Array();

function key_init(){
 document.onkeydown=key_down;

 if(document.getElementsByTagName){
  var a_links=document.getElementsByTagName('link');
  for(var i=0;i<a_links.length;i++){
   if(typeof a_links[i]['rel'] != 'undefined' && typeof a_links[i]['href'] != 'undefined'){
    keys[a_links[i]['rel']]=a_links[i]['href'];
   }
  }
 }
}

function key_down(ev){
 var e=ev||window.event;
 if(e.ctrlKey&&e.keyCode==36){
  key_go(e,'home');
 }else
 if(e.keyCode==37){
  key_go(e,'previous');
 }else
 if(e.ctrlKey&&e.keyCode==38){
  key_go(e,'up');
 }else
 if(e.keyCode==39){
  key_go(e,'next');
 }
}
function key_go(e,rel){
 if(typeof keys[rel] != 'undefined'){
  if(keys[rel]!=false){
   window.location.href=keys[rel];
   keys[rel]=false;
  }
  if(e.preventDefault){
   e.preventDefault();
  }else{
   e.returnValue=false;
  }
 }
}
function link_set(rel,href){
 if(document.getElementsByTagName){
  var a_head=document.getElementsByTagName('head')[0];
  var a_links=document.getElementsByTagName('link');
  for(var i=0;i<a_links.length;i++){
   if(typeof a_links[i]['rel'] != 'undefined'){
    if(a_links[i]['rel']==rel){
     a_head.removeChild(a_links[i]);
    }
   }
  }
  if(href){
   var link=document.createElement('link');
   link.rel=rel;
   link.href=href;
   a_head.appendChild(link);
  }
  keys[rel]=href;
 }
}

$(document).ready(key_init);

var xmlhttp
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
  try {
  xmlhttp=new ActiveXObject("Msxml2.XMLHTTP")
 } catch (e) {
  try {
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
  } catch (E) {
   xmlhttp=false
  }
 }
@else
 xmlhttp=false
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
 try {
  xmlhttp = new XMLHttpRequest();
 } catch (e) {
  xmlhttp=false
 }
}

function myXMLHttpRequest(){
 var xmlhttplocal;
 try{
  xmlhttplocal= new ActiveXObject("Msxml2.XMLHTTP")
 }
 catch (e){
  try{
   xmlhttplocal= new ActiveXObject("Microsoft.XMLHTTP")
  }
  catch (E){
   xmlhttplocal=false;
  }
 }
 if (!xmlhttplocal && typeof XMLHttpRequest!='undefined') {
  try{
   var xmlhttplocal=new XMLHttpRequest();
  }
  catch (e){
   var xmlhttplocal=false;
  }
 }
 return xmlhttplocal;
}

function rp(id,rating,path){
 if(xmlhttp.readyState==0||xmlhttp.readyState==4){
  xmlhttp.open('get',path+'rate.php?id='+id+'&rating='+rating);
  xmlhttp.onreadystatechange=handleResponse;
  xmlhttp.send(null);
 }else{
  setTimeout("rp('"+id+"','"+rating+"','"+path+"');",1500);
 }
}

function handleResponse(){
 try{
  if(xmlhttp.readyState==4){
   if(xmlhttp.status==200){
    var response=xmlhttp.responseText;
    var update=new Array();
    if(response.indexOf('|')!=-1){
     update=response.split('|');
     document.getElementById(update[0]).innerHTML=update[1];
    }
   }
  }
 }
 catch(e){
  //alert('Chyba na stran� serveru, omlouv�me se: '+e.message+' // '+e.name+' // '+e.description);
 }
}

function getFancyboxSettings()
{
	if (typeof photoList == 'undefined')
	{
		fancyboxSettings =
		{
			'hideOnContentClick': true,
			'overlayShow': true
		}
	}
	else
	{
		fancyboxSettings =
		{
			'hideOnContentClick': true,
			'overlayShow': true,
			'itemArray': photoList
		}
	}
	return fancyboxSettings;
}

$(document).ready(function(){
	$("A").focus(function(){$(this).blur();});
	$('#photos-list div.pb a').fancybox(getFancyboxSettings());
	$('a.light').fancybox({ 'hideOnContentClick': true, 'overlayShow': true });
});

