/* ----------------------------------------------------------------------------------------------------------
*
*	JAVASCRIPT INIT
*	Michal Pelech (www.michalpelech.cz, info@michalpelech.cz)
*
/* ---------------------------------------------------------------------------------------------------------- */

$(document).ready(function(){

	// Cufon
	Cufon.replace('.product h3 a', { hover: true });
	Cufon.replace('#nav a', { hover: true });
	Cufon.replace('.right-col h1, .right-col h2, #footer .phone, #footer .right-col strong');
	
	// Center slider controls
	var sliderControlsWidth = 0;
	$('#slider .slider-controls a').each(function(){
		sliderControlsWidth += 15;
	});
	$('#slider .slider-controls').css({
		'width': sliderControlsWidth + 'px',
		'margin-left': (((sliderControlsWidth + 20) / 2) * -1) + 'px'
	});
	
	// Show categories
	$('#slider #categories').hover(function(){
		$(this).find('ul').stop(true, true).animate({
			'bottom': '0px'
		}, 500);
	}, function(){
		$(this).find('ul').stop(true, true).animate({
			'bottom': '-101px'
		}, 500);
	});
	
	// Carousel
	jQuery(".slider ul").jcarousel({
		 auto: 5,
		 wrap: 'last',
		 animation: 1000,
		 scroll: 1,
		 initCallback: initialize,
		 itemLoadCallback: change,
		 // This tells jCarousel NOT to autobuild prev/next buttons
		 buttonNextHTML: null,
		 buttonPrevHTML: null
	});

});

function initialize(carousel) {
    jQuery('.slider-controls a').bind('click', function() {
        carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
        return false;
    });

    jQuery('.slider-next').bind('click', function() {
        carousel.next();
        return false;
    });

    jQuery('.slider-prev').bind('click', function() {
        carousel.prev();
        return false;
    });
};

function change(carousel) {
    for (var i = carousel.first; i <= carousel.last; i++) {
          $('.slider-controls a').each(function(){
               if ($(this).html() == i){
                    $(this).addClass('active');
               } else {
                    $(this).removeClass('active');
               }
          });
    }
}
