$(document).ready(function(){

	// categories tree, selecting parents and hiding...	
	$('#categories ul.sub').hide();	// hide all menu links

	$('#categories a.current').parents('ul').show();
	$('#categories a.current').parents('ul li').children('a.head').addClass('current');
	
	$('#categories a.current').parent().children('ul').show();
	$('#categories a.current').parent().parent().children('ul').show();
	
	
	
	// reordering categories memu, active on top
	var activeList = $('#categories > li a.head.current').parent('li').html();

	if(activeList != null && $('#categories a.head').size() > 1) {	
		
		$('#categories > li a.head.current').parent('li').remove();
		$('<li>' + activeList + '</li>').insertBefore('#categories li:first');
	}
	
	
	
	// similar products on dateil page
	$(".similar-products").jCarouselLite({
        btnNext: ".next",
        btnPrev: ".prev",
        auto: 5000,
    	speed: 1000,
    	visible: 3,
    });
	
	
	
	
	// confirmation dialog
	$.fn.extend({
        triggerAndReturn: function (name, data) {
            var event = new $.Event(name);
            this.trigger(event, data);
            return event.result !== false;
        }
    });

   $('a[data-confirm], button[data-confirm], input[data-confirm]').live('click', function (e) {
        var el = $(this);
        if (el.triggerAndReturn('confirm')) {
            if (!confirm(el.attr('data-confirm'))) {
                return false;
            }
        }
    });
    
    
    
    // search form focus animations...
    $('#search input[type=text]').focus(function() {
    	
    	if($(this).val() == 'Chci si koupit...')
    		$(this).val('');
    		
    	$(this).animate({
    		width: 250,
    		left: '-100'
			
    	}, 150);
		
    });
    
    $('#search input[type=text]').focusout(function() {
    	
    	if($(this).val() == '')
    		$(this).val('Chci si koupit...');
    		
    	$(this).animate({
    		width: 150,
    		left: 0
			
    	}, 150);
		
    });
    
    $('#searchSubmit').click(function() {	// send form
		
		$(this).closest('form').submit()	
    });
    
    
    
    
    
    // main poge 			
	$('.categories img').tipsy({
		title : 'alt',
		gravity : 'ne',
		delayIn : 500,
	});

	$('.categories img').hide();
	$('.categories img').fadeIn('slow');
	

	
	
	//filter form
	$('.filter-form input[type=submit]').hide();
	
	$('.filter-form').change(function() {
		
		$(this).closest('form').submit();
		
	});
	
	
	
	// reordering categories memu, active on top
	var activeList = $('#categories > li a.head.current').parent('li').html();

	if(activeList != null && $('#categories a.head').size() > 1) {	
		
		$('#categories > li a.head.current').parent('li').remove();
		$('<li>' + activeList + '</li>').insertBefore('#categories li:first');
	} 
	
	
	
	
	//detail page	
	$('.product-title img').tipsy({
		title : 'alt',
		gravity : 'nw',
	});
	
	$('.product-title .discount').tipsy({
		gravity : 'e',
	}); 

	

});


