
$.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; });
};

$(document).ready(function()
{
	// $('.att-images a').kfBox();

	$('a.external').click(function(){window.open(this.href);return false;});

	$('#q').inputDefaultText({ text: 'Hledaný výraz'});
	$('#newsletter').inputDefaultText({ text: 'Váš e-mail'});

 	$.fn.cycle && $('.partners').cycle({
		fx: 'fade',
		pause: 1,
		speed: 1000,
		timeout: 4000
		}
	);

	/* vkládání flashe */
	$.fn.flash && $('.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");
	});

	$(".share-video").click(function(){
		$(this).select();
	});

});

$(window).load(function()
{
/*
	var $prevnext = $('<div class="prevnext"><a href="#" class="btn-prev">předchozí</a> <a href="#" class="btn-next">další</a></div>');
    $('.intro-box .article-list').prepend($prevnext);
    var introScroller = new kff.widgets.Scroller('.intro-box .article-list .scroll-box', {
		scrollWidth: 243/3,
		carouselWidth: 243,
		prev: '.intro-box .article-list .btn-prev',
		next: '.intro-box .article-list .btn-next',
		axis: 'y',
		speed: 600
	});
	introScroller.activate();
*/

	var autoScrollTimer = null;
	var bindAutoScroll = function()
	{
		clearInterval(autoScrollTimer);
		autoScrollTimer = setInterval(function(){
			// introScroller.scrollNext();
			$next = $('.col-left .col-news-home1 .news ul li.active').next();
			if($next.size() == 0)
			{
				$('.col-left .col-news-home1 .news ul li:first-child').triggerHandler('mouseenter');
				// introScroller.scrollFirst();
			}
			else
			{
				$('.col-left .col-news-home1 .news ul li.active').next().triggerHandler('mouseenter');
			}
		}, 5000);
	}

	$('.col-left .col-news-home1 .news ul li').bind('mouseenter', function(){
		if($(this).hasClass('active')) return false;
		$('.col-left .col-news-home1 .news ul li.active').removeClass('active');
		$(this).addClass('active');
		var fullImageUrl = this.getAttribute('data-fullimage');
		var title = this.getAttribute('title');
		var $oldImg = $('.col-videobox .video-box img').fadeOut(500);
		$('.col-videobox a.btn-play').attr('href', $('a', this).attr('href'));
		var $fullImage = $('<img />');
		$fullImage.bind('load', function(){
			$fullImage.css('opacity', 0);
			$oldImg.after($fullImage);
			$oldImg.remove();
			$fullImage.fadeTo(500, 1);
			$('.col-videobox .video-desc').html(title);
		}).attr('src', fullImageUrl);
	});
	$('.col-left .col-news-home1 .news ul li').bind('click', function(event){
		window.location = $('a', this).attr('href');
	});
	$('.col-left .col-news-home1 .news ul li a').bind('click', function(event){
		event.preventDefault();
	});
	$('.col-left .col-news-home1 .news').bind('mouseenter', function(event){
		clearInterval(autoScrollTimer);
	}).bind('mouseleave', function(event){
		bindAutoScroll();
	});

	bindAutoScroll();
});

