﻿/// <reference path="jquery-vsdoc.js" />
function supports_video() {
    return !!document.createElement('video').canPlayType;
}
var Base64 = {

    // private property
    _keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",

    // public method for encoding
    encode: function(input) {
        var output = "";
        var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
        var i = 0;
        var breakAfter = 32;
        input = Base64._utf8_encode(input);
        myy = 0;
        while (i < input.length) {

            chr1 = input.charCodeAt(i++);
            chr2 = input.charCodeAt(i++);
            chr3 = input.charCodeAt(i++);

            enc1 = chr1 >> 2;
            enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
            enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
            enc4 = chr3 & 63;

            if (isNaN(chr2)) {
                enc3 = enc4 = 64;
            } else if (isNaN(chr3)) {
                enc4 = 64;
            }

            output = output +
            this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
            this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
            myy = myy + 4;
            if (myy % breakAfter == 0)
                output = output + "\n";
        }

        return output;
    },

    // public method for decoding
    decode: function(input) {
        var output = "";
        var chr1, chr2, chr3;
        var enc1, enc2, enc3, enc4;
        var i = 0;
        var breakAfter = 10;
        input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

        while (i < input.length) {

            enc1 = this._keyStr.indexOf(input.charAt(i++));
            enc2 = this._keyStr.indexOf(input.charAt(i++));
            enc3 = this._keyStr.indexOf(input.charAt(i++));
            enc4 = this._keyStr.indexOf(input.charAt(i++));

            chr1 = (enc1 << 2) | (enc2 >> 4);
            chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
            chr3 = ((enc3 & 3) << 6) | enc4;

            output = output + String.fromCharCode(chr1);

            if (enc3 != 64) {
                output = output + String.fromCharCode(chr2);
            }
            if (enc4 != 64) {
                output = output + String.fromCharCode(chr3);
            }

        }

        output = Base64._utf8_decode(output);

        return output;

    },

    // private method for UTF-8 encoding
    _utf8_encode: function(string) {
        string = string.replace(/\r\n/g, "\n");
        var utftext = "";

        for (var n = 0; n < string.length; n++) {

            var c = string.charCodeAt(n);

            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if ((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }

        }

        return utftext;
    },

    // private method for UTF-8 decoding
    _utf8_decode: function(utftext) {
        var string = "";
        var i = 0;
        var c = c1 = c2 = 0;

        while (i < utftext.length) {

            c = utftext.charCodeAt(i);

            if (c < 128) {
                string += String.fromCharCode(c);
                i++;
            }
            else if ((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i + 1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            }
            else {
                c2 = utftext.charCodeAt(i + 1);
                c3 = utftext.charCodeAt(i + 2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }

        }

        return string;
    }

}





function shortenURL(url) {
    var defaults = {
        version: '2.0.1',
        login: 'nflpa',
        apiKey: 'R_3c52121c24a5023aa1928355e1370c94',
        history: '0',
        longUrl: url
    };

    // Build the URL to query
    var daurl = "http://api.bit.ly/shorten?"
            + "version=" + defaults.version
            + "&longUrl=" + defaults.longUrl
            + "&login=" + defaults.login
            + "&apiKey=" + defaults.apiKey
            + "&history=" + defaults.history
            + "&format=json&callback=?";

    // Utilize the bit.ly API
    $.getJSON(daurl, function(data) {

        // Make a good use of short URL
        var ret = data.results[url].shortUrl;
        return ret;

    });

}

//Cookies

function setCookie(name, value, days) {
    if (days && days != 0) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else if (days == 0) {
        var expires = "; expires=";
    }
    else var expires = "";
    var domain = location.host.match('.nflplayers.com') ? 'nflplayers.com' : location.host;
    
    document.cookie = name + "=" + value + expires + "; path=/;domain=" + domain;
}
function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
}

function eraseCookie(name) {
    setCookie(name, "", -1);
}

//timeStamp
function epoch(date) {
    var datum = new Date(date);
    return (datum.getTime() / 1000.0);
}
//equalize heights
$.fn.equalizeHeights = function () {
    return this.height(Math.max.apply(this, $(this).map(function (i, e) { return $(e).height() }).get()))
}
function sortDD($dd) {
    if ($dd.length > 0) { // make sure we found the select we were looking for

        // save the selected value
        var selectedVal = $dd.val();

        // get the options and loop through them
        var $options = $('option', $dd);
        var arrVals = [];
        $options.each(function () {
            // push each option value and text into an array
            arrVals.push({
                val: $(this).val(),
                text: $(this).text()
            });
        });

        // sort the array by the value (change val to text to sort by text instead)
        arrVals.sort(function (a, b) {
            if (a.val > b.val) {
                return 1;
            }
            else if (a.val == b.val) {
                return 0;
            }
            else {
                return -1;
            }
        });


        // loop through the sorted array and set the text/values to the options
        for (var i = 0, l = arrVals.length; i < l; i++) {
            $($options[i]).val(arrVals[i].val).text(arrVals[i].text);
        }

        // set the selected value back
        $dd.val(selectedVal);
    }
}
function js()
{
    //do nothing (prevent error in IE)
}
String.prototype.trim = function () {
    return this.replace(/^\s+|\s+$/g, "");
}

function trackEvent(cat, action, label) {
    _gaq.push(['v1._trackEvent', cat, action, label]);
    _gaq.push(['v2._trackEvent', cat, action, label]);
}
function trackPageview(URL) {
    _gaq.push(['v1._trackPageview'], URL);
    _gaq.push(['v2._trackPageview'], URL);
}
//Fix rendering bug in IE fade
(function ($) {
    $.fn.fadeIn = function (speed, callback) {
        return this.animate({ opacity: 'show' }, speed, function () {
            if ($.browser.msie) {
                this.style.removeAttribute('filter');
            }
            if ($.isFunction(callback)) {
                callback.call(this);
            }
        });
    };

    $.fn.fadeOut = function (speed, callback) {
        return this.animate({ opacity: 'hide' }, speed, function () {
            if ($.browser.msie) {
                this.style.removeAttribute('filter');
            }
            if ($.isFunction(callback)) {
                callback.call(this);
            }
        });
    };

    $.fn.fadeTo = function (speed, to, callback) {
        return this.animate({ opacity: to }, speed, function () {
            if (to == 1 && $.browser.msie) {
                this.style.removeAttribute('filter');
            }
            if ($.isFunction(callback)) {
                callback.call(this);
            }
        });
    };
})(jQuery);

        function validateEmail(val) {
            var filter = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
            return filter.test(val);
        }
