//Load gallery theme
Galleria.loadTheme('/js/libs/galleria/themes/classic/galleria.classic.js');

$(document).ready(function () {    
    // jQuery SmoothScroll | Version 10-04-30
    $('a[href*=#]').click(function() {

       // duration in ms
       var duration=1000;

       // easing values: swing | linear
       var easing='swing';

       // get / set parameters
       var newHash=this.hash;
       var target=$(this.hash).offset().top;
       var oldLocation=window.location.href.replace(window.location.hash, '');
       var newLocation=this;

       // make sure it's the same location      
       if(oldLocation+newHash==newLocation)
       {
          // animate to target and set the hash to the window.location after the animation
          $('html:not(:animated),body:not(:animated)').animate({ scrollTop: target }, duration, easing, function() {

             // add new hash to the browser location
             window.location.href=newLocation;
          });

          // cancel default click action
          return false;
       }
    });
	
			
	//product catalogue	
	$('#product_menu').tabify();
	//$('.product_list a').tipsy({fade: true, gravity: 'n' });
	
	//this is for browsers that don's support css3
	$('.product_list li:nth-child(4n)').addClass('end-row');
	$('.product_list li:nth-child(4n+1)').addClass('first-row');

    //open the products in a modal window
	$('.tabify_content a').fancybox({
	    hideOnOverlayClick: false,
		transitionIn: 'fade',
		transitionOut: 'fade',
		speedIn: 600, 
		speedOut: 200,
		autoScale: false,
		autoDimensions: false,
		height: 540,
		width: 910,
        type: 'ajax',
        overlayOpacity: 0.5,
        ajax: {
               dataFilter: function(data) {
                  return jQuery(data).find('#contentbody')[0];
               }
           },
           onComplete: startGalleria           
        });
        
    function startGalleria() {
        //run galleria and add some options
        $('#galleria').galleria({
            image_crop: true,
            data_config: function(img) {
                // will extract and return image captions from the source:
                return  {
                    title: $(img).parent().next('strong').html(),
                    description: $(img).parent().next('strong').next().html()
                };
            }
        });       
    }; 

});
