/* ----------------------------------------------------------------------------------------------------------
*
*	JAVASCRIPT INIT
*	Michal Pelech (www.michalpelech.cz, info@michalpelech.cz)
*
/* ---------------------------------------------------------------------------------------------------------- */

$(document).ready(function(){

	Cufon.replace('#nav a, .footer-nav a', { hover: true })('#content > h1, #content > h2, .contact h2, .support h2, .projects a');
	
	$('.footer-nav li').hover(function(){
	
		var itemId = $(this).attr('id');
		$('#.projects .project, .projects .project a').css('height', '0px').hide();
	
		if (!($('.projects').hasClass('open'))) {
			$('.projects, #' + itemId + ' .project, #' + itemId + ' .project a').stop(true, true).animate({
				height: '205px'
			}, 800, function(){
				$('.projects').addClass('open');
			});
		} else {
			$('#' + itemId + ' .project, #' + itemId + ' .project a').show().css('height', '205px');
		}
		
		
	});
	
	$('.footer-nav').mouseleave(function(){

		$('.projects, .projects .project, .projects .project a').stop(true, true).animate({
			height: '0px'
		}, 800, function(){
			$('.projects').removeClass('open');
		});

	});
	
	$('.project a, a.open, a.external').click(function(){
		window.open($(this).attr('href'));
		
		return false;
	});
	
	$('#footer').find('.green').hover(function(){
		var $tooltip = $(this).find('.tooltip');
		$tooltip.stop().fadeIn(500);
	}, function(){
		var $tooltip = $(this).find('.tooltip');
		$tooltip.stop().fadeOut(500);
	});

});

function initTextScroll(){

	$(function() {

		var scrollPane = $('#content-slider');
		var scrollContent = $('.content-slider-in');
		var pos = 0;
		var posun = 100;

		$('.btn-down').live('click',function(){
			if( scrollContent.height() > scrollPane.height() ){
				pos+=posun;
				var maxScroll = scrollContent.height() - scrollPane.height() +33;
				if(maxScroll<pos) pos=maxScroll;
				scrollContent.animate({marginTop: -(pos) }, 1000);
			}
			else { 
				scrollContent.css('margin-top', 0); 
			}
		});

		$('.btn-up').live('click',function(){	
			if( scrollContent.height() > scrollPane.height() ){
				pos-=posun;
				var maxScroll = scrollContent.height() - scrollPane.height() +33;
				if(pos<0) pos=0;
				scrollContent.animate({marginTop: -(pos) }, 1000);
			}
			else { 
				scrollContent.css('margin-top', 0); 
			}
		});

	});
}

