﻿/// <reference path="jquery-1.4.4.js" />

//JSON
eval(function (p, a, c, k, e, d) { e = function (c) { return (c < a ? "" : e(parseInt(c / a))) + ((c = c % a) > 35 ? String.fromCharCode(c + 29) : c.toString(36)) }; if (!''.replace(/^/, String)) { while (c--) d[e(c)] = k[c] || e(c); k = [function (e) { return d[e] } ]; e = function () { return '\\w+' }; c = 1; }; while (c--) if (k[c]) p = p.replace(new RegExp('\\b' + e(c) + '\\b', 'g'), k[c]); return p; } ('3(!o.l){l={}}(5(){5 f(n){7 n<10?\'0\'+n:n}3(6 14.y.q!==\'5\'){14.y.q=5(h){7 o.1P()+\'-\'+f(o.1M()+1)+\'-\'+f(o.1J())+\'T\'+f(o.1W())+\':\'+f(o.1T())+\':\'+f(o.1v())+\'Z\'};W.y.q=1w.y.q=1y.y.q=5(h){7 o.1z()}}A L=/[\\1E\\1a\\18-\\17\\19\\13\\1k\\1n-\\1m\\1l-\\1c\\1e-\\1f\\1g\\1b-\\1d]/g,M=/[\\\\\\"\\1H-\\1A\\1D-\\1C\\1a\\18-\\17\\19\\13\\1k\\1n-\\1m\\1l-\\1c\\1e-\\1f\\1g\\1b-\\1d]/g,8,I,1h={\'\\b\':\'\\\\b\',\'\\t\':\'\\\\t\',\'\\n\':\'\\\\n\',\'\\f\':\'\\\\f\',\'\\r\':\'\\\\r\',\'"\':\'\\\\"\',\'\\\\\':\'\\\\\\\\\'},p;5 O(m){M.1t=0;7 M.R(m)?\'"\'+m.G(M,5(a){A c=1h[a];7 6 c===\'m\'?c:\'\\\\u\'+(\'1p\'+a.1s(0).Y(16)).1r(-4)})+\'"\':\'"\'+m+\'"\'}5 H(h,w){A i,k,v,e,K=8,9,2=w[h];3(2&&6 2===\'z\'&&6 2.q===\'5\'){2=2.q(h)}3(6 p===\'5\'){2=p.P(w,h,2)}1R(6 2){C\'m\':7 O(2);C\'12\':7 1S(2)?W(2):\'E\';C\'1X\':C\'E\':7 W(2);C\'z\':3(!2){7\'E\'}8+=I;9=[];3(U.y.Y.1K(2)===\'[z 1L]\'){e=2.e;D(i=0;i<e;i+=1){9[i]=H(i,2)||\'E\'}v=9.e===0?\'[]\':8?\'[\\n\'+8+9.N(\',\\n\'+8)+\'\\n\'+K+\']\':\'[\'+9.N(\',\')+\']\';8=K;7 v}3(p&&6 p===\'z\'){e=p.e;D(i=0;i<e;i+=1){k=p[i];3(6 k===\'m\'){v=H(k,2);3(v){9.1j(O(k)+(8?\': \':\':\')+v)}}}}V{D(k 1o 2){3(U.1q.P(2,k)){v=H(k,2);3(v){9.1j(O(k)+(8?\': \':\':\')+v)}}}}v=9.e===0?\'{}\':8?\'{\\n\'+8+9.N(\',\\n\'+8)+\'\\n\'+K+\'}\':\'{\'+9.N(\',\')+\'}\';8=K;7 v}}3(6 l.Q!==\'5\'){l.Q=5(2,x,J){A i;8=\'\';I=\'\';3(6 J===\'12\'){D(i=0;i<J;i+=1){I+=\' \'}}V 3(6 J===\'m\'){I=J}p=x;3(x&&6 x!==\'5\'&&(6 x!==\'z\'||6 x.e!==\'12\')){15 1i 1N(\'l.Q\')}7 H(\'\',{\'\':2})}}3(6 l.11!==\'5\'){l.11=5(B,X){A j;5 S(w,h){A k,v,2=w[h];3(2&&6 2===\'z\'){D(k 1o 2){3(U.1q.P(2,k)){v=S(2,k);3(v!==1I){2[k]=v}V{1V 2[k]}}}}7 X.P(w,h,2)}L.1t=0;3(L.R(B)){B=B.G(L,5(a){7\'\\\\u\'+(\'1p\'+a.1s(0).Y(16)).1r(-4)})}3(/^[\\],:{}\\s]*$/.R(B.G(/\\\\(?:["\\\\\\/1F]|u[0-1G-1B-F]{4})/g,\'@\').G(/"[^"\\\\\\n\\r]*"|1x|1Q|E|-?\\d+(?:\\.\\d*)?(?:[1u][+\\-]?\\d+)?/g,\']\').G(/(?:^|:|,)(?:\\s*\\[)+/g,\'\'))){j=1O(\'(\'+B+\')\');7 6 X===\'5\'?S({\'\':j},\'\'):j}15 1i 1U(\'l.11\')}}})();', 62, 122, '||value|if||function|typeof|return|gap|partial|||||length|||key||||JSON|string||this|rep|toJSON||||||holder|replacer|prototype|object|var|text|case|for|null||replace|str|indent|space|mind|cx|escapable|join|quote|call|stringify|test|walk||Object|else|String|reviver|toString|||parse|number|u17b4|Date|throw||u0604|u0600|u070f|u00ad|ufff0|u202f|uffff|u2060|u206f|ufeff|meta|new|push|u17b5|u2028|u200f|u200c|in|0000|hasOwnProperty|slice|charCodeAt|lastIndex|eE|getUTCSeconds|Number|true|Boolean|valueOf|x1f|fA|x9f|x7f|u0000|bfnrt|9a|x00|undefined|getUTCDate|apply|Array|getUTCMonth|Error|eval|getUTCFullYear|false|switch|isFinite|getUTCMinutes|SyntaxError|delete|getUTCHours|boolean'.split('|'), 0, {}));

var customLightBoxConfig = {
    imageBtnClose: globalBaseUrl + '/scripts/lightbox/images/lightbox-btn-close.gif',
    imageLoading: globalBaseUrl + '/scripts/lightbox/images/lightbox-ico-loading.gif',
    afterShow: function () {
        var target = $('#jquery-overlay');
        target.height(target.height() + 300);
    }
};

function ajaxRequestJson(jsonString, pageName, webMethodFunc, func, opts) {
    if (typeof (jsonString) == 'object') { jsonString = JSON.stringify(jsonString); }
    var options = {
        type: "POST",
        processUpdates: true,
        onParseError: function (exception, webMethodFunc) {
            var msg = "Não foi possível ler o JSON retornado de '" + webMethodFunc + "'.";
            alert(msg);
            return { sucess: false };
        },
        onAjaxError: function (xhr, status, error) {
            alert('Erro na chamada assíncrona "' + webMethodFunc + '".');
        }
    };
    options = jQuery.extend(options, opts);
    $.ajax({
        type: options.type,
        data: jsonString,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        url: pageName + "/" + webMethodFunc,
        dataFilter: function (data) {
            try {
                if (data !== '') {
                    var msg = JSON.parse(data);
                    if (msg.d) { return msg.d; } else { return msg; }
                }
            }
            catch (e) {
                options.onParseError.call(e, webMethodFunc);
            }
        },
        success: function (d) {
            func.call(this.constructor, d);
        },
        error: function (xhr, status, error) {
            switch (xhr.status) {
                case 401:
                    if (confirm("Atenção, sua sessão expirou. Deseja prosseguir para a página de login?")) {
                        window.location = window.location;
                    }
                    break;
                case 0:
                    break;
                default:
                    options.onAjaxError.call(xhr, status, error);
                    break;
            }
        }
    });
}

function installRoundabout(galleryId) {

    $('#'+galleryId+' li').each(function (i) {

        if ($.browser.msie) {
            $(this).css({
                width: ($(this).find('img').width() + 20) + 'px',
                heigth: ($(this).find('img').height() + 20) + 'px'
            });

        }
        else {
            $(this).css({
                width: $(this).find('img').width() + 'px',
                heigth: $(this).find('img').height() + 'px'
            });
        }

        $(this).find('img').css({ width: '100%' });
    });

    $('#'+galleryId).roundabout({
        tilt: -2,
        btnNext: '#'+galleryId+'Next',
        btnPrev: '#' + galleryId + 'Prev',
        easing: 'swing',
        minScale: .8,
        maxScale: 1,
        minOpacity: .10,
        clickToFocus: true
    });

//    if (jQuery.browser.webkit) {
//        $('#' + galleryId).css('margin-left', '40px');
//    }

    //$('#' + galleryId).find('a').live('click', function (e) { e.preventDefault(); });

    $('#' + galleryId + ' li a').focus(function () {
        $('#' + galleryId + ' li a').unbind('click');
        $('#' + galleryId + ' li a').blur();
        $('#' + galleryId + ' li.roundabout-in-focus a').lightBox(customLightBoxConfig);
    });
}

//GLOBAL STARTUP
$(document).ready(function () {
    $('.box').each(function () { $(this).find('ul:first').not('.notAddLines').find('a').not('a:last').after('<div class="singleFloatingLine"></div>'); });
    $('.rowTable').find('td').each(function () {
        $(this).children('div.inner').height($(this).height());
    });
    $('#menu .n2 a.active').parent().parent().prev().addClass('active');
    $('.bigActionBtn').hover(function () { $(this).addClass('bigActionBtnHover'); }, function () { $(this).removeClass('bigActionBtnHover'); });
    $('.rigidBox').each(function () {
        var link = $(this).find('.knowMore a');
        $(this).click(function () { window.location = link.attr('href'); });
    });

    jQuery.modal.defaults = jQuery.extend(jQuery.modal.defaults, {
        focus: false,
        autoResize: true,
        autoPosition: true,
        zIndex: 1000,
        close: true,
        closeHTML: '<a class="modalCloseImg" title="Close"></a>',
        escClose: true,
        overlayClose: true,
        modal: true
    });

    var icos = $('.spriteIco').append('<p></p>');
});

var bannerController = {
    timeout: 7,
    stop: false,
    installBanner: function (bannerGroupId) {
        var bannerGroup = $('#' + bannerGroupId);
        bannerGroup.find('.banner').each(function () {
            if (this.href == '') {
                $(this).css('cursor', 'default');
            }
        });
        var timer = bannerController.timeout;
        var banners = bannerGroup.find('.banner');

        banners.first().addClass('active');

        if (banners.length > 1) {
            verifyTime();
        }

        function verifyTime() {
            window.setTimeout(function () {
                if (!bannerController.stop) {
                    timer--;
                }
                if (timer == 0) {
                    timer = bannerController.timeout;
                    bannerController.swapBanners(banners);
                }
                verifyTime();
            }, 1000);
        }

        bannerController.bindControlsEvents(bannerGroup.find('.controls'), banners);
    },
    swapBanners: function (banners, forceIndex) {
        var length = banners.length;
        var currentBanner = banners.filter('.active');
        var currentIndex = banners.index(currentBanner);
        var nextIndex;
        if (forceIndex !== undefined) {
            nextIndex = forceIndex;
        }
        else {
            if (currentIndex == length - 1) {
                nextIndex = 0;
            }
            else {
                nextIndex = currentIndex + 1;
            }
        }
        if (nextIndex != currentIndex) {
            var nextBanner = banners.eq(nextIndex);
            nextBanner.addClass('next').show();
            currentBanner.fadeOut(300, function () {
                currentBanner.removeClass('active');
                nextBanner.removeClass('next').addClass('active');
            });

            $('#bannerBtn_' + nextIndex).addClass('active').siblings().removeClass('active');
        }
    },
    bindControlsEvents: function (controls, banners) {
        if (banners.length > 1) {

            controls.width(banners.length * 30 + 10);

            controls.hover(function () {
                bannerController.stop = true;
            }, function () {
                bannerController.stop = false;
            });

            banners.each(function (i) {
                $('<a>').text(i + 1).data('index', i).attr('id', 'bannerBtn_' + i).click(function () {
                    bannerController.swapBanners(banners, $(this).data('index'));
                }).appendTo(controls).css({ position: 'absolute', left: (i * 30) + 'px' });
            });
            controls.find('a:first').addClass('active');
        }
        else {
            controls.hide();
        }
    }
};

