window.BASE_HREF = window.BASE_HREF || '../';

Cufon.replace('.signpost ul li h2, .partners-box h2');

$(document).ready(function()
{
	$('.jshide').hide();
	$.fn.kfBox && $('.lightbox').kfBox();

	$('#q').inputDefaultText({ text: 'Hledaný výraz'});
	
	var introSlider = new KIntroSlider();
	introSlider.init();
	
});

$.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; });
};


var KIntroSlider = function()
{
	this.$sliderBox = $('.intro-slider');
	this.$frames = this.$sliderBox.find('.frame');
	
} 

KIntroSlider.prototype.init = function()
{
	var h = 0, that = this;
	this.active = 0;
	this.timer = null;
	this.$paging = $('<div class="slider-paging"/>');
	this.$frames.each(function(i)
	{
		that.$paging.append('<a href="#" class="page">' + i + '</a>');
		var ch = $(this).height();
		h = ch > h ? ch : h;
	});
	this.$prev = $('<a href="#" class="prev">&lt;</a>').prependTo(this.$paging);
	this.$next = $('<a href="#" class="next">&gt;</a>').appendTo(this.$paging);
	
	this.$frames.height(h);
	
	
	this.$framesWrapper = $('<div/>').prependTo(this.$sliderBox);
	this.$framesWrapper.append(this.$frames);
	this.$framesWrapper.css({ position: 'relative', height: h, overflow: 'hidden'});
	this.$paging.appendTo(this.$sliderBox);
	this.$frames.hide();
	
	this.$paging.find('.page').bind('click', $.proxy(function(event){
		this.show(parseInt($(event.currentTarget).text()));
		return false;
	},this));
	
	this.$paging.find('.next').bind('click', $.proxy(function(event){
		this.show((this.active + 1) % this.$frames.size() );
		return false;
	},this));
	
	this.$paging.find('.prev').bind('click', $.proxy(function(event){
		this.show((this.active - 1 + this.$frames.size()) % this.$frames.size());
		return false;
	},this));
	
	this.show(0);
}

KIntroSlider.prototype.show = function(i)
{
	if(i != this.active) this.$frames.eq(this.active).stop().fadeTo(600, 0, function(){ $(this).hide(); });
	this.$frames.eq(i).stop().css({opacity: 0}).show().fadeTo(300, 1);
	this.$paging.find('.page').removeClass('active').eq(i).addClass('active');
	this.active = i;
	clearTimeout(this.timer);
	this.timer = setTimeout($.proxy(function(){ this.next(); }, this), 5000);
}

KIntroSlider.prototype.next = function()
{
	this.show((this.active + 1) % this.$frames.size());
}

