(function($){
	
	$.fn.splashScreen = function(settings){
		
		// Providing default options:
		
		settings = $.extend({
			textLayers		: [],
			textShowTime	: 1500			
		},settings);
		
		var base = this;

		// Creating the splashScreen div.
		// The rest of the styling is in splashscreen.css
		
		var splashScreen = $('<div>',{
			id	: 'splashScreen',
			css:{				
				height				: $(document).height()
			}
		});
		
		var insideSplashScreen1 = $('<div>',{
            	id  : 'insideSplashScreen1',
				css : { left: (($(document).width() - 960) / 2) }
			});
	
	var insideSplashScreen2 = $('<div>',{
            	id  : 'insideSplashScreen2',
				css : { left: (($(document).width() - 960) / 2) }
			});
		
		$('body').append(splashScreen);
		$('#splashScreen').append(insideSplashScreen1);
		$('#splashScreen').append(insideSplashScreen2);
		
		splashScreen.click(function(){
			splashScreen.fadeOut('slow');
		});
		
		splashScreen.bind('changeImage',function(e,newID){
			
			var image1 = $('<img>',{
                src:settings.textLayers[1],
                css: {
                    marginTop : "130px"
                }
            });
			insideSplashScreen1.append(image1);
			
			var image2 = $('<img>',{
                src:settings.textLayers[0],
                css: {
                    marginTop : "130px"
                }
            }).hide();
			
			image2.load(function(){
                image2.fadeIn(2000,function(){insideSplashScreen2.fadeOut(3000,function(){
                    insideSplashScreen2.remove().delay(1500);
					image1.fadeOut(1000,function() {
						splashScreen.fadeOut(500);
					});
					});
                });
            }); 
			insideSplashScreen2.append(image2);
		});
		
		splashScreen.trigger('changeImage','0');
		
	}
	
})(jQuery);
