﻿//* Globals.js */
    //* BOOLEAN */
var w = w || window,
    d = d || w.document,
    body = d.body || d.documentElement,
    B_TRUE = true,
    B_FALSE = false,
    //* NULL */
    N_NULL = null,
    //* STRINGS */
    S_UNDEFINED = 'undefined',
    S_BOOLEAN = 'boolean',
    S_NULL = 'null',
    S_ARRAY = 'array',
    S_OBJECT = 'object',
    S_FUNCTION = 'function',
    S_STRING = 'string',
    S_NUMBER = 'number',
    S_WINDOW = 'window',
    S_HTMLDOCUMENT = 'htmldocument',
    S_MOBILE = 'mobile',
    S_ANDROID = 'android',
    S_BLACKBERRY = 'blackberry',
    S_IPHONE = 'iphone',
    S_IPAD = 'ipad',
    S_DESKTOP = 'desktop',
    S_MSIE = 'msie',
    S_FF = 'firefox',
    S_CHROME = 'chrome',
    S_SAFARI = 'safari',
    S_OPERA = 'opera',
    S_MOUSEWHEEL = 'mousewheel',
    S_CLICK = "click",
    S_LOAD = "load",
    S_RESIZE = "resize",
    S_SCROLL = "scroll",
    S_OPEN_MODAL = "open modal",
    S_ACTION_NOT_FOUND = "Action not found",
    S_CANNOT_BIND = "Can't bind",
    S_CANNOT_DOWNLOAD = "Can't download",
    S_CANNOT_OPEN_MODAL = "Can't open modal",
    S_CANNOT_GET_JSON = "Can't get json",
    S_USER_AGENT = ( w.navigator.userAgent || w.navigator.vendor || w.opera ).toLowerCase(),
    //* REGEXP */
    R_USER_AGENT_DESKTOP = new RegExp('(MSIE[\s\/][0-9\.\-]+|Firefox[\s\/][0-9\.\-]+|Safari[\s\/][0-9\.\-]+|Chrome[\s\/][0-9\.\-]+|Opera[\s\/][0-9\.\-]+)','i'),
    R_USER_AGENT_MOBILE = new RegExp('(android.+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od|ad)|iris|kindle|lge |maemo|midp|mmp|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino|/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|e\-|e\/|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(di|rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|xda(\-|2|g)|yas\-|your|zeto|zte\-)','i'),
    //* IS */
    IS_BRAZIL = ( function () {
        var scripts = d.getElementsByTagName('script'),
            script;
        for ( script in scripts ) {
            if ( /g\=jsH|Globals\.js/i.test( scripts[script].src ) ) {
                content = scripts[script].innerText || scripts[script].textContent || scripts[script].text || scripts[script].innerHTML;
                if ( /IS_BRAZIL\s*\=\s*(true|false)/i.test( content ) ) {
                    if ( RegExp.$1 === 'true' ) {
                        return true;
                    }
                }
                break;
            }
        }
        return false;
    }()),
    IS_IE = ( /MSIE (\d+\.\d+);/.test( S_USER_AGENT ) ),
    IS_IE_VERSION = new Number(RegExp.$1),
    //* HAS */
    HAS_GLOBALSJS = true,
    HAS_JQUERY = ( typeof w.jQuery !== S_UNDEFINED ),
    HAS_CONSOLE = ( typeof w.console !== S_UNDEFINED && IS_IE === B_FALSE ),
    //* OBJECTS */
    O_AGENT = ( function () {

        var _is = R_USER_AGENT_MOBILE.exec( S_USER_AGENT ),
            name,
            version;

        if ( _is !== N_NULL && typeof _is !== S_UNDEFINED && _is[1] !== N_NULL && typeof _is[1] !== S_UNDEFINED ) {

            _is = _is[1].replace(/^\s+|\s+$/g,'').toLowerCase();

            if ( _is != '' ) {

                name = _is;

                return {
                    name: name,
                    version: undefined,
                    is: S_MOBILE
                };

            }

        }

        _is = R_USER_AGENT_DESKTOP.exec( S_USER_AGENT );

        if ( _is !== N_NULL && typeof _is !== S_UNDEFINED && _is[1] !== N_NULL && typeof _is[1] !== S_UNDEFINED ) {

            _is = _is[1].replace(/^\s+|\s+$/g,'').toLowerCase();

            if ( _is != '' ) {

                if ( _is.indexOf('/') > -1 ) {
                    name    = _is.split('/')[0];
                    version = _is.split('/')[1];
                } else {
                    name    = _is.split(' ')[0];
                    version = _is.split(' ')[1];
                }

                return {
                    name: name,
                    version: version,
                    is: S_DESKTOP
                };

            }

        }

    }()),
    //* FUNCTIONS */
    F_NOOP = function () {},
    F_SET_TIMEOUT = w.setTimeout || F_NOOP,
    F_CLEAR_TIMEOUT = w.clearTimeout || F_NOOP,
    F_SET_INTERVAL = w.setInterval || F_NOOP,
    F_CLEAR_INTERVAL = w.clearInterval || F_NOOP,
    F_ARRAYSLICE = Array.prototype.slice,
    F_TOSTRING = Object.prototype.toString,
    F_TYPEOF = function ( obj ) {
        if ( typeof obj === S_UNDEFINED ) return S_UNDEFINED; // first
        if ( obj === N_NULL ) return S_NULL;
        if ( obj === B_TRUE || obj === B_FALSE ) return S_BOOLEAN;
        return F_TOSTRING.call( obj ).match(/^\[object\s(.*)\]$/)[1].toLowerCase();
    },
    F_LOG = ( function ( console ) { return HAS_CONSOLE ? function () { console.log.apply( console, arguments ); } : F_NOOP; } )( w.console ),
    F_RANDOM = function ( min , max ) { return Math.floor( ( Math.random() * ( min - max - 1) + max ) ); },
    F_ADDEVENT = function ( context , event , handler , capture ) {
        context = context || d || w.document || window.document;
        handler = handler || F_NOOP;
        capture = ( capture === B_FALSE || capture === B_TRUE ) ? capture : B_TRUE;
        if ( event ) {
            if ( HAS_JQUERY ) {
                $( context ).bind( event , handler );
            } else if ( context.addEventListener ) {
                context.addEventListener( event , handler , capture );
            } else if ( context.attachEvent ) {
                context.attachEvent( 'on' + event , handler );
            }
        }
    },
    F_UID = function () { var newDate = new Date(); return newDate.getTime(); },
    F_SCROLL_TO = function ( el , left , top , animate , duration ) {

        el   = el   || w;
        left = left || 0;
        top  = top  || 0;
        animate = (animate === B_FALSE || animate === B_TRUE ) ? animate : B_TRUE;
        duration = duration || 1000 ;

        if ( animate === B_TRUE && HAS_JQUERY === B_TRUE ) {
            $(el).animate({scrollLeft: left, scrollTop: top}, duration );
        } else {
            F_SCROLL_LEFT( el , left );
            F_SCROLL_TOP( el , top );
        }

    },
    F_SCROLL = function ( el , left , top ) {
        el = el || w;
        left = left || N_NULL;
        top = top || N_NULL;

        var scrollTop = ( ( el.scrollTop ) ? el.scrollTop
                            : ( ( 'pageYOffset' in el ) ? el.pageYOffset
                                : ( ( 'scrollTop' in el.document.documentElement ) ? el.document.documentElement.scrollTop : N_NULL ) ) ),
            scrollLeft = ( ( el.scrollLeft ) ? el.scrollLeft
                             : ( ( 'pageXOffset' in el ) ? el.pageXOffset
                                 : ( ( 'scrollLeft' in el.document.documentElement ) ? el.document.documentElement.scrollLeft : N_NULL ) ) );

        if ( left !== N_NULL && scrollLeft !== N_NULL ) {
            scrollLeft = left;
        }
        if ( top !== N_NULL && scrollTop !== N_NULL ) {
            scrollTop = top;
        }

        return { 'left': scrollLeft , 'top': scrollTop };
    },
    F_SCROLL_TOP = function ( el , top ) {
        return F_SCROLL( el , N_NULL , top ).top;
    },
    F_SCROLL_LEFT = function ( el , left ) {
        return F_SCROLL( el , left ).left;
    },
    F_LOADING = function ( show ) {

        show = ( show === B_TRUE || show === B_FALSE ) ? show : B_TRUE;

        if ( show === B_TRUE ) {
            var loading = d.createElement('div');
            loading.id = 'loading';
            loading.innerHTML = '<div class="degrade"></div><div class="image"><img src="img/full/ico/loading.gif" width="148" height="148" alt="Carregando..." title="Carregando..." /></div>';
            loading.style.display = 'block';
            body.insertBefore( loading , body.childNodes[0] );
        } else {
            var loading = d.getElementById('loading');
            if ( loading )
                body.removeChild(loading);
        }

    };


