var BASE_HREF = BASE_HREF || '../';

$.fn.fbGet = function(get, dimension) {
	var result;
	var m = Math[get];
	this.each(function(index) {
		var newResult = $(this)[dimension]();
		result = index ? m(result, newResult) : newResult;
	});
	return result;
};

$.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()
{
	$.fn.kfBox && $('.lightbox').kfBox();
	
	$('table tr:nth-child(even)').addClass('even');
	
	$('#q').inputDefaultText({ text: 'Hledaný výraz'});
	
	// Ovládátka pro dopravu a platbu
	var SPPrices = SPPrices || [
		[1, 1, 0, 1],
		[0, 1, 1, 1]
	];
		
	$('input[id^=order-shipping]').bind('click', function()
	{
		var i = parseInt(this.id.substr(15)) - 1;
		for(var j = 0; j < SPPrices[i].length; j++)
		{
			if(SPPrices[i][j] == 0) $('input#order-payment-' + (j + 1)).attr('disabled', true).attr('checked', false);
			else $('input#order-payment-' + (j + 1)).removeAttr('disabled');
		}
	}).filter(':checked').triggerHandler('click');

	$.fn.kfTooltip && $('td.boxik .ico-help').kfTooltip({ loadContent: function($this, $box)
		{
		    var id = $this.parents('td').attr('id');
			$box.append('<h2>'+data[id]['name']+' - Barva: '+ id + '</h2>');
			$box.append('<div class="inner"><img src="'+data[id]['image']+'"</div>');
		} });
		
			/* Featured articles sliding */
		$.fn.cycle && $('#motives').cycle({
			speed:  1000,
			timeout: 6000,
			pause: 1
		});

	
});

