var cache = [];
var inview;

this.imagePreview = function(){
	$("div.preview").click(function(){
	    src     = this.id;
	    l       = $(this).position().left;

        $("#preview").fadeOut("slow", function () {

    	    if ( src === inview ) {
    	        inview = false;
    	        return false;
    	    }
    	    inview = src;

    		$("#preview_img").attr("src", src);
    		$("#preview")
    			.css("top",  "15px")
    			.css("left", l - ( $("#preview").outerWidth() + 10 ) + "px")
    			.fadeIn("slow")
    			.click(function(){
    			    inview = false;
    		        $(this).fadeOut("slow");
                });
            });
    });
};

this.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
        var cacheImage = document.createElement('img');
        cacheImage.src = arguments[i];
        cache.push(cacheImage);
    }
}

// starting the script on page load
$(document).ready(function(){
	imagePreview();
});
