function fbs_click() {
        u=location.href;
        t=document.title;
        window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
        return false;
}

function linkuj_click() {
        u=location.href;
        t=document.title;
        window.open('http://linkuj.cz/?id=linkuj&url='+encodeURIComponent(u)+'&title='+encodeURIComponent(t),'linkuj');
        return false;
}

function prepni_nej() {
        var temp = $('.prepinaci:first').html();
        var temp2 = $('.prepinaci:last').html();
        $('.prepinaci:first').html(temp2);
        $('.prepinaci:last').html(temp);
}

function setCookie(key, value) {
        value = encodeURIComponent(value);
        value+='; path=/';
        var date = new Date();
        date.setTime(date.getTime() + 7 * 24 * 60 * 60 * 1000); // 7 dní
        //value+='; expires=' + date.toGMTString();
        document.cookie = key + '=' + value;
}

$(document).ready(function(){

//------cookies--------
var cookieArray = document.cookie.split("; ");
var allCookies = new Array();

for (var i = 0; i < cookieArray.length; i++) {
  var name = cookieArray[i].split("=");
  allCookies[unescape(name[0])] = unescape(name[1]);
}

//------komentáře------

// helptexty
$('#kom_text').addClass('soft').val('Tvůj podnětný komentář');
$('#kom_podpis').addClass('soft').val('Tvůj podpis');

$('#kom_text').blur(function() {
    if ($(this).val() == '') $(this).addClass('soft').val('Tvůj podnětný komentář');})
$('#kom_podpis').blur(function() {
    if ($(this).val() == '') $(this).addClass('soft').val('Tvůj podpis');})    
    
$('#kom_text').focus(function() {
    if ($(this).val() == 'Tvůj podnětný komentář') $(this).removeClass('soft').val('');})
$('#kom_podpis').focus(function() {
    if ($(this).val() == 'Tvůj podpis') $(this).removeClass('soft').val('');})

//resize textarea
$('#kom_text').keyup(
  function() {
    var sh = document.getElementById('kom_text').scrollHeight;
    if ($(this).height() != sh && sh > 108) {$(this).animate({height: sh},{queue:false});}}
)


$('#neukazane').hide();
$('#rozbal_komentar').click(function(){
  $('#neukazane').slideToggle('fast');
})

//odeslání komentáře
$('#button_komentar').click(function(){
    if ($('input#kom_podpis').val() != 'Tvůj podpis' && $('textarea#kom_text').val() != 'Tvůj podnětný komentář') {
        $(this).hide();
        form_data = $(this).parents('form').serialize();
        $('input#kom_podpis, textarea#kom_text').attr('disabled', 'disable');
        $.ajax({type:"POST", async:true, url: "?", data: "ajax=true&"+form_data, success: function(html){
            $('#pravy_sloup').append(html);
            $('input#kom_podpis, textarea#kom_text').removeAttr('disabled');
            $('input#kom_podpis, textarea#kom_text').val('');
            $('#button_komentar').show();
            if ($('#rozbal_komentar').text() == '+ Přidej první komentář') {
                $('#rozbal_komentar').text('+ Přidej komentář');
                $('form#komentar').removeClass('odsad');}}
            });
    }
    return false;
});
  

//button hovery
$('button#hledej').hover(
function () {$(this).css('backgroundImage',"url('/_blog/img/hledej_b.gif')");},
function () {$(this).css('backgroundImage',"url('/_blog/img/hledej.gif')");})  
$('button#button_komentar').hover(
function () {$(this).css('backgroundImage',"url('/_blog/img/poslat_b.gif')");},
function () {$(this).css('backgroundImage',"url('/_blog/img/poslat.gif')");})
$('form#str_hledani button').hover(
function () {$(this).css('backgroundImage',"url('/_blog/img/hledej_2_b.gif')");},
function () {$(this).css('backgroundImage',"url('/_blog/img/hledej_2.gif')");})


//menuo
aktualni_kec = 0;
$('#menu1, #menu2, #menu3').click(function(){
  var x = $(this).attr('id');
  x = x.substr(x.length-1, x.length);
  if (x == aktualni_kec) x = 0;
  if (x != 0) $('a#menu'+x+' span').addClass('ac'+x);
  if (aktualni_kec != 0) $('a#menu'+aktualni_kec+' span').removeClass('ac'+aktualni_kec);
  $('#lp'+aktualni_kec).fadeOut('fast', function(){$('#lp'+x).fadeIn('fast')}); aktualni_kec = x;
  setCookie('lp', aktualni_kec);
  return false;
})

aktualni_kec2 = 7;
$('#menu4, #menu5, #menu6').click(function(){
  var x = $(this).attr('id');
  x = x.substr(x.length-1, x.length);
  if (x == aktualni_kec2) x = 7;
  if (x != 7) $('a#menu'+x+' span').addClass('ac'+x);
  if (aktualni_kec2 != 7) $('a#menu'+aktualni_kec2+' span').removeClass('ac'+aktualni_kec2);

  $('#lp'+aktualni_kec2).fadeOut('fast', function(){$('#lp'+x).fadeIn('fast')}); aktualni_kec2 = x;
  setCookie('pp', aktualni_kec2);
  return false;
})

$('#lp2 li, #lp3 li').hover(
    function(){$(this).css('color','7c5e3c')},
    function(){$(this).css('color','#9b7851')});

if (typeof(allCookies['lp']) != 'undefined') {
    $('#menu'+allCookies['lp']).trigger('click');
    $('.levy_prostor').stop(true, true);}
if (typeof(allCookies['pp']) != 'undefined') {
    $('#menu'+allCookies['pp']).trigger('click');
    $('.pravy_prostor, #lp7').stop(true, true);}


/*starší novější*/
$('a.starsi').live('mouseover', function() {
     $(this).animate({textIndent: '36px'},{queue:false, duration:250})})
$('a.starsi').live('mouseout', function() {
     $(this).animate({textIndent: '24px'},{queue:false})})
$('a.novejsi').live('mouseover', function() {
     $(this).animate({width: '154px', paddingRight: '36px'},{queue:false, duration:250})})
$('a.novejsi').live('mouseout', function() {
     $(this).animate({width: '166px', paddingRight: '24px'},{queue:false})})
/*nejnovější*/

$('a.starsi').live('click', function() {

    $('.starsi').replaceWith('<span class="starsi">načítám...</span>');
    $('.novejsi').remove();
    var urlko = $(this).attr('href')+"&ajax=true";

    $.ajax({type:"GET", async:true, url: urlko, success: function(html){

        $('.sloupokno').after('<div class="sloupokno2"></div>');
        $('.sloupokno2').html(html);
        $('.trojsloup address').hide();
        $('.sloupokno2').animate({left: '0px'}, 1000, 'swing', function () {
            });
        $('.sloupokno').animate({left: '-960px'}, 1000, 'swing', function () {
           $('.sloupokno').remove();
           $('.sloupokno2').removeClass('sloupokno2').addClass('sloupokno');
           $('.trojsloup address').show();
            });    
    }});
   
        return false;
})

$('a.novejsi').live('click', function() {
    
    $('.starsi').remove();
    $('.novejsi').replaceWith('<span class="novejsi">načítám...</span>');
    var urlko = $(this).attr('href')+"&ajax=true";

    $.ajax({type:"GET", async:true, url: urlko, success: function(html) {
    
        $('.sloupokno').after('<div class="sloupokno3"></div>');
        $('.sloupokno3').html(html);
        $('.trojsloup address').hide();
        $('.sloupokno3').animate({left: '0'}, 1000, 'swing', function () {
            });
        $('.sloupokno').animate({left: '960px'}, 1000, 'swing', function () {
           $('.sloupokno').remove();
           $('.sloupokno3').addClass('sloupokno').removeClass('sloupokno3');
           $('.trojsloup address').show();
            });
    }});       
    
    return false;
})

$('.cs2').hide();

// nej a antinej
$('a.obratme').hover(
            function(){$(this).css('background-position','0px 0px')},
            function(){$(this).css('background-position','0px -134px')}
)

$('a.obratme').toggle(
    function() {
        $(this).css('background-position','-163px -134px');
        $(this).hover(
            function(){$(this).css('background-position','-163px 0px')},
            function(){$(this).css('background-position','-163px -134px')}
            )
        prepni_nej();
        setCookie('ok_ko', 'ko');
        },
    function() {
        $(this).css('background-position','0px -134px');
        $(this).hover(
            function(){$(this).css('background-position','0px 0px')},
            function(){$(this).css('background-position','0px -134px')}
            )
        prepni_nej();
        setCookie('ok_ko', 'ok');
        }
)

if (allCookies['ok_ko'] == 'ko') $("a.obratme").trigger('click');

// hodnocení
$('#hodnot a').click(function(){
    $('#hodnot td:last').html('Posílám...');
    var urlko = $(this).attr('href') + '&ajax=true';
    odpoved = $.ajax({type:"POST", async:true, url: urlko, success: function() {$('#hodnot td:last').html('Díky za názor!');}})
    return false;});

// vyhledávání
$("#str_hledani input").focus();

});


