/*jslint devel: true, unparam: true, browser: true, type: true, maxerr: 50, indent: 4 */
/*global jQuery, $, SITE_URL*/
/**
 * Global Feature Detection CoursePro JavaScript Class
 *
 * @package coursepro
 * @version $Id: boot.js 494 2011-06-14 08:04:02Z pete.walker $
 * @copyright Cap2 Solutions 2010
 */

// Border-radius
jQuery(function() {
    "use strict";
    var cl, prefixes, str1, str2, str3;
    jQuery.support.borderRadius = false;
    jQuery.each(['borderRadius','MozBorderRadius','WebkitBorderRadius','OBorderRadius','KhtmlBorderRadius'], function() {
        if (document.body.style[this] !== undefined) {
            jQuery.support.borderRadius = true;
        }
        return (!jQuery.support.borderRadius);
    });
    jQuery.support.boxSizing = false;
    jQuery.each(['boxSizing','MozBoxSizing','WebkitBoxSizing','OBoxSizing','KhtmlBoxSizing','msBoxSizing'], function() {
        if (document.body.style[this] !== undefined) {
            jQuery.support.boxSizing = true;
        }
        return (!jQuery.support.boxSizing);
    });
    jQuery.support.cssAnimation = false;
    jQuery.each(['transition','MozTransition','WebkitTransition','OTransition','KhtmlTransition','msTransition'], function() {
        if (document.body.style[this] !== undefined) {
            jQuery.support.cssAnimation = true;
        }
        return (!jQuery.support.cssAnimation);
    });
    // CSS property tests
    cl = document.createElement('div');
    jQuery.support.cssGradients = false;
    prefixes = ['-webkit-', '-moz-', '-o-', '-ms-', '-khtml-'];
    str1 = 'background-image:';
    str2 = 'gradient(linear,left top,right bottom,from(#9f9),to(white));';
    str3 = 'linear-gradient(left top,#9f9, white);';
    cl.style.cssText = (str1 + prefixes.join(str2 + str1) + prefixes.join(str3 + str1)).slice(0, -str1.length);    
    jQuery.support.cssGradients = (String(cl.style.backgroundImage).indexOf('gradient') !== -1);
});

// Console replacement
if (typeof (console) === 'undefined') {
    var console = {
        log: function () {
            "use strict";
        },
        error: function () {
            "use strict";
        },
        info: function () {
            "use strict";
        }
    };
} 

$.fn.preload = function() {
    "use strict";
    this.each(function(){ 
        var src = this;
        if (typeof (SITE_URL) !== 'undefined') {
            src = SITE_URL + 'images/' + src;
        } else {
            src = '/images/' + src;
        }
        $('<img/>')[0].src = src;
    });
};

$(document).ready(function(e) {
    "use strict";
    if (!$.support.borderRadius && typeof (SITE_URL) !== 'undefined') {
        $([
            'buttons-aaa.png',
            'buttons-b0ccfc.png',
            'buttons-b7181f.png',
            'buttons-ccc.png',
            'buttons-cfe0ff.png',
            'buttons-ddd.png',
            'buttons-e4e4e4.png',
            'buttons-e8e2c5.png',
            'buttons-eee.png',
            'buttons-f8f8f8.png',
            'buttons-ff7700.png',
            'buttons-fff.png',
            'buttons-fff9d7.png'
        ]).preload();
    }
    if (!$.support.borderRadius) {
        $('body').addClass('no-border-radius');
    } else {
        $('body').addClass('border-radius');
    }
    if (!$.support.boxSizing) {
        $('body').addClass('no-box-sizing');
    } else {
        $('body').addClass('box-sizing');
    }
    if (!$.support.cssGradients) {
        $('body').addClass('no-gradients');
    } else {
        $('body').addClass('gradients');
    }
    if (!$.support.cssAnimation) {
        $('body').addClass('no-animation');
    } else {
        $('body').addClass('animation');
    }
});
