$.fadeBackground = function(image,url) {

	var imgList = [];

	$('body').append('<div id="fadeBackground"></div>');
	$('#fadeBackground').css({
		'position': 'absolute',
		'background-image': $('body').css('background-image'),
		'background-color': '#000000',
		'background-position': 'top center',
		'background-repeat': 'no-repeat',
		'top': '0', 'left': '0', 'right': '0',
		// 'bottom': '0',
		'height': $(document).height(),
		'z-index': '-2'
	});
	
	$('body').append('<div id="fadeBackground-Loader"></div>');
	$('#fadeBackground-Loader').css({
		'position': 'fixed',
		'background': 'url(images/fadebackground-loader.gif) center center no-repeat',
		'background-color': '#000000',
		'left': '0', 'right': '0', 'top': '0', 'bottom': '0',
		'z-index': '-1'
	});
	
	imgList.push($("<img />").attr("src", image).load(function() {
	
			$('#fadeBackground-Loader').remove();
			$('body').css('background-image','url('+ image + ')');
			$('body').css('background-color','#000000');
			$('#fadeBackground').fadeOut(1000,function(){
				$(this).remove();
				$.get('fadeBackground.php', { bg: image }, function(data) {
					if (typeof url != 'undefined') window.location.href = url;
				});		
			});
			
		})
	
	);
	
return false;	
};

$.first_fadeBackground = function(image,url) {

	var imgList = [];

	$('body').append('<div id="fadeBackground"></div>');
	$('#fadeBackground').css({
		'position': 'absolute',
		'background-position': 'top center',
		'background-color': '#000000',
		'background-repeat': 'no-repeat',
		'top': '0', 'left': '0', 'right': '0',
		// 'bottom': '0',
		'height': $(document).height(),
		'z-index': '-2',
		'display:': 'none'
	}).fadeOut(1, function() {
	
		$('body').append('<div id="fadeBackground-Loader"></div>');
		$('#fadeBackground-Loader').css({
			'position': 'fixed',
			'background': 'url(images/fadebackground-loader.gif) center center no-repeat',
			'background-color': '#000000',
			'left': '0', 'right': '0', 'top': '0', 'bottom': '0',
			'z-index': '-1'
		});
		
		imgList.push($("<img />").attr("src", image).load(function() {
		
				$('#fadeBackground-Loader').remove();
				$('#fadeBackground').css('background-image','url('+ image + ')');
				// $('#fadeBackground').css('height', $(document).height());
				$('#fadeBackground').fadeIn(1000,function(){
					$('body').css('background','url('+ image + ') top center no-repeat');
					$('body').css('background-color','#000000');
					$(this).remove();
					$.get('fadeBackground.php', { bg: image }, function(data) {
						if (typeof url != 'undefined') window.location.href = url;
					});		
				});
				
			})
		
		);
	
	});
	
return false;	
};

$(document).ready(function() {

	$('a.fadeBG').click(function() {
	
		var ref = $(this).attr('ref');
		var href = $(this).attr('href');
		
		$.fadeBackground(ref,href);
	
	return false;
	});

});
