// JavaScript Document
var $anterior=0;
function slideSwitch() {
    var $active = $('#main_content_botigues_imatges IMG.active');

    if ( $active.length == 0 ) $active = $('#main_content_botigues_imatges IMG:last');

    //si nomÃƒÂ©s hi ha una imatge retorna (evita fer un transició a blanc)
	if($active.next().length==0 && $anterior==0)
		return;

    // mostrem les imatges amb el mateix ordre com les hem posat
    var $next =  $active.next().length ? $active.next()
        : $('#main_content_botigues_imatges IMG:first');
	$anterior=$active.next().length;
    
	
	// descomentar les 3 linies si volem mostrar les imatges de manera al·leatòria
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );


    $active.addClass('last-active');
	//alert($active.next().length);
    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

function slideBanner1Switch() {
    var $active = $('#banner1 IMG.active');

    if ( $active.length == 0 ) $active = $('#banner1 IMG:last');

    //si nomÃƒÂ©s hi ha una imatge retorna (evita fer un transició a blanc)
	if($active.next().length==0)
		return;

    // mostrem les imatges amb el mateix ordre com les hem posat
    var $next =  $active.next().length ? $active.next()
        : $('#banner1 IMG:first');
	
    
	
	// descomentar les 3 linies si volem mostrar les imatges de manera al·leatòria
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );


    $active.addClass('last-active');
	//alert($active.next().length);
    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

function slideBanner2Switch() {
    var $active = $('#banner2 IMG.active');

    if ( $active.length == 0 ) $active = $('#banner2 IMG:last');

    //si nomÃƒÂ©s hi ha una imatge retorna (evita fer un transició a blanc)
	/*if($active.next().length==0)
		return;*/

    // mostrem les imatges amb el mateix ordre com les hem posat
    var $next =  $active.next().length ? $active.next()
        : $('#banner2 IMG:first');
	
    
	
	// descomentar les 3 linies si volem mostrar les imatges de manera al·leatòria
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );


    $active.addClass('last-active');
	//alert($active.next().length);
    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

function slideBannerIDSwitch(id) {
	
    var id_banner = "#banner" + id;
	
	
	
    var $active = $(id_banner + ' IMG.active');

    if ( $active.length == 0 ) $active = $(id_banner + ' IMG:last');

    //si nomÃƒÂ©s hi ha una imatge retorna (evita fer un transició a blanc)
	/*if($active.next().length==0)
		return;*/

    // mostrem les imatges amb el mateix ordre com les hem posat
    var $next =  $active.next().length ? $active.next()
        : $(id_banner + ' IMG:first');
	
    
	
	// descomentar les 3 linies si volem mostrar les imatges de manera al·leatòria
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );


    $active.addClass('last-active');
	//alert($active.next().length);
    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}


$(function() {
    setInterval( "slideSwitch()", 3000 );
	//setInterval( "slideBanner1Switch()", 3000 );
	//setInterval( "slideBanner2Switch()", 3000 );
});
