var liTemps = null;

var liRound = 0;

$ ( document ).ready 
( 
	function ( ) 
	{
		$ ( ".image_thumb ul li" ).click 
		(
			function ( )
			{
				var blockId = $ ( this ).find ( ".block" ).attr ( "id" );  


				var imgAlt = $ ( ".detail_banner ." + blockId ).find ( "img" ).attr ( "alt" );

				var imgSrc = $ ( ".detail_banner ." + blockId ).find ( "img" ).attr ( "src" ); 

				var imgLink = $ ( ".detail_banner ." + blockId ).find ( "img" ).attr ( "value" ); 

				var imgDesc = $ ( ".detail_banner" ).find ( "." + blockId ).html ( );  

				var imgDescHeight = $ ( ".detail_banner" ).find ( "." + blockId ).height ( ); 



				if ( $ ( this ).is ( ".active" ) ) 
				{  
					return false; 
				} 
				else 
				{ 
					$ ( ".main_image .block" ).animate ( { opacity: 0.9, marginBottom: -imgDescHeight }, 250 , function ( ) 
						{ 
							$ ( ".main_image .block" ).slideUp ( "normal", function ( ) 
								{ 
									$ ( ".main_image .block" ).html ( imgDesc );

									$ ( ".main_image img" ).attr ( { src: imgSrc, alt: imgAlt } );

									$ ( ".main_image a.link" ).attr ( { href: imgLink, title: imgAlt } );
								} 
							); 

							$ ( ".main_image .block" ).slideDown ( "normal", function ( ) 
								{ 
									// do something.
								} 
							); 
						}
					);
				}
	
				

				$ ( ".image_thumb ul li").removeClass ( "active" );

				$ ( this ).addClass ( "active" );

				return false; 
			}
		).hover ( 
			function ( )
			{ 
				$ ( this ).addClass ( "hover" ); 
			}
			, function ( ) 
			{
				$ ( this ).removeClass ( "hover" ); 
			}
		);

		$ ( ".main_image a.collapse" ).click 
		(
			function ( )
			{
				$ ( ".main_image .block" ).slideToggle ( "normal" ); 

				$ ( ".main_image a.collapse" ).toggleClass ( "show" ); 
			}
		);

		
		liTemps = $ ( ".image_thumb ul" ).children ( );
		
		window.setInterval ( "showAds()", 4000 );
	} 
);



function showAds ( )
{
	$ ( liTemps [ liRound ] ).click ( );
	
	liRound++;
	
	if ( liRound >= liTemps.length )
	{
		liRound = 0;
	}
}
