$("document").ready(go);

function go () {
    if (isFontFaceSupported()) {
        $("td.fontimg > a").each(function(x){
                var p = this.parentNode;
                var f = this.getAttribute("fontid");
                var ff = this.getAttribute("font");
                this.rme();
                var outbox = ce("div", {className: "ffoutbox"});
                var inbox = ce("div", {className: "ffinbox"});

                var text = ["ABCDEFGHIJKLM", "NOPQRSTUVWXYZ"];
                if (font_text[f] != undefined) {
                    text = font_text[f];
                }
                addSpans(inbox, text[0]); 
                inbox.ace("br");
                addSpans(inbox, text[1]); // presently hard-coded that there are two lines

                inbox.style.fontFamily = ff;

                outbox.ac(inbox); // a display-speed optimization
                p.ac(outbox);

                $("#showcase").jqm( {onShow: function(h) {
                        h.w.css('opacity',1).fadeIn("fast"); 
                        }});
                $("#showcase").click(function(){ $("#showcase").jqmHide(); });
                
            });
    }
}

function addSpans (n, t) {
    all = t.split("");
    all.map (function(x) { 
            var c = n.ace("span");
            c.actn(x); 
            $(c).mouseenter(function() { $(this).addClass("hilite"); });
            $(c).mouseleave(function() { $(this).removeClass("hilite"); });
            $(c).click(function() { 
                    var s = $("#showcase_in")[0];
                    s.style.fontFamily = this.parentNode.style.fontFamily;
                    $(s).text($(this).text());
                    $("#showcase").jqmShow();
                });
        });
}

/*!
* isFontFaceSupported - Inference variant - v0.9 - 02/22/2010
*
* Copyright (c) 2010 Marc G.
* MIT license - Free as in French. ;)
*/

/* This is an object-inference based feature detection.
It is not sniffing the browser userAgent, nor is it testing the actual feature
Instead it is testing properties in the target browsers.
It is also synchronous.
*/


var isFontFaceSupported = function(){

    var isNoSupport = false ||
        (('MozOpacity' in document.body.style)&&(!document.body.children)) ||
        ((window.opera)&&(!document.querySelector)) ||
        (m=/*@cc_on!@*/0) ||
        (((/source/.test(/a/.toString+''))||(window.chrome))&&(!window.openDatabase)) ||
        ((/a/.__proto__=='//')&&(!document.querySelector));
          
    return !isNoSupport;

}


