/* Nupi homepage slideshow recoded */

var fadingImgId = false;
var timer = null;
var inFade = false;
var clicked = false;
var items = null;

var keepCircleUp = false;
var keepCircleEnabled = true;

var currentSlideshowDivision = '';

// Slider.js START (moved here)
jQuery(slider_init);
function slider_init(){


	var slides = jQuery('li','.slider').mouseover(function(){
			var self = this;
			if (typeof slides.timer != 'undefined') window.clearTimeout(slides.timer);
			slides.timer = window.setTimeout(function(){
				do_slide.apply(self);
			},50);
		});
	jQuery('.closed span',slides).hide();


	jQuery(".closed img").animate({opacity: "0.3"}, 10);


    jQuery('li.open','.slider').click(slider_click);
}

function do_slide(){
			if (jQuery(this).is('.open')) return;
			var myself = this;
			var slider = jQuery(this).parents('.slider:first');
			jQuery('li span',slider).stop(true,true).hide();
			jQuery('li.open',slider).animate({width:'53px'},{duration:500,easing:'easeInOutExpo',queue:false}).addClass('closed').removeClass('open');
			jQuery(this).animate({width:'149px'},{duration:500,easing:'easeInOutExpo',queue:false,complete:function(){
				//show_slidetext.apply(myself);
			}}).addClass('open').removeClass('closed');
    jQuery('li.open',slider).click(slider_click);

			jQuery(".closed img").animate({opacity: "0.3"}, 500);
			jQuery(".open img").animate({opacity: "1"}, 500);
}

function slider_click()
{
    var division = jQuery(this).attr("id").substr(6);
    if(do_slide.current_division==division) return; // prevent unnecessary fade
    do_slide.current_division=division;
    clearTimeout(window.timeoutscroll);

    if (currentSlideshowDivision.length > 1)
    {
        // slider was already clicked so we just need to stop previoues division slideshow
        jQuery('#' +currentSlideshowDivision + '_slideshow').cycle('stop');
        jQuery('#' +currentSlideshowDivision + '_slideshow').hide();
        // hiding previous category
        jQuery('#' +currentSlideshowDivision + '_info').hide();
    }
    else
    {
        // this is the FIRST click, we stop the main website top_categories slideshow and preparing the sub slideshows for each division
        jQuery('.top_categories').cycle('stop');
        jQuery('.top_categories > div').css("opacity", "1");
        jQuery('.top_categories > div').hide();
        jQuery('.logo2').hide();

    }

    jQuery("#" + division + "_slideshow").show();
    jQuery("#" + division + "_info").show();
    jQuery("#" + division + "_info div").show();

    // start the selected slideshow
    jQuery('#' +division + '_slideshow').cycle({
	    fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
	    timeout:5000,
	    slideExpr:'.big_pic'
	});
    currentSlideshowDivision = division;
}
// Slider.js END

jQuery(document).ready(function () {
    jQuery(".category_info > div").css("display", "none");
    jQuery('.top_categories').cycle({
	    fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
	    timeout:5000,
	    slideExpr:'div.big_img'
	});

})

function doFade(i_sName, i_iItemIndex) {
    if (!timer)
        return false;
    inFade = true;
    fadingImgId = i_sName;
    var iNextIndex = 0;
    if (jQuery(".top_categories img[name=img_" + i_sName + "]:eq(" + (i_iItemIndex + 1) + ")").length > 0)
        iNextIndex = (i_iItemIndex + 1);

    jQuery(".top_categories img[name=img_" + i_sName + "]:eq(" + i_iItemIndex + ")").fadeOut(500);
    jQuery(".top_categories img[name=img_" + i_sName + "]:eq(" + iNextIndex + ")").fadeIn(500, function() {
        inFade = false;
        if (timer && !clicked) {
            timer = setTimeout("doFade('" + i_sName + "', " + iNextIndex + ")", 1000);
        }
    });

}



