function obfuscateM(sDom, sUser){
    return("mail"+"to:"+sUser+"@"+sDom.replace(/%23/g,"."));
}

function lPad(s,n,p) {
	var toPad=s+"";
	while(toPad.length<n) {
		toPad=p+toPad;
	}
	return toPad;
}

jQuery.fn.vjustify=function() {
    var maxHeight=0;
    this.each(function(){
        if (this.offsetHeight>maxHeight) {maxHeight=this.offsetHeight;}
    });
    this.each(function(){
        $(this).height(maxHeight + "px");
        if (this.offsetHeight>maxHeight) {
            $(this).height((maxHeight-(this.offsetHeight-maxHeight))+"px");
        }
    });
};



//temp work around for $(function()) problems with unsized after-ready loaded images, etc.

function runOnLoad(f) {
    if (runOnLoad.loaded) f();    // If already loaded, just invoke f() now.
    else runOnLoad.funcs.push(f); // Otherwise, store it for later
}

runOnLoad.funcs = []; // The array of functions to call when the document loads
runOnLoad.loaded = false; // The functions have not been run yet.

// Run all registered functions in the order in which they were registered.
// It is safe to call runOnLoad.run() more than once: invocations after the
// first do nothing. It is safe for an initialization function to call
// runOnLoad() to register another function.
runOnLoad.run = function() {
    if (runOnLoad.loaded) return;  // If we've already run, do nothing

    for(var i = 0; i < runOnLoad.funcs.length; i++) {
        try { runOnLoad.funcs[i](); }
        catch(e) { /* An exception in one function shouldn't stop the rest */ }
    }

    runOnLoad.loaded = true; // Remember that we've already run once.
    //do some forced-last cleanup
    $("#jqSupport").hide("slow");
    $("#formLoading").hide("slow");
    delete runOnLoad.funcs;  // But don't remember the functions themselves.
    delete runOnLoad.run;    // And forget about this function too!
};

// Register runOnLoad.run() as the onload event handler for the window
if (window.addEventListener)
    window.addEventListener("load", runOnLoad.run, false);
else if (window.attachEvent) window.attachEvent("onload", runOnLoad.run);
else window.onload = runOnLoad.run;


runOnLoad(function() {
    $(".jqmp3").each(function(i){
        var thisID="mp3player"+lPad(i,3,"0");
        $(this).attr("id",thisID);
        var thatID=thisID.replace(/player/,"links");
        $("body").append("<div id='"+thatID+"' class='jqPopUp'></div>");
        $("#"+thatID).prepend("<div style='color:white;background:black; text-align:right; padding:2px 0;'><img style='cursor:pointer' class='jqPopUpClose' width='14' height='14' src='"+molajsResources+"/icons/close.gif"+"'></div>");
        $("#"+thatID).append("<div class='jqPopUpContent'>"+$(this).html()+"</div>");
        var thisSet=$("#"+thisID+" a[@href$=.mp3]");
        var fileSwitch=thisSet.length>1?"mp3multi.swf":"mp3single.swf";
        var heightSwitch=thisSet.length>1?"150":"50";
        var so=new SWFObject(molajsResources+"/flash/"+fileSwitch,"lc_"+thisID,"220",heightSwitch,"7");
        $("#"+thisID+" a[@href$=.mp3]").each( function(j) {
            so.addVariable("passedAudio"+lPad(j,3,"0"), this.href);
            so.addVariable("passedTitle"+lPad(j,3,"0"),$(this).text());
        });
        so.addParam("wmode","transparent");
        so.write(thisID);
        $(this).append("<div class='mp3switch'>get downloads and info</div>").children('.mp3switch').click(
            function() {
                var thatID="#"+$(this).parent().attr("id").replace(/player/,"links");
                $(thatID).slideToggle(200);
            }
        );
    });
    //$(".jqPopUpContent").css("padding","1em");
    //$(".mp3close").css("background-image","url("+molajsResources+"/icons/close.gif)");
    $(".jqPopUpClose").click( function() {$(this).parent().parent().slideToggle(200);} );
    $(".jqColumn").vjustify();
    $(".jqZebra tr:nth-child(odd)").addClass("jqOdd");
    $(".jqZebra tr:nth-child(even)").addClass("jqEven");
});




