$(document).ready(function(){    
    //menu animaiton
    $('.menu_list li').hover(function() {                
        $(this).find('ul').hide().slideUp(1).slideDown(200);        
    }, function() {
        $(this).find('ul').slideUp(300);
    });
    
    
    //typewriter effect
    $('.hp_left blockquote span').each(function() {
        var $ele = $(this), str = $ele.text(), progress = 0;
        $ele.text('');
        $('.hp_left blockquote em').hide();
        var timer = setInterval(function() {
            $ele.text(str.substring(0, progress++) + (progress & 1 ? '_' : ''));
            if (progress >= str.length) {
            	clearInterval(timer);
            	if($ele.text().substring(progress-1)=='_'){
            		$ele.text(str.substring(0, progress));
            	}
            	$('.hp_left blockquote em').fadeIn(500);
            }
        }, 100);
    });
    
    
    //animation loading precaution
    $('.top_left_img, #top_center img, .top_right_img').not('.active').css('top','-5000px');
    
    setTimeout(function(){
    	$('.top_left_img').css('top','-50px');
        $('#top_center img').css('top','-94px');
        $('.top_right_img').css('top','0px');
        
      //bridge fading
        $('#top_center').FadeGallery({
        	'items' : '#top_center img',
        	'speed' : 1000,
        	'intervalSpeed' : 12000
        }); 
        
        $('#top_left').FadeGallery({
        	'items' : '#top_left img:not(".stin1")',
        	'speed' : 1000,
        	'intervalSpeed' : 12000
        }); 
        
        $('#top_right').FadeGallery({
        	'items' : '#top_right img:not(".stin2")',
        	'speed' : 1000,
        	'intervalSpeed' : 12000
        }); 
    },10000);
    
    //Show more functionality
    var showMore = ($('.lang_selected').html()=='cz')? 'Více' :'More' ;
    $('.collapse').before('<a href="#" title="" class="more">'+ showMore+'</a>');
    $('.hp_center .more').click(function(){
    	$('.collapse').slideDown(200);
    	$(this).hide();
    	return false;
    });
    
});



/*!
 * FadeGallery jQuery plugin
 * http://userte.ch/
 *
 * Copyright 2011, Jan Beranek
 * Release: May 2011
 */
(function( $ ){
    $.fn.FadeGallery = function( options ) {  
        var s = {
          'speed'   : 1500,
          'intervalSpeed' : 6000,
          'items' : '',
          'activeClass' : 'active',
          'lastActiveClass' : 'last-active',
        };
        var oThis = this;
        
        var methods = {
            init : function( s ) {
                //if there are no items do not proceed
                if(!s.items) return;
                //$(s.items + ':first').addClass(s.activeClass);
                
                setInterval( function(){
                	//alert(s.items);
                	methods.change(s);
                }, s.intervalSpeed );
            },
            
            change : function ( s ){//alert(s.activeClass);
            	var $active = $(s.items + '.' + s.activeClass);

                if ( $active.length == 0 ) {//alert($($active).attr('src'));
                	$active = $(s.items + ':last');
                }
                //alert($active.next().length);
                var $next =  $active.next('img').length ? $active.next('img') : $(s.items + ':first');
                //alert($next.attr('src'));

                $active.addClass(s.lastActiveClass);

                $next.css({opacity: 0.0}).addClass(s.activeClass).animate({opacity: 1.0}, s.speed, function() {
                    $active.removeClass(s.activeClass + ' ' + s.lastActiveClass);
                });
            }
        };
        
        
        //core of the plugin
        return this.each(function() {        
            if ( options ) { 
                $.extend( s, options );
            }
           
            //initialize
            methods.init(s);
        });

    };
})( jQuery );
