$().ready(function(){
	
	//mainmenu
	$('#menu').removeClass('nojs');
	
	var menuCount = $('#menu li').length;
	
	for(i=0; i<menuCount; i++){
		$('#menu li:eq('+i+') .i').width( $('#menu li:eq('+i+') .i').width() );
		$('#menu li:eq('+i+') .i').css( 'margin-left', ($('#menu li:eq('+i+')').width() - $('#menu li:eq('+i+') .i').width()) /2 );
		$('#menu li:eq('+i+') .i').css( 'margin-right', ($('#menu li:eq('+i+')').width() - $('#menu li:eq('+i+') .i').width()) /2 );
	}
	$('#menu li a').mouseover(function() {
		$('.hover', this).stop().fadeTo(300, 1);
	});
	$('#menu li a').mouseout(function() {
		$('.hover', this).stop().fadeTo(300, 0);
	});
	
	//scroll to top
	$('.up a').click(function(){
    	$('html, body').animate({scrollTop: 0}, 300);
    	return false;
	});
	
	//scroll to target position
	$('.jump_to_loc').click(function(){
		var jump = $(this).attr('href');
		var new_position = $(jump).offset();
		$('html, body').animate({scrollTop: new_position.top}, 300);
		return false;
	});
	
});

//equal column height
	
var c1, c2, c3;

function eq_column(cName){
	
	c1 = $(cName + ':eq(0)').height();
	c2 = $(cName + ':eq(1)').height();
	c3 = $(cName + ':eq(2)').height();
	
	if( (c1 > c2) && (c1 > c3) ){
	
		$(cName + ':eq(1)').height(c1);
		$(cName + ':eq(2)').height(c1);
		
	}else if( (c2 > c1) && (c2 > c3) ){
	
		$(cName + ':eq(0)').height(c2);
		$(cName + ':eq(2)').height(c2);
	
	}else{
	
		$(cName + ':eq(0)').height(c3);
		$(cName + ':eq(1)').height(c3);
	
	}
	
}//eq_column

//gallery
function gallery(container, prevBtn, nextBtn){
var pView = 0;
	var plength = $(container + ' li').length;
	var pwidth = $(container + ' li img').width();
	
	chBtn();
	
	$(prevBtn).click(function() {
	
		if( pView != 0 ){
			$(container).animate({ left: '+='+pwidth }, 500 );
			$(container + ' li:eq('+pView+') img').stop().fadeTo(200, 0);
			$(container + ' li:eq('+(pView - 1)+') img').fadeTo(0, 0);
			$(container + ' li:eq('+(pView - 1)+') img').stop().delay(300).fadeTo(200, 1);
			pView--;
			chBtn();
		}
	});
	
	$(nextBtn).click(function() {
		if( pView != (plength - 1) ){
			$(container).animate({ left: '-='+pwidth }, 500 );
			$(container + ' li:eq('+pView+') img').stop().fadeTo(200, 0);
			$(container + ' li:eq('+(pView + 1)+') img').fadeTo(0, 0);
			$(container + ' li:eq('+(pView + 1)+') img').stop().delay(300).fadeTo(200, 1);
			pView++;
			chBtn();
		}
	});

	function chBtn(){
		if( pView == 0 ){
			$(prevBtn).hide();
		}else{
			$(prevBtn).show();
		}
		if( pView == (plength - 1) ){
			$(nextBtn).hide();
		}else{
			$(nextBtn).show();
		}
	}//chBtn

}//gallery

function slideshow(){
		
	var intId;
	var gMenuIndex = 0;
	
	$('#lead #imgCon img').fadeTo(0,0);
	$('#lead #imgCon img:eq(0)').fadeTo(500,1);
	
	pokazSlajdow();
	
	$("#choise li").hover(
		function () {
			clearInterval(intId);
			addHover($('#choise li').index(this));
			$('#lead #imgCon').stop().fadeTo(500,0.4);
			$('#lead #headline').stop().fadeTo(500,0);
		}, 
		function () {
			intId = setInterval(chImgInt, 6000);
			removeHover();
			$('#lead #imgCon').stop().fadeTo(500,1);
			$('#lead #headline').stop().fadeTo(500,1);
		}
	);
	
	function chImg(){
		
		$('#lead #imgCon img').stop().fadeTo(500,0);
		$('#lead #imgCon img:eq(' + gMenuIndex + ')').stop().fadeTo(500,1);
		
	}
	
	function pokazSlajdow(){
        intId = setInterval(chImgInt, 6000);
    
    }//pokazSlajdow
    
    function chImgInt(){
    	if( gMenuIndex < ($('#lead #imgCon img').length - 1) ){
			gMenuIndex++;
		}else{
			gMenuIndex = 0;
		}
    	chImg();
    }
    
    function addHover(id){
    	$('<div class="imghover o' + id + '"></div>').insertBefore('#lead #imgCon');
    	$('#lead .imghover').stop().fadeTo(0,0);
		$('#lead .imghover').stop().fadeTo(500,1);
    }
    
    function removeHover(){
    	$('#lead div').filter(".imghover").remove();
    }
    
}//slideshow
