$(document).ready(
	function()
	{
		var carusel_tabs = $( 'div#carusel div.carusel_item' );
		var carusel_links = $( 'div#content div.switcher a' );
		var countTabs = carusel_links.length;
		var currentIndex = 0;
		var allowToRun = true;
		if( carusel_links.length > 0 )
		{
			$( carusel_links[ 0 ] ).parent().parent().addClass( 'selected' );
			$( carusel_tabs[ 0 ] ).show();
			carusel_links.each( function( index ) 
			{
				$( this ).click( function( event ) 
				{
					event.preventDefault();
					if ( index != currentIndex )
					{
						showCaruselTabs( index );
					}
				} );
			} );
			
			$( 'div#carusel' ).mouseenter( function() 
			{
				allowToRun = false;
			} );
			
			$( 'div#carusel' ).mouseleave( function() 
			{
				allowToRun = true;
			} );
			
			$( 'div#content div.switcher' ).mouseenter( function() 
			{
				allowToRun = false;
			} );
			
			$( 'div#content div.switcher' ).mouseleave( function() 
			{
				allowToRun = true;
			} );
			
			var showCaruselTabs = function( tabIndex )
			{
				$( carusel_links[ currentIndex ] ).parent().parent().removeClass( 'selected' );
				$( carusel_tabs[ currentIndex ] ).fadeOut( 1000 );
				$( carusel_links[ tabIndex ] ).parent().parent().addClass( 'selected' );
				$( carusel_tabs[ tabIndex ] ).fadeIn( 1600 );
				currentIndex = tabIndex;
			}
			
			var periodicFunction = function()
			{
				if ( allowToRun )
				{
					var tempIndex = currentIndex;
					tempIndex += 1;
					if( tempIndex == countTabs )
					{
						tempIndex = 0;
					}
					showCaruselTabs( tempIndex );
				}
			}
			
			setInterval(periodicFunction, 6000 ); 
		}
	}
);