jQuery.fn.galletri = function(options){
var defaults = { TNL: "#" + $(this).attr("id"), attributes: "Picture1,Picture2,Picture3", Description: "#PictureDesc", fadeInterval: 400, fill: false };
var opts = $.extend(defaults, options);
var TNL = opts.TNL;
var attributes = opts.attributes.split(",");
var fadeInterval = opts.fadeInterval;
var PictureDesc = opts.Description;
var fill = opts.fill;

$(TNL + " img").fadeTo(0, 0.4);

$(TNL + " img").hover(function(){
$(this).stop().fadeTo(100, 1);
}, 
function(){
$(this).fadeTo(100, 0.4);});

$(TNL + " a").click(function(){
var CurLink = $(this);
$("#" + attributes[1]).addClass("loading");
$(PictureDesc).fadeOut(300, function(){
$(this).html('<p>' + ReplaceLineBreaks($(CurLink).attr("title")) + '</p>').fadeIn(fadeInterval);
});
for(var i in attributes){
NewPic("#" + attributes[i], $(this).attr(attributes[i]), i*fadeInterval+fadeInterval);
};
return false;
});

function ReplaceLineBreaks(mystring){
mystring = mystring.replace(/\n/,"<br />");
mystring = mystring.replace(/\n/,"<br />");
mystring = mystring.replace(/\n/,"<br />");
mystring = mystring.replace(/\n/,"<br />");
mystring = mystring.replace(/\n/,"<br />");
mystring = mystring.replace(/\n/,"<br />");
return mystring;
}

function NewPic(id, src, fadeTime){
if ($.browser.msie){
src += "?" + Math.random()*101 + "=" + Math.random()*10001;
}
pic = $(id + " img");
if(pic.length){
if(fill){
$(id).append("<p id='fill'>&nbsp;</p>");
}
pic.stop().fadeOut(300).remove();
}
if(src != ""){
var largeImage = new Image();
$(largeImage).attr("src", src).load(function()
             	{
if (!($(id + " img").length)){
                $(largeImage).hide();
                $("#" + attributes[1]).removeClass("loading");
                $(id).append(largeImage);
                $(largeImage).fadeIn(fadeTime);
if(fill){
                $("#fill").remove();
}
}               });     
}}
};
