// #################### BEGIN Slider ###################
jQuery.fn.slider = function() {

    var btn_prev = jQuery('div#left_slide', this);
    var btn_next = jQuery('div#right_slide', this);
    var slider = jQuery('#slider', this);
    var lis = jQuery('#slider li div.slider_item', this);
    var down = true;
    var total_items = lis.length;
    var current_index = 0;
    var lst_index = 0;
    var total_width = 0;
    var lock = true;

    //Inicializa os estados dos botoes
    if (total_items <= 1)
        btn_next.css({ 'visibility': 'hidden' });
    btn_prev.css({ 'visibility': 'hidden' });

    slider.attr('scrollLeft', 0);

    //jQuery('div.ad_spc_pl8',this).removeClass('ad_spc_pl8');

    jQuery(lis).each(function(index) {
        total_width += jQuery(this).width();
        jQuery('div.number_container').append('<span rel="' + (index + 1) + '">' + (index + 1) + '</span>');
    });

    var list_number = jQuery('div.number_container span');

    list_number.eq(current_index).addClass('active');

    slider.css({ 'overflow': 'hidden' });

    btn_next.click(function(event) {

        if (lock) {
            lock = false;
            if (current_index < total_items - 1) {
                slider.animate({ scrollLeft: slider.attr('scrollLeft') + lis.eq(current_index).width() }, 750, 'swing', function() { lock = true; });
                list_number.eq(current_index).removeClass('active');
                current_index++;
                list_number.eq(current_index).addClass('active');
                if (current_index == total_items - 1) {
                    btn_next.css({ 'visibility': 'hidden' });
                }
                if (total_items > 1) {
                    btn_prev.css({ 'visibility': 'visible' });
                }
            } else {
                lock = true;
            }
        }
    });

    list_number.click(function() {

        if (lock) {

            lock = false;

            var ci = list_number.index(this);

            if (ci < current_index) {

                slider.animate({ scrollLeft: slider.attr('scrollLeft') - (902 * (current_index - ci)) }, 750, 'swing', function() { lock = true; });

            } else if (ci > current_index) {

                slider.animate({ scrollLeft: slider.attr('scrollLeft') + (902 * (ci - current_index)) }, 750, 'swing', function() { lock = true; });

            }

            if (ci == total_items - 1 && total_items > 1) {
                btn_prev.css({ 'visibility': 'visible' });
                btn_next.css({ 'visibility': 'hidden' });
            } else if (ci == 0 && total_items > 1) {
                btn_prev.css({ 'visibility': 'hidden' });
                btn_next.css({ 'visibility': 'visible' });
            } else if (total_items > 1) {
                btn_prev.css({ 'visibility': 'visible' });
                btn_next.css({ 'visibility': 'visible' });
            }

            list_number.eq(current_index).removeClass('active');
            list_number.eq(ci).addClass('active');
            current_index = ci;

        }

    });

    btn_prev.click(function(event) {
        if (lock) {
            lock = false;
            if (current_index > 0) {
                slider.animate({ scrollLeft: slider.attr('scrollLeft') - lis.eq(current_index - 1).width() }, 750, 'swing', function() { lock = true; });
                list_number.eq(current_index).removeClass('active');
                current_index--;
                list_number.eq(current_index).addClass('active');
                if (current_index == 0) {
                    btn_prev.css({ 'visibility': 'hidden' });
                }
                if (total_items > 1) {
                    btn_next.css({ 'visibility': 'visible' });
                }
            } else {
                lock = true;
            }
        }
    });



};

// #################### BEGIN Carousel Handling ###################
var meoCarousel = {
    elementChanging: function(carousel, item, i, state, evt) {
        jquery('.jcarousel-control span', carousel.container).removeClass("active");
        jquery('.jcarousel-control span[rel="' + i + '"]', carousel.container).addClass("active");
    },
    init: function(carousel) {
        jquery('.jcarousel-control span', carousel.container).bind('click', function() {
            carousel.startAuto(0);
            carousel.scroll(jquery.jcarousel.intval(jquery(this).attr("rel")));
            return false;
        });

        // Disable autoscroll if a button is clicked
        carousel.buttonNext.bind('click', function() { carousel.startAuto(0); });
        carousel.buttonPrev.bind('click', function() { carousel.startAuto(0); });
    }
};
// #################### END Carousel Handling ###################

// #################### BEGIN Carousel Handling - Números ###################
var meoCarouselNum = {
    elementChanging: function(carousel, item, i, state, evt) {
        jquery('.jcarousel-control_2 span', carousel.container).removeClass("active");
        jquery('.jcarousel-control_2 span[rel="' + i + '"]', carousel.container).addClass("active");
    },
    init: function(carousel) {
        jquery('.jcarousel-control_2 span', carousel.container).bind('click', function() {
            carousel.startAuto(0);
            carousel.scroll(jquery.jcarousel.intval(jquery(this).attr("rel")));
            return false;
        });

        // Disable autoscroll if a button is clicked
        carousel.buttonNext.bind('click', function() { carousel.startAuto(0); });
        carousel.buttonPrev.bind('click', function() { carousel.startAuto(0); });
    }
};
// #################### END Carousel Handling ###################

// #################### BEGIN Videobox handling ###################
var Videobox = {
    anchors: [],
    init: function() {
        // init default options
        this.options = {
            resizeDuration: 400, // Duration of height and width resizing (ms)
            initialWidth: 250, 	// Initial width of the box (px)
            initialHeight: 250, 	// Initial height of the box (px)
            defaultWidth: 600, 	// Default width of the box (px)
            defaultHeight: 380, // Default height of the box (px)
            animateCaption: true, // Enable/Disable caption animation
            flvplayer: '/Style%20Library/MeoVideo/swf/FlowPlayerDark.swf'
        };


        jquery('a[rel="vidbox"]').each(function(i) {
            var el = jquery(this).click(Videobox.click);
            Videobox.anchors.push(el);
        });

        this.overlay = jquery('<div id="lbOverlay"></div>').appendTo('body');
        this.overlay.click(Videobox.close);

        this.center = jquery('<div id="lbCenter" style="width:' + this.options.initialWidth + 'px;height:' + this.options.initialHeight + 'px;margin-left:-' + (this.options.initialWidth / 2) + 'px;display:none"></div>').appendTo('body');

        this.botC = jquery('<div id="lbBottomContainer" style="display:none;"></div>').appendTo('body');

        this.bottom = jquery('<div id="lbBottom"></div>').appendTo(this.botC);

        jquery('<a id="lbCloseLink" href="#"></a>').appendTo(this.bottom).click(Videobox.close);

        this.caption = jquery('<div id="lbCaption"></div>').appendTo(this.bottom);

        this.number = jquery('<div id="lbNumber"></div>').appendTo(this.bottom);

        jquery('<div style="clear:both;"></div>').appendTo(this.bottom);
    },

    click: function() {
        var jquery_obj = jquery(this);
        return Videobox.open(jquery_obj.attr("href"), jquery_obj.attr("title"), jquery_obj.attr("rel"));
    },
    open: function(sLinkHref, sLinkTitle, sLinkRel) {
        var lnk = this;
        lnk.href = sLinkHref;
        lnk.title = sLinkTitle;
        lnk.rel = sLinkRel;
        lnk.position();
        lnk.setup();
        lnk.video(lnk.href);
        lnk.top = jQuery(window).scrollTop() + (jQuery(window).height() / 15);
        Videobox.center.css({ top: lnk.top + 'px', display: '' });
        Videobox.overlay.css({ 'opacity': '0', 'display': 'block' });
        Videobox.overlay.fadeTo('500', '0.8', function() {
            Videobox.center.css('background', '#202020 url(/Style%20Library/MEOImages/video/loading.gif) no-repeat center');
            Videobox.caption.html(lnk.title);
            Videobox.center.animate({ 'height': [Videobox.options.contentsHeight], 'width': [Videobox.options.contentsWidth], 'marginLeft': [Videobox.options.contentsWidth / -2] }, function() {
                Videobox.center.css('background', '#202020');
                Videobox.flash ? Videobox.center.html(Videobox.so) : Videobox.center.html(Videobox.other);
                var botHeight = Videobox.botC.height();
                Videobox.botC.css({ 'top': (Videobox.top + Videobox.center.height()) + 'px', 'height': '0px', 'margin-left': Videobox.center.css('margin-left'), 'width': Videobox.options.contentsWidth + 'px', 'display': '' })
                if (Videobox.options.animateCaption) {
                    Videobox.botC.css('margin-top', -botHeight);
                    Videobox.bottom.css('margin-top', 10);
                    Videobox.botC.animate({ marginTop: '0' }, 500, function() {
                        Videobox.botC.animate({ height: botHeight }, 500);
                    });
                }
                else
                    Videobox.botC.css('height', '');
            });
        });
        return false;
    },

    setup: function() {
        var aDim = this.rel.match(/[0-9]+/g);
        this.options.contentsWidth = (aDim && (aDim[0] > 0)) ? aDim[0] : this.options.defaultWidth;
        this.options.contentsHeight = (aDim && (aDim[1] > 0)) ? aDim[1] : this.options.defaultHeight;

    },

    position: function() {
        Videobox.overlay.css({ 'top': 0 + 'px', 'height': (document.height || document.body.offsetHeight) + 'px' });
    },

    video: function(sLinkHref) {
        if (sLinkHref.match(/youtube\.com\/watch/i)) {
            this.flash = true;
            var hRef = sLinkHref;
            var videoId = hRef.split('=');
            this.videoID = videoId[1];
            this.so = jquery.flash({
                swf: 'http://www.youtube.com/v/' + this.videoID,
                name: 'flvvideo',
                height: this.options.contentsHeight,
                width: this.options.contentsWidth,
                flashvars: {
                    wmode: 'transparent'
                }
            });
        }
        else if (sLinkHref.match(/metacafe\.com\/watch/i)) {
            this.flash = true;
            var hRef = sLinkHref;
            var videoId = hRef.split('http://www.meo.pt/');
            this.videoID = videoId[4];
            this.so = jquery.flash({
                swf: 'http://www.metacafe.com/fplayer/' + this.videoID + '/.swf',
                name: 'flvvideo',
                height: this.options.contentsHeight,
                width: this.options.contentsWidth,
                flashvars: {
                    wmode: 'transparent'
                }
            });
        }
        else if (sLinkHref.match(/sapo\.pt/i)) {
            this.flash = false;
            var hRef = sLinkHref;
            var videoId = hRef.split('http://www.meo.pt/');
            this.videoID = videoId[3];
            this.other = '<embed height="' + this.options.contentsHeight + '" width="' + this.options.contentsWidth + '" flashvars=\'config={"autoPlay":true,"autoBuffering":true,"controlBarBackgroundColor":"0","initialScale":"scale","videoFile":"' + sLinkHref + '","showFullScreenButton":false,"showMenu":false}\' pluginspage="http://www.adobe.com/go/getflashplayer" type="application/x-shockwave-flash" quality="high" allowscriptaccess="always" allowfullscreen="false" bgcolor="#ffffff" src="' + this.options.flvplayer + '"/>';
        }
        else if (sLinkHref.match(/google\.com\/videoplay/i)) {
            this.flash = true;
            var hRef = sLinkHref;
            var videoId = hRef.split('=');
            this.videoID = videoId[1];
            this.so = jquery.flash({
                swf: 'http://video.google.com/googleplayer.swf?docId=' + this.videoID + '&hl=en',
                name: 'flvvideo',
                height: this.options.contentsHeight,
                width: this.options.contentsWidth,
                flashvars: {
                    wmode: 'transparent'
                }
            });
        }
        else if (sLinkHref.match(/ifilm\.com\/video/i)) {
            this.flash = true;
            var hRef = sLinkHref;
            var videoId = hRef.split('video/index.html');
            this.videoID = videoId[1];
            this.so = jquery.flash({
                swf: 'http://www.ifilm.com/efp',
                name: 'flvvideo',
                height: this.options.contentsHeight,
                width: this.options.contentsWidth,
                flashvars: {
                    flvbaseclip: this.videoID + '&',
                    wmode: 'transparent'
                }
            });
        }
        else if (sLinkHref.match(/\.mov/i)) {
            this.flash = false;
            if (navigator.plugins && navigator.plugins.length) {
                this.other = '<object id="qtboxMovie" type="video/quicktime" codebase="http://www.apple.com/qtactivex/qtplugin.cab" data="' + sLinkHref + '" width="' + this.options.contentsWidth + '" height="' + this.options.contentsHeight + '"><param name="src" value="' + sLinkHref + '" /><param name="scale" value="aspect" /><param name="controller" value="true" /><param name="autoplay" value="true" /><param name="bgcolor" value="#000000" /><param name="enablejavascript" value="true" /></object>';
            } else {
                this.other = '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab" width="' + this.options.contentsWidth + '" height="' + this.options.contentsHeight + '" id="qtboxMovie"><param name="src" value="' + sLinkHref + '" /><param name="scale" value="aspect" /><param name="controller" value="true" /><param name="autoplay" value="true" /><param name="bgcolor" value="#000000" /><param name="enablejavascript" value="true" /></object>';
            }
        }
        else if (sLinkHref.match(/\.wmv/i) || sLinkHref.match(/\.asx/i)) {
            this.flash = false;
            this.other = '<object NAME="Player" WIDTH="' + this.options.contentsWidth + '" HEIGHT="' + this.options.contentsHeight + '" align="left" hspace="0" type="application/x-oleobject" CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6"><param NAME="URL" VALUE="' + sLinkHref + '"><param><param NAME="AUTOSTART" VALUE="false"></param><param name="showControls" value="true"></param><embed WIDTH="' + this.options.contentsWidth + '" HEIGHT="' + this.options.contentsHeight + '" align="left" hspace="0" SRC="' + sLinkHref + '" TYPE="application/x-oleobject" AUTOSTART="false"></embed></object>'
        }
        else if (sLinkHref.match(/\.flv/i)) {
            this.flash = false;
            var hRef = sLinkHref;
            var videoId = hRef.split('http://www.meo.pt/');
            this.videoID = videoId[3];
            this.other = '<embed height="' + this.options.contentsHeight + '" width="' + this.options.contentsWidth + '" flashvars=\'config={"autoPlay":true,"loop":false,"autoBuffering":true,"controlBarBackgroundColor":"0","initialScale":"scale","videoFile":"' + sLinkHref + '","showFullScreenButton":false,"showMenu":false}\' pluginspage="http://www.adobe.com/go/getflashplayer" type="application/x-shockwave-flash" quality="high" allowscriptaccess="always" allowfullscreen="true" bgcolor="#ffffff" src="' + this.options.flvplayer + '"/>';
        }
        else {
            this.flash = true;
            this.videoID = sLinkHref;
            this.so = jquery.flash({
                swf: this.videoID,
                name: 'flvvideo',
                height: this.options.contentsHeight,
                width: this.options.contentsWidth,
                flashvars: {
                    wmode: 'transparent'
                }
            });
        }
    },

    close: function() {
        Videobox.overlay.fadeOut('500');
        Videobox.center.css('display', 'none');
        Videobox.botC.css('display', 'none');
        Videobox.center.html('');
        return false;
    }

};

jquery(document).ready(function() {
    Videobox.init();
});
// #################### END Videobox handling ###################

// #################### BEGIN Tooltip Box ###################
var tooltipPanel = {
    _tipOn: false,
    _instance: null,
    _ns5: false,
    _ie5: false,
    _ie4: false,
    _dom: false,
    _t1: null,
    _t2: null,
    _standardBody: null,
    _positionTip: function(evt) {
        if (!tooltipPanel._tipOn)
            return;

        var mouseX = (tooltipPanel._ns5) ? evt.pageX : window.event.clientX + tooltipPanel._standardBody.scrollLeft;
        var mouseY = (tooltipPanel._ns5) ? evt.pageY : window.event.clientY + tooltipPanel._standardBody.scrollTop;

        // tooltip width and height
        var tpWd = tooltipPanel._instance.width();
        var tpHt = tooltipPanel._instance.height();
        // document area in view (subtract scrollbar width for ns)
        var winWd = (tooltipPanel._ns5) ? window.innerWidth - 20 + window.pageXOffset : tooltipPanel._standardBody.clientWidth + tooltipPanel._standardBody.scrollLeft;
        var winHt = (tooltipPanel._ns5) ? window.innerHeight - 20 + window.pageYOffset : tooltipPanel._standardBody.clientHeight + tooltipPanel._standardBody.scrollTop;

        // check mouse position against tip and window dimensions
        // and position the tooltip
        if ((mouseX + 2 + tpWd) > winWd)
            tooltipPanel._instance.css({ 'left': ((mouseX - (tpWd + 2)) + 'px') });
        else
            tooltipPanel._instance.css({ 'left': ((mouseX + 2) + 'px') });

        if ((mouseY + tpHt + 20) > winHt)
            tooltipPanel._instance.css({ 'top': ((winHt - (tpHt + 20)) + 'px') });
        else
            tooltipPanel._instance.css({ 'top': ((mouseY + 20) + 'px') });
    },
    doTooltip2: function(evt, num, desc, color, width) {
        var messages = new Array();
        if (tooltipPanel._instance != null && desc != "") {
            var startStr = '<table width="' + width + '" cellspacing="0" cellpadding="0" border="0" style="padding:0px;margin:0px;"><tr><td style="padding:10px;">';
            var endStr = '</td></tr></table>';
            if (color == 1)
                messages[num] = new Array('../Style%20Library/MEOImages/top_desc.gif', desc, "#8F8D8E", "#FFFFFF");
            else
                messages[num] = new Array('../Style%20Library/MEOImages/top_desc_2.gif', desc, "#E5E5E5", "#969698");

            if (tooltipPanel._t1) clearTimeout(tooltipPanel._t1);
            if (tooltipPanel._t2) clearTimeout(tooltipPanel._t2);
            tooltipPanel._tipOn = true;

            // set colors if included in messages array
            if (messages[num][2])
                var curBgColor = messages[num][2];
            else
                curBgColor = tipBgColor;
            if (messages[num][3])
                var curFontColor = messages[num][3];
            else
                curFontColor = tipFontColor;

            if (tooltipPanel._ie4 || tooltipPanel._ie5 || tooltipPanel._ns5) {
                tooltipPanel._instance.css({ 'background-color': curBgColor });
                var tip = startStr + '<span style="font-family:Arial, Helvetica, sans-serif !important; font-size:11px !important; color:' + curFontColor + ' !important;">' + messages[num][1] + '</span>' + endStr;
                tooltipPanel._instance.html(tip);
            }

            tooltipPanel._t1 = setTimeout("tooltipPanel._instance.show()", 100);
        }
    },
    hideTip: function() {
        if (tooltipPanel._instance == null) return;
        tooltipPanel._t2 = setTimeout("tooltipPanel._instance.hide()", 100);
        tooltipPanel._tipOn = false;
    },
    init: function() {
        tooltipPanel._instance = jquery("#tipDiv");
        document.onmousemove = tooltipPanel._positionTip;

        tooltipPanel._standardBody = (document.compatMode == "CSS1Compat") ? document.documentElement : document.body //create reference to common "body" across doctypes
        tooltipPanel._dom = (document.getElementById) ? true : false;
        tooltipPanel._ns5 = (!document.all && tooltipPanel._dom || window.opera) ? true : false;
        tooltipPanel._ie5 = ((navigator.userAgent.indexOf("MSIE") > -1) && tooltipPanel._dom) ? true : false;
        tooltipPanel._ie4 = (document.all && !tooltipPanel._dom) ? true : false;
    }
};

document.write('<div id="tipDiv" style="position:absolute; display:none; z-index:100"></div>');
jquery(document).ready(function() {
    tooltipPanel.init();
});
// #################### END Tooltip Box ###################


// #################### TABVOD manager ###################
var tabManager = {
    timeout: 0,
    closetimer: 0,
    ddmenuitem: 0,
    tbleft: 0,
    tbcenter: 0,
    tbright: 0,
    open: function() {
        tabManager.canceltimer();
        tabManager.close();
        tabManager.ddmenuitem = jquery(this).find('.menukinds').eq(0).css('visibility', 'visible');
        tabManager.tbleft = jquery(this).children().find('.tab_inactiva_left').eq(0).attr('class', 'tab_activa_left');
        tabManager.tbcenter = jquery(this).children().find('.tab_inactiva').eq(0).attr('class', 'tab_activa');
        tabManager.tbright = jquery(this).children().find('.tab_inactiva_right').eq(0).attr('class', 'tab_activa_right');
    },
    close: function() {
        if (tabManager.ddmenuitem) {
            tabManager.ddmenuitem.css('visibility', 'hidden');
            tabManager.tbleft.attr('class', 'tab_inactiva_left');
            tabManager.tbcenter.attr('class', 'tab_inactiva');
            tabManager.tbright.attr('class', 'tab_inactiva_right');
        }
    },
    timer: function() {
        tabManager.closetimer = window.setTimeout(tabManager.close, tabManager.timeout);
    },
    canceltimer: function() {
        if (tabManager.closetimer) {
            window.clearTimeout(tabManager.closetimer);
            tabManager.closetimer = null;
        }
    },
    init: function() {
        jquery('.tab').bind('mouseover', tabManager.open);
        jquery('.tab').bind('mouseout', tabManager.timer);
    }
};

jquery(document).ready(function() {
    tabManager.init();
});
// #################### END TABVOD manager ###################


// #################### BEGIN Drop Down/ Overlapping ###################
// #### Drop Down/ Overlapping Content: http://www.dynamicdrive.com ####
//Last Update: Sept 11th, 08
var dropdowncontent = {
    disableanchorlink: true, //when user clicks on anchor link, should link itself be disabled (always true if "revealbehavior" above set to "click")
    hidedivmouseout: [true, 200], //Set hiding behavior within Drop Down DIV itself: [hide_div_onmouseover?, miliseconds_before_hiding]
    ajaxloadingmsg: "Loading content. Please wait...", //HTML to show while ajax page is being feched, if applicable
    ajaxbustcache: true, //Bust cache when fetching Ajax pages?

    getposOffset: function(what, offsettype) {
        return (what.offsetParent) ? what[offsettype] + this.getposOffset(what.offsetParent, offsettype) : what[offsettype]
    },

    isContained: function(m, e) {
        var e = window.event || e
        var c = e.relatedTarget || ((e.type == "mouseover") ? e.fromElement : e.toElement)
        while (c && c != m) try { c = c.parentNode } catch (e) { c = m }
        if (c == m)
            return true
        else
            return false
    },

    show: function(anchorobj, subobj, e) {
        if (!this.isContained(anchorobj, e) || (e && e.type == "click")) {
            var e = window.event || e
            if (e.type == "click" && subobj.style.visibility == "visible") {
                subobj.style.visibility = "hidden"
                return
            }
            var horizontaloffset = (subobj.dropposition[0] == "left") ? -(subobj.offsetWidth - anchorobj.offsetWidth) : 0 //calculate user added horizontal offset
            var verticaloffset = (subobj.dropposition[1] == "top") ? -subobj.offsetHeight : anchorobj.offsetHeight //calculate user added vertical offset
            subobj.style.left = this.getposOffset(anchorobj, "offsetLeft") + horizontaloffset + "px"
            subobj.style.top = this.getposOffset(anchorobj, "offsetTop") + verticaloffset + "px"
            subobj.style.clip = (subobj.dropposition[1] == "top") ? "rect(auto auto auto 0)" : "rect(0 auto 0 0)" //hide drop down box initially via clipping
            subobj.style.visibility = "visible"
            subobj.startTime = new Date().getTime()
            subobj.contentheight = parseInt(subobj.offsetHeight)
            if (typeof window["hidetimer_" + subobj.id] != "undefined") //clear timer that hides drop down box?
                clearTimeout(window["hidetimer_" + subobj.id])
            this.slideengine(subobj, (subobj.dropposition[1] == "top") ? "up" : "down")
        }
    },

    curveincrement: function(percent) {
        return (1 - Math.cos(percent * Math.PI)) / 2 //return cos curve based value from a percentage input
    },

    slideengine: function(obj, direction) {
        var elapsed = new Date().getTime() - obj.startTime //get time animation has run
        if (elapsed < obj.glidetime) { //if time run is less than specified length
            var distancepercent = (direction == "down") ? this.curveincrement(elapsed / obj.glidetime) : 1 - this.curveincrement(elapsed / obj.glidetime)
            var currentclip = (distancepercent * obj.contentheight) + "px"
            obj.style.clip = (direction == "down") ? "rect(0 auto " + currentclip + " 0)" : "rect(" + currentclip + " auto auto 0)"
            window["glidetimer_" + obj.id] = setTimeout(function() { dropdowncontent.slideengine(obj, direction) }, 10)
        }
        else { //if animation finished
            obj.style.clip = "rect(0 auto auto 0)"
        }
    },

    hide: function(activeobj, subobj, e) {
        if (!dropdowncontent.isContained(activeobj, e)) {
            var objDiv = document.getElementById('imgBobcontent2');
            objDiv.src = '../Style%20Library/MeoImages/bt_acessoclose.gif';
            window["hidetimer_" + subobj.id] = setTimeout(function() {
                subobj.style.visibility = "hidden"
                subobj.style.left = subobj.style.top = 0
                clearTimeout(window["glidetimer_" + subobj.id])
            }, dropdowncontent.hidedivmouseout[1])
        }
    },


    hidediv2: function(subobjid, subobjid2) {
        var obj1 = document.getElementById(subobjid)
        var obj2 = document.getElementById(subobjid2)
        if (obj1 != null)
        { obj1.style.visibility = "hidden" }
        if (obj2 != null)
        { obj2.style.visibility = "hidden" }
    },

    hidediv3: function(subobjid, subobjid2, subobjid3) {
        var obj1 = document.getElementById(subobjid)
        var obj2 = document.getElementById(subobjid2)
        var obj3 = document.getElementById(subobjid3)
        if (obj1 != null)
        { obj1.style.visibility = "hidden" }
        if (obj2 != null)
        { obj2.style.visibility = "hidden" }
        if (obj3 != null)
        { obj3.style.visibility = "hidden" }
    },

    hidediv: function(subobjid) {
        document.getElementById(subobjid).style.visibility = "hidden"
    },

    ajaxconnect: function(pageurl, divId) {
        var page_request = false
        var bustcacheparameter = ""
        if (window.XMLHttpRequest) // if Mozilla, IE7, Safari etc
            page_request = new XMLHttpRequest()
        else if (window.ActiveXObject) { // if IE6 or below
            try {
                page_request = new ActiveXObject("Msxml2.XMLHTTP")
            }
            catch (e) {
                try {
                    page_request = new ActiveXObject("Microsoft.XMLHTTP")
                }
                catch (e) { }
            }
        }
        else
            return false
        document.getElementById(divId).innerHTML = this.ajaxloadingmsg //Display "fetching page message"
        page_request.onreadystatechange = function() { dropdowncontent.loadpage(page_request, divId) }
        if (this.ajaxbustcache) //if bust caching of external page
            bustcacheparameter = (pageurl.indexOf("?") != -1) ? "&" + new Date().getTime() : "?" + new Date().getTime()
        page_request.open('GET', pageurl + bustcacheparameter, true)
        page_request.send(null)
    },

    loadpage: function(page_request, divId) {
        if (page_request.readyState == 4 && (page_request.status == 200 || window.location.href.indexOf("http") == -1)) {
            document.getElementById(divId).innerHTML = page_request.responseText
        }
    },

    init: function(anchorid, pos, glidetime, revealbehavior) {
        var anchorobj = document.getElementById(anchorid)
        if (anchorobj != null) {
            var subobj = document.getElementById(anchorobj.getAttribute("rel"))
            var subobjsource = anchorobj.getAttribute("rev")
            if (subobjsource != null && subobjsource != "")
                this.ajaxconnect(subobjsource, anchorobj.getAttribute("rel"))
            subobj.dropposition = pos.split("-")
            subobj.glidetime = glidetime || 1000
            subobj.style.left = subobj.style.top = 0
            if (typeof revealbehavior == "undefined" || revealbehavior == "mouseover") {
                anchorobj.onmouseover = function(e) { dropdowncontent.show(this, subobj, e) }
                anchorobj.onmouseout = function(e) { dropdowncontent.hide(subobj, subobj, e) }
                if (this.disableanchorlink) anchorobj.onclick = function() { return false }
            }
            else
                anchorobj.onclick = function(e) { dropdowncontent.show(this, subobj, e); return false }
            if (this.hidedivmouseout[0] == true) //hide drop down DIV when mouse rolls out of it?
                subobj.onmouseout = function(e) { dropdowncontent.hide(this, subobj, e) }
        }
    }
};
// #################### END Drop Down/ Overlapping ###################

// #################### BEGIN Content Fader ###################
var fadecontentviewer = {
    csszindex: 1,
    fade: function(allcontents, togglerid, selected, speed) {
        var selected = parseInt(selected)
        var togglerdiv = jquery("#" + togglerid)
        var target = allcontents.eq(selected)
        if (togglerdiv.attr('lastselected') == null || parseInt(togglerdiv.attr('lastselected')) != selected) {
            var toc = jquery("#" + togglerid + " .toc")
            var selectedlink = toc.eq(selected)
            jquery("#" + togglerid + " .next").attr('nextpage', (selected < allcontents.length - 1) ? selected + 1 + 'pg' : 0 + 'pg')
            jquery("#" + togglerid + " .prev").attr('previouspage', (selected == 0) ? allcontents.length - 1 + 'pg' : selected - 1 + 'pg')
            target.css({ zIndex: this.csszindex++, visibility: 'visible' })
            target.hide()
            target.fadeIn(speed)
            toc.removeClass('selected')
            selectedlink.addClass('selected')
            togglerdiv.attr('lastselected', selected + 'pg')
        }
    },

    setuptoggler: function(allcontents, togglerid, speed) {
        var toc = jquery("#" + togglerid + " .toc")
        toc.each(function(index) {
            jquery(this).attr('pagenumber', index + 'pg')
        })

        var next = jquery("#" + togglerid + " .next")
        var prev = jquery("#" + togglerid + " .prev")
        next.click(function() {
            fadecontentviewer.fade(allcontents, togglerid, jquery(this).attr('nextpage'), speed)
            return false
        })
        prev.click(function() {
            fadecontentviewer.fade(allcontents, togglerid, jquery(this).attr('previouspage'), speed)
            return false
        })
        toc.click(function() {
            fadecontentviewer.fade(allcontents, togglerid, jquery(this).attr('pagenumber'), speed)
            return false
        })
    },

    init: function(fadeid, contentclass, togglerid, selected, speed) {
        jquery(document).ready(function() {
            var faderheight = jquery("#" + fadeid).height()
            var fadecontents = jquery("#" + fadeid + " ." + contentclass)
            fadecontents.css({ top: 0, left: 0, height: faderheight, visibility: 'hidden' })
            fadecontentviewer.setuptoggler(fadecontents, togglerid, speed)
            setTimeout(function() { fadecontentviewer.fade(fadecontents, togglerid, selected, speed) }, 100)
            jquery(window).bind('unload', function() { //clean up
                jquery("#" + togglerid + " .toc").unbind('click')
                jquery("#" + togglerid + " .next", "#" + togglerid + " .prev").unbind('click')
            })
        })
    }
}
// #################### END Content Fader ###################

// #################### BEGIN Misc Functions ###################
function swapImage(imgId, imgUrl, imgName, imgNameOver) {
    var objImg = jquery('#' + imgId);
    if (objImg.attr('src') == (imgUrl + imgName))
        objImg.attr('src', imgUrl + imgNameOver);
    else
        objImg.attr('src', imgUrl + imgName);

    return false;
}

function openDiv(divId, divNum) {
    var objDiv = jquery('#' + divId + divNum);
    if (objDiv.css('display') == 'block')
        objDiv.css('display', 'none');
    else
        objDiv.css('display', 'block');

    return false;
}

function SetFrameSrc(frameId, frameSrc) {
    var objFrame = document.getElementById(frameId);
    if (objFrame != null)
        objFrame.src = frameSrc;

    return false;
}

function simulateMouse(element, eventName) {
    if (isIE()) {
        document.getElementById(element).click();
    }
    else {
        var oEvent = document.createEvent("MouseEvents");
        oEvent.initMouseEvent(eventName, true, true, document.defaultView,
1, 0, 0, 0, 0, false, false, false, false, 0, document.getElementById(element));
        document.getElementById(element).dispatchEvent(oEvent);
    }
}
function isIE() { return /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent); }

function abrir_janela_popup(theURL) {
    var features = 'scrollbars=yes,width=210,height=400,top=150,left=400';
    window.open(theURL, '', features);
}

function jumpSite(drpDwn) {
    var selectedIndex = drpDwn.selectedIndex;
    if (selectedIndex == 0) return;
    window.open(drpDwn.options[selectedIndex].value);
}

function showHideLogin(div, div2) {
    var objDiv = jquery('#' + div);
    var objDiv2 = jquery('#' + div2);

    objDiv2.css('display', 'none');
    if (objDiv.css('display') == 'block')
        objDiv.css('display', 'none');
    else
        objDiv.css('display', 'block');

    return false;
}


// #################### END Misc Functions ###################

// #################### BEGIN News Ticker ###################
var tableInitString = '<table border="0" cellspacing="0" cellpadding="0" width="100%"><tr><td class="';
var tableEndString = '</td></tr></table>';

function browserCheck() {

    //	if (typeof document.documentElement.style.maxHeight != "undefined") {
    //	return true;
    //	} 
    //	else {
    //	    return false
    //	}	
    return /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent);
}

function domticker(content, divId, contentClass, separatorClass, numItems, delay, fadeornot) {
    this.content = content

    this.tickerid = divId //ID of master ticker div. Message is contained inside first child of ticker div
    this.delay = delay //Delay between msg change, in miliseconds.
    this.mouseoverBol = 0 //Boolean to indicate whether mouse is currently over ticker (and pause it if it is)
    this.pointer = numItems
    this.numOfItems = numItems //Number of items to display each time
    this.CssContentClass = contentClass;
    this.CssSeparatorClass = separatorClass;
    var shouldFade = false;
    if (!browserCheck() && (typeof fadeornot != "undefined")) {
        shouldFade = true;
    }
    this.opacitystring = (shouldFade ? "width: 100%; filter:progid:DXImageTransform.Microsoft.alpha(opacity=100); -moz-opacity: 1" : "")

    if (this.opacitystring != "")
        this.delay += 500 //add 1/2 sec to account for fade effect, if enabled
    this.opacitysetting = 0.2 //Opacity value when reset. Internal use.
    document.write('<div id="' + divId + '"><div style="' + this.opacitystring + '">')
    if (this.content.length > 0) {
        document.write(content[0])
        for (i = 1; i < this.content.length && i < this.numOfItems; i++) {
            //document.write('<div class="' + this.CssSeparatorClass + '" />')
            document.write(content[i])
        }
    }
    document.write('</div></div>')
    var instanceOfTicker = this
    setTimeout(function() {
        instanceOfTicker.initialize()
    }, delay)
}

domticker.prototype.initialize = function() {
    var instanceOfTicker = this
    this.contentdiv = document.getElementById(this.tickerid).firstChild //div of inner content that holds the messages
    document.getElementById(this.tickerid).onmouseover = function() {
        instanceOfTicker.mouseoverBol = 1
    }
    document.getElementById(this.tickerid).onmouseout = function() {
        instanceOfTicker.mouseoverBol = 0
    }
    if (this.numOfItems < this.content.length)
        this.rotatemsg()
}

domticker.prototype.rotatemsg = function() {
    var str = ""
    var instanceOfTicker = this
    if (this.mouseoverBol == 1) //if mouse is currently over ticker, do nothing (pause it)
        setTimeout(function() {
            instanceOfTicker.rotatemsg()
        }, 100)
    else {
        this.fadetransition("reset") //FADE EFFECT- RESET OPACITY
        if (this.pointer < this.content.length) {
            str = this.content[this.pointer]
            for (i = this.pointer + 1; i < this.content.length && i < (this.numOfItems + this.pointer); i++) {
                // str = str + '<span class="' + this.CssSeparatorClass + '" />'
                str = str + this.content[i]
            }
        }
        this.contentdiv.innerHTML = str
        this.fadetimer1 = setInterval(function() {
            instanceOfTicker.fadetransition('up', 'fadetimer1')
        }, 100) //FADE EFFECT- PLAY IT
        this.pointer = (this.pointer + this.numOfItems < (this.content.length)) ? this.pointer + this.numOfItems : 0
        setTimeout(function() {
            instanceOfTicker.rotatemsg()
        }, this.delay) //update container
    }
}

// -------------------------------------------------------------------
// fadetransition()- cross browser fade method for IE5.5+ and Mozilla/Firefox
// -------------------------------------------------------------------

domticker.prototype.fadetransition = function(fadetype, timerid) {
    var contentdiv = this.contentdiv
    if (fadetype == "reset")
        this.opacitysetting = 0.2
    if (contentdiv.filters && contentdiv.filters[0]) {
        if (typeof contentdiv.filters[0].opacity == "number") //IE6+
            contentdiv.filters[0].opacity = this.opacitysetting * 100
        else //IE 5.5
            contentdiv.style.filter = "alpha(opacity=" + this.opacitysetting * 100 + ")"
    }
    else
        if (typeof contentdiv.style.MozOpacity != "undefined" && this.opacitystring != "") {
        contentdiv.style.MozOpacity = this.opacitysetting
    }
    else
        this.opacitysetting = 1
    if (fadetype == "up")
        this.opacitysetting += 0.2
    if (fadetype == "up" && this.opacitysetting >= 1)
        clearInterval(this[timerid])
}
// #################### END News Ticker ###################

// #################### BEGIN Image Swap ###################
function MM_preloadImages() { //v3.0
    var d = document; if (d.images) {
        if (!d.MM_p) d.MM_p = new Array();
        var i, j = d.MM_p.length, a = MM_preloadImages.arguments; for (i = 0; i < a.length; i++)
            if (a[i].indexOf("#") != 0) { d.MM_p[j] = new Image; d.MM_p[j++].src = a[i]; }
    }
}

function MM_swapImgRestore() { //v3.0
    var i, x, a = document.MM_sr; for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) x.src = x.oSrc;
}

function MM_findObj(n, d) { //v4.01
    var p, i, x; if (!d) d = document; if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document; n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all) x = d.all[n]; for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
    for (i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n, d.layers[i].document);
    if (!x && d.getElementById) x = d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
    var i, j = 0, x, a = MM_swapImage.arguments; document.MM_sr = new Array; for (i = 0; i < (a.length - 2); i += 3)
        if ((x = MM_findObj(a[i])) != null) { document.MM_sr[j++] = x; if (!x.oSrc) x.oSrc = x.src; x.src = a[i + 2]; }
}

function MM_showHideLayers() { //v9.0
    var i, p, v, obj, args = MM_showHideLayers.arguments;
    for (i = 0; i < (args.length - 2); i += 3)
        with (document) if (getElementById && ((obj = getElementById(args[i])) != null)) {
        v = args[i + 2];
        if (obj.style) { obj = obj.style; v = (v == 'show') ? 'visible' : (v == 'hide') ? 'hidden' : v; }
        obj.visibility = v;
    }
}
// #################### END Image Swap ###################



// #################### MODAL Windows (Trailer MOX) ###########################

/* MODAL DIALOG*/

function Modal(source, width, height, close) {
    jquery.modal('<iframe frameborder="0" allowtransparency="true" src="' + source + '"></iframe>', { width: width, height: height, close: close });
    jquery("#simplemodal-container iframe").css('width', '' + width + 'px');
    jquery("#simplemodal-container iframe").css('height', '' + height + 'px');
    return false;
}

function ChangeModalContent(mainwindow, source, width, height, close) {
    try {
        this.parent.jquery.modal.close();
    }
    catch (err) { }
    mainwindow.jquery.modal('<iframe frameborder="0" allowtransparency="true" src="' + source + '"></iframe>', { width: width, height: height, close: close });
    mainwindow.jquery("#simplemodal-container iframe").css('width', '' + width + 'px');
    mainwindow.jquery("#simplemodal-container iframe").css('height', '' + height + 'px');
}

function CloseModal() {
    try {
        this.parent.jquery.modal.close();
    }
    catch (err) { }
}


//---------------VER TRAILER------------------------------
function ButtonClick_Trailer() {

    Modal("trailerShow.htm", 700, 550);
}


function ButtonClick_ShowPage(pageurl, modalwidth, modalheight) {

    Modal(pageurl, modalwidth, modalheight);

}


//---------------END--------------------------------------


// #################### End of MODAL Windows (Trailer MOX) ###########################


// #################### BEGIN TABS MENU Handling ###################

var lastClickedTab;
window.onload = function() {
    _spBodyOnLoadWrapper();
};
function SmallTabs() {
    var obj = document.getElementById('smalltab_1');
    var image = obj.src;
    var t = image.split('/');
    var imagename = t[t.length - 1].split('.')[0];
    imagename = imagename + '_on.' + t[t.length - 1].split('.')[1];
    t[t.length - 1] = imagename;
    image = "";
    for (i = 3; i < t.length; i++) {
        image += '/' + t[i];
    }
    fiximage('smalltab_1', obj.src, 'smalltab_1', image);
}
function fiximage(objectid, imgUrl, defaulttab, defaultimgUrl) {
    if (lastClickedTab == undefined) {
        lastClickedTab = defaulttab;
        defaulttabobj = document.getElementById(defaulttab);
        defaulttabobj.src = defaultimgUrl;
    }
    else {
        lastClickedTabObjec = document.getElementById(lastClickedTab);
        lastClickedTab = objectid;


        if (lastClickedTabObjec != undefined)
            lastClickedTabObjec.src = lastImgURL;
    }
    lastImgURL = imgUrl;
}

function MM_swapImgRestoreValidation(objectId) {

    if (objectId != lastClickedTab)
        MM_swapImgRestore();

}


// #################### END TABS MENU Handling ###################

// ####################### MENU DE TOPO ##########################

function MeoMenuOnMouseOver(object, imgurl, imgwidth) {
    jquery("#" + object).attr("style", "background:url(" + imgurl + ") no-repeat left -30px; width:" + imgwidth);
}

function MeoMenuOnMouseOut(object, imgurl, imgwidth) {
    jquery("#" + object).attr("style", "background:url(" + imgurl + ") no-repeat; width:" + imgwidth);
}


// #################### END MENU DE TOPO ########################

//MENU NAVEGACAO DE TOPO 
jquery(document).ready(function() {
    function megaHoverOver() {
        jquery(this).find(".sub").stop().fadeTo('fast', 1).show();

        //Calculate width of all ul's
        (function(jquery) {
            jQuery.fn.calcSubWidth = function() {
                rowWidth = 0;
                //Calculate row
                jquery(this).find("ul").each(function() {
                    rowWidth += jquery(this).width();
                });
            };
        })(jQuery);

        if (jquery(this).find(".row").length > 0) { //If row exists...
            var biggestRow = 0;
            //Calculate each row
            jquery(this).find(".row").each(function() {
                jquery(this).calcSubWidth();
                //Find biggest row
                if (rowWidth > biggestRow) {
                    biggestRow = rowWidth;
                }
            });
            //Set width
            jquery(this).find(".sub").css({ 'width': biggestRow });
            jquery(this).find(".row:last").css({ 'margin': '0' });

        } else { //If row does not exist...

            jquery(this).calcSubWidth();
            //Set Width
            jquery(this).find(".sub").css({ 'width': rowWidth });

        }
    }

    function megaHoverOut() {
        jquery(this).find(".sub").stop().fadeTo('fast', 0, function() {
            jquery(this).hide();
        });
    }
    var config = {
        sensitivity: 1, // number = sensitivity threshold (must be 1 or higher)    
        interval: 0, // number = milliseconds for onMouseOver polling interval    
        over: megaHoverOver, // function = onMouseOver callback (REQUIRED)    
        timeout: 50, // number = milliseconds delay before onMouseOut    
        out: megaHoverOut // function = onMouseOut callback (REQUIRED)    
    };

    jquery("ul#topnav li .sub").css({ 'opacity': '0' });
    jquery("ul#topnav li").hoverIntent(config);
});

// ####################### FILTRO DE CANAIS ##########################

function CheckFiltroCategorias(cb, catTemp, color) {
    if (cb.checked) {
        jquery("a[cat=" + catTemp + "]").css("background-color", "" + color + "");
    }
    else {
        jquery("a[cat=" + catTemp + "]").css("background-color", "");
    }
}

function HideShowText(cb) {
    if (cb.checked) {
        jquery('div[class=canal_txt]').show();
    }
    else {
        jquery('div[class=canal_txt]').hide()
    }
}

// ####################### END FILTRO DE CANAIS ##########################
