var widgetId = 'chjWidget';
var CRAZYHOTWIDGET = {
    addStylesheet: function(path) {
        var head = document.getElementsByTagName('head')[0];
        var link = document.createElement('link');
        link.setAttribute('href', path);
        link.setAttribute('type', 'text/css');
        link.setAttribute('rel', 'stylesheet');
        head.appendChild(link);
    },
    setClass: function(e, cssClass) {
        e.className = cssClass;
    },
    makeLink: function(text, cssClass, navigateUrl, tooltip, target) {
        var a = document.createElement('a');
        if (cssClass != '') {
            a.className =  cssClass;
        }
        a.setAttribute('href', navigateUrl);
        if (tooltip != '') {
            a.setAttribute('title', tooltip);
        }
        a.setAttribute('target', target);
        a.innerHTML = text;
        return a;
    },
    init: function() {
        CRAZYHOTWIDGET.addStylesheet('http://crazyhotjob.com/_resources/Styles/Widget/main.css');
        var isIe = /msie|MSIE/.test(navigator.userAgent);
        var isIe6 = /msie|MSIE 6/.test(navigator.userAgent);
        var isIe7 = /msie|MSIE 7/.test(navigator.userAgent);
        var isIe8 = /msie|MSIE 8/.test(navigator.userAgent);
        if (isIe) {
            CRAZYHOTWIDGET.addStylesheet('http://crazyhotjob.com/_resources/Styles/Widget/ie.css');
        }
        if (isIe6) {
            CRAZYHOTWIDGET.addStylesheet('http://crazyhotjob.com/_resources/Styles/Widget/ie6.css');
        }
        if (isIe7) {
            CRAZYHOTWIDGET.addStylesheet('http://crazyhotjob.com/_resources/Styles/Widget/ie7.css');
        }
        if (isIe8) {
            CRAZYHOTWIDGET.addStylesheet('http://crazyhotjob.com/_resources/Styles/Widget/ie8.css');
        }
        document.write('<div id=\'' + widgetId + '\'></div>');
    },
    renderHeader: function(widget) {
        var headerText = 'CrazyHotJob.com. One day. One job.';
        var header = CRAZYHOTWIDGET.makeLink(headerText, 'header', 'http://crazyhotjob.com', headerText, '_blank');
        widget.appendChild(header);
    },
    renderTodaysJob: function(widget) {
        var todaysJob = document.createElement('div');
        CRAZYHOTWIDGET.setClass(todaysJob, 'todaysJob');
        var hTitle = document.createElement('h4');
        hTitle.innerHTML = 'Manager, Corporat...';
        todaysJob.appendChild(hTitle);
        var hCompany = document.createElement('h5');
        var ltlCompany = document.createTextNode('Company:');
        var hlCompany = CRAZYHOTWIDGET.makeLink('Nintendo', '', 'http://www.nintendo.com/corp/', '', '_blank');
        hCompany.appendChild(ltlCompany);
        hCompany.appendChild(hlCompany);
        todaysJob.appendChild(hCompany);
        var hLocation = document.createElement('h5');
        var ltlLocation = document.createTextNode('Location: Redwood City, AR');
        hLocation.appendChild(ltlLocation);
        todaysJob.appendChild(hLocation);
        widget.appendChild(todaysJob);
    },
    renderDescription: function(widget) {
        var description = document.createElement('div');
        CRAZYHOTWIDGET.setClass(description, 'jobDescription');
        var p = document.createElement('p');
        p.innerHTML = 'The worldwide pioneer in the creation of interactive entertainment, Nintendo Co., Ltd., of Kyoto, Japan, manufactures and markets hardware and software for its Wii™ home console and Nintendo DS™ family of portable systems. Since 1983, when it launched the Nintendo Entertainment System™, Nintendo has sold more than 3.4 billion video games and more than 565 million hardware units globally, including the current-generation Wii, Nintendo DS, Nintendo DSi™ and Nintendo DSi XL™, as well as the Game Boy™, Game Boy Advance, Super NES™, Nintendo 64™ and Nintendo GameCube™ systems. It has also created industry icons that have become well-known, household names such as Mario™, Donkey Kong™, Metroid™, Zelda™ and Pok&#233;mon™. A wholly owned subsidiary, Nintendo of America Inc., based in Redmond, Wash., serves as headquarters for Nintendo\'s operations in the Western Hemisphere.';
        description.appendChild(p);
        var hlReadMore = CRAZYHOTWIDGET.makeLink('read more', '', 'http://crazyhotjob.com', '', '_blank');
        description.appendChild(hlReadMore);
        var hlIWantThisJob = CRAZYHOTWIDGET.makeLink('', 'iWantThisJob', 'http://crazyhotjob.com', 'I Want This Job!', '_blank');
        var imgIWant = document.createElement('img');
        imgIWant.setAttribute('src', 'http://crazyhotjob.com/Images/widget_iWant.png');
        imgIWant.setAttribute('title', 'I Want This Job!');
        imgIWant.setAttribute('alt', 'I Want This Job!');
        var isIe6 = /msie|MSIE 6/.test(navigator.userAgent);
        if (isIe6) {
            imgIWant.setAttribute('src', '/Images/blank.gif');
            imgIWant.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='http://crazyhotjob.com/Images/widget_iWant.png', sizingMethod='image');"
        }
        hlIWantThisJob.appendChild(imgIWant);
        description.appendChild(hlIWantThisJob);
        widget.appendChild(description);
    },
    renderTrending: function(widget) {
        var trending = document.createElement('div');
        CRAZYHOTWIDGET.setClass(trending, 'trendingHot');
        var hlViewAll = CRAZYHOTWIDGET.makeLink('View all on CrazyHotJob.com', 'viewAll', 'http://crazyhotjob.com/Choose/', 'View all on CrazyHotJob.com', '_blank');
        trending.appendChild(hlViewAll);
        widget.appendChild(trending);
    },
    renderWidget: function() {
        var widget = document.getElementById(widgetId);
        CRAZYHOTWIDGET.renderHeader(widget);
        CRAZYHOTWIDGET.renderTodaysJob(widget);
        CRAZYHOTWIDGET.renderDescription(widget);
        CRAZYHOTWIDGET.renderTrending(widget);
    }
};
if (CRAZYHOTWIDGET) {
    CRAZYHOTWIDGET.init();
    CRAZYHOTWIDGET.renderWidget();
}
