
var Class_Main = function(){
}

Class_Main.prototype = {
    bind: function()
    {		
        if($('#banner_slide.load_slider').length)
        {
            $('#banner_slide').before('<div id="baner_nav">').cycle({ 
                fx:     'fade', 
                speed:   1000, 
                timeout: 9000, 
                pager:  '#baner_nav' 
            });
        }
                
        if($('#outer').length)
        {
            $('#outer ul').cycle({ 
                fx:     'fade', 
                speed:   1000, 
                //timeout: 4000, 
                timeout: 0,
                pager:  '#jcarousel-control',
                activePagerClass:'active',
                onPagerEvent: function(zeroBasedSlideIndex, slideElement) {
                    var sObj = $('#jcarousel-control a:eq(' + (zeroBasedSlideIndex) + ')');
                    
                    if (sObj.attr('href') != '#')
                    {
                        var base = $('base').attr('href');
                        window.location = base + sObj.attr('href');
                    }
                },
                pagerAnchorBuilder: function(idx, slide) {
                    // return sel string for existing anchor
                    return '#jcarousel-control a:eq(' + (idx) + ')';
                },
                next:'#mycarousel-next',
                prev:'#mycarousel-prev'
            });
            
            $('#jcarousel-control a').hover(function(){
                var index = $(this).index();
                $('#outer ul').cycle(index);
            }, function(){
                return;
            });
        }
		
		$('.first_level').click( function(){
		
			$('.first_level').next().slideUp(200);
			
			var ulObj = $(this).next();
			
			if(ulObj.is(':visible'))
			{
				ulObj.slideUp(200);
			}
			else
			{
				ulObj.slideDown(200);
			}
			
			return false;	
		});
        
        //produktu filtras pagal produkto paskirti
        $('#product_filter').click( function(){
			if($('#product_filter_items').is(':visible'))
			{
				$('#product_filter_items').slideUp(500);
			}else
			{
				$('#product_filter_items').slideDown(500);
			}
		});        

        $('a.fancybox').fancybox();
        
        //Centruojam slaiderio navigaciją
        var slideControlWidth = $('.slider_control').width();
        var slideControlLeftMargin = Math.round($('.slider_control').width()/2);        
        $('.slider_control').css('margin-left','-'+slideControlLeftMargin+'px');
        
        $('#content a[href^=#]:not(.tabs_nav li a)').bind('click', function(event) {
            event.preventDefault();
            var name = $(this).attr('href').substr(1);

            if(!name)
            {
                return false;
            }

            if($('a[name='+name+']').length)
            {
                $.scrollTo('a[name='+name+']', 800, {offset: {top: -15}});
            }
            else if($('#'+name).length)
            {
                $.scrollTo('#'+name, 800, {offset: {top: -15}});
            }

            return false;
        });
        
        $("a[rel='fancybox']").fancybox();
        
        //Product image script
        $('.small li').click( function()
        {            
            $('.big a').each(function(index) {
                $(this).css('display','none');
            });
                        
            var imgindex = $(this).index();           

            $('.big a:eq('+imgindex+')').css('display','block');
                                    
            return false;
        });
        
        
    }    
}

var Main = new Class_Main();

function mycarousel_initCallback(carousel) {
	$('#jcarousel-control a').bind('click', function() {
        if($(this).attr('href') != '#')
        {
            return true;
        }
        
		$('#jcarousel-control a').removeClass('active');
		carousel.scroll($.jcarousel.intval($(this).find('.nav_index').text()));
		$(this).addClass('active');
        
		return false;
	});					

	$('#mycarousel-next').bind('click', function() {
		carousel.next();
		$('#jcarousel-control a.active:not(:last-child)').next().addClass('active');
		$('#jcarousel-control a.active + a.active').prev().removeClass('active');
		return false;
	});

	$('#mycarousel-prev').bind('click', function() {
		carousel.prev();
		$('#jcarousel-control a.active:not(:first-child)').prev().addClass('active');
		$('#jcarousel-control a.active + a.active').removeClass('active');
		return false;
	});
};

$(document).ready(function(){
    Main.bind();
    /*
	$("#mycarousel").jcarousel({
		visible:1,
		scroll: 1,
		initCallback: mycarousel_initCallback,
		// This tells jCarousel NOT to autobuild prev/next buttons
		buttonNextHTML: null,
		buttonPrevHTML: null
	});
    */
    
    if($('#product_slider').length)
    {
        $('#product_slider').jcarousel({		
            visible:4,
            scroll: 1
        });
    }
    
    if($('#galery_slide ul').length)
    {
        $('#galery_slide').jcarousel({		
            visible:6,
            scroll: 6
        });
    }
});

