/** add_page_load_event.js allows us to run one or multiple functions on page load
The advantage of this funtion is it won't override any previously set onload functions,
and also that it will trigger at the point of HTML being ready, rather than waiting for every image to load */

var event_interval = false;

function mycarousel_initCallback(carousel)
{
    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        //carousel.stopAuto();
    }, function() {
       // carousel.startAuto();
    });
};

/** Code to run on page load, including image rollovers and anything else fancy */
function page_setup()
{
	if( $('#s1') )
	{
		textfield_setDefaultValue( 's1', 'Search...' );
	}
	
	// initialise plugins
	$("#mainmenu").eq(0).supersubs({ 
		minWidth:    10,   // minimum width of sub-menus in em units 
		maxWidth:    27,   // maximum width of sub-menus in em units 
		extraWidth:  1     // extra width can ensure lines don't sometimes turn over 
						   // due to slight rounding differences and font-family 
	}).superfish();
	
	if( $('.page_home' ).length > 0 )
	{
		$('.clients').eq(0).jcarousel({
			auto: 4,
			scroll: 1,
			wrap: 'last',
			animation: 2000,
			initCallback: mycarousel_initCallback
		});
		$('.testimonials_list').eq(0).jcarousel({
			auto: 4,
			scroll: 1,
			wrap: 'last',
			animation: 2000,
			initCallback: mycarousel_initCallback
		});
		
		if( $('.events').eq(0).length > 0 )
		{
			var eventPanel = $('.events').eq(0);
			
			$( eventPanel )
				.data('paused', false)
				.bind('mouseover', 
					function()
					{
						$(this).data('paused', true);
					}
				)
				.bind('mouseout', 
					function()
					{
						$(this).data('paused', false);
					}
				);
				
			setTimeout( function(){
			
				event_show();
				event_interval = setInterval(event_show, 6000);
			
			}, 4000 );
			
		}
	}
}

function event_show()
{
	if( $('.events').eq(0).data('paused') == false)
	{
		$('.events:eq(0) .event:eq(0)').slideUp(2000, 
			function()
			{
				$('.events:eq(0) .event:eq(0)').remove().appendTo('.events:eq(0)').show();
			}
		);
	}
}

$(document).ready( page_setup );

