$(document).ready(function(){
    topArticleBox();
    weeklyBox();
    promoHeaderAnimation();
    $('#promo-article').jcarousel({
    	scroll: 1,
    	animation: 2000,
    	auto: 5,
    	wrap: 'circular',
    	buttonNextHTML: '<a id="promo-button-next" href="#"><img src="/images/hlavne-clanky-2-arrow-right.png" alt="" /></a>',
    	buttonPrevHTML: '<a id="promo-button-prev" href="#"><img src="/images/hlavne-clanky-2-arrow-left.png" alt="" /></a>'
    });
    
    $('#carousel-promo li').mouseenter(function(){
    	$(this).children().find('div.main_top_article2_img_text>a').css('text-decoration', 'underline');
    });
    $('#carousel-promo li').mouseleave(function(){
    	$(this).children().find('div.main_top_article2_img_text>a').css('text-decoration', 'none');
    });
    
    $('div.cel_box2_header_hledat_a_z>a').click(function(){
    	$('#cel_box2_articles').hide();
    	$('#celebrity-az').show();
    	return false;
    });
    $('div.cel_box2_header_hledat>a').click(function(){
    	$('#cel_box2_articles').show();
    	$('#celebrity-az').hide();
    	return false;
    });
    
    $('.celebrity-pager a.fl').click(function(){
    		$.ajax({
    		  url: '/celebrity-az.html?page_num='+$(this).attr('rel'),
    		  success: function(data) {
    			data = data.split('|||');
    		    $('#celebrity-az-list').html(data[0]);
    		    $('.celebrity-pager a.fl').attr('rel', parseInt(data[1])-1);
    		    $('.celebrity-pager a.fr').attr('rel', parseInt(data[1])+1);
    		    $('.celebrity-pager a.fl').show();
      		    $('.celebrity-pager a.fr').show();
      		    if ($('.celebrity-pager a.fl').attr('rel') < 1) $('.celebrity-pager a.fl').hide();
      		    if ($('.celebrity-pager a.fr').attr('rel') > parseInt(data[2])) $('.celebrity-pager a.fr').hide();
    		  }
    		});
	  		return false;
	})
	$('.celebrity-pager a.fr').click(function(){
		$.ajax({
  		  url: '/celebrity-az.html?page_num='+$(this).attr('rel'),
  		  success: function(data) {
  			data = data.split('|||');
  		    $('#celebrity-az-list').html(data[0]);
  		    $('.celebrity-pager a.fl').attr('rel', parseInt(data[1])-1);
  		    $('.celebrity-pager a.fr').attr('rel', parseInt(data[1])+1);
  		    $('.celebrity-pager a.fl').show();
  		    $('.celebrity-pager a.fr').show();
  		    if ($('.celebrity-pager a.fl').attr('rel') < 1) $('.celebrity-pager a.fl').hide();
  		    if ($('.celebrity-pager a.fr').attr('rel') > parseInt(data[2])) $('.celebrity-pager a.fr').hide();
  		  }
  		});
	  		return false;
	})
    
    
    
//    promoHeaderOtherAnimation();
    topMenu();
//    $("[title]").tooltip({ position: {offset: "5 5"} });
//    $( ".header_menu_link" ).tooltip({ disabled: true });
    
    $('a[rel=send2friend]').colorbox({
      iframe:true, width:'400px', height:'300px', slideshow:false, transition:'fade',close:'Zavřít',current:'{current} z {total}', previous: false, next: false
    });

    $('#main_page_article1_article a[href*="jpg"]').colorbox({
      rel:'group', width:'920px', height:'580px', slideshow:false, transition:'fade',close:'| Zavřít',current:'{current} z {total}', previous: "předchozí", next: "další"
    });
    
    if (jQuery.trim($('#main_page_right_tip_body .item-ad').text()) == '')
    {
       $('#main_page_right_tip_bottom,#main_page_right_tip_body,#main_page_right_tip_top').css('display','none');
    }
    
    if ($('.comment_vote_up'))
    {
      $('.comment_vote_up').click(function(){
        url = $(this).attr('href');
        $(this).load(url, function() {
          $(this).parent().html('<img src="/images/hand-up-voted.png" alt="" />');
        });
        $(this).parent().parent().find('.comment_vote_down:first-child').replaceWith('<img src="/images/hand-down.png" alt="" />');
        return false;
      });
    }
    if ($('.comment_vote_down'))
    {
      $('.comment_vote_down').click(function(){
        url = $(this).attr('href');
        $(this).load(url, function() {
          $(this).parent().html('<img src="/images/hand-down-voted.png" alt="" />');
        });
        $(this).parent().parent().find('.comment_vote_up:first-child').replaceWith('<img src="/images/hand-up.png" alt="" />');
        return false;
      });
    }
});

function topMenu()
{
	$('li.nav-home').mouseenter(function(){
		$('.submenu').removeClass('active');
		$('.nav-item').removeClass('act');
		Cufon.replace('.header_menu_link');
	});
	
	$('a.header_menu_link').mouseenter(function(){
		$('.submenu').removeClass('active');
		$('.nav-item').removeClass('act');
		
		$(this).next().addClass('active');
		$(this).parent('.nav-item').addClass('act');
		Cufon.replace('.header_menu_link');
	});
	
	$('#header_menu').mouseleave(function(){
		$('.submenu').removeClass('active');
		$('.nav-item').removeClass('act');
		Cufon.replace('.header_menu_link');
	})
}

function hideAllPromoOther()
{
	for (var i=1;i<10;i++)
	{
		$('#promo-other-'+i).hide();
	}
}

function setPromoOther(roll)
{
	hideAllPromoOther();
	$('#promo-button-prev').show()
	$('#promo-button-next').show()
	if (roll == 1) 
	{
		$('#promo-button-prev').hide()
		$('#promo-other-1').show();
		$('#promo-other-2').show();
		$('#promo-other-3').show();
	} 
	if (roll == 2) 
	{
		$('#promo-other-4').show();
		$('#promo-other-5').show();
		$('#promo-other-6').show();
	} 
	if (roll == 3) 
	{
		$('#promo-button-next').hide()
		$('#promo-other-7').show();
		$('#promo-other-8').show();
		$('#promo-other-9').show();
	} 
	
}
function promoHeaderOtherAnimation()
{
	hideAllPromoOther();
	var roll = 1;
	setPromoOther(roll);
	$('#promo-button-prev').hide();
	
	$('#promo-button-next').click(function(){
		roll += 1;
		setPromoOther(roll);
	});
	
	$('#promo-button-prev').click(function(){
		roll -= 1;
		setPromoOther(roll);
	});
	
}
function promoHeaderAnimation()
{
	$('#main_top_article>div.article>div>div.article_text').hide();
	$('#main_top_article>div.article>div.article_box').addClass('article_box2');
	$('#main_top_article>div.article>div.article_box').removeClass('article_box');
	$('#main_top_article>div.article').mouseenter(function(){
		$(this).children().find('a').css('text-decoration', 'underline');
		$(this).children().find('div.article_text>a').css('text-decoration', 'none');
		var child_div = this.children[1]; 
		var child_div_text = child_div.children[1]
		$(child_div).addClass('article_box');
		$(child_div).removeClass('article_box2');
		$(child_div_text).slideToggle('fast');
	});
	$('#main_top_article>div.article').mouseleave(function(){
		$('#main_top_article>div.article>div>div.article_text').hide();
		$(this).children().find('a').css('text-decoration', 'none');
		var child_div = this.children[1];
		var child_div_text = child_div.children[1]
		$(child_div).addClass('article_box2');
		$(child_div).removeClass('article_box');
	});
}

function topArticleBox()
{
    $("#content-nejctenejsi-clanky");
    $("#content-nejdiskutovanejsi-clanky").hide();
    $("#content-nejnovejsi-clanky").hide();

    $("#nejctenejsi-clanky").click(function(){
        $("#content-nejdiskutovanejsi-clanky").hide();
        $("#content-nejnovejsi-clanky").hide();
        $("#content-nejctenejci-clanky").show();

        $("#nejctenejsi-clanky").removeClass('tabs');
        $("#nejctenejsi-clanky").addClass('select');

        $("#nejnovejsi-clanky").removeClass('select');
        $("#nejnovejsi-clanky").addClass('tabs');
        $("#nejdiskutovanejsi-clanky").removeClass('select');
        $("#nejdiskutovanejsi-clanky").addClass('tabs');
        Cufon.replace('#main_page_right_tabs_top');
    });

    $("#nejdiskutovanejsi-clanky").click(function(){

        $("#content-nejnovejsi-clanky").hide();
        $("#content-nejctenejci-clanky").hide();
        $("#content-nejdiskutovanejsi-clanky").show();

        $("#nejdiskutovanejsi-clanky").removeClass('tabs');
        $("#nejdiskutovanejsi-clanky").addClass('select');

        $("#nejnovejsi-clanky").removeClass('select');
        $("#nejnovejsi-clanky").addClass('tabs');
        $("#nejctenejsi-clanky").removeClass('select');
        $("#nejctenejsi-clanky").addClass('tabs');
        Cufon.replace('#main_page_right_tabs_top');
    });

    $("#nejnovejsi-clanky").click(function(){
        $("#content-nejdiskutovanejsi-clanky").hide();
        $("#content-nejctenejci-clanky").hide();
        $("#content-nejnovejsi-clanky").show();

        $("#nejnovejsi-clanky").removeClass('tabs');
        $("#nejnovejsi-clanky").addClass('select');

        $("#nejdiskutovanejsi-clanky").removeClass('select');
        $("#nejdiskutovanejsi-clanky").addClass('tabs');
        $("#nejctenejsi-clanky").removeClass('select');
        $("#nejctenejsi-clanky").addClass('tabs');
        Cufon.replace('#main_page_right_tabs_top');
    });
}

function weeklyBox()
{
    $("#tab-content-holky");
    $("#tab-content-video").hide();
    $("#tab-content-hry").hide();

    $("#tab-holky-tydne").click(function(){
        $("#tab-content-video").hide();
        $("#tab-content-hry").hide();
        $("#tab-content-holky").show();

        $("#tab-holky-tydne").removeClass('tabs2');
        $("#tab-holky-tydne").addClass('select');

        $("#tab-hry-tydne").removeClass('select');
        $("#tab-hry-tydne").addClass('tabs2');
        $("#tab-video-tydne").removeClass('select');
        $("#tab-video-tydne").addClass('tabs2');
        Cufon.replace('#main_page_right_tabs2_top');
    });

    $("#tab-hry-tydne").click(function(){

    	$("#tab-content-video").hide();
        $("#tab-content-holky").hide();
        $("#tab-content-hry").show();

        $("#tab-hry-tydne").removeClass('tabs2');
        $("#tab-hry-tydne").addClass('select');

        $("#tab-video-tydne").removeClass('select');
        $("#tab-video-tydne").addClass('tabs2');
        $("#tab-holky-tydne").removeClass('select');
        $("#tab-holky-tydne").addClass('tabs2');
        Cufon.replace('#main_page_right_tabs2_top');
    });

    $("#tab-video-tydne").click(function(){
        $("#tab-content-hry").hide();
        $("#tab-content-holky").hide();
        $("#tab-content-video").show();

        $("#tab-video-tydne").removeClass('tabs2');
        $("#tab-video-tydne").addClass('select');

        $("#tab-hry-tydne").removeClass('select');
        $("#tab-hry-tydne").addClass('tabs2');
        $("#tab-holky-tydne").removeClass('select');
        $("#tab-holky-tydne").addClass('tabs2');
        Cufon.replace('#main_page_right_tabs2_top');
    });
}

