/*
 * main.js
 *
 * Copyright (c) 2010 http://wwww.motorsport.com/
 * Dual licensed under the MIT and GPL licenses. 
 * 
 * http://wwww.motorsport.com/design/js/main.js
 */
 

var global = {
    flashParams: {
        scale: "noscale",
        wmode: "opaque",
        allowFullScreen: "true",
        allowScriptAccess: "always",
        bgcolor: '#000000',
        quality: "high"
    },
    cookie: {
        favoriteSeries:  'fseries'
    }
}

var utils = {
    gaTrack: function(){
        var account = gaAccount.id;
        if(!account){
            return;
        }
        var hash = arguments[0];
        if(!hash){
            var l = window.location.hash.replace(/^#/,''),
            hash = (l == '' ? '/' : l);
        }
        _gaq.push(['_setAccount', account], ['_trackPageview', hash]);
    },
    responseError: function(place, errorType, _form, error) {
        $.ajaxAlert({
            title: '',
            text: error || i18n.m31,
            styleClass: 'error',
            buttonClose: true,
            speedClose: 5000
        });
        if(_form){
            _form.trigger('submitAjaxIndikatorHide');
        }
        if (typeof error == "undefined") {
            utils.logger(place, errorType);
        }
    },
    logger: function(place, error) {
        $.ajax({
            url: '/error-log/',
            type: 'POST',
            cache: false,
            data: {
                error: error,
                place: place
            }
        });
    },
    objToSepStr: function(obj){
        var sep = arguments[1] || '|',
        arr = [], j = 0;
        for(var i in obj){
            arr[j] = i;
            j++;
        }
        return arr.join(sep);
    },
    objClone: function(o) {
        if(!o || 'object' !== typeof o)  {
            return o;
        }
        var c = 'function' === typeof o.pop ? [] : {};
        var p, v;
        for(p in o) {
            if(o.hasOwnProperty(p)) {
                v = o[p];
                if(v && 'object' === typeof v) {
                    c[p] = clone(v);
                }
                else {
                    c[p] = v;
                }
            }
        }
        return c;
    },
    fileName: function(file){
        var fileName = file.replace(/.*\\(.*)/, "$1"); 
        fileName = fileName.replace(/.*\/(.*)/, "$1");
        return fileName;
    },
    objToSelectDataArr: function(o){
        var arr = [],j=0;
        for(var i in o){
            arr[j] = {
                title: arguments[1] ? i18n['m' + o[i]] : o[i],
                value: i
            };
            j++;
        }
        return arr;
    },
    arrToSelectDataArr: function(arr){
        var narr = [];
        for(var i = 0, c = arr.length; i < c; i++){
            narr[i] = {
                title: arr[i],
                value: arr[i]
            };
        }
        return narr;
    },
    arrInObjToSelectDataArr: function(arr, obj, limit){
        var narr = [],
            limit = limit || arr.length,
            i = 0;
        while(i < limit){
            if(obj[arr[i]]){
                narr[i] = {
                    title: obj[arr[i]],
                    value: arr[i]
                };
                i++;
            }
        }
        return narr;
    }
};

var path = {
    "filter": "/filter",
    "user": "/users/",
    "rate": "/rate/",
    "commentsList": "/comments/list/",
    "commentRating": "/comments/rate/",
    "commentsCreate": "/comments/create/",
    "message": "/users/a/activity/message/"
}


/*
 * ajaxIndikator [R] 17.11.2010
 * 
 * Method creates and manage indicator data load.
 * Applies to the container.
 * 
 */
$.fn.submitAjaxIndikator = function(options){
    var options = $.extend({
        eq: 0,
        ns: false,
        styleClass: 'loaderBW'
    },options);
    
    var _this = $(this),
    _submit = $('[type="submit"]',_this).eq(options.eq),
    _reset = $('a[href="#form_reset"]',_this);
    if(_submit.length){
        var ns = options.ns ? '.s-' + options.eq : ''
        _this.bind('submitAjaxIndikatorShow' + ns, function(){
            _submit.addClass(options.styleClass).attr('disabled','disabled');
            if(_reset.length){
                _reset.hide();
            }
        });
        _this.bind('submitAjaxIndikatorHide' + ns, function(){
            _submit.removeClass(options.styleClass).removeAttr('disabled');
            if(_reset.length){
                _reset.show();
            }
        });
        _this.bind('submitDisable' + ns, function(){
            _submit.attr('disabled','disabled');
        });
        _this.bind('submitEnable' + ns, function(){
            _submit.removeAttr('disabled');
        });
    }
}
 
$.fn.ajaxIndikator = function(options){
    var options = $.extend({
        title: i18n.m385,
        styleClass: false,
        orientation: 'center',
        position: 'absolute',
        backlight: true,
        opacity: 0.75,
        offset: 30
    },options);
    var _body = $(document.body),
    _box = $(this),
    _window = $(window);
    _body[0].indicators = _body[0].indicators ? ++_body[0].indicators : 1;   
    if(options.backlight){   
        var backlight = $('<div id="aib_' + _body[0].indicators + '" class="ajaxIndicatorBacklight"></div>');
        _box.append(backlight);
        backlight.css({
            'opacity': options.opacity,
            'display': 'none',
            'z-index': '9997'
        });
        if($.browser.msie && parseInt($.browser.version) <= 6){
            backlight.css('height', _box.height() + 'px');
            backlight.css('width', _box.width() + 'px');
        }
    }
    var indicator = $('<div id="ai_' + _body[0].indicators + '" class="ajaxIndicator' + (options.styleClass ? ' ' + options.styleClass : '') + '">' + options.title + '</div>');
    _box.append(indicator);
    indicator.css({
        'position':options.position,
        'z-index':'9998'
    });
    var indicatorPos = function(){  
        indicator.stop(true,false);    
        var _box_ofs_top = _box.offset().top,
        _box_h = _box.height(),
        pos = _window.height()/2 + (_window.scrollTop() - _box_ofs_top),
        minPos = indicator.height()/2+options.offset,
        maxPos = _box_h-options.offset-indicator.height()/2;
        if(pos < minPos){
            pos = minPos;
        }
        else if (pos > maxPos){
            pos = maxPos;
        }
        indicator.animate({
            top: pos + 'px'
        },100);
    }
    
    if(typeof (options.orientation) == 'object'){
        if(options.orientation.left){
            indicator.css('left',options.orientation.left);
        }
        if(options.orientation.right){
            indicator.css('right',options.orientation.right);
        }
        if(options.orientation.top){
            indicator.css('top',options.orientation.top);
        }
        if(options.orientation.left){
            indicator.css('bottom',options.orientation.bottom);
        }

    }else{
        switch(options.orientation){
            case 'left top':
            case 'top left':
                indicator.css({
                    'top':'0',
                    'left':'0'
                });
                break;
            case 'center top':
            case 'top center':
                indicator.css({
                    'top':'0',
                    'left':'50%'
                });
                break;
            case 'right top':
            case 'top right':
                indicator.css({
                    'top':'0',
                    'right':'0'
                });
                break;
            case 'center left':
            case 'left center':
                indicator.css({
                    'top':'50%',
                    'left':'0'
                });
                break;
            case 'center right':
            case 'right center':
                indicator.css({
                    'top':'50%',
                    'right':'0'
                });
                break;
            case 'left bottom':
            case 'bottom left':
                indicator.css({
                    'bottom':'0',
                    'left':'0'
                });
                break;
            case 'center bottom':
            case 'bottom center':
                indicator.css({
                    'bottom':'0',
                    'left':'50%'
                });
                break;
            case 'right bottom':
            case 'bottom right':
                indicator.css({
                    'bottom':'0',
                    'right':'0'
                });
                break;
            case 'center scroll':
            case 'scroll center':
                indicator.css({
                    'top':'50%',
                    'left':'50%'
                });
                break;
            default:
                indicator.css({
                    'top':'50%',
                    'left':'50%'
                });
        }
    }
    indicator.hide();
    _box.bind('ajaxIndikatorShow',function(event){
        event.stopPropagation();
        
        if(typeof (options.orientation) != 'object'){
            switch(options.orientation){
                case 'center left':
                case 'left center':
                case 'center right':
                case 'right center':
                    indicator.css({
                        'margin-top':-indicator.outerHeight()/2
                    });
                    break;
                case 'top center':
                case 'center top':
                case 'center bottom':
                case 'bottom center':
                    indicator.css({
                        'margin-left':-indicator.outerWidth()/2
                    });
                    break;
                default:
                    indicator.css({
                        'margin-left':-indicator.outerWidth()/2,
                        'margin-top':-indicator.outerHeight()/2
                    });
            }
        }
        var title = options.title;

        if(arguments[1] && typeof arguments[1].title == 'string'){
            title = arguments[1].title;
            indicator.html(title);
        }           
        if(arguments[1] && typeof arguments[1].titleData == 'object'){
            indicator.html(title.supplant(arguments[1].titleData));
        }
        if(arguments[1] && arguments[1].lock == true){
            indicator.addClass('ajaxIndicatorLock').wrapInner('<div></div>').prepend('<span class="icon64 icon64-lock"></span>');
        }
        if(options.backlight){
            backlight.fadeIn('fast');
        }
        if(options.orientation == 'center scroll' || options.orientation == 'scroll center'){
            indicatorPos();
            _window.scroll(indicatorPos);
            _window.resize(indicatorPos);
        }
        if(arguments[1] && arguments[1].title == false){
            return;
        }
        indicator.css('display','block');
    });
    this.bind('ajaxIndikatorHide',function(){
        if(options.backlight){
            backlight.fadeOut('fast');
        }
        if(options.orientation == 'center scroll' || options.orientation == 'scroll center'){
            _window.unbind('scroll',indicatorPos);
            _window.unbind('resize',indicatorPos);
        }
        indicator.fadeOut('fast',function(){
            indicator.removeClass('ajaxIndicatorLock').html(options.title);
        });
        

    });
    return this;
}

$.fn.hashProvider = function(options){
    var options = $.extend({
        pref: '/'
    },options);

    var selector = 'a[href^="' + options.pref + '"]',
    iever = 7;
    if($.browser.msie && parseInt($.browser.version) <= iever){
        var locn = window.location,
        h = locn.protocol + '//' + locn.hostname + options.pref;
        selector = 'a[href^="' + h + '"], a[href^="' + options.pref + '"]'
    }

    $(this).delegate(selector, 'click', function(event){
        var $link = $(this),
        href = $link.attr('href');
        if($.browser.msie && parseInt($.browser.version) <= iever){
            href = href.replace(h, options.pref);
            $(window).focus();
            if(href == '/#'){
                return;
            }
        }
        if($link.attr('rel').length > 0){
            return true;
        }
        event.preventDefault();
        if($link.is('.disabled')){
            return;
        }
        $.history.load(href);
    });
    return this;
}

$.extend({
    setHeadTitle: function(options){
        var options = $.extend({
            siteName: 'Motorsport',
            series: false,
            section: false,
            subsection: false,
            item: false,
            separator: ' | '
        },options);
        var seriesName = (options.series ? (series.list[options.series] ? series.list[options.series] + options.separator: '') : ''),
            section = (options.section ? options.section + options.separator : ''), 
            subsection = (options.subsection ? options.subsection + options.separator : ''), 
            item = (options.item ? options.item + options.separator : ''),
            title = item + subsection + section + seriesName + options.siteName;
        document.title = title;
    },
    banners: function(){

        $('.ap').each(function(){
            var $self = $(this),
                id = $self.attr('id').replace(/^ap_/, '');
            
            if($self.text() == ''){
                $self.html('Banner #' + id + ' load <span>1</span> times');
            }else{
                var $times = $self.find('span');
                $times.text(parseInt($times.text()) + 1);
            }
        });
    },
    ajaxAlert: function(options){
        var options = $.extend({
            title: i18n.m62,
            styleClass: 'error',
            text: i18n.m62,
            buttonClose: false,
            speedClose: 3000,
            speedOpen: 500,
            orientation: 'right' /* center */
        },options);
        var _body = $(document.body),
        ajax_alert_box = $('#ajax_alert_box_' + options.orientation);
        if (!ajax_alert_box.attr('id')) {
            ajax_alert_box = $('<div id="ajax_alert_box_' + options.orientation + '" class="ajaxAlertBox"></div>')
            .appendTo(_body);
        }
        switch(options.orientation){
            case 'center':
                ajax_alert_box.css({
                    'left':'50%',
                    'margin-left':-(ajax_alert_box.width()/2)
                });
                break;
            default:
                ajax_alert_box.css('right',(_body.width() - $("#header_box").width())/2);
        }
        $('<div class="item ' + options.styleClass + '"><h3>' + options.title + '</h3><span class="icon icon48"></span>' + (options.buttonClose ? '<span class="buttonClose icon16 icon16-close" title="' + i18n.m144 + '"></span>' : '') + '<p>' + options.text + '</p></div>')
        .prependTo(ajax_alert_box)
        .hide(function(){
            var _this = $(this);
            _this.css('margin-top',-_this.innerHeight());
        })
        .show()
        .animate({
            marginTop: '0'
        },options.speedOpen)
        .delay(options.speedClose)
        .fadeOut('slow', function() {
            $(this).remove();
        })
        .find('.buttonClose').css('cursor','pointer').bind('click',function(){
            $(this).parent().stop(true,true).fadeOut('fast',function(){
                $(this).remove();
            });
        });
        return this;
    },
    jsonProxy: function(options){
        var options = $.extend({
            url: false,
            before: false,
            onsuccess: false,
            onerror: false,
            after: false
        },options);

        if(options.url){
            if($.isFunction(options.before)){
                options.before.call(this);
            }
            $.ajax({
                url: options.url,
                dataType: 'json',
                cache: false,
                success: function(data) {
                    if((!data || data == '') && $.isFunction(options.onerror)){
                        options.onerror.call(this, i18n.m381, i18n.m382 + ': empty response.', 1);
                    }else if(data.status && $.isFunction(options.onsuccess)){
                        options.onsuccess.call(this, data);
                    }
                    else if(!data.status && $.isFunction(options.onerror)){
                        options.onerror.call(this, data.title ? data.title : i18n.m10, data.message ? data.message : i18n.m11, data.code ? data.code : 2); 
                    }
                    if($.isFunction(options.after)){
                        options.after.call(this);
                    }
                },
                error: function(XMLHttpRequest, textStatus, errorThrown){
                    if($.isFunction(options.onerror)){
                        options.onerror.call(this, i18n.m381, i18n.m382 + ': ' + textStatus + '.', 1);
                    }
                    if($.isFunction(options.after)){
                        options.after.call(this);
                    }
                    utils.logger(options.url, textStatus);
                    return;
                }
            });
        }
    }
});

var tmpl = {
    pageError: {
        code1: '<div class="errorPage errorPage-code-1"><h1>{{html title}}</h1><div class="message">{{html message}}</div><p class="code">Code: ${code}</p></div>',
        code2: '<div class="errorPage errorPage-code-2"><h1>{{html title}}</h1><div class="message">{{html message}}</div><p class="code">Code: ${code}</p></div>',
        code3: '<div class="errorPage errorPage-code-3"><h1>{{html title}}</h1><div class="message">{{html message}}</div><p class="code">Code: ${code}</p></div>',
        code4: '<div class="errorPage errorPage-code-4"><h1>{{html title}}</h1><div class="message">{{html message}}</div><div class="form"></div><p class="code">Code: ${code}</p></div>',
        code5: '<div class="errorPage errorPage-code-5"><h1>{{html title}}</h1><div class="message">{{html message}}</div><p class="code">Code: ${code}</p></div>'
    }
}
// implement JSON.stringify serialization
var JSON = JSON || {};
JSON.stringify = JSON.stringify || function (obj) {
    var t = typeof (obj);
    if (t != "object" || obj === null) {
        // simple data type
        if (t == "string") obj = '"'+obj+'"';
        return String(obj);
    }
    else {
        // recurse array or object
        var n, v, json = [], arr = (obj && obj.constructor == Array);
        for (n in obj) {
            v = obj[n]; t = typeof(v);
            if (t == "string") v = '"'+v+'"';
            else if (t == "object" && v !== null) v = JSON.stringify(v);
            json.push((arr ? "" : '"' + n + '":') + String(v));
        }
        return (arr ? "[" : "{") + String(json) + (arr ? "]" : "}");
    }
};

String.prototype.sprintf = function( ) {
    // Return a formatted string  
    // 
    // version: 1009.2513
    // discuss at: http://phpjs.org/functions/sprintf    // +   original by: Ash Searle (http://hexmen.com/blog/)
    // + namespaced by: Michael White (http://getsprink.com)
    // +    tweaked by: Jack
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: Paulo Freitas    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: Brett Zamir (http://brett-zamir.me)
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: sprintf("%01.2f", 123.1);
    // *     returns 1: 123.10    // *     example 2: sprintf("[%10s]", 'monkey');
    // *     returns 2: '[    monkey]'
    // *     example 3: sprintf("[%'#10s]", 'monkey');
    // *     returns 3: '[####monkey]'

    var regex = /%%|%(\d+\$)?([-+\'#0 ]*)(\*\d+\$|\*|\d+)?(\.(\*\d+\$|\*|\d+))?([scboxXuidfegEG])/g;
    var a = arguments, i = 0, format = this/*a[i++]*/;

    // pad()
    var pad = function (str, len, chr, leftJustify) {
        if (!chr) {
            chr = ' ';
        }
        var padding = (str.length >= len) ? '' : Array(1 + len - str.length >>> 0).join(chr);
        return leftJustify ? str + padding : padding + str;
    };
 
    // justify()    
    var justify = function (value, prefix, leftJustify, minWidth, zeroPad, customPadChar) {
        var diff = minWidth - value.length;
        if (diff > 0) {
            if (leftJustify || !zeroPad) {
                value = pad(value, minWidth, customPadChar, leftJustify);
            } else {
                value = value.slice(0, prefix.length) + pad('', diff, '0', true) + value.slice(prefix.length);
            }
        }
        return value;
    };
 
    // formatBaseX()
    var formatBaseX = function (value, base, prefix, leftJustify, minWidth, precision, zeroPad) {
        // Note: casts negative numbers to positive ones        
        var number = value >>> 0;
        prefix = prefix && number && {
            '2': '0b',
            '8': '0',
            '16': '0x'
        }
        [base] || '';
        value = prefix + pad(number.toString(base), precision || 0, '0', false);
        return justify(value, prefix, leftJustify, minWidth, zeroPad);
    }; 
    // formatString()
    var formatString = function (value, leftJustify, minWidth, precision, zeroPad, customPadChar) {
        if (precision != null) {
            value = value.slice(0, precision);
        }
        return justify(value, '', leftJustify, minWidth, zeroPad, customPadChar);
    };
 
    // doFormat()    
    var doFormat = function (substring, valueIndex, flags, minWidth, _, precision, type) {
        var number;
        var prefix;
        var method;
        var textTransform;
        var value;
 
        if (substring == '%%') {
            return '%';
        }
 
        // parse flags        
        var leftJustify = false, positivePrefix = '', zeroPad = false, prefixBaseX = false, customPadChar = ' ';
        var flagsl = flags.length;
        for (var j = 0; flags && j < flagsl; j++) {
            switch (flags.charAt(j)) {
                case ' ':
                    positivePrefix = ' ';
                    break;
                case '+':
                    positivePrefix = '+';
                    break;
                case '-':
                    leftJustify = true;
                    break;
                case "'":
                    customPadChar = flags.charAt(j+1);
                    break;
                case '0':
                    zeroPad = true;
                    break;
                case '#':
                    prefixBaseX = true;
                    break;
            }
        }
 
        // parameters may be null, undefined, empty-string or real valued
        // we want to ignore null, undefined and empty-string values        
        if (!minWidth) {
            minWidth = 0;
        } else if (minWidth == '*') {
            minWidth = +a[i++];
        } else if (minWidth.charAt(0) == '*') {
            minWidth = +a[minWidth.slice(1, -1)];
        } else {
            minWidth = +minWidth;
        }
        // Note: undocumented perl feature:
        if (minWidth < 0) {
            minWidth = -minWidth;
            leftJustify = true;
        } 
        if (!isFinite(minWidth)) {
            throw new Error('sprintf: (minimum-)width must be finite');
        }
        if (!precision) {
            precision = 'fFeE'.indexOf(type) > -1 ? 6 : (type == 'd') ? 0 : undefined;
        } else if (precision == '*') {
            precision = +a[i++];
        } else if (precision.charAt(0) == '*') {
            precision = +a[precision.slice(1, -1)];
        } else {
            precision = +precision;
        }
        // grab value using valueIndex if required?
        value = valueIndex ? a[valueIndex.slice(0, -1)] : a[i++];
 
        switch (type) {
            case 's':
                return formatString(String(value), leftJustify, minWidth, precision, zeroPad, customPadChar);
            case 'c':
                return formatString(String.fromCharCode(+value), leftJustify, minWidth, precision, zeroPad);
            case 'b':
                return formatBaseX(value, 2, prefixBaseX, leftJustify, minWidth, precision, zeroPad);
            case 'o':
                return formatBaseX(value, 8, prefixBaseX, leftJustify, minWidth, precision, zeroPad);
            case 'x':
                return formatBaseX(value, 16, prefixBaseX, leftJustify, minWidth, precision, zeroPad);
            case 'X':
                return formatBaseX(value, 16, prefixBaseX, leftJustify, minWidth, precision, zeroPad).toUpperCase();
            case 'u':
                return formatBaseX(value, 10, prefixBaseX, leftJustify, minWidth, precision, zeroPad);
            case 'i':
            case 'd':
                number = parseInt(+value, 10);
                prefix = number < 0 ? '-' : positivePrefix;
                value = prefix + pad(String(Math.abs(number)), precision, '0', false);
                return justify(value, prefix, leftJustify, minWidth, zeroPad);
            case 'e':
            case 'E':
            case 'f':            case 'F':
            case 'g':
            case 'G':
                number = +value;
                prefix = number < 0 ? '-' : positivePrefix;
                method = ['toExponential', 'toFixed', 'toPrecision']['efg'.indexOf(type.toLowerCase())];
                textTransform = ['toString', 'toUpperCase']['eEfFgG'.indexOf(type) % 2];
                value = prefix + Math.abs(number)[method](precision);
                return justify(value, prefix, leftJustify, minWidth, zeroPad)[textTransform]();
            default:
                return substring;
        }
    };
 
    return format.replace(regex, doFormat);
}

/**
 * supplant [R] 6.04.2010
 * 
 * Templating.
 * Applies to the string.
 * 
 */
String.prototype.supplant = function(o) {
    return this.replace(/{([^{}]*)}/g,
        function(a, b) {
            var r = o[b];
            return typeof r === 'string' || typeof r === 'number' ? r : a;
        }
        );
}

var BrowserDetect = {
    init: function () {
        this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
        this.version = this.searchVersion(navigator.userAgent)
        || this.searchVersion(navigator.appVersion)
        || "an unknown version";
        this.OS = this.searchString(this.dataOS) || "an unknown OS";
    },
    searchString: function (data) {
        for (var i=0;i<data.length;i++)    {
            var dataString = data[i].string;
            var dataProp = data[i].prop;
            this.versionSearchString = data[i].versionSearch || data[i].identity;
            if (dataString) {
                if (dataString.indexOf(data[i].subString) != -1)
                    return data[i].identity;
            }
            else if (dataProp)
                return data[i].identity;
        }
    },
    searchVersion: function (dataString) {
        var index = dataString.indexOf(this.versionSearchString);
        if (index == -1) return;
        return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
    },
    dataBrowser: [
        {
            string: navigator.userAgent,
            subString: "Chrome",
            identity: "Chrome"
        },
        {
            string: navigator.userAgent,
            subString: "OmniWeb",
            versionSearch: "OmniWeb/",
            identity: "OmniWeb"
        },
        {
            string: navigator.vendor,
            subString: "Apple",
            identity: "Safari",
            versionSearch: "Version"
        },
        {
            prop: window.opera,
            identity: "Opera"
        },
        {
            string: navigator.vendor,
            subString: "iCab",
            identity: "iCab"
        },
        {
            string: navigator.vendor,
            subString: "KDE",
            identity: "Konqueror"
        },
        {
            string: navigator.userAgent,
            subString: "Firefox",
            identity: "Firefox"
        },
        {
            string: navigator.vendor,
            subString: "Camino",
            identity: "Camino"
        },
        {        // for newer Netscapes (6+)
            string: navigator.userAgent,
            subString: "Netscape",
            identity: "Netscape"
        },
        {
            string: navigator.userAgent,
            subString: "MSIE",
            identity: "Explorer",
            versionSearch: "MSIE"
        },
        {
            string: navigator.userAgent,
            subString: "Gecko",
            identity: "Mozilla",
            versionSearch: "rv"
        },
        {         // for older Netscapes (4-)
            string: navigator.userAgent,
            subString: "Mozilla",
            identity: "Netscape",
            versionSearch: "Mozilla"
        }
    ],
    dataOS : [
        {
            string: navigator.platform,
            subString: "Win",
            identity: "Windows"
        },
        {
            string: navigator.platform,
            subString: "Mac",
            identity: "Mac"
        },
        {
            string: navigator.userAgent,
            subString: "iPhone",
            identity: "iPhone"
        },
        {
            string: navigator.userAgent,
            subString: "iPad",
            identity: "iPad"
        },
        {
            string: navigator.platform,
            subString: "Linux",
            identity: "Linux"
        }
    ]
};

$(function(){
    $body = $(document.body),
    $head = $(document.getElementsByTagName("head")[0]),
    $window = $(window),
    $layoutRoot = $('#root'),
    $sectionMenu = $('#section_menu'),
    $layoutHeader = $('#header'),
    $layoutFooter = $('#footer'),
    $layoutContent = $('#content'),
    $layoutCenterBox = $('#center_box');

    var l = window.location;
});

 
function layoutInit(){
    $.validator.setDefaults({
        errorElement: 'em'
    });

    $body
      .addClass($.client.os + 'OS')
      .addClass($.client.browser + 'UA');
}
BrowserDetect.init();
    
window.$.client = {
    os : BrowserDetect.OS,
    browser : BrowserDetect.browser
}; 

var _gaq = _gaq || [];

