/*
*/
examples=[]
Randomcolor=""
selected=false;
$().ready(function() {
    randomcolor();    
/*
	$(".submenu h1").FontEffect({
        outline             :true,
        outlineColor1       :"rgb(56,80,158)",
        outlineColor2       :"rgb(41,59,115)",
        outlineWeight       :1,
        shadow              :false,
        shadowColor         :"rgb(41,61,119)",
        shadowOffsetTop     :1,
        shadowOffsetLeft    :1,
        shadowBlur          :1,
        shadowOpacity  :1
    });    
    $("h1").FontEffect({
        outline             :true,
        outlineColor1       :"rgb(254,203,0)",
        outlineColor2       :"rgb(157,125,0)",
        outlineWeight       :1,
        shadow              :false,
        shadowColor         :"rgb(157,125,0)",
        shadowOffsetTop     :1,
        shadowOffsetLeft    :1,
        shadowBlur          :1,
        shadowOpacity  :1
    });    
*/
	$("#menu1 a").FontEffect({
        outline             :true,
        outlineColor1       :"rgb(230,230,230)",
        outlineColor2       :"rgb(250,250,250)",
        outlineWeight       :1,
        shadow              :false,
        shadowColor         :"rgb(250,250,250)",
        shadowOffsetTop     :1,
        shadowOffsetLeft    :0,
        shadowBlur          :1,
        shadowOpacity  :1
    });

	$("#menu1 ul a").FontEffect({
        outline             :false,
        outlineColor1       :"rgb(255,255,255)",
        outlineColor2       :"rgb(255,255,255)",
        outlineWeight       :0,
        shadow              :false,
        shadowColor         :"rgb(255,255,255)",
        shadowOffsetTop     :0,
        shadowOffsetLeft    :0,
        shadowBlur          :0,
        shadowOpacity  :0
    });

	/*$('#menu1 ul a').removeFE(true);*/
    $(".example").each(function(i){
        var ind=i
        var a=$("#style"+ind).html()
        uuu=$("#options"+ind)
        aaa=uuu.html()
        b=0
        examples[ind]={
            options :$("#options"+ind).html().replace(/[\n\s]/gi,""),
            style   :a.substring(a.indexOf("{")+1,a.lastIndexOf("}")),
            html    :$("#example"+ind),
            top     :$("#example"+ind).offset().top-50
            }
        var str=""
        str+="<a href='#' onclick='$(\".codebox:visible\").toggle();return false'>X</a>"
        str+="JAVASCRIPT<xmp class='xmpcode'>$('#example"+ind+"').FontEffect({\n    "+examples[ind].options.replace(/\,/gi,",\n    ")+"\n})</xmp>"
        str+="CSS<xmp class='xmpstyle'>#example"+ind+"{"+examples[ind].style+"}</xmp>"
        str+="HTML<xmp class='xmphtml'><"+examples[ind].html[0].tagName+" id='example"+ind+"'>\n    "+examples[ind].html[0].innerHTML+"\n</"+examples[ind].html[0].tagName+"></xmp>"
        $("#example"+ind).after($("<div></div>").addClass("codebox").html(str).attr("id","example"+i+"src"))
        })
    chkposition()
    $(window).scroll(function(){
        chkposition()
        })
    // sandbox onload
    //cpick=$.farbtastic('#picker');
    $(".colore")
        .each(function(){cpick.linkTo(this)})
        .focus(function(){
            if(selected){
                apply()
                }
            if(selected!=this){
                cpick.linkTo(this);
                $(this).after($("<a href='#' onclick='apply();return false'>Apply</a>"))
                $("#boxpicker").css({top:$(this).position().top-200+"px",left:$(this).position().left+"px"}).show()
                selected=this
                }
            })
    $("#sandboxtext").css({
        margin:"30px 0px 0px 80px",
        fontFamily:"Verdana",
        color:"#77c",
        fontSize:"90px"
        })
    });
    //
function randomcolor(){
    Randomcolor=("rgb("+Math.round(Math.random()*255)+","+Math.round(Math.random()*255)+","+Math.round(Math.random()*255)+")")
    $("#xmp16").html("<xmp>$('#example16').redrawFE({gradientColor:'"+Randomcolor+"'})</xmp>")
    }
function chkposition(){
    var wst=$(window).scrollTop()
    var whe=$(window).height()
    $(examples).each(function(ii){
        if(examples[ii].top < wst+whe && examples[ii].top > wst){
            activateExample(ii)
            }
        })
    }
function activateExample(iii){
    eval('$("#example"+iii).FontEffect({'+examples[iii].options+'})')
    examples[iii].top=99999999999
    $("#example"+iii)
        .click(function(e){
            $(".codebox:visible").toggle("fast")
            var a=$(".codebox:visible")
            var b=$("#example"+iii+"src")
            if(((a.length>0)?a[0].id:"")!=((b)?b[0].id:""))$(b).toggle("slow")
            })
        .css("cursor","pointer")
    }
// sabdbox functions
function apply(){
    var nome=selected.name
    var valore=cpick.color
    $("#boxpicker").hide()
    $(selected).next().remove()
    selected=false
    switch(nome){
        case "fontColor":
            $("#sandboxtext").css("color",valore)
            break;
        case "backgroundColor":
            $("#sandbox").css("backgroundColor",valore)
            break;
        default:
            eval('$("#sandboxtext").redrawFE({'+nome+':"'+valore+'"})');
        }
    return(false);
    }

function changeop(ob){
    var nome=ob.name
    if(ob.type.indexOf("select")!=-1){
        var valore=ob.options[ob.selectedIndex].value
        if(valore=="Other..."){
            var valore = window.prompt("Insert a value for the "+nome+" option","default");
            }
        if(nome=="fontFamily"|| nome=="fontSize"|| nome=="marginTop"|| nome=="marginLeft"){
            $("#sandboxtext").css(nome,valore)
            return false;
            }
        if(nome=="backgroundImage"){
            $("#sandbox").css("backgroundImage","url("+valore+")")
            return false;
            }
        }
    if(ob.type.indexOf("checkbox")!=-1){
        $("#"+nome+"_o").toggle()
        if($("#ojs :checked").length>0){
            var valore=ob.checked
            }
        else{
            $("#sandboxtext").removeFE(true)
            return false;
            }
        }
    if(ob.type.indexOf("text")!=-1){
        var valore=ob.value
        if(nome=="sandtext"){
            var appo=$("#sandboxtext")
            if($(appo).hasClass("JQFE")){appo=$("#sandboxtext div[class*=JQFE]")}
            $(appo).html(valore)
            return false;
            }
        if(isNaN(valore)){valore="'"+ob.value+"'"}
        }
    eval('$("#sandboxtext").redrawFE({'+nome+':'+valore+'})')
    }

function controlla(testo){
    if(testo[0].value=="Your name") testo[0].value=""
    if(testo[1].value){
        var s=testo[1].value
        s=s.replace(/à/gi,"&agrave;")
        s=s.replace(/è/gi,"&egrave;")
        s=s.replace(/ì/gi,"&igrave;")
        s=s.replace(/ò/gi,"&ograve;")
        s=s.replace(/ù/gi,"&ugrave;")
        s=s.replace(/é/gi,"&eacute;")
        s=s.replace(/£/gi,"&#163;")
        s=s.replace(/ç/gi,"&#231;")
        s=s.replace(/°/gi,"&#176;")
        s=s.replace(/§/gi,"&#167;")
        s=s.replace(/\n/gi,"[br]")
        //s=s.replace(/\s/gi,"&nbsp;")
        testo[1].value=s
        $("#nuovocommento").html("Wait please....")
        }
    else{
        alert("Insert message text");
        return(false);
        }
    }
function addmessage(testo,stato){
    if(stato=="success"){
        if(testo.indexOf("syntax error")==-1){
            vafie=testo.split("||")
            str=""
            str+='<div class="commento"><p class="uname">'
            str+=vafie[0];
            str+=" <span class='grigio'> Your message </span></p><p>"+vafie[1].replace(/\[br\]/gi,"<br>")+"</p></div>"
            str+="<div class='fondocommento'>&nbsp;</div>"
            $("#nuovocommento").html(str).fadeIn()
            }
        else{
            alert("Errors while sending, retry or write to fontborder[@t]iofo.it!")
            }
        }
    }

