/*
*
* tabs
*
*/

jQuery.fn.init_recatalog_tabs = function (){
    var context = this;
    var config = {
        onClick: function(event, tabIndex) {

		    // the "this" variable is a pointer to the API. You can do a lot with it.
		    var tabPanes = this.getPanes();

             /*
             By returning false here the default behaviour is cancelled.
            This time another tab cannot be clicked when "terms" are not accepted
            */
            tabPanes.each(function (index){

                var $st = jQuery(this).find('.slideshow_tabs');
                if (! $st.length){
                    return
                }
                if(index === tabIndex){
                    $st.data('slideshow').play();
                }
                else {
                    $st.data('slideshow').stop();
                }
            });
	    }    
    };


//    jQuery(".tabs",context).tabs("div.panes > div",config);
    jQuery(".productformTabs",context).tabs("> .productformPanes > div",config);
    return context;

};


/*
*
* imagetabs
*
*/

jQuery.fn.init_recatalog_gallery = function (){
    var context = this;

    jQuery('.productformGallery',context).boxscrollable({horizontal:true,
//                                                     number_items:4, 
                                                     minheight:100, 
                                                     minwidth:100,
                                                     easing:'easeInOutCirc'});

    jQuery('.productformGallery img',context).click(function (evt){
        var $this = jQuery(this);
        var $link = jQuery(this).parent();
        var url = $link.attr('href');

        if ($link.hasClass('selected')){
            return false;
        }

        $link.parents('.productformGallery').find('a').removeClass('selected');
        $link.addClass('selected');

        var newimg = jQuery('<div class="imagebig"><img src="' + url + '"/></div>').css('opacity','0').appendTo('#productformImage_big');
        newimg.children('img').bind('load',function (evt){
            var $div = jQuery(this).parent();
            $div.animate({opacity:1});
            $div.siblings().animate({opacity:0},function (){
                jQuery(this).remove();
            });
        });

//        jQuery('#productformImage_big img').attr('src',url);
        return false;
    });
    jQuery('.productformGallery img:first',context).click();


    return context;

};


/*
*
* init
*
*/

(function($){
$(document).ready(function (){
    $(this).init_recatalog_tabs().init_recatalog_gallery();
});
})(jQuery);



