$jQuery(document).ready(function() { 
	
	/* Set some default JQuery Ajax parameters */
	$jQuery.ajaxSetup( { timeout: 0,global: true,type: "POST" });
	
	/* This sets the global var to allow the offers call to be active, if set to false then the ajax does not run */
	var active = true;
	
	/* Stop the refresh if we have our mouse over a link */
	$jQuery("#offers-container").mouseover( function() { active = false; } );
	$jQuery("#offers-container").mouseout( function() { active = true; } );
	
	/* Run a timer to update the offers display */
	$jQuery("#offers-container").everyTime(5000,function(i) { getOffers(); });
	
	/* This does the grunt of the work to get the offers */
	function getOffers()
	{
		/* Only run providing active is true */
		if (active) {
			
			/* Run the AJAX Request */
			$jQuery.ajax({
				url: 'index.php?action=ajax.sidebar-offers', type: 'POST', data: "brand="+brand+"&section="+section,dataType: 'html', 
				error: function(){ active = false; },
				success: function( data ){

					/* Check for any errors */
					if (data == ''){ active = false; return; } 

					/* Update content */
					if (active == true) { $jQuery("#offers-container").html(data); }
				}
			});
		}
	}
});