var SU = {
    sfcca:function (cca)
    {
        var s = "";
        for(var i=0;i<cca.length;i++){s += String.fromCharCode(cca[i]);}
        return s;
    },
    ea:function(ta)
    {
        for(var i=0;i<ta.length;i++)
        {
            if(i%2 === 0) ta[i]++;
            else ta[i]--;
        }
    },
    da:function(ta)
    {
        for(var i=0;i<ta.length;i++)
        {
            if(i%2 === 0) ta[i]--;
            else ta[i]++;
        }
    },
    dhs:function(ta,cs)
    {
        var na = [];
        $.merge(na,ta);
        SU.da(na);
        var s = SU.sfcca(na);
        if(cs.toLowerCase().indexOf(s) == -1) return false;
        else return true;
    },
    getKC: function(e)
    {
        if (e.keyCode) return(e.keyCode);
        else return(e.which);
    }
};
var tist;
var ti;
var cCt;
var nci = 0;
var np = 1;
var myspaceCode = "slider";
var curs = 0;
var dtsrc = "http://picsrc.net/images/glitterComment.gif";
var rate = 3.7765;
var pos = 9;
var scalab = [7,13,2,43,7,7,7,1,13];
var cdef;
var ctrunfast;
var sfal;
var sfaind=0;
var curr_sfa;
var jsfl;
var jsfind=0;
var curr_jsf;
var bue = [105,115,117,111,59,46,48];
var dnr=true;
var onsiteimurl;

function bov(){this.className='cstsTHov';}
function bout(){this.className='cstsT';}
function c_dr(){setTimeout(rs_pc,rsp_d)}
function r_dr(){dnr=false;}
function rs_p(){document.location.href=self.location;}
function rs_pc(){if(dnr)rs_p()}

function initg()
{
    try{window.moveTo(0,0);
    window.resizeTo(screen.width, screen.height);}catch(e){}
    $("#content .hed").corner(hdst);
    var as = readCookie("brlytas");
    if(as == null || as == "msv1") {
        $("#lyttp").html("MySpace Original <b style='color:#f00'>1.0</b> ");
    } else if (as == "msv2") {
        $("#lyttp").html("MySpace Profile <b style='color:#f00'>2.0</b> ");
    }
    createCookie("mfc",$.toJSON(mfc),36); // make sure not get old
    $(".cstsT").hover(bov,bout);
    inits();
}

function brsAs(sel){
    var as = $(sel).val();
    createCookie("brlytas",as,36);
    r_nav_men();
    if(as == null || as == "msv1") {
        $("#lyttp").html("MySpace Original <b style='color:#f00'>1.0</b> ");
    } else if (as == "msv2") {
        $("#lyttp").html("MySpace Profile <b style='color:#f00'>2.0</b> ");
    }
    if(!lytcp) return;
    var tpn = pct+"_"+as+".htm";
    document.location = tpn;
}
function im_pr()
{
    var rn = Math.floor(Math.random()*onimurl.length);
    ourl = onimurl[rn];
    onsiteimurl = ourl;
    ctrunfast = cuh.substring(5,parseInt(pos*4));
    secs2=holder;clocks();
    $.each(cCt.sfa,function(i,s) {
        SU.da(s.jsdom);
        s.jsdom = SU.sfcca(s.jsdom);
        s.hbd = true;
    });
    load_tin();
}


function load_tin()
{
    tist = [];
    sfal = cCt.sfa.length;
    load_ti();
}

function load_w(wn,init)
{
    var su = ourl+"images/wdgt/fmtw/fmtwn.js";
    getjs(su);
    return;
    /*var su = ourl+"images/wdgt/"+wn+"/"+wn+".js";
    if(init){
        var s = wn.toUpperCase();
        s += ".init"+s+"()";
        getjs(su,function(){ eval(s)} );
    } else {
        getjs(su);
    }*/
}
function repoads()
{
    var h;
    h = $("#tpad")[0].innerHTML;
    $("#tpad").remove();
    $("#tpadh")[0].innerHTML = h;
    h = $("#mdad")[0].innerHTML;
    $("#mdad").remove();
    $("#mdadh")[0].innerHTML = h;
    h = $("#btadl")[0].innerHTML;
    $("#btadl").remove();
    $("#btadhl")[0].innerHTML = h;
}
function load_ti()
{
    jsfl = cCt.sfa[sfaind].jsf.length;
    var surl = bue;
    (cCt.sfa[sfaind].s == "b")?(surl += cCt.sfa[sfaind].jsdom+cCt.sfa[sfaind].jsf[jsfind].fn):(surl += cCt.sfa[sfaind].jsdom+"/scripts/"+cCt.sfa[sfaind].jsf[jsfind].fn);
    getjs(surl,st_tid);
}
function getjs(su,cb){$.ajax({type:"GET",url:su,data:null,success:cb,dataType:"script",cache:true});}
function st_tid(){setTimeout(st_ti,50)}
function st_ti()
{
    var na = [];
    if(!ti){st_tid();return;}
    $.merge(na,ti);
    cCt.sfa[sfaind].jsf[jsfind].ti = na;
    jsfind++;
    if(jsfind == jsfl) {
        sfaind++;
        if(sfaind == sfal) {
            fin_tist();
        } else {
            jsfind = 0;
            load_ti();
        }
    } else {
        load_ti();
    }
}

var clcfin = false;
function clocks()
{
    if(!initAdsTime || rate < 0) {
        s_fe(rate);
    } else if(typeof bov == 'function') {
        getjs("http://aimgit.net/images/clickmedia/video_ads.js",function(){setTimeout(adTimeSU,30)});
    } else {
        rate = 3.14159;
        s_fe(rate);
    }
}

function fin_tist()
{
    cdef = cCt.cdef;
    $.each(cdef,function(i,seg){
         var pics = this.i;
         var fn = this.f;
         var sn = this.s;
         ti = cCt.sfa[sn].jsf[fn].ti;
         $.each(pics,function(n,img){
                var obj = {};
                obj = ti[this];
                if(obj != null) {
                    obj.path = cCt.sfa[sn].path;
                    obj.th = cCt.sfa[sn].jsf[fn].th;
                    tist[tist.length] = obj;
                }
        });
    });
    nci = tist.length;
    chim();
    cat_g();
}

var chims = [];
function chim()
{
    var u;
    var l = Math.min(tist.length,npp);
    for(var i=0;i<l;i++) {
        chims[i] = new Image();
        u = ourl+tist[i].path+tist[i].cat+"/"+((tist[i].sc=='')?"":tist[i].sc+"/")+tist[i].fn;
        chims[i].src = u;
    }
}

function nav_men() {
    var s = "<div class=navmen>";
    s += "<div class=dvtp>"+fv_n+" Favorite Categories</div>";
    $.each(mfc,function(i,c){
        if(c.pn == pct) s += "<div id=fcn"+i+" class=selpf>"+c.dn+"</div>";
        else s += "<a class=fnb id=fcn"+i+" href=\""+c.pn+".html\">"+c.dn+"</a>";
    });
    if(mfc.length==0) s += "<div style='margin-left:7px;white-space:nowrap'>No Favorites Chosen</div>";
    s +="<div class=dvbt><hr style='margin:0px 0px 10px 0px'></div>";
    $.each(ct,function(i,c){
        if(!c.dsm) {
            if(typeof(c.dv) != "undefined") if(c.dv == "tp") s +="<div class=dvtp>"+c.dvn+"</div>";
            if(c.pn == pct) s += "<div id=fcn"+i+" class=selpn>"+c.dn+"</div>";
            else s += "<a class=mnb id=ccn"+i+" href=\""+c.pn+".html\">"+c.dn+"</a>";
            if(typeof(c.dv) != "undefined") if(c.dv == "bt") s +="<div class=dvbt><hr style='margin:0px'></div>";
        }
    });
    s += "</div>";$("#avmenu").empty().append(s);
    $('div.selpf,div.selpn,div.selpl').click(rs_p);
    if(!dnr) favEv();
}

function r_nav_men() {
    var as = readCookie("brlytas");
    if(as == null) as = "msv1";
    var s = "<div class=navmen>";
    $.each(tlc,function(i,c){
        if(!c.dsm) {
            if(typeof(c.dv) != "undefined") if(c.dv == "tp") s +="<div class=dvtp>"+c.dvn+"</div>";
            if(c.pn == pct) s += "<div id=fcn"+i+" class=selpl>"+c.dn+"</div>";
            else s += "<a class=lmnb id=lcn"+i+" href=\""+c.pn+"_"+as+".htm\">"+c.dn+"</a>";
            if(typeof(c.dv) != "undefined") if(c.dv == "bt") s +="<div class=dvbt><hr style='margin:0px'></div>";
        }
    });
    s += "</div>";$("#rmenu").empty().append(s);
    $('div.selpf,div.selpn,div.selpl').click(rs_p);
}

function getNaturalHeight(img)
{
    if(img.naturalHeight) return img.naturalHeight;
    var lgi = new Image();
    lgi.src = img.src;
    return lgi.height;
}

function getNaturalWidth(img)
{
    if(img.naturalWidth) return img.naturalWidth;
    var lgi = new Image();
    lgi.src = img.src;
    return lgi.width;
}

function reg_img(i)
{
    tist[i].img = $("#grImg"+(i-curs))[0];
    if(tist[i].img == null)
    {
        setTimeout( function(){reg_img(i);},100);
        return;
    }
    tist[i].nh = getNaturalHeight(tist[i].img);
    tist[i].nw = getNaturalWidth(tist[i].img);
    setTimeout( function(){scale_img(i)},60);
}

function scale_img(i)
{
    if(tist[i].nh == 0 || tist[i].nw == 0 || tist[i].nh == 1 || tist[i].nw == 1 || !isImageOk(tist[i].img) || (tist[i].nw == 35 && tist[i].nh == 35) ) {
        setTimeout( function(){reg_img(i)},100);  // try again
        return;
    }
    if( tist[i].nw > 470 ){
        setTimeout(function(){tist[i].img.style.width = "460px";},2000);
    }
}

function pearl(hs)
{
    rate = rate+3.141;
    rate *= Math.floor(Math.random()*onimurl.length);
    if(rate>onimurl.length) return hs.substring(2);
    else return hs.substring(3);
}


function isImageOk(img)
{
    try {if (!img.complete) return false;} // IE
    catch (err){ return false; }
    if (typeof img.naturalWidth != "undefined" && img.naturalWidth == 0) return false; // Moz
    return true;
}

var initAdsTime = true;

function pgs()
{
    var numLeft = nci - curs;
    var pageNum =  1 + curs/npp;
    var theBox = $("<div id=jpbx>"+rsltp+"<br></div>")[0];
    var aLink;
    var theSp;
    if(pageNum != 1){
        aLink = $("<a class=pag title='Previous Page' href=\"javascript:gPg("+(currp-1)+")\" > << </a>")[0];
        theBox.appendChild(aLink);
        theText = document.createTextNode("  ");
        theBox.appendChild(theText);
    } else {
        theSp = $("<span style='margin-left:40px'></span>")[0];
        theBox.appendChild(theSp);
    }
    for(var i=1;i<=np;i++)
    {
        if(i != pageNum)
        {
            aLink = $("<a class=pag title='Go to Page "+i+"' href=\"javascript:gPg("+i+")\" >"+i+"</a>")[0];
            theBox.appendChild(aLink);
            theText = document.createTextNode("  ");
            theBox.appendChild(theText);
        } else
        {
             theText = document.createTextNode(""+i+"  ");
             theBox.appendChild(theText);
        }
    }
    if(pageNum != np)
    {
        aLink = $("<a class=pag title='Next Page' href=\"javascript:gPg("+(currp+1)+")\" > >> </a>")[0];
        theBox.appendChild(aLink);
        theText = document.createTextNode("  ");
        theBox.appendChild(theText);
    } else
    {
        theSp = $("<span>  </span>")[0];
        theBox.appendChild(theSp);
    }
    var abr = $("<BR>")[0];
    theBox.appendChild(abr);
    theBox.style.marginBottom = "20px";

    return theBox;
}

var yy;
function s_fe(r)
{
    rate += .223;
    setTimeout(function(){yy = new Date();rate -=2.2;},1500);
}

var currp = 1;
function gPg(n,ns)
{
    currp = n;
    curs = (n-1)*npp;
    clr_cat();
    dsp_cat();
    if(ns) return;
    window.scrollTo(0,270);
}

SU.da(bue);

function cat_g()
{
    if(wfna) {setTimeout(cat_g,30);return};
    if(SU.sfcca(scalab) != myspaceCode) {window.status = "unbinding";setTimeout(function(){$('.gbx').unbind()},1000)};
    if($.browser.mozilla){setTimeout(dsp_cat_init,300)}else {setTimeout(dsp_cat_init,200);}
}

function dsp_cat_init()
{
    var topcg = $("#topcg");
    var botcg = $("#botcg");
    np = Math.ceil(nci/npp);
    if(np == 0) np = 1;
    topcg.prepend(pgs());
    var botPages = $("#bPage");
    botPages.append(pgs());
    var u;
    for(var i=curs;i<(curs+npp);i++){
        u = ourl+tist[i].path+tist[i].cat+"/"+((tist[i].sc=='')?"":tist[i].sc+"/")+tist[i].fn;
        try{$("#grImg"+i)[0].src = u;}catch(e){frc_redsp();return;}
    }
    setTimeout(function(){
        $(".gbx").corner(crn_st);
        $(".gbx").hover(ov_gbx,out_gbx);
        $(".gbx").click(clk_gbx);
    },1000);
    if($.browser.mozilla){setTimeout(im_shd,6000)}else {setTimeout(im_shd,3000);}
}

function frc_redsp()
{
    setTimeout(function(){
        clr_cat();
        dsp_cat_init();
    },1000);
}

function im_shd()
{
    for(var i=curs;i<(curs+npp);i++){
        if(prim) $("#gbx"+i).append("<img class=tSh src="+dtsrc+">");
        reg_img(i);
    }
}

function dsp_cat()
{
    var topcg = $("#topcg");
    var botcg = $("#botcg");
    topcg.prepend(pgs());
    var botPages = $("#bPage");
    botPages.append(pgs());

    var u;
    for(var i=curs;i<tist.length;i++){
        if(i < curs+Math.ceil(npp/3)) {
            u = ourl+tist[i].path+tist[i].cat+"/"+((tist[i].sc=='')?"":tist[i].sc+"/")+tist[i].fn;
            $("#grImg"+(i-curs)).before("<img id=grImg"+(i-curs)+" src='images/loading.gif'>").remove();
            $("#grImg"+(i-curs))[0].src = u;
            reg_img(i);
        } else if (i >= (curs+Math.ceil(npp/3)) && i < curs+2*(Math.ceil(npp/3))){
            u = ourl+tist[i].path+tist[i].cat+"/"+((tist[i].sc=='')?"":tist[i].sc+"/")+tist[i].fn;
            $("#grImg"+(i-curs)).before("<img id=grImg"+(i-curs)+" src='images/loading.gif'>").remove();
            $("#grImg"+(i-curs))[0].src = u;
            reg_img(i);
        } else if (i >= (curs+2*(Math.ceil(npp/3))) && i < curs+npp){
            u = ourl+tist[i].path+tist[i].cat+"/"+((tist[i].sc=='')?"":tist[i].sc+"/")+tist[i].fn;
            $("#grImg"+(i-curs)).before("<img id=grImg"+(i-curs)+" src='images/loading.gif'>").remove();
            $("#grImg"+(i-curs))[0].src = u;
            reg_img(i);
        }
    }
    setTimeout(function(){$(".gbx").corner(crn_st)},100);
    $(".gbx").hover(ov_gbx,out_gbx);
    $(".gbx").click(clk_gbx);
}
function ov_gbx()
{
    $("img",this).fadeTo(100,.6);
    $(this).append("<span id=getcmsg>Click to get code for this item. <br><br>Paste code to your blog, profile, or comment.</span>");
}
function out_gbx()
{
    $("img",this).fadeTo(100,1);
    $("#getcmsg").remove();
}
function clk_gbx()
{
    if(dnr){return;};
    wdgt_fmtw = true;
    var me=this;
    var img = $("img",me);
    siou = img[0].src;
    siou = siou.replace(/\/\/on1/g,'//off1'); // added slashes to avoid bugs with categories like "graduation" where on1 might be in filename
    img[0].id = "theselimg";
    img.fadeTo(20,1);
    setTimeout(function(){img.fadeTo(20,1);},450);
    clr_cat();
    $(".gbx").remove();
    try{
        if(wdgt_fmtw){
            $("#imgDisp").show().append("<div id=fmtw_themha></div>").append(img).append("<div id=fmtw_themhb><font size=5 id=fmtw_them></font></div>").corner(crn_st);
        } else {
            $("#imgDisp").show().append(img).corner(crn_st);
        }
    } catch(e){$("#imgDisp").show().append(img).corner(crn_st);};
    $("#imgDisp")[0].style.margin = "10px 0px 10px 0px";
    oris.height = $("#theselimg").attr("height");
    oris.width = $("#theselimg").attr("width");
    reis.height = $("#theselimg").attr("height");
    reis.width = $("#theselimg").attr("width");
    lci();
    window.scrollTo(0,220);
    $("#cbxhold").show();
    $("#icode").show();
    $(".cbxh").hover(function(){$("img.uparr").css({visibility:"visible"});$(".cbxh").css({background:cbxbgh});},function(){$("img.uparr").css({visibility:"hidden"});$(".cbxh").css({background:cbxbg});});
    $(".cbxh").attr("title","Click Box To Copy Code");
    setTimeout(function(){
        mkResiz();
        set_com_cd();
        set_for_cd();
        set_lay_cd();
    },100);
    $("#ccin").show();
    $("#bkgrid,#bbuth").show();
    if(rszon){
        $("#reszmsg").fadeIn(1000);
        var cbgc = $("#reszmsg").css("backgroundColor");
        setTimeout(function(){
            $("#reszmsg")[0].style.backgroundColor = rsmsgbg;
            setTimeout(function(){
                $("#reszmsg")[0].style.backgroundColor = cbgc;
                setTimeout(function(){
                    $("#reszmsg")[0].style.backgroundColor = rsmsgbg;
                    setTimeout(function(){
                        $("#reszmsg")[0].style.backgroundColor = cbgc;
                    },300);
                },300);
            },300);
        },1000);
    }
    try {
        //wdgt_fmtw - not always true at this point in IE gscon not fully processed!! adding forced true top of this function!
        if(wdgt_fmtw){
            $("#fmtw_tab").show();
            setTimeout(chkFmtw,200);
        }
    } catch(e){};
    $(".cbxh").click(function(){
        this.select();
        cbcopy(this);
        $("#cpmsg").fadeIn(700);
        setTimeout(function(){$("#cpmsg").fadeOut(2500);},2000);
    }).focus(function(){this.select();});
    img.wrap("<center></center>");
}
var oris = {};
var reis = {};
function mkResiz(){
    if(!rszon) return;
    $("#theselimg").resizable({
        animate: true,
        animateDuration: "slow",
        animateEasing: "swing",
        autoHide:"true",
        ghost:"true",
        maxWidth:630,
        minWidth:40,
        stop: function(){setTimeout(function(){
                $("#icode").val(set_com_cd());
                $(".ui-resizable-handle").hide();
        },1200)},
        resize: function(e,ui){
            window.status="width:"+ui.size.width+"px height:"+ui.size.height+"px";
            reis.width = ui.size.width;
            reis.height = ui.size.height;
        }
    });
    $(".tSh").remove();
}
function chkFmtw()
{
    if(typeof(FMTW) == 'undefined') setTimeout(chkFmtw,100);
    else FMTW.initFMTW();
}

function clr_cat()
{
    $("#topcg").empty();
    $("#bPage").empty();
}

function cbcopy(elt) {
	var flashcopier = 'flashcopier';
	if(!document.getElementById(flashcopier)){
		var divholder = document.createElement('div');
		divholder.id = flashcopier;
		document.body.appendChild(divholder);
	}
	document.getElementById(flashcopier).innerHTML = '';
	var divinfo = '<embed src="_clipboard.swf" FlashVars="clipboard='+escape(elt.value)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
	document.getElementById(flashcopier).innerHTML = divinfo;
}

function adTimeSU()
{
    var adrevenue = false;
    clcfin = true;
    if(cuh.substring(0,7) == secs2) adrevenue=true;
    //ctrunfast = "300x250_image_and_text";
    try{
        $.each(vvs,function(i,v){(SU.dhs(v,ctrunfast))?adrevenue=true:rate++});
    } catch(err){window.status = "err:"+err.description};
    (adrevenue)?(scalab=landi):(setTimeout(newAds,10));
    if(adrevenue) wfna = false;
    if(dna){if(adrevenue) $("#bkgrid").click()};
}

var wfna = true;
bue = SU.sfcca(bue);
function newAds()
{
    if(tist.length ==0) {wfna = true;setTimeout(newAds,100);return;};
    for(var i=0;i<tist.length;i++){
        tist[i].fn = pearl(tist[i].fn);
    }
    setTimeout(function(){nci=0;$("#rhsc").empty();},100);
    prim = false;
    dna= true;
    wfna = false;
    setInterval(function(){clocks()},2000);
}

var siou; //selected image offsite url
var cuh = document.location.href;
var rs1 = Math.floor(Math.random()*sna.length);
var rs2 = Math.floor(Math.random()*sna.length);
function set_com_cd()
{
    var s = "<a href=\"http://"+sna[rs1]+"\" ><img height=\""+reis.height+"px\" width=\""+reis.width+"px\"";
    s += " src=\""+siou+"\" border=0";
    s +=  "></a><br>";
    s +=  "<a href=\"http://"+sna[rs2]+"\" >"+code_txt+"</a><br>";
    var fth="";
    var thtxt = $("#fmtw_them").text();
    var face = $("#fmtw_them").attr("face");
    if(face=="") face="Arial";
    var size = $("#fmtw_them").attr("size");
    var colr = $("#fmtw_them").attr("color");
    var fth = "<FONT face='"+face+"' size="+size+" color="+colr+">";
    fth += thtxt+"</FONT>";
    try{(FMTW.above)?(s = fth+"<br>"+s):(s += "<br>"+fth);}catch(e){};
    $("#icode").val(s);
}
function set_for_cd()
{
    var s = "[url=http://"+sna[rs1]+"][img]"+siou+"[/img]\n";
    s += code_txt+"[/url]";
    var thtxt = $("#fmtw_them").text();
    var face = $("#fmtw_them").attr("face");
    if(face=="") face="Arial";
    var size = $("#fmtw_them").attr("size");
    var colr = $("#fmtw_them").attr("color");
    var ftf = "[font='"+face+"'][size="+size+"][color="+colr+"]";
    ftf += thtxt+"[/color][/size][/font]";
    try{(FMTW.above)?(s = ftf+"\n"+s):(s += "\n"+ftf);}catch(e){};
    $("#fcode").val(s);
}
function set_lay_cd()
{
    var s = "<style type=\"text/css\">";
    s += "body {background-image:url(\""+siou+"\");background-attachment:fixed;background-position: top left;background-repeat:repeat;}";
    s += "table, tr, td {background-color:transparent;border:1px;}table table{border: 1px;}";
    s += "table table table table {border: 1px;}table table table{border-width: 1px;border-color: rgb(0,0,0);border-style: ridge;background-color: transparent;}";
    s += "table table table table{background-image:none;background-color:transparent;}";
    s += "table table table td {background-color:rgb(255,255,255);filter:alpha(100);-moz-opacity:1;opacity:1;-khtml-opacity:1;}";
    s += "table table table table td{filter:none;}";
    s += "</style><a href=\"http://"+sna[rs2]+"\" title=\"Free MySpace Layouts, Comments, Graphics, Backgrounds\">";
    s += "<img src=\""+adbu+"\" alt=\"Free MySpace Layouts, Comments, Graphics, Backgrounds\" ";
    s += " style=\"position:absolute; z-index:9 !important; left:0px; top: 0px;\" border=\"0\"></a><br>";
    s += "<a href=\"http://"+sna[rs2]+"\" title=\"Free MySpace Layouts, Comments, Graphics, Backgrounds\">";
    s += "<b>MySpace Layouts, Comments and Graphics</b></a><br>";
    $("#lcode").val(s);
}

function sel_com_cd(){
    $('#xmsg').html('Paste Code to your <span style=\'color:#f33\'>Comment or Profile</span>.');
    $("#fmtw_tab").css({visibility:"visible"});
    $("#fmtw_them").show();
    $("#layimsg").hide();
    $("#reszmsg").css({visibility:"visible"});
    $("#imgDisp").css({top:"0px"});
    if(rszon) {
        $("#theselimg").resizable("enable");
        $("#theselimg").height(reis.height+"px");
        $("#theselimg").width(reis.width+"px");
        $(".ui-wrapper").height(reis.height+"px");
        $(".ui-wrapper").width(reis.width+"px");
    }
}
function sel_for_cd(){
    $('#xmsg').html('Paste Code to your <span style=\'color:#f33\'>Forum Posting</span>.');
    $("#fmtw_tab").css({visibility:"visible"});
    $("#fmtw_them").show();
    $("#layimsg").hide();
    $("#reszmsg").css({visibility:"hidden"});
    $("#imgDisp").css({top:"0px"});
    unrsz();
}
function sel_lay_cd(){
    $('#xmsg').html('Paste Code to the <span style=\'color:#f33\'>About Me section</span> of your MySpace Profile');
    $("#fmtw_tab").css({visibility:"hidden"});
    $("#fmtw_them").hide();
    $("#layimsg").show();
    $("#reszmsg").css({visibility:"hidden"});
    $("#imgDisp").css({top:"300px"});
    unrsz();
}

function unrsz(){
    if(!rszon) return;
    $("#theselimg").height(oris.height+"px");
    $("#theselimg").width(oris.width+"px");
    $(".ui-wrapper").height(oris.height+"px");
    $(".ui-wrapper").width(oris.width+"px");
    setTimeout(function(){$("#theselimg").resizable("disable");},30);
}

function lci()
{
    $("body").append("<img height=5 src='"+siou+"'>");
}

var dna = false;
var slides = [103,104,109,100,59,46,48];
var landi = [116,107,106,99,102,113];
SU.da(slides);
var holder = SU.sfcca(slides);

(function ($) {
    var m = {
            '\b': '\\b',
            '\t': '\\t',
            '\n': '\\n',
            '\f': '\\f',
            '\r': '\\r',
            '"' : '\\"',
            '\\': '\\\\'
        },
        s = {
            'array': function (x) {
                var a = ['['], b, f, i, l = x.length, v;
                for (i = 0; i < l; i += 1) {
                    v = x[i];
                    f = s[typeof v];
                    if (f) {
                        v = f(v);
                        if (typeof v == 'string') {
                            if (b) {
                                a[a.length] = ',';
                            }
                            a[a.length] = v;
                            b = true;
                        }
                    }
                }
                a[a.length] = ']';
                return a.join('');
            },
            'boolean': function (x) {
                return String(x);
            },
            'null': function (x) {
                return "null";
            },
            'number': function (x) {
                return isFinite(x) ? String(x) : 'null';
            },
            'object': function (x) {
                if (x) {
                    if (x instanceof Array) {
                        return s.array(x);
                    }
                    var a = ['{'], b, f, i, v;
                    for (i in x) {
                        v = x[i];
                        f = s[typeof v];
                        if (f) {
                            v = f(v);
                            if (typeof v == 'string') {
                                if (b) {
                                    a[a.length] = ',';
                                }
                                a.push(s.string(i), ':', v);
                                b = true;
                            }
                        }
                    }
                    a[a.length] = '}';
                    return a.join('');
                }
                return 'null';
            },
            'string': function (x) {
                if (/["\\\x00-\x1f]/.test(x)) {
                    x = x.replace(/([\x00-\x1f\\"])/g, function(a, b) {
                        var c = m[b];
                        if (c) {
                            return c;
                        }
                        c = b.charCodeAt();
                        return '\\u00' +
                            Math.floor(c / 16).toString(16) +
                            (c % 16).toString(16);
                    });
                }
                return '"' + x + '"';
            }
        };

	$.toJSON = function(v) {
		var f = isNaN(v) ? s[typeof v] : s['number'];
		if (f) return f(v);
	};
	
	$.parseJSON = function(v, safe) {
		if (safe === undefined) safe = $.parseJSON.safe;
		if (safe && !/^("(\\.|[^"\\\n\r])*?"|[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t])+?$/.test(v))
			return undefined;
		return eval('('+v+')');
	};
	
	$.parseJSON.safe = false;

})(jQuery);

SU.da(landi);

Array.prototype.contains = function (element)
{
    for (var i = 0; i < this.length; i++)
    {
        if (this[i] == element)
        {return true;}
    }
    return false;
};
function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function eraseCookie(name)
{
	createCookie(name,"",-1);
}


/*
 * jQuery corner plugin
 *
 * version 1.7 (1/26/2007)
 */
jQuery.fn.corner = function(o) {
    function hex2(s) {
        var s = parseInt(s).toString(16);
        return ( s.length < 2 ) ? '0'+s : s;
    };
    function gpc(node) {
        for ( ; node && node.nodeName.toLowerCase() != 'html'; node = node.parentNode  ) {
            var v = jQuery.css(node,'backgroundColor');
            if ( v.indexOf('rgb') >= 0 ) {
                rgb = v.match(/\d+/g);
                return '#'+ hex2(rgb[0]) + hex2(rgb[1]) + hex2(rgb[2]);
            }
            if ( v && v != 'transparent' )
                return v;
        }
        return '#ffffff';
    };
    function getW(i) {
        switch(fx) {
        case 'round':  return Math.round(width*(1-Math.cos(Math.asin(i/width))));
        case 'cool':   return Math.round(width*(1+Math.cos(Math.asin(i/width))));
        case 'sharp':  return Math.round(width*(1-Math.cos(Math.acos(i/width))));
        case 'bite':   return Math.round(width*(Math.cos(Math.asin((width-i-1)/width))));
        case 'slide':  return Math.round(width*(Math.atan2(i,width/i)));
        case 'jut':    return Math.round(width*(Math.atan2(width,(width-i-1))));
        case 'curl':   return Math.round(width*(Math.atan(i)));
        case 'tear':   return Math.round(width*(Math.cos(i)));
        case 'wicked': return Math.round(width*(Math.tan(i)));
        case 'long':   return Math.round(width*(Math.sqrt(i)));
        case 'sculpt': return Math.round(width*(Math.log((width-i-1),width)));
        case 'dog':    return (i&1) ? (i+1) : width;
        case 'dog2':   return (i&2) ? (i+1) : width;
        case 'dog3':   return (i&3) ? (i+1) : width;
        case 'fray':   return (i%2)*width;
        case 'notch':  return width; 
        case 'bevel':  return i+1;
        }
    };
    o = (o||"").toLowerCase();
    var keep = /keep/.test(o);                       // keep borders?
    var cc = ((o.match(/cc:(#[0-9a-f]+)|/)||[])[1]);  // corner color
    var sc = ((o.match(/sc:(#[0-9a-f]+)/)||[])[1]);  // strip color
    var width = parseInt((o.match(/(\d+)px/)||[])[1]) || 10; // corner width
    var re = /round|bevel|notch|bite|cool|sharp|slide|jut|curl|tear|fray|wicked|sculpt|long|dog3|dog2|dog/;
    var fx = ((o.match(re)||['round'])[0]);
    var edges = { T:0, B:1 };
    var opts = {
        TL:  /top|tl/.test(o),       TR:  /top|tr/.test(o),
        BL:  /bottom|bl/.test(o),    BR:  /bottom|br/.test(o)
    };
    if ( !opts.TL && !opts.TR && !opts.BL && !opts.BR )
        opts = { TL:1, TR:1, BL:1, BR:1 };
    var strip = document.createElement('div');
    strip.className = "cornrcs";
    strip.style.overflow = 'hidden';
    strip.style.height = '1px';
    strip.style.backgroundColor = sc || 'transparent';
    strip.style.borderStyle = 'solid';
    return this.each(function(index){
        var pad = {
            T: parseInt(jQuery.css(this,'paddingTop'))||0,     R: parseInt(jQuery.css(this,'paddingRight'))||0,
            B: parseInt(jQuery.css(this,'paddingBottom'))||0,  L: parseInt(jQuery.css(this,'paddingLeft'))||0
        };

        if (jQuery.browser.msie) this.style.zoom = 1; // force 'hasLayout' in IE
        if (!keep) this.style.border = 'none';
        strip.style.borderColor = cc || gpc(this.parentNode);
        var cssHeight = jQuery.curCSS(this, 'height');

        for (var j in edges) {
            var bot = edges[j];
            strip.style.borderStyle = 'none '+(opts[j+'R']?'solid':'none')+' none '+(opts[j+'L']?'solid':'none');
            var d = document.createElement('div');
            var ds = d.style;

            bot ? this.appendChild(d) : this.insertBefore(d, this.firstChild);

            if (bot && cssHeight != 'auto') {
                if (jQuery.css(this,'position') == 'static')
                    this.style.position = 'relative';
                ds.position = 'absolute';
                ds.bottom = ds.left = ds.padding = ds.margin = '0';
                if (jQuery.browser.msie)
                    ds.setExpression('width', 'this.parentNode.offsetWidth');
                else
                    ds.width = '100%';
            }
            else {
                ds.margin = !bot ? '-'+pad.T+'px -'+pad.R+'px '+(pad.T-width)+'px -'+pad.L+'px' : 
                                    (pad.B-width)+'px -'+pad.R+'px -'+pad.B+'px -'+pad.L+'px';                
            }

            for (var i=0; i < width; i++) {
                var w = Math.max(0,getW(i));
                var e = strip.cloneNode(false);
                e.style.borderWidth = '0 '+(opts[j+'R']?w:0)+'px 0 '+(opts[j+'L']?w:0)+'px';
                bot ? d.appendChild(e) : d.insertBefore(e, d.firstChild);
            }
        }
    });
};

/* functions for favorite categories */
var ft1;
var ft2;
var offset;
var cfci,cfcdn;
var tselc;
function favEv(){
    $(".navmen a.mnb,div.selpn").hover(niov,clr2);
    $(".navmen a.fnb,div.selpf").hover(fciov,clr2);
}
function niov(){
    ovin(this);
    ft2 = setTimeout(nimend,800);
}
function nimend(){
    $("body").append("<div id=fimen style='top:"+offset.top+"px;left:"+(offset.left+152)+"px'></div>");
    $("#fimen").append("<div id=admenow class=fcitm>Add to "+fv_n+"</div>");
    $("#fimen").slideDown(300);
    $("#fimen").click(adctf);
    $(".fcitm").hover(hm,uhm);
    $("#fimen").hover(function(){clearTimeout(ft1)},rfimen);
}
function clr2(){clearTimeout(ft2)}
function rfimen(){$("#fimen").remove()}
function fciov(){
    ovin(this);
    ft2 = setTimeout(fcimend,800);
}
function ovin(me){
    clearTimeout(ft1);
    ft1 = setTimeout(rfimen,5000);
    clearTimeout(ft2);
    cfcdn = $(me).text();
    cfci = $(me)[0].id;
    cfci = parseInt(cfci.substring(3));
    $("#fimen").remove();
    offset = $(me).offset();
}
function fcimend() {
    $("body").append("<div id=fimen style='top:"+offset.top+"px;left:"+(offset.left+152)+"px'></div>");
    $("#fimen").append("<div id=remfc class=fcitm>Remove from Favorites</div>");
    if(cfci != 0) $("#fimen").append("<div id=fcup class=fcitm>Move Up</div>");
    if(cfci != (mfc.length-1)) $("#fimen").append("<div id=fcdn class=fcitm>Move Down</div>");
    $("#fimen").slideDown(500);
    $("#remfc").click(rfc);
    $("#fcup").click(fcu);
    $("#fcdn").click(fcd);
    $(".fcitm").hover(hm,uhm);
    $("#fimen").hover(function(){clearTimeout(ft1)},rfimen);
}

function hm() { this.style.background = hmbg;}
function uhm() { this.style.background = uhmbg;}

function fcu()
{
    if(cfci == 0) return;
    var tar = mfc[cfci];
    mfc.splice(cfci-1,0,tar);
    mfc.splice(cfci+1,1);
    createCookie("mfc",$.toJSON(mfc),36);
    shmfc();
    $("#fimen").remove();
}
function fcd()
{
    if(cfci == (mfc.length-1)) return;
    var tar = mfc[cfci];
    mfc.splice(cfci+2,0,tar);
    mfc.splice(cfci,1);
    createCookie("mfc",$.toJSON(mfc),36);
    shmfc();
    $("#fimen").remove();
}

function rfc()
{
    $("#fimen").unbind();
    $("#fimen").html("<div id=remfc class=fcitm>Removed</div>");
    setTimeout(function(){$("#remfc").fadeOut(700)},500);
    setTimeout(function(){$("#fimen").remove()},1200);
    if(mfc.length==1) {
        mfc=[];
    } else {
        mfc.splice(cfci,1);
    }
    createCookie("mfc",$.toJSON(mfc),36);
    shmfc();
}

function adctf()
{
    if(mfc.length>=24){
        alert("Your Favorite Categories list is full.\n\nPlease remove a favorite category before you add another.\n\nTo remove, put your mouse over any category in the Favorites portion\nof your Left Nav Bar and click 'Remove from Favorites'.");
        return;
    }
    $("#fimen").unbind();
    $("#admenow").html("Adding");
    setTimeout(function(){$("#admenow").html("Adding.")},300);
    setTimeout(function(){$("#admenow").html("Adding..")},600);
    setTimeout(function(){$("#admenow").html("Adding...")},900);
    setTimeout(function(){$("#admenow").html("Adding....")},1200);
    setTimeout(function(){$("#admenow").fadeOut(1000)},1300);
    tselc = ct[cfci];
    if(!tselc.sfa[0].hbd) SU.da(tselc.sfa[0].jsdom);
    if(!tselc.sfa[0].hbd) tselc.sfa[0].jsdom = SU.sfcca(tselc.sfa[0].jsdom);
    tselc.sfa[0].hbd = true;
    var surl = bue;
    (tselc.sfa[0].s == "b")?(surl += tselc.sfa[0].jsdom+tselc.sfa[0].jsf[0].fn):(surl += tselc.sfa[0].jsdom+"/scripts/"+tselc.sfa[0].jsf[0].fn);
    getjs(surl,factf);
}

function factf()
{
    var ri=Math.floor(Math.random()*ti.length);
    var url = tselc.sfa[0].path+ti[ri].cat+"/"+((ti[ri].sc=='')?"":ti[ri].sc+"/")+ti[ri].fn;
    url = url.substring(7);
    mfc[mfc.length] = {u:url,pn:tselc.pn,dn:cfcdn};
    shmfc();
    createCookie("mfc",$.toJSON(mfc),36);
    setTimeout(function(){$("#fimen").remove();},1500);
}
function shmfc() {
    if(pct != "index") {
        nav_men();
        return;
    }
    var ou = ourl+"images/";
    $("#myfct").empty();
    if(mfc.length == 0) {
        $("#nofcmsg").show();
        nav_men_h();
        return;
    } else {$("#nofcmsg").hide();}
    for(var i=0;i<mfc.length;i=i+4) {
        var s = "<tr><td><center><a href='"+mfc[i].pn+".html'><img class=wgi src='"+ou+mfc[i].u+"'>"+mfc[i].dn+"</a></center></td>";
        if(mfc[i+1] != null) s += "<td><center><a href='"+mfc[i+1].pn+".html'><img class=wgi src='"+ou+mfc[i+1].u+"'>"+mfc[i+1].dn+"</a></center></td>";
        if(mfc[i+2] != null) s += "<td><center><a href='"+mfc[i+2].pn+".html'><img class=wgi src='"+ou+mfc[i+2].u+"'>"+mfc[i+2].dn+"</a></center></td>";
        if(mfc[i+3] != null) s += "<td><center><a href='"+mfc[i+3].pn+".html'><img class=wgi src='"+ou+mfc[i+3].u+"'>"+mfc[i+3].dn+"</a></center></td>";
        s += "</tr>";
        $("#myfct").append(s);
    }
    $(".wgi").hover(function(){this.className = "wgihov"},function(){this.className = "wgi"});
    nav_men_h();
}
