// JavaScript Document

photogallery_const = 0;
pg_sh = null;

window.onload = function () {
   $("#main_menu").children().hover(
      function(){
         sr = this.src.split("/");
         sr = sr[sr.length-1].substring(0,sr[sr.length-1].length-6)
         if(sr != _current_page) {
            sr = this.src.substring(0,this.src.length-6)
            this.src = sr+"_1.gif"
         }
      },function(){
         sr = this.src.split("/");
         sr = sr[sr.length-1].substring(0,sr[sr.length-1].length-6)
         if(sr != _current_page) {
            sr = this.src.substring(0,this.src.length-6)
            this.src = sr+"_0.gif"
         }
      })
   $("#main_menu").children().click(
      function () {
         sr = this.src.split("/");
         sr = sr[sr.length-1].substring(0,sr[sr.length-1].length-6)
         location.href = sr+".php"
      })
   $("#main_menu").children().css("cursor","pointer")
   $("#main_menu").children().each(function(){
      sr = this.src.split("/");
      sr = sr[sr.length-1].substring(0,sr[sr.length-1].length-6)
      $(this).attr("id",sr)
      if(sr == _current_page) {
         sr = this.src.substring(0,this.src.length-6)
         this.src = sr+"_2.gif";
      }
   })
}

hover = function (_obj) {
   sr = _obj.src.substring(0,_obj.src.length-6)
   _obj.src = sr+"_1.gif";
   _obj.onmouseout = function() {
      sr = this.src.substring(0,_obj.src.length-6)
      this.src = sr+"_0.gif";
   }
}

setHigh = function (_obj,id) {
   sr = _obj.src.substring(0,_obj.src.length-6);
   _obj.src = sr+"_"+id+".gif";
}

hoverBkg = function (_obj) {
   _obj.className = 'photo_preview2';
   _obj.onmouseout = function() {
      this.className = 'photo_preview'
   }
}

  if(navigator.appName=="Microsoft Internet Explorer"){IE = true;}else{IE=false}
  if(navigator.appName=="Netscape"){Mozilla = true;}else{Mozilla=false}
  if(navigator.appName=="Opera"){Opera = true;}else{Opera=false}
  
openBox = function (ev, html) {
  if(Mozilla){
    w = document.width;
  } else if (Opera) {
    w = window.innerWidth;
  } else {
    w = document.body.clientWidth;
  }

  if(!Mozilla) {
    ev = window.event;
  }

  elm = jQuery("<div style=\"width: "+parseInt(w)+"px; height: 3000px; display: none\" class=\"shadow\"></div>");
  elm.prependTo($(document.body));
  elm.fadeIn()
  inel = jQuery("<div style=\"display: none\" class=\"photo_view\"></div>");
  inel.css("left",Math.round(w/2-400)+"px");
  if(Opera) {
    inel.css("top",(parseInt(document.body.scrollTop)+30)+"px");
  }else if (IE){
    inel.css("top",(parseInt(document.body.scrollTop)+30)+"px");
  }else{
    inel.css("top",(parseInt(ev.pageY)-parseInt(ev.clientY)+30)+"px");
  }
  inel.prependTo($(document.body));
  inel.html(html)
  img = jQuery("<img style=\"cursor: pointer\" src=\"ext/img/buttons/close_0.gif\" alt=\"\" title=\"zavřít\" onmouseover=\"hover(this)\">")
  img.click(function () {
    elm.fadeOut("normal",function(){elm.remove()});
    inel.fadeOut("normal",function(){inel.remove()});
  })
  img.prependTo(inel);
  return [inel,elm];
}

showVideo = function (e, src, comment) {
   if(!Mozilla) {
      e = window.event;
   }
   src = src.split("?");
   src = src[1].substr(2,11);
   htm = '<object width="500" height="405"><param name="movie" value="http://www.youtube.com/v/'+src+'&hl=cs_CZ&fs=1&color1=0x000000&color2=0x999999&border=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/'+src+'&hl=cs_CZ&fs=1&color1=0x000000&color2=0x999999&border=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="500" height="405"></embed></object>';
   html = "";
   if(comment!=""){html+="<br><br>"+comment+"<br><br>"}
   html+=htm;
   ell = openBox(e,html);
   ell[0].fadeIn()
}

showPhoto = function (e, src, comment) {
   if(!Mozilla) {
      e = window.event;
   }
   html="<br><br>";
   if(comment!=""){html+=comment+"<br>"}
   html+="<img src='http://trambus.cz/ext/img.php?a=photoFull&photo="+src+"' alt=''>";
   ell = openBox(e,html);
   ell[0].fadeIn()
   ell[0].click(function(){
      ell[0].fadeOut("normal",function(){ell[0].remove()});
      ell[1].fadeOut("normal",function(){ell[1].remove()});
   })
}

/*
showAllPhotos = function (ev) {
   photogallery_const = 0;
  if(Mozilla){
    w = document.width;
  } else if (Opera) {
    w = window.innerWidth;
  } else {
    w = document.body.clientWidth;
  }

  if(!Mozilla) {
    ev = window.event;
  }

  elm = jQuery("<div style=\"width: "+parseInt(w)+"px; height: 3000px; display: none\" class=\"shadow\"></div>");
  elm.prependTo($(document.body));
  elm.fadeIn()
  inel = jQuery("<div style=\"display: none\" style=\"height:900px\" class=\"photo_view\"></div>");
  inel.css("left",Math.round(w/2-400)+"px");
  if(Opera) {
    inel.css("top",(parseInt(document.body.scrollTop)+30)+"px");
  }else if (IE){
    inel.css("top",(parseInt(document.body.scrollTop)+30)+"px");
  }else{
    inel.css("top",(parseInt(ev.pageY)-parseInt(ev.clientY)+30)+"px");
  }
  inel.prependTo($(document.body));
  inel.html("")
  img = jQuery("<img hspace='2' style=\"cursor: pointer\" src=\"ext/img/buttons/next_0.gif\" alt=\"\" title=\"následující\" onmouseover=\"hover(this)\">")
  img.click(function () {
      showCPhoto(cimg,1)
  })
  img.prependTo(inel);
  img = jQuery("<img hspace='2'  style=\"cursor: pointer\" src=\"ext/img/buttons/close_0.gif\" alt=\"\" title=\"zavřít\" onmouseover=\"hover(this)\">")
  img.click(function () {
    elm.fadeOut("normal",function(){elm.remove()});
    inel.fadeOut("normal",function(){inel.remove()});
  })
  img.prependTo(inel);
  img = jQuery("<img hspace='2'  style=\"cursor: pointer\" src=\"ext/img/buttons/prev_0.gif\" alt=\"\" title=\"předchozí\" onmouseover=\"hover(this)\">")
  img.click(function () {
      showCPhoto(cimg,-1)
  })
  img.prependTo(inel);

  br = jQuery("<br><br>");
  br.appendTo(inel)
  cimg = jQuery("<img src=\""+photos[photogallery_const][0]+"\" alt=\"\">");
  cimg.click(function () {
      showCPhoto(cimg,1)
  })
  cimg.appendTo(inel);
  inel.fadeIn();
}
*/

showAllPhotos = function(ev) {
   photogallery_const = 0;
   showCPhoto(ev, 0);
   pg_sh = jQuery("<div style=\"width: "+parseInt(w)+"px; height: 3000px; display: none\" class=\"shadow\"></div>");
   pg_sh.prependTo($(document.body));
   pg_sh.fadeIn();
}


showCPhoto = function (e, con) {
  if(Mozilla){
    w = document.width;
  } else if (Opera) {
    w = window.innerWidth;
  } else {
    w = document.body.clientWidth;
  }

  if(!Mozilla) {
    e = window.event;
  }
  photogallery_const+=con;
  if(photogallery_const == -1) {photogallery_const = photos.length-1}
  if(photogallery_const == photos.length) {photogallery_const = 0}
  inel = jQuery("<div style=\"display: none\" style=\"height:900px\" class=\"photo_view\"></div>");
  inel.css("left",Math.round(w/2-400)+"px");
  if(Opera) {
    inel.css("top",(parseInt(document.body.scrollTop)+30)+"px");
  }else if (IE){
    inel.css("top",(parseInt(document.body.scrollTop)+30)+"px");
  }else{
    inel.css("top",(parseInt(e.pageY)-parseInt(e.clientY)+30)+"px");
  }
  inel.prependTo($(document.body));
  inel.html("")
  img = jQuery("<img hspace='2' style=\"cursor: pointer\" src=\"ext/img/buttons/next_0.gif\" alt=\"\" title=\"následující\" onmouseover=\"hover(this)\">")
  img.click(function () {
      inel.fadeOut("normal",function(){inel.remove();showCPhoto(e,1)});
  })
  img.prependTo(inel);
  img = jQuery("<img hspace='2'  style=\"cursor: pointer\" src=\"ext/img/buttons/close_0.gif\" alt=\"\" title=\"zavřít\" onmouseover=\"hover(this)\">")
  img.click(function () {
    pg_sh.fadeOut("normal",function(){pg_sh.remove()});
    inel.fadeOut("normal",function(){inel.remove()});
  })
  img.prependTo(inel);
  img = jQuery("<img hspace='2'  style=\"cursor: pointer\" src=\"ext/img/buttons/prev_0.gif\" alt=\"\" title=\"předchozí\" onmouseover=\"hover(this)\">")
  img.click(function () {
      inel.fadeOut("normal",function(){inel.remove();showCPhoto(e,-1)});
  })
  img.prependTo(inel);

  br = jQuery("<br><br>");
  br.appendTo(inel)
  cimg = jQuery("<img alt=\"\">");
  cimg.attr("src","http://trambus.cz/ext/img.php?a=photoFull&photo="+photos[photogallery_const][0])
  cimg.click(function () {
      inel.fadeOut("normal",function(){inel.remove();showCPhoto(e,1)});
  })
  cimg.appendTo(inel);
  inel.fadeIn();
}


showItem = function (e, src) {
   if(!Mozilla) {
      e = window.event;
   }
   html="<br><br>";
   html+="<img src='ext/img.php?a=shopFull&amp;item="+src+"' alt=''>";
   ell = openBox(e,html);
   ell[0].fadeIn()
   ell[0].click(function(){
      ell[0].fadeOut("normal",function(){ell[0].remove()});
      ell[1].fadeOut("normal",function(){ell[1].remove()});
   })
}

playSong = function (_el, sn) {
   tar = _el.parentNode.parentNode.childNodes[1];
   $(".player").each(function() {
      $(this).slideUp("normal", function(){$(this).remove()});
   })
   cen = jQuery("<center class=\"player\" style=\"display: none\"></center>");
   cen.appendTo($(tar));
   img = jQuery("<img style=\"margin: 10px\" src=\"ext/img/icons/loading.gif\" alt=\"\">");
   img.appendTo(cen);
   cen.slideDown()
   $.post("ext/main.php", { getHash: "1", sng: sn  },
   function(data){
      pl = jQuery('<object style="margin: 5px; display: none" type="application/x-shockwave-flash" data="ext/player.swf" width="300" height="34"><param name="movie" value="ext/player.swf"><param name="FlashVars" value="autostart=yes&amp;soundFile='+escape("http://trambus.cz/ext/player.php?sid="+data.sng+"&hash="+data.hash)+'"><param name="quality" value="high"><param name="menu" value="true"><param name="wmode" value="transparent"></object>');
      img.fadeOut("slow",function(){img.remove();pl.appendTo(cen);pl.fadeIn("normal");})
   }, "json");
}

showLyrics = function (ev, sng) {
   im = jQuery("<div><br><br><img src=\"ext/img/icons/loading.gif\" alt=\"\"></div>");
   ell = openBox(ev,"");
   im.appendTo(ell[0]);
   ell[0].fadeIn("slow");
   $.post("ext/main.php", {getLyrics: sng},
   function(data){
      im.fadeOut("slow",function(){
         el = jQuery("<div style=\"display: none\">"+data.getElementsByTagName("data")[0].childNodes[0].nodeValue+"</div>");
         el.appendTo(ell[0]);
         el.slideDown("slow");
      })
   }, "xml");
}
   
addSmiley = function(smiley, wh) {
   wh.value += " [s"+smiley+"] ";
}

gbook_react = function (_for) {
   document.getElementById("reaction").value=_for;
   $(add_msg_form).slideDown("slow");
}

loadDiaryNote = function (_to, _i) {
   $(".diaryNote").hide();
   _to.slideDown("slow");
   $.post("ext/main.php", {getDiary: 1, note: _i},
   function(data){
      _to.html(data.getElementsByTagName("data")[0].childNodes[0].nodeValue)
      _to.slideDown("slow");
   }, "xml");
}
