var doddCarousel;

function initHomePage()
{
	loadDownloads();
	
	if( $( 'dodd-2' )) {
	
		doddCarousel = new Carousel( 'carousel-wrapper',
									 $$( '#carousel-content .slide' ),
									 $$( 'a.carousel-jumper' ),
									 { 
										auto: 			true,
										effect: 		'scroll',
										circular:		true,
										duration: 		0.25, 
										frequency: 		10,
										wheel:			false,
										beforeMove: 	function()
														{ 
															$$( '.carousel-jumper' ).each( function( el )
															{
																el.removeClassName( 'carousel-selected' );
															} );
														},
										afterMove: 		function()
														{
															var el = $$( '.' + doddCarousel.current.id );
										
															el[0].addClassName( 'carousel-selected' );
														}
									  });

		doddCarousel.next();
	}
}

function loadDownloads()
{
	new Ajax.Updater( 'latestDownloads', getRootPath(), 
	{
		parameters: { 
			act: 		'software.downloads', 
			type: 		'latest'
		},
		onComplete: function( response ) 
		{
			setupTooltips( '#latestDownloads .help' );
		}
	} );

	new Ajax.Updater( 'recommendedDownloads', getRootPath(), 
	{
		parameters: { 
			act: 		'software.downloads', 
			type: 		'recommended'
		},
		onComplete: function( response ) 
		{
			setupTooltips( '#recommendedDownloads .help' );
		}
	} );

	new Ajax.Updater( 'mostPopularDownloads', getRootPath(), 
	{
		parameters: { 
			act: 		'software.downloads', 
			type: 		'mostPopular'
		},
		onComplete: function( response ) 
		{
			setupTooltips( '#mostPopularDownloads .help' );
		}
	} );

	new Ajax.Updater( 'editorsChoiceDownloads', getRootPath(), 
	{
		parameters: { 
			act: 		'software.downloads', 
			type: 		'editorsChoice'
		},
		onComplete: function( response ) 
		{
			setupTooltips( '#editorsChoiceDownloads .help' );
		}
	} );

	new Ajax.Updater( 'userRecommendedDownloads', getRootPath(), 
	{
		parameters: { 
			act: 		'software.downloads', 
			type: 		'userRecommended'
		},
		onComplete: function( response ) 
		{
			setupTooltips( '#userRecommendedDownloads .help' );
		}
	} );

	new Ajax.Updater( 'recentlyViewedDownloads', getRootPath(), 
	{
		parameters: { 
			act: 		'software.downloads', 
			type: 		'recentlyViewed'
		},
		onComplete: function( response ) 
		{
			setupTooltips( '#recentlyViewedDownloads .help' );
		}
	} );
}

function reloadSoftware( ops )
{
	var f = $( ops.type + 'DownloadsForm' );
	var rating = f.elements[ 'rating' ];
	var license = f.elements[ 'license' ];
	var category = f.elements[ 'category' ];
	var args = {
		act: 		'software.downloads', 
		page: 		f.elements[ 'page' ].value, 
		orderBy: 	f.elements[ 'orderBy' ].value, 
		orderDesc: 	ops.orderBy ? (( f.elements[ 'orderDesc' ].value == 'desc' ) ? 'asc' : 'desc' ) : f.elements[ 'orderDesc' ].value, 
		rating: 	rating.options[ rating.selectedIndex ].value, 
		license: 	license.options[ license.selectedIndex ].value, 
		category: 	category.options[ category.selectedIndex ].value
	};

	new Ajax.Updater( ops.type + 'Downloads', getRootPath(), 
	{
		parameters: $H( args ).merge( ops ).toObject(),
		onComplete: function( response ) 
		{
			setupTooltips( '#' + ops.type + 'Downloads .help' );
		}
	} );
	
	return( false );
}

