Cufon.replace('h1, .content-box h2, .signpost h2, .content-box h3:not(.poll *), .content-box caption, .side-box h2, .cuf', { fontFamily: 'Myriad Pro' });
//Cufon.replace('#main-menu a', { hover: true, textShadow: '#385f15 1px 1px' });
Cufon.replace('.date-box .day, .date-box .month', { fontFamily: 'Franklin Gothic Demi' });

$(document).ready(function()
{
	$.fn.kfBox && $('.lightbox').kfBox();

	$('table tr:nth-child(even)').addClass('even');

	$('a.external').click(function(){return !window.open($(this).attr("href"))});

	$('#q').inputDefaultText({ text: 'Hledaný výraz'});
	$('#qs').inputDefaultText({ text: 'Zadej název své školy'});
	$('#newsletter-email').inputDefaultText({ text: 'Zadejt svůj e-mail'});

	$.fn.autocomplete && $('#qs').autocomplete('/get/autocomplete/run/');

	if($.fn.cycle)
	{
		$('.become-boss-box').append('<div class="paging"></div>');
		$('.become-boss-box .frames').cycle({
			fx: 'scrollHorz',
			easing: 'easeInOutQuint',
			speed: 1500,
			timeout: 5000,
			pause: true,
			pager: '.become-boss-box .paging'
		});

		$('.side-slider').append('<div class="paging"></div>');
		$('.side-slider .frames').cycle({
			fx: 'scrollHorz',
			easing: 'easeInOutQuint',
			speed: 1500,
			timeout: 5000,
			pause: true,
			pager: '.side-slider .paging'
		});

		$('.superindex-slider ul').cycle({
			fx: 'fade',
			speed: 1500,
			timeout: 5000
		});
	}

	/*if(!logoList){
		var logoList = [
			{file: 'logo-palace.jpg', alt: '', title: '', href: ''},
			{file: 'logo-praha.jpg', alt: '', title: '', href: ''},
			{file: 'logo-dpp.jpg', alt: '', title: '', href: ''},
			{file: 'logo-gambrinus.jpg', alt: '', title: '', href: ''},
			{file: 'logo-palace.jpg', alt: '', title: '', href: ''},
			{file: 'logo-praha.jpg', alt: '', title: '', href: ''},
			{file: 'logo-dpp.jpg', alt: '', title: '', href: ''}
		];
	}//*/
	if(typeof logoList != 'undefined'){
		setTimeout(function(){
			$('.partners-box-rotator li>a').kfImageRotator({
		      rowTimeOut: 5000,
		      imageTimeOut: 100,
		      fadeOut: 250,
		      fadeIn: 250,
		      imagesPath: '',//../img/samples/
		      imagesList: logoList
		    });
		}, 5000);
	}

	/* vkládání flashe */
	$('.flash-banner').each(function(){
		flashsize = $(this).find('a').attr('data-flashsize');
		flashsize = flashsize.split("x");
		$(this).flash(
		{
			src: $(this).find('a').attr('href'),
			width: flashsize[0],
			height: flashsize[1],
			wmode: 'opaque',
			flashvars: {}
		});
		$(this).find('.alt').css("display","none");
	});

	$('.flash-player').each(function(){
 		flashsize = $(this).find('a').attr('data-flashsize');
 		flashsize = flashsize.split("x");
 		$(this).flash(
        {
             src: '/inc/flash/player.swf',
             width: flashsize[0],
             height: flashsize[1],
             wmode: 'opaque',
             allowfullscreen: true,
             flashvars: {file: $(this).find('a').attr('href'), searchbar: 'false', autostart: 'false', frontcolor: '0x666666', image: $(this).find('img').attr('src')}
        });
     	// nebudeme zobrazovat alt
     	$(this).find('.alt').css("display","none");
	});

	// označení spamu
	$('a.ajax').click(function(){ $.get($(this).attr("href")); alert('Bylo odesláno hlášení');return false; });

	/* Postupné vybírání kraj-město-škola-fakulta selectů */
	if($('#form-county').size())
	{
		$('#form-county').bind('change', function(){
			$('#form-cityx, #form-school, #form-faculty').parent().addClass('hidden');
			var id = $(this).val();
			if(id != '')
			{
				$('#form-cityx').parent().addClass('loading').removeClass('hidden');
				$.get('/get/cities/' + id + '/', function(html){ $('#form-cityx').parent().removeClass('loading').html(html); bindCity(); })
			}
		});

		var bindCity = function()
		{
			$('#form-cityx').bind('change', function(){
				$('#form-school, #form-faculty').parent().addClass('hidden');
				var id = $(this).val();
				if(id != '')
				{
					$('#form-school').parent().addClass('loading').removeClass('hidden');
					$.get('/get/schools/' + id + '/', function(html){ $('#form-school').parent().removeClass('loading').html(html); bindSchool(); })
				}
			});
		};

		var bindSchool = function()
		{
			$('#form-school').bind('change', function(){
				$('#form-faculty').parent().addClass('hidden');
				var id = $(this).val();
				if(id != '')
				{
					$('#form-faculty').parent().addClass('loading').removeClass('hidden');
					$.get('/get/faculties/' + id + '/', function(html){
						$('#form-faculty').parent().removeClass('loading').html(html);
						if($('#form-faculty').parent().find('option').size() <= 1) $('#form-faculty').parent().addClass('hidden');
					})
				}
			});
		};
	}
	if($('#form-county2').size())
	{
		$('#form-county2').bind('change', function(){
			$('#form-cityx2, #form-school2, #form-faculty2').parent().addClass('hidden');
			var id = $(this).val();
			if(id != '')
			{
				$('#form-cityx2').parent().addClass('loading').removeClass('hidden');
				$.get('/get/cities2/' + id + '/', function(html){ $('#form-cityx2').parent().removeClass('loading').html(html); bindCity(); })
			}
		});

		var bindCity = function()
		{
			$('#form-cityx2').bind('change', function(){
				$('#form-school2, #form-faculty2').parent().addClass('hidden');
				var id = $(this).val();
				if(id != '')
				{
					$('#form-school2').parent().addClass('loading').removeClass('hidden');
					$.get('/get/schools2/' + id + '/', function(html){ $('#form-school2').parent().removeClass('loading').html(html); bindSchool(); })
				}
			});
		};

		var bindSchool = function()
		{
			$('#form-school2').bind('change', function(){
				$('#form-faculty2').parent().addClass('hidden');
				var id = $(this).val();
				if(id != '')
				{
					$('#form-faculty2').parent().addClass('loading').removeClass('hidden');
					$.get('/get/faculties2/' + id + '/', function(html){
						$('#form-faculty2').parent().removeClass('loading').html(html);
						if($('#form-faculty2').parent().find('option').size() <= 1) $('#form-faculty2').parent().addClass('hidden');
					})
				}
			});
		};
	}

});

$.fn.inputDefaultText = function(options)
{
	options = $.extend({
		text: 'Hledany vyraz'
	}, options);

	return this
		.val(options.text)
		.bind('focus', function(){ if(this.value == options.text) this.value = ''; })
		.bind('blur', function(){ if(this.value == '') this.value = options.text; });
};


$.fn.kfImageRotator = function(options)
{
	var o = $.extend({
		rowTimeOut: 3000,
		imageTimeOut: 20,
		fadeOut: 150,
		fadeIn: 150,
		imagesList: [],
		imagesPath: ''
  	}, options);

	var $elems = $(this);
	var length = $elems.size();
	var imgBuffer = [];
    var rotIndex = -1;
    var imagesListLength = o.imagesList.length;

    var rotateCountdown = length;
    var preloadCountdown = 0;
    var timeOutReady = false;

    init();
    return this;

    function init()
    {
		prepareNextRound();

    };

	function rotate()
	{
		rotateCountdown = length;
		$elems.each(function(i)
		{
			var that = this;
			setTimeout(function(){ rotateSingle($(that), i); }, o.imageTimeOut * (i+1));
		});
	};

	function rotateSingle($e, i)
	{
		var targetHeight = imgBuffer[i][0].height;
		var targetWidth = imgBuffer[i][0].width;

		$('img', $e).animate({ height: '0', width: 143, marginTop: 53 }, o.fadeOut, 'easeOutCirc' , function(){
				var href = $.data(imgBuffer[i][0], 'href');
				if(href) $e.filter('a').attr('href', href);
				else $e.filter('a').removeAttr('href');
				imgBuffer[i]
					.css({ height: '0', width: targetWidth, marginTop: 53})
					.appendTo($e.empty())
					.animate({ height: targetHeight + 'px', marginTop: (107 - targetHeight)/2 + 'px' }, o.fadeIn, 'easeInCirc');
			});

		var that = this;
		if(--rotateCountdown <= 0) setTimeout( prepareNextRound, o.imageTimeOut * (i+1));
	};

	function prepareNextRound()
	{
		preloadCountdown = $elems.size();
		imgBuffer = [];
		timeOutReady = false;
		var that = this;
		for(var i = 0, l = preloadCountdown; i <l; i++)
		{
			rotIndex = (rotIndex + i+1) % imagesListLength;
			var img = document.createElement('img')
			imgBuffer[i] = $(img)
				.bind('load', function(){ --preloadCountdown; preloadCallback(); })
				.attr({
					'src': o.imagesPath + o.imagesList[rotIndex].file,
					'alt': o.imagesList[rotIndex].alt,
					'title': o.imagesList[rotIndex].title
				});

			if(o.imagesList[rotIndex].href) $.data(img, 'href', o.imagesList[rotIndex].href);
		}
		setTimeout(function(){ timeOutReady = true; preloadCallback(); }, o.rowTimeOut);
	};

	function preloadCallback()
	{
		if(preloadCountdown <= 0 && timeOutReady) rotate();
	};


};

