var main = $('#content-area')[0].appendChild(cE('ul'));
main.className = "projects";
function cE(e){return document.createElement(e);}
function make_project_round(name,link){
    var a = main.appendChild(cE("li")).appendChild(cE('a'));
    var that = a.appendChild(cE("img"));
    var color = "#FFF";
    that.className = "project";
    that.src = 'http://jaredforsyth.com/sites/default/files/images/'+name+'.shot.png';
    a.href='javascript:void(0)';
    a.onclick = function(){
        
    }
    that.style.borderColor = "#3561B1";
    Rounded(a,"#FFF","#3561B1");
    return that;
}

var top = 1;
var tp = 1;
function make_project(real,name,link,src,row,zi){
    var dv = main.appendChild(cE("li")).appendChild(cE('div'));
    dv.className = 'project';
    var tr = dv.appendChild(cE('table')).appendChild(cE('tr'));
    var img = tr.appendChild(cE('td')).appendChild(cE('img'))
    img.src = 'http://jaredforsyth.com/projects/images/'+name+'.shot.png';
    img.title = 'See More';
    dv.onclick = function(){
        // show the popup
        show_project(real,name,link,src,row);
    }
    var more = tr.appendChild(cE('td'));
    more.style.paddingLeft='10px';
    more.appendChild(cE('span')).innerHTML = real;
    more.appendChild(cE('br'));
    if (link){
     var hi = more.appendChild(cE('a'));
     hi.innerHTML = 'Try It';
     hi.href = link;
     more.appendChild(cE('br'));
    }
    if (src){
     var hs = more.appendChild(cE('a'));
     hs.innerHTML = 'Source';
     hs.href = src;
    }
    dv.style.zIndex = zi;
    var tm = null;
    var closing = false;
    dv.onmouseover = function(){
        if (closing)return;
        clearTimeout(tm);
        $(dv).animate({width:'195px'},200,0);
    }
    dv.onmouseout = function(){
        tm = setTimeout(function(){
            closing = true;
            $(dv).animate({width:'80px'},150,0,function(){closing=false;});
        },50);
    }
    return dv;
}

function cTN(e){return document.createTextNode(e);}

function show_project(real,name,link,src,row){
    var bk = document.body.appendChild(cE('div'));
    bk.className = 'project_back';
    
    /** loader **/
    var loader = document.body.appendChild(cE('div'));
    loader.className = 'project_load';
    loader.appendChild(cE('img')).src= '/sites/default/files/images/projectload.gif';
    
    var dv = document.body.appendChild(cE('div'));
    dv.className = 'project_frame';
    dv.style.visibility='hidden';
    var ia = dv.appendChild(cE('a'));
    ia.href = link;
    /*var img = ia.appendChild(cE('img'))
    img.onload = function(){
        dv.style.marginTop = -(dv.offsetHeight/2)+"px";
        dv.style.visibility = 'visible';
    }
    img.src = 'http://jaredforsyth.com/sites/default/files/images/'+name+'.big.png';
    */
    bk.onclick = function(){document.body.removeChild(bk);document.body.removeChild(loader);document.body.removeChild(dv);}
    var txt = dv.appendChild(cE('div'));
    var body_txt = $('td.views-field-body p',row)[0].innerHTML;
    txt.innerHTML = body_txt;
    txt.appendChild(cE('br'));
    if (link){
     var play = txt.appendChild(cE('a'));
     play.innerHTML = 'Try It';
     play.href = link;
     dv.style.marginTop = -(dv.offsetHeight/2)+"px";
     txt.appendChild(cE('br'));
    }
    if (src){
     var play = txt.appendChild(cE('a'));
     play.innerHTML = 'Download the Source Code';
     play.href = src;
     dv.style.marginTop = -(dv.offsetHeight/2)+"px";
     txt.appendChild(cE('br'));
    }
    dv.style.marginTop = -(dv.offsetHeight/2)+"px";
    dv.style.visibility = 'visible';
}

var aas = $('td.views-field-title a')
aas.each(function(x,y){
    var link = $('td.views-field-field-link-url a',y.parentNode.parentNode)[0];
    var src = $('td.views-field-field-source-url a',y.parentNode.parentNode)[0];
    var short = y.href.split('/').slice(-1)[0];
    var play = link && link.href;
    var sc = src && src.href;
    make_project(y.innerHTML,short,play,src,y.parentNode.parentNode,aas.length-x);
});

