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://www.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://www.crazyhotjob.com/_resources/Styles/Widget/ie.css');
        }
        if (isIe6) {
            CRAZYHOTWIDGET.addStylesheet('http://www.crazyhotjob.com/_resources/Styles/Widget/ie6.css');
        }
        if (isIe7) {
            CRAZYHOTWIDGET.addStylesheet('http://www.crazyhotjob.com/_resources/Styles/Widget/ie7.css');
        }
        if (isIe8) {
            CRAZYHOTWIDGET.addStylesheet('http://www.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://www.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 = 'Sr. Flavorist';
        todaysJob.appendChild(hTitle);
        var hCompany = document.createElement('h5');
        var ltlCompany = document.createTextNode('Company:');
        var hlCompany = CRAZYHOTWIDGET.makeLink('Kerry Ingredients...', '', 'http://www.kerry.com/', '', '_blank');
        hCompany.appendChild(ltlCompany);
        hCompany.appendChild(hlCompany);
        todaysJob.appendChild(hCompany);
        var hLocation = document.createElement('h5');
        var ltlLocation = document.createTextNode('Location: Beloit, WI');
        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 = 'Kerry is a leader in the global food industry. Over the years, Kerry has become one of the largest and most technologically advanced manufacturers of ingredient systems in the world. Spanning all major food categories, our core technologies and global resources provide innovative, practical product solutions to food manufacturers and foodservice companies. Kerry Group employs some 23,000 people throughout its manufacturing, sales and technical centers across Europe, North America, South America, Australia, New Zealand and Asia Markets.';
        description.appendChild(p);
        var hlReadMore = CRAZYHOTWIDGET.makeLink('read more', '', 'http://www.crazyhotjob.com', '', '_blank');
        description.appendChild(hlReadMore);
        var hlIWantThisJob = CRAZYHOTWIDGET.makeLink('', 'iWantThisJob', 'http://www.crazyhotjob.com', 'I Want This Job!', '_blank');
        var imgIWant = document.createElement('img');
        imgIWant.setAttribute('src', 'http://www.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://www.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://www.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();
}
