
function mycarousel_itemLoadCallback(carousel, state)
{
    // Check if the requested items already exist
    if (carousel.has(carousel.first, carousel.last)) {
        return;
    }
    var data = {
        first: carousel.first,
        last: carousel.last,
        type: jQuery("ul.az_tabs li.az_tabs_sel").attr('id')
    };
    data[AZ_SESS_NAME] = AZ_SESS_VAL;
    jQuery.get(
        'products_carosel_loader.php',
        data,
        function(xml) {
            mycarousel_itemAddCallback(carousel, carousel.first, carousel.last, xml);
        },
        'xml'
    );
};
function mycarousel_itemAddCallback(carousel, first, last, xml)
{
    // Set the size of the carousel
    carousel.size(parseInt(jQuery('total', xml).text()));
    jQuery('image_url', xml).each(function(i) {
        carousel.add(first + i, jQuery(this).text());
    });
    jQuery("img.slide_reflect").reflect({height: 0.2});
};

myCarousel = null; // This will be the carousel object

function mycarousel_onInitCarousel(carousel, state) {
    if (state == 'init') {
        myCarousel = carousel;
    }
}

function mycarousel_init( ){
    jQuery('#mycarousel').jcarousel({
        // Uncomment the following option if you want items
        // which are outside the visible range to be removed
        // from the DOM.
        // Useful for carousels with MANY items.
        initCallback: mycarousel_onInitCarousel, 
		scroll: 6,
        itemVisibleOutCallback: {onAfterAnimation: function(carousel, item, i, state, evt) { carousel.remove(i); }},
        itemLoadCallback: mycarousel_itemLoadCallback
    });
}

jQuery(document).ready(function($) {

    $("ul.az_tabs li:first").addClass("az_tabs_sel");
    $("ul.az_tabs li a").click(function(){
        var li = $(this).parent();
        if ( li.hasClass('az_tabs_sel') ) return false;
        $("ul.az_tabs li").removeClass('az_tabs_sel');
        li.addClass('az_tabs_sel');
        myCarousel.reset();
        return false;
    });

    mycarousel_init();

    var config = {
		 sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)
		 interval: 50, // number = milliseconds for onMouseOver polling interval
		 over: function(e){
            $(this).children('a').addClass('hover');
			if ( $('.az_subcategories',this) )
				if ( $(this).offset().left + $('.az_subcategories', this).width() > $(window).width() )
					$('.az_subcategories',this).css('left',$(this).offset().left - $('.az_subcategories', this).width() + $(this).width() );
			$('.az_subcategories', this).show();
		}, // function = onMouseOver callback (REQUIRED)
		 timeout: 200, // number = milliseconds delay before onMouseOut
		 out: function(e){
            $(this).children('a').removeClass('hover');
			$('.az_subcategories', this).hide();
		} // function = onMouseOut callback (REQUIRED)
	};

	$(".az_main_menu li").hoverIntent( config );

});
jQuery.noConflict();
