﻿GlobalLang = 'sk';
hashAktivny = '';


$(document).ready(function(){

$('#Menu a').click(function() {

 if ( $(this).attr('target') != '' && $(this).attr('target') != undefined) { alert($(this).attr('target'));return; };  
 
 //$.history.load( $(this).attr('href').slice($(this).attr('href').search(/\Page=/)+5) );
 if ( $(this).parents('ul').attr('id') != 'Menu' || $(this).parents('li').children('ul').length == 0) {
  $.history.load( $(this).attr('href').slice($(this).attr('href').search(/\Page=/)+5) );
 } else {
  AFirstHref = $(this).parents('li').children('ul').children('li').children('a:first').attr('href');
  $.history.load( AFirstHref.slice(AFirstHref.search(/\Page=/)+5) );
 };
 $(this).blur();
 return false;
 
});

$.history.init(pageload);

ssInitLeto = true; 
SlideShowLeto();
ssInitLeto = false;
ssInitZima = true; 
SlideShowZima();
ssInitZima = false;

setInterval("SlideShowLeto()", 30000);
setInterval("SlideShowZima()", 33000);

TZCDInit();	//countdown

//facebook links
FbHover = false;
$('#FbLink').hover( function() { $('#FbLinkList').slideDown(200); }, function() { $('#FbLinkList').hide(); } );
$('#FbLinkList').hover( function(){ $(this).show(); }, function(){ $(this).slideUp(200); } );

});


	//jquery load history
function pageload(hash) {

if (!hash) {
 if (document.URL.search(/\?Page=/) != -1) { document.location = document.URL.replace(/index.php\?Page=/, "#"); };
 if (document.URL.search(/&Page=/) != -1) { document.location = document.URL.replace(/&Page=/, "#"); };
 hash = StartPage; 
};

if (GlobalLang == 'sk') { LangDirExt = ''; } else { LangDirExt = '-'+ GlobalLang; };

if (Number(hash)) {
 File = BaseDir + hash +".htm";
} else {
 if (hash.search(/\?/) != -1) {	//if hash contains GET data
  File = BaseDir + hash.slice(0, hash.search(/\?/)) +".php"+ hash.slice(hash.search(/\?/));
  hash = hash.slice(0, hash.search(/\?/));
 } else {
  if (hash.search(/\//) == -1) { File = BaseDir + hash +".php";
  } else { File = hash; };
 };
};

if (hash.search('Kategoria') != -1) { return; };	//v ucastnici.php pri odkazovani na <a name='#Kategoria$$'>
$('#Menu').css('position', 'static');
$('#ReklamaBanner').show();
$('#Status').fadeIn(200);
$('a[href*='+hash+']').blur();
hashAktivny = hash;

$.ajax({ url: File, success: function(content) {
 $('#Status').fadeOut(200);
 if (hash == hashAktivny) {	//zobraz nacitany obsah len ak sa pocas nacitavania nezobrazil iny obsah  
  $('#Main').html(content);
  $('#Main a').click(function() {
   if ( $(this).attr('href').slice(0, 15) == 'index.php?Page=' || $(this).attr('href').slice(0, 15) == 'index.php?Lang=' ) {
    $.history.load( $(this).attr('href').slice( $(this).attr('href').search(/Page=/)+5 ) );  
    return false;
   };
  });
  if ( $('#Main img').length > 0 && $('#Main img').eq(0).attr('src').search(location.host+"/"+BaseDir) != -1 ) { $('#Main img').each(function() { $(this).attr('src', $(this).attr('src').slice( $(this).attr('src').search(location.host+"/"+BaseDir) + location.host.length+1+BaseDir.length , $(this).attr('src').length ) ); }); };	//webkit img proxy workaround
  MenuHilite(hash);
  PoNacitani();
 };
 if (GlobalLang != 'sk') { PrelozObsah(hash); };
 quiteview();
 mapaview();
 Gallery();
 $.tablesorter.defaults.widgets = ['zebra']; $('table[class=tablesorter]').tablesorter(); 
}});

}


function MenuHilite(hash) {
if ($('#Menu a[href*='+hash+']').html() != null) {
   MainbarText = $('#Menu a[href*='+hash+']').html();
   if ( $('#Menu a[href*='+hash+']').parents('ul').attr('id') != 'Menu') {
    MainbarText = $('#Menu a[href*='+hash+']').parents('ul').parents('li').children('a').html() +"&nbsp;&nbsp;•&nbsp;&nbsp;"+ MainbarText;
   };
   $('#Mainbar').html( MainbarText );
  };

$('#Menu a').css('color', '');
$('#Menu ul a').css('font-weight', 'normal');
$('#Menu a[href*='+hash+']').css('color','#be3144');
if ( $('#Menu a[href*='+hash+']').parents('ul').attr('id') != 'Menu') {
 $('#Menu a[href*='+hash+']').css('font-weight','bold');
};
$('#Menu a[href*='+hash+']').blur();
 
$('#Menu a[href*='+hash+']').parents('ul').parents('li').children('a:first').css('color', '#be3144');	//higlight group name
$('#Menu ul').slideUp(200); $('#Menu a[href*='+hash+']').parents('li').children('ul').stop(false,false);
$('#Menu a[href*='+hash+']').parents('li').children('ul').slideDown(200);
}


function PoNacitani() {
Obsah = $('#Main').html();
if (Obsah.search(/\[video\]/) != -1) {
 $('#Main').html( Obsah.replace(/\[video\]/, "<div id='Videoprehravac'>Klikni na odkaz pre spustenie prehrávania.</div>") );
 $('#Main a').click(function() {
   if ( $(this).attr('href').slice(0, 10) == 'index.php?' ) {
    $.history.load( $(this).attr('href').slice($(this).attr('href').search(/\Page=/)+5) );  
    return false;
   };
  });
 quiteview();
};
if (Obsah.search(/\[novinky\]/) != -1) {
 function ParseObsah(Callback) {
  if (GlobalLang == 'sk') { MenuFile = "obsah/novinky.txt";
  } else { MenuFile = "obsah-"+ GlobalLang +"/novinky.txt"; };  
  $.ajax({ url: MenuFile, success: function(Novinky) {
   Novinky = Novinky.replace(new RegExp("\r", "gm"), "");
   Novinky = Novinky.replace(new RegExp("\n", "gm"), "");
   Novinky = Novinky.replace(new RegExp("<zobraz>", "gm"), "");
   Novinky = Novinky.replace(new RegExp("</obsah>", "gm"), "");
   Novinky = Novinky.replace(new RegExp("<zaznam><datum>", "gm"), "<tr><td style='padding:3px; text-align:right; vertical-align:top; font-weight:bold'>");   
   Novinky = Novinky.replace(new RegExp("</datum><obsah>", "gm"), "<td style='padding:3px; text-align:justify'>");
   Novinky = Novinky.replace(new RegExp("</zobraz>", "gm"), "</table><table id='NovinkySkryte' style='font-size:14px; display:none'>");
   Novinky = "<h2 style='position:relative; top:-5px; margin:0; text-align:center'>NOVINKY</h2><table style='width:512px; font-size:14px'>"+ Novinky +"</table><div style='margin:5px; text-align:center'><a href=\"javascript:Toggle('NovinkySkryte')\">staršie novinky</a></div><div style='margin-bottom:18px; text-align:center'><img src='lejautpics/main-line.png'></div>";
   Obsah = Obsah.replace(/\[novinky\]/, Novinky);
   Obsah = Obsah.replace(/\[video-uvod\]/, "<div id='Videoprehravac' style='margin-bottom:18px'><a href='http://www.macromedia.com/go/getflashplayer'>Stiahnite si Flash Player</a> pre prehranie tohto videa.</div>");
   if (GlobalLang == 'en') { Obsah = Obsah.replace("NOVINKY", "NEWS"); Obsah = Obsah.replace("staršie novinky", "previous news");};
   if (GlobalLang == 'de') { Obsah = Obsah.replace("NOVINKY", "AKTUELLES"); Obsah = Obsah.replace("staršie novinky", "ältere Einträge");};
   if (GlobalLang == 'hu') { Obsah = Obsah.replace("NOVINKY", "ÚJDONSÁGOK"); Obsah = Obsah.replace("staršie novinky", "régi újságok");};
   if (GlobalLang == 'pl') { Obsah = Obsah.replace("NOVINKY", "WIADOMOŚCI"); Obsah = Obsah.replace("staršie novinky", "starsze wiadomości");};
   Callback(Obsah);
  }});  
 };
 ParseObsah(function(Obsah) {
  $('#Main').html( Obsah.replace(/\[vsa-video\]/, "<object width='480' height='385' data='http://www.youtube.com/v/B16Q6N32iKc&amp;hl=en_US&amp;fs=1&amp;' type='application/x-shockwave-flash'><param name='data' value='http://www.youtube.com/v/B16Q6N32iKc&amp;hl=en_US&amp;fs=1&amp;' /><param name='allowFullScreen' value='true' /><param name='allowscriptaccess' value='always' /><param name='src' value='http://www.youtube.com/v/B16Q6N32iKc&amp;hl=en_US&amp;fs=1&amp;' /><param name='allowfullscreen' value='true' /></object>") );
  $('#Main').html( Obsah.replace(/\[youtube-video\]/, "<object width='425' height='350' data='http://www.youtube.com/v/dNYZMXOAzB8&amp;hl=en_US&amp;fs=1&amp;' type='application/x-shockwave-flash'><param name='data' value='http://www.youtube.com/v/dNYZMXOAzB8&amp;hl=en_US&amp;fs=1&amp;' /><param name='allowFullScreen' value='true' /><param name='allowscriptaccess' value='always' /><param name='src' value='http://www.youtube.com/v/dNYZMXOAzB8&amp;hl=en_US&amp;fs=1&amp;' /><param name='allowfullscreen' value='true' /></object>") );
  $('#Main a').click(function() {
   if ( $(this).attr('href').slice(0, 10) == 'index.php?' ) {
    $.history.load( $(this).attr('href').slice($(this).attr('href').search(/\Page=/)+5) );  
    return false;
   };
  });
  quiteview();
  PrehrajVideo('home.flv', '512', '308', 'noautoplay');
 });  
};
}


function Nacitaj(Ktore) { $.history.load(Ktore); };


function Gallery() {
 $('#Gallery h1').click(function() {
 GalleryActive = $("#Gallery ul:eq("+ $('#Gallery h1').index( $(this) ) +")");
 if (GalleryActive.css('display') == 'none') {
  GalleryActive.slideDown(300);
 } else {
  GalleryActive.slideUp(300);
 };
 });
}


	//zvysne funkcie

function PrehrajVideo(subor, sirka, vyska, autoplay) {
if (document.getElementById('Videoprehravac')) {

obrazok = subor.slice(0, subor.search(/\./));

flashvarsParams = "file=../video/"+subor+"&image=../video/"+obrazok+".jpg&screencolor=000000";

if (autoplay == 'autoplay') {
 flashvarsParams = flashvarsParams + "&autostart=true";
 if (document.body.scrollTop > 250) {window.scrollTo(0, 250)};
};

var s1 = new SWFObject("jwplayer/player.swf","ply",sirka,vyska,"9","#FFFFFF");
s1.addParam("allowfullscreen","true");
s1.addParam("allowscriptaccess","always");
s1.addParam("flashvars",flashvarsParams);
s1.addParam("wmode","transparent");

s1.write("Videoprehravac");

if (autoplay == 'autoplay' && document.getElementById('Videoprehravac').style.backgroundColor != '#ffffff') {
 $("#Videoprehravac").hide();
 $("#Videoprehravac").ready(function () { $("#Videoprehravac").slideDown("slow"); });
};

document.getElementById('Videoprehravac').style.backgroundColor = '#ffffff';

};
}


function Toggle(Ktory, Rychlost) {
if (document.getElementById(Ktory).style.display == 'none') {
 if (Rychlost == 'hned') {
  document.getElementById(Ktory).style.display='block';
 } else {
  $('#'+Ktory).slideDown(300);
 };
} else {
 $('#'+Ktory).slideUp(300);
 //document.getElementById(Ktory).style.display='none';
 };
}

function UkazVsetky() { $('div[id*=Zaznam]').slideDown(200); }
function SkryVsetky() { $('div[id*=Zaznam]').slideUp(200); }


function SlideShowLeto() {

/*if (!ssInitLeto) {
 ssInstanceEqLeto = Math.floor( Math.random()* $('#ssPicLeto div.ssPicTop').length-1 )+1;
};*/
ssInstanceEqLeto = 0;
ssPicLetoImg = new Image();

ssPicLetoImg.onload = function() {
 $('#ssPicLeto div.ssPicBottom').eq(ssInstanceEqLeto).hide();
 $('#ssPicLeto div.ssPicBottom').eq(ssInstanceEqLeto).css('background-image', 'url('+ ssPicLetoImg.src +')');
 $('#ssPicLeto div.ssPicBottom').eq(ssInstanceEqLeto).fadeIn(5000);
 $("#ssPicLeto a[rel='ssPicLinkLeto']").eq(ssInstanceEqLeto).attr('href', ssPicLetoImg.src.replace("-s.jpg", "-l.jpg") );
 $('#ssPicLeto div.ssPicTop').eq(ssInstanceEqLeto).fadeOut(5000, function() {
  $('#ssPicLeto div.ssPicTop').eq(ssInstanceEqLeto).css('background-image', 'url('+ ssPicLetoImg.src +')');
  $('#ssPicLeto div.ssPicTop').eq(ssInstanceEqLeto).show();  
 });
};

if (ssPicsLeto.length > 1) {
do {
 ssPicIndexUniqueLeto = true;
 ssPicIndexLeto = Math.floor( Math.random()* ssPicsLeto.length-1 )+1;
 $('#ssPicLeto div.ssPicTop').each(function() {
  if ( $(this).css('background-image').search(ssPicsLeto[ssPicIndexLeto]) != -1 )
  { ssPicIndexUniqueLeto = false; };
 });
 if ( $('#ssPicLeto div.ssPicTop').length >= ssPicsLeto.length ) { ssPicIndexUniqueLeto = true; };
} while ( ssPicIndexUniqueLeto == false );

if (!ssInitLeto) {
 ssPicLetoImg.src = 'topbar/leto/'+ ssPicsLeto[ssPicIndexLeto] +'-s.jpg';
} else {
 $('#ssPicLeto div.ssPicTop').eq(ssInstanceEqLeto).css('background-image', 'url('+ 'topbar/leto/'+ ssPicsLeto[ssPicIndexLeto] +'-s.jpg' +')');
 $("#ssPicLeto a[rel='ssPicLinkLeto']").eq(ssInstanceEqLeto).attr('href', 'topbar/leto/'+ ssPicsLeto[ssPicIndexLeto] +'-l.jpg' );
};
};

}


function SlideShowZima() {

/*if (!ssInitZima) {
 ssInstanceEqZima = Math.floor( Math.random()* $('#ssPicLeto div.ssPicTop').length-1 )+1;
};*/
ssInstanceEqZima = 0;
ssPicZimaImg = new Image();

ssPicZimaImg.onload = function() {
 $('#ssPicZima div.ssPicBottom').eq(ssInstanceEqZima).hide();
 $('#ssPicZima div.ssPicBottom').eq(ssInstanceEqZima).css('background-image', 'url('+ ssPicZimaImg.src +')');
 $('#ssPicZima div.ssPicBottom').eq(ssInstanceEqZima).fadeIn(5000);
 $("#ssPicZima a[rel='ssPicLinkZima']").eq(ssInstanceEqZima).attr('href', ssPicZimaImg.src.replace("-s.jpg", "-l.jpg") );
 $('#ssPicZima div.ssPicTop').eq(ssInstanceEqZima).fadeOut(5000, function() {
  $('#ssPicZima div.ssPicTop').eq(ssInstanceEqZima).css('background-image', 'url('+ ssPicZimaImg.src +')');
  $('#ssPicZima div.ssPicTop').eq(ssInstanceEqZima).show();  
 });
};

if (ssPicsZima.length > 1) {
do {
 ssPicIndexUniqueZima = true;
 ssPicIndexZima = Math.floor( Math.random()* ssPicsZima.length-1 )+1;
 $('#ssPicZima div.ssPicTop').each(function() {
  if ( $(this).css('background-image').search(ssPicsZima[ssPicIndexZima]) != -1 )
  { ssPicIndexUniqueZima = false; };
 });
 if ( $('#ssPicZima div.ssPicTop').length >= ssPicsZima.length ) { ssPicIndexUniqueZima = true; };
} while ( ssPicIndexUniqueZima == false );

if (!ssInitZima) {
 ssPicZimaImg.src = 'topbar/zima/'+ ssPicsZima[ssPicIndexZima] +'-s.jpg';
} else {
 $('#ssPicZima div.ssPicTop').eq(ssInstanceEqZima).css('background-image', 'url('+ 'topbar/zima/'+ ssPicsZima[ssPicIndexZima] +'-s.jpg' +')');
 $("#ssPicZima a[rel='ssPicLinkZima']").eq(ssInstanceEqZima).attr('href', 'topbar/zima/'+ ssPicsZima[ssPicIndexZima] +'-l.jpg' );
};
};

}


