// JavaScript Document
jQuery(function(){
	jQuery('ul.nav').superfish();
	});

function mycarousel_initCallback(carousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
       carousel.startAuto();
   });
};

var switchOpenClosed = function(productGroupHeader, productGroupTable, productGroupOpener) {
  if(productGroupHeader.hasClass('opened')) {
	productGroupTable.hide();
	productGroupHeader.removeClass('opened');
	productGroupOpener.html('Otvori');
	productGroupHeader.addClass('closed');
  }
  else {
	productGroupTable.show();
	productGroupHeader.removeClass('closed');
	productGroupOpener.html('Zatvori');
	productGroupHeader.addClass('opened');
  }
}

jQuery(document).ready(function() {
    jQuery('#mycarousel').jcarousel({
        auto: 2,
        wrap: 'last',
        initCallback: mycarousel_initCallback
    });
	
	$('.hide-email').each(function() {
      var $email = $(this);
      var address = $email.text().replace(/\s*\[at\]\s*/, '@')
                                 .replace(/\s*\[dot\]\s*/g, '.');
      $email.html('<a href="mailto:' + address + '">' + address + '</a>');
	});
   
	// form stuff
	$('#form-order-form .row div, #form-order-form .row textarea, #form-order-form .row select, #form-order-form .row input').focus(function(){
		$(this).parents('.row').addClass("order-form-highlight");
	}).blur(function(){
		$(this).parents('.row').removeClass("order-form-highlight");
	});
	
	$('.product-group-opener a').click(function(){
	  var productGroupHeader = $(this).parent().parent();
	  var productGroupTable = productGroupHeader.next();
	  var productGroupOpener = $(this);
	  switchOpenClosed(productGroupHeader, productGroupTable, productGroupOpener);
	});
	$('a.product-group-title').click(function(){
	  var productGroupHeader = $(this).parent();
	  var productGroupTable = productGroupHeader.next();
	  var productGroupOpener = $(this).next().children();
	  switchOpenClosed(productGroupHeader, productGroupTable, productGroupOpener);
	});

});

$(document).ready(function() {
 $(".fancy").fancybox();
 });

