$( function()
{
	var rollTime = 5,
		newsList = $( '.news ul a' ),
		newsImages = $( '.newsphoto img' );
    
	newsList.click( function( event )
	{
		var self = $( this ),
			visibleImages;

		if ( ! self.hasClass( 'active' ) ) {
			newsList.removeClass( 'active' );
			self.addClass( 'active' );
			
			visibleImages = newsImages.filter(':visible').fadeOut( 'slow', function()
			{
				newsImages.filter( '[id=img' + self.attr( 'id' ) + ']' ).fadeIn( 'slow' );
			} );


			event.preventDefault();

			rollTime = 5;
		}
	} ).first().click();

	setInterval( function()
	{
		rollTime--;

		if ( rollTime < 1 )
		{
			var activeIndex = $( '.news ul a.active' ).index( '.news ul a' );
			newsList.eq( activeIndex + 1 == newsList.length ? 0 : activeIndex + 1 ).click();
		}
	}, 1000 );
} );

/*// JavaScript Document
$(function(){
    $('.news UL A').click(function() {
        stop_roll_promo();
        
        var id = $(this).attr('id');
        if(this.className != 'active') {
            $('.newsphoto IMG.active').fadeOut('0');
            $('.news UL A').removeClass('active');
            $(this).addClass('active');
            $('.newsphoto IMG.active').removeClass('active');
            $('#img'+id).fadeIn('500',function () {
                }
           );
            $('#img'+id).addClass('active');            
        }
        else {
            stop_roll_promo();
            timeoutIdPromo = setTimeout(roll_promo, 0);
            return false;
        }
    });
});

function stop_roll_promo()
{
    if ( typeof timeoutIdPromo != 'undefined' )
    {
        clearTimeout(timeoutIdPromo);
    }
}

function roll_promo()
{
    stop_roll_promo();    
    
    if ( typeof roll_promo.counter == 'undefined' ) {
        roll_promo.counter = 0;
    }
    roll_promo.counter = roll_promo.counter % 5;
    roll_promo.counter++;
    
    // alert( '#promo0'+roll_promo.counter );
    $('#promo0'+roll_promo.counter).click();    
    stop_roll_promo();
    
    timeoutIdPromo = setTimeout(roll_promo, 5000);   
}

$(document).ready(function(){
    timeoutIdPromo = setTimeout(roll_promo, 0);
});
*/
/*----- Селектор в форме обратной связи -----------------------------------------------------------------------------------------------------------*/
function openPalette(what){
	if(document.getElementById("wherelist").style.display != "block"){
	document.getElementById("wherelist").style.display = "block";
	}else{
	document.getElementById("wherelist").style.display = "none";	
	}
}
function setValue(what) {
	var x = what.innerHTML;
	document.getElementById("where").innerHTML = x;
	document.getElementById("wherelist").style.display = "none";
}

$(document).ready(function(){
$('#mycarousel').jcarousel({ visible: 4 });
$('#mycarouseles').jcarousel({ visible: 4 });
});

