/**
 * File download cookie handlers - setting the to and fro cookies 
 */

var file_downloads = {
	
	start: function() {
		
		$('a').each( function() {
					
			var thisLink = $(this);
			if ( thisLink.attr( 'href' ).indexOf( '?fileID=' ) != -1 ) {						
				thisLink.bind( 'click', function( e ){
					e.preventDefault();
					$.cookie( 'downloadReturnUrl', window.location, { expires: 1, path: '/' } );
					window.location = thisLink.attr( 'href' );
				});				
			}
			
			$('a.file_downloadReturn').click( function() {
				$.cookie("downloadReturnUrl", null);
			});
			
		});
		
	}
	
};

$(file_downloads.start);
