/* Author: bsparks

*/

var navTmpl = _.template([
    "hi"
    ].join(''));

var css = [];

css.push({
    cssDescription: 'VARIABLES AND BASIC RESET',
    cssVariables: {
        //Layout
        docWidth: '940px',
        docWidthPadded: '1020px',

        pColor: '#333333',
        pDark: '$lightness($pColor, 15)',
        pLight: '$lightness($pColor, 55)',
        sColor: '#ABFF04',
        sLight: '$lightness($sColor, 85)',
        sMedium: "$lightness($sColor, 30)",
        sDark: '$lightness($sColor, 15)',
        tColor: '$hsl($sColor, 50, 20, 100)',
        tLight: '$lightness($tColor, 75)',
        tDark: '$lightness($tColor, 15)'
    },
    html: {
        position: 'relative',
        background: "$pDark url(images/gibson.jpg) no-repeat",
        "background-size": "100%"
    },
    '@font-face': {
        font_family: 'google-font',
        src: "url('styles/Montserrat-Regular.woff')"
    },
    body: {
        overflow_x: 'hidden',
        margin: 0,
        padding: 0,
        position: 'relative',
        height: '100%',
        font_family: "google-font !important"
    },
    "#main": {
        "min-height": "600px"
    },
    a: {
        text_decoration: 'none',
        font_weight: 'bold',
        transitionAll: '500ms',
        text_shadow: '0px 1px 1px #000',
        subs: {
            ':visited': {
                color: '$sLight'
            },
            ':active': {
                color: '$sLight'
            },
            ':link': {
                color: '$sLight'
            },
            ':hover': {
                color: '#fff'
            }
        }
    },
    '.section a': {
        text_decoration: 'none',
        font_weight: 'bold',
        transitionAll: '500ms',
        text_shadow: '0px 1px 1px #000',
        subs: {
            ':visited': {
                color: '$sColor'
            },
            ':active': {
                color: '$sColor'
            },
            ':link': {
                color: '$sColor'
            },
            ':hover': {
                color: '$sLight'
            }
        }
    },
    '.alt li a': {
        text_decoration: 'none',
        font_weight: 'bold',
        text_shadow: 'none',
        subs: {
            ':visited': {
                color: '$pColor'
            },
            ':active': {
                color: '$pColor'
            },
            ':link': {
                color: '$pColor'
            },
            ':hover': {
                color: '$sDark',
                text_decoration: 'underline'
            }
        }
    },
    'h1, h2, h3, p': {
        margin: '5px 0 5px 0'
    },
    'p': {
        margin_bottom: '15px',
        margin_top: '0px',
        text_align: 'justify'
    },
    '.secondary': {
        color: '$pLight',
        text_transform: 'lowercase'
    },
    '.emph': {
        transitionAll: '300ms',
        color: '#000',
        text_shadow: '0px 1px 1px $sColor'
    },
    'h2': {
        font_weight: 'bold'
    },
    'h3, h4': {
        color: '$sColor'
    },
    '.focus': {
        font_weight: 'bold',
        text_transform: 'uppercase'
    },
    'ul, ol': {
        margin_left: 0,
        padding_left: 0,
        list_style: 'inside'
    },
    'li': {
        subs: {
            ' h1': {
                display: 'inline-block'
            },
            ' h2': {
                display: 'inline-block'
            },
            ' h3': {
                display: 'inline-block'
            },
        }
    }

});

css.push({
    'cssDescription': 'header and footers',
    '.footer-header': {
        background: '$pColor',
        position: 'relative',
        padding: '0 80px',
        color: '#fff',
        margin_right: 'auto',
        margin_left: 'auto',
        subs: {
            ' .container': {
                width: '$docWidth',
                margin_left: 'auto',
                margin_right: 'auto',
                position: 'relative',
                overflow: 'visible'
            },
            ' .container-inner': {
                overflow: 'hidden'
            },
            ' .title': {
                display: 'inline-block',
                'float': 'left',
                font_size: '32px',
                padding: '5px 0 5px 0',
                color: "$sLight"
            },
            ' .items': {
                'float': 'right',
                margin: 0,
                padding: 0,
                text_align: 'right'
            },
            ' li': {
                display: 'inline-block',
                margin_left: '5px',
                padding: '15px 20px',
                vertical_gradient: '$pLight $pDark'
            },
            ' li:hover': {
                vertical_gradient: '$pdark #000'
            },
            ' li.selected, li.selected:hover': {
                vertical_gradient: '$sColor $sDark'
            },
            ' li.selected a, li.selected a:hover': {
                color: '#fff'
            },
            ' a': {
                padding: '5px'
            }
        }
    },
    '.navbar .title': {
        cursor: 'pointer'
    },
    '#logo-image': {
        position: 'absolute',
        left: '-40px',
        top: '-10px',
        z_index: 99999
    },
    'h2.emph': {
        transitionAll: '300ms',
        color: '$sLight',
        text_shadow: '1px 1px 2px $pDark'
    },
    'h2.emph:hover': {
        text_shadow: '$sDark'
    },
    '.indent ul': {
        padding_left: '50px'
    }

});

css.push({
    cssDescription: "the meat",
    ".terminal": {
        background: "#000",
        border: "2px solid $sLight",
        box_shadow: "0 0 15px $sLight",
        width: "600px",
        margin: "20px auto",
        color: "$sMedium",
        padding: "20px",
        opacity: "0.88",
        gigwatts: "1.21"
    }
});

// inject the styles
$.dicejs('superior-css', css).injectStyles();

var gibsonOS = function(command, term) {
    if(command != "") {
        term.echo(command);
    } else {
        term.echo("");
    }
};

var validSystems = [
        {
            name: "Gibson Technologies",
            code: "GIB0001",
            config: {
                prompt: "gibson>",
                name: "gibson_term",
                greetings: "Welcome to Gibson Technologies, unauthorized access will be prosecuted."
            },
            os: gibsonOS
        }
    ];

var superOS = function(command, term) {
    if (command !== '' && command.substr(0,3) == "js:") {
        var result = window.eval("(" + command.substr(3) + ")");
        if (result !== undefined) {
            term.echo(String(result));
        }
    } else if(command == "systems") {
        _.each(validSystems, function(sys) { term.echo(" - " + sys.name + " : " + sys.code); });
    } else if(command.substr(0, 8) == "connect ") {
        var system = command.substr(8);
        var sys = _.find(validSystems, function(sys) { return sys.code == system; });
        
        if(sys) {
            term.push(sys.os, sys.config);
        } else {
            term.error("invalid system");
        }
    } else {
       term.echo('');
    }
};

$(document).ready(function() {
    $("#termbox").terminal(superOS, {
        greetings: 'Superior Systems 1.0',
        name: 'user_term',
        height: 200,
        prompt: '>'
    });
});
