$(document).ready(function(){	
	bind_hover ();
	bind_cycle_code ();
	bind_cycle ();
	bind_cufon ();
	bind_contact_switcher ();
});

function bind_contact_switcher ()
{
	if ($('.detail').length > 1) {
		$('.detail').hide();

	
		$('.contact .more').click(function(){
			$(this).parent().next().toggle();
			return false;
		});
	
		$('.detail .close').click(function(){
			$(this).parent().parent().toggle();
			return false;
		});
	}
	else {
		$('.content .more,.content .close').hide();
		$('.detail').next().hide();
	}
}

/**
 * hover efekt na menu
 **/
function bind_hover ()
{
	$(".menu li, .path li").hover(
		function() {
			$(this).addClass("sfhover");
		},
		function() {
			$(this).removeClass("sfhover");
		}
	);
}

/**
 * cufon
 **/
function bind_cufon ()
{
	Cufon.replace('#desc h2');
	Cufon.replace('#cycle h2');
	Cufon.replace('.cufon h1');
	// Cufon.replace('.cufon h2');
	// Cufon.replace('.cufon h3');
}

/**
 * cycle
 **/
function bind_cycle ()
{
	$('#cycle') 
	//.before('<div id="nav">') 
	.cycle({ 
	    fx:     'fade', 
	    speed:  1200, 
	    timeout: 10000, 
	    pager:  '#control' 
	});
	
	// pridani nuly pred cislo
	$('#control').each(function()
	{
		$("a", this).prepend('0');
	});

}

/**
 * prepis HTML kodu pro cycle 
 * vstup: ul li seznam s textem, odkazem a obrazkem
 * vystup: layout v divech
 **/
function bind_cycle_code ()
{
	var images = new Array();
	var texts = new Array();
	var headings = new Array();
	var a = new Array();
	var hrefs = new Array();
 
	if ($('#cycle ul li').length > 0)
	{
		// pole s nadpisy, texty a obrazky
		$("#cycle ul li").each(
			function()
			{
				if ( $(this).children().is('img') )
				{
					images.push( $(this).children().attr("src") );
					headings.push( $(this).children().attr("title") );
				}
				else if ( $(this).children().is('a') )
				{
					hrefs.push( $(this).children().attr("href") );
					a.push( $(this).children().text() );
				}
				else
				{
					texts.push( $(this).text() );
				}
			}
		);
 
		// smazani ul li seznamu
		$("#cycle ul").remove();
 
		// novy layout v divech
		if(images.length == texts.length && images.length == headings.length && images.length == hrefs.length)
		{
			for (var i = 0; i < images.length; i++) 
			{
				$("#cycle").append("<div class='item item" + (i+1) + "'><div class='excerpt'><h2>" + headings[i] + "</h2><p>" + texts[i] + "<br /><br /><a href='" + hrefs[i] + "'>" + a[i] + "</a></p></div><img src='" + images[i] + "' alt='' /></div>");
			}	
		}
	}
	else {

	}
}
