$(function(){



        /**
         * --------------------------------------------------------------------
         * links
         * --------------------------------------------------------------------
         */
        $("a:not([href^='http://agentura.irossler.cz'])").attr('target','_blank').addClass("external");
        $("a[href^='mailto:']").attr('target','').removeClass("external");
        $("a[href^='javascript:']").attr('target','').removeClass("external");
        $("a[href^='skype:']").attr('target','').removeClass("external");
        $("a[href^='/']").attr('target','').removeClass("external");
        $("a[href^='#']").attr('target','').removeClass("external");
        $("a[href^='..']").attr('target','').removeClass("external");
        $("a[href='']").attr('target','').removeClass("external");
        $(".content a[href$='.mp3']").addClass("audio");
        
        
        
        /**
         * --------------------------------------------------------------------
         * lightbox
         * --------------------------------------------------------------------
         */
        $("a[rel=lightbox], .body a:has(img)[href$='.jpg']").lightBox({
            overlayOpacity: 0.6,
            containerResizeSpeed: 350,
            imageLoading: dirClientside+'/lib/jquery.lightbox/lightbox-ico-loading.gif',
            imageBtnClose: dirClientside+'/lib/jquery.lightbox/lightbox-btn-close.gif',
            imageBtnPrev: dirClientside+'/lib/jquery.lightbox/lightbox-btn-prev.gif',
            imageBtnNext: dirClientside+'/lib/jquery.lightbox/lightbox-btn-next.gif',
            imageBlank: dirClientside+'/lib/jquery.lightbox/lightbox-blank.gif'
        });
    


        /**
         * --------------------------------------------------------------------
         * navigation
         * --------------------------------------------------------------------
         */

	if($('.content .subcategories-list li').length==1) {
		if($('.content .subcategories-list li').text()=='No categories') {
			$('.content .subcategories-list').hide();
		}		
	}

    $('.menu2 li:first, .menu.line2 li:first, .commentlist li:first').addClass('first');
    
    $('.menu2 li').mouseover(function(){
    	if(
			!$(this).hasClass('page-item-16')
		 && !$(this).hasClass('page-item-31')
		)
			$(this).find('ul').show();
	});
    $('.menu2 li').mouseout(function(){
		$(this).find('ul').hide();
	});
	
	if(!$('.content .navigation a').length) {
		$('.content .navigation').hide();
	}
	
	$('.content .post .entry').each(function(){
		var found = $(this).find('br');
		if(found.length==1) {
			found.remove();
		}
	});
	
	if($('.content').height()<400){
		$('.content').height(400);
	}
	
	
	$('.searchform .input-text').focus(function(){
        $(this).parent().parent().removeClass('unfocused').addClass('focused');
    });
    
    $('.searchform').mouseover(function(){
        $(this).removeClass('unfocused');
    });
    
    $('.searchform').mouseout(function(){
        if(!$(this).hasClass('focused')) {
            $(this).addClass('unfocused');
        }
    });
    
    function agentura() 
    {        
        var slideshowImagesCount = $(".agentura .slideshow ul li").length;
        var slideshowObject = $(".agentura .slideshow ul");
        var slideshowIndex = 1;
        var direction = "down";
        if(slideshowImagesCount > 1) {
            function slideshow() {
                if(slideshowIndex == slideshowImagesCount) {
                    direction = "up";
                } else if(slideshowIndex == 1) {
                    direction = "down";
                }
                if(direction=="down") {
                    slideshowIndex++;
                    slideshowObject.animate({"top": "-=0px"},4000,"swing");
                    slideshowObject.animate({"top": "-=170px"},1500,"swing",slideshow);
                } else {
                    slideshowIndex--;
                    slideshowObject.animate({"top": "-=0px"},4000,"swing");
                    slideshowObject.animate({"top": "+=170px"},1500,"swing",slideshow);
                }
            }
            slideshow();
        }
    }
    agentura();
    
    function tipy() 
    {        
        var slideshowImagesCount = $(".tipy .slideshow ul li").length;
        var slideshowObject = $(".tipy .slideshow ul");
        var slideshowIndex = 1;
        var direction = "down";
        if(slideshowImagesCount > 1) {
            slideshowObject.animate({"top": "-=0px"},2000,"swing");
            function slideshow() {
                if(slideshowIndex == slideshowImagesCount) {
                    direction = "up";
                } else if(slideshowIndex == 1) {
                    direction = "down";
                }
                if(direction=="down") {
                    slideshowIndex++;
                    slideshowObject.animate({"top": "-=0px"},4000,"swing");
                    slideshowObject.animate({"top": "-=170px"},1500,"swing",slideshow);
                } else {
                    slideshowIndex--;
                    slideshowObject.animate({"top": "-=0px"},4000,"swing");
                    slideshowObject.animate({"top": "+=170px"},1500,"swing",slideshow);
                }
            }
            slideshow();
        }
    }
    tipy();
    
    
    function blogy() 
    {        
        var slideshowImagesCount = $(".blogy .slideshow ul li").length;
        var slideshowObject = $(".blogy .slideshow ul");
        var slideshowIndex = 1;
        var direction = "down";
        if(slideshowImagesCount > 1) {
            slideshowObject.animate({"top": "-=0px"},4000,"swing");
            function slideshow() {
                if(slideshowIndex == slideshowImagesCount) {
                    direction = "up";
                } else if(slideshowIndex == 1) {
                    direction = "down";
                }
                if(direction=="down") {
                    slideshowIndex++;
                    slideshowObject.animate({"top": "-=0px"},4000,"swing");
                    slideshowObject.animate({"top": "-=170px"},1500,"swing",slideshow);
                } else {
                    slideshowIndex--;
                    slideshowObject.animate({"top": "-=0px"},4000,"swing");
                    slideshowObject.animate({"top": "+=170px"},1500,"swing",slideshow);
                }
            }
            slideshow();
        }
    }
    blogy();
    
    
  
    
        /**
         * --------------------------------------------------------------------
         * audio player
         * --------------------------------------------------------------------
         */
         
        var audioPlayer = $("#jplayer");
        var audioFileLinks = $(".content a[href$='.mp3']");
        
        audioPlayer.jPlayer({
            swfPath: dirClientside + '/lib/jquery.jplayer'
        });
        
        audioFileLinks.click(handleAudioLink);
        function handleAudioLink() 
        {
              if($(this).hasClass("playing")) {
                  audioPlayer.setFile('');
                  $(this).removeClass("playing");
              } else {
                  audioFileLinks.removeClass("playing");
                  $(this).addClass("playing");
                  var musicFile = $(this).attr('href');
                  audioPlayer.setFile(musicFile).play();
              }
              return false;
        }
    
    
});


