﻿function showHtmlPopup(pTitle, pMessage, pWidth, pHeight, pCustomPage, pOnClosedJavascript) {
    pMessage = '<div class="box_mensagem"><strong>Mensagem:</strong><br /><br />' + pMessage + '</div>';
    if (pCustomPage == '') {
        $.fancybox(
		    pMessage,
		    {
		        'title': pTitle,
		        'showCloseButton': true,
		        'autoDimensions': false,
		        'width': 350,
		        'height': 'auto',
		        'centerOnScroll': true,
		        'scrolling': 'no',
		        'transitionIn': 'elastic',
		        'transitionOut': 'elastic',
		        'easingIn': 'easeOutBack',
		        'easingOut': 'easeInBack',
		        'opacity': true,

		        'onClosed': function() {
		            if (pOnClosedJavascript != '') {
		                eval(pOnClosedJavascript);
		            }
		        }

		    }
	    );

    }
    else {
        $.fancybox(
		    {
		        'width': parseInt(pWidth),
		        'height': parseInt(pHeight),
		        'title': pTitle,
		        'showCloseButton': true,
		        'centerOnScroll': true,
		        'transitionIn': 'elastic',
		        'transitionOut': 'elastic',
		        'easingIn': 'easeOutBack',
		        'easingOut': 'easeInBack',
		        'type': 'iframe',
		        'href': pCustomPage,
		        'opacity': true,
		        onClosed: function() {
		            if (pOnClosedJavascript != '') {
		                eval(pOnClosedJavascript);
		            }
		        }
		    }
	    );
    }
}



function showMessagePopup(pMessage) {
    pMessage = '<div class="box_mensagem"><strong>Mensagem:</strong><br /><br />' + pMessage + '</div>';

    $.fancybox(
		    pMessage,
		    {
		        'showCloseButton': true,
		        'autoDimensions': true,
		        'centerOnScroll': true,
		        'scrolling': 'no',
		        'transitionIn': 'elastic',
		        'transitionOut': 'elastic',
		        'easingIn': 'easeOutBack',
		        'easingOut': 'easeInBack',
		        'opacity': true,
		        'onComplete': function() {
		            unBlockUI()
		        }
		    }
	    );
}

function showPopupImage(pUrl, pTitle) {
    $.fancybox(
		    {
		        'title': pTitle,
		        'href': pUrl,
		        'showCloseButton': true,
		        'autoDimensions': true,
		        'centerOnScroll': true,
		        'scrolling': 'no',
		        'transitionIn': 'elastic',
		        'transitionOut': 'elastic',
		        'easingIn': 'easeOutBack',
		        'easingOut': 'easeInBack',
		        'opacity': true
		    }
	    );
}

function BeginRequestHandler(sender, args) {
    if (args.get_postBackElement().id.toLowerCase().indexOf('avoidblockui') == -1) {
        blockUI();
    }
}

function blockUI() {
    $('#loading_progress').show();
}

function EndRequestHandler(sender, args) {
    unBlockUI();
}

function unBlockUI() {
    $('#loading_progress').hide();
}

var avoidOnBeforeUnload = false;

function onLeavingPage() {
    if (!avoidOnBeforeUnload) {
        blockUI();
    }
    else {
        avoidOnBeforeUnload = false;
    }
}

function AddTag(pArea, pTitulo, pComportamento) {
    javascript: _gaq.push(['_trackEvent', '' + pArea + '', '' + TreatString(pTitulo) + '', '' + pComportamento + '']);
}

function AddTagUrl(pArea, pTitulo, url) {
    javascript: _gaq.push(['_trackEvent', '' + pArea + '', '' + TreatString(pTitulo) + '', location.href = '' + url + '']);
}

function TreatString(pValue) {
    pValue = pValue.toString().replace("\\", "\\");
    pValue = pValue.toString().replace("'", "\\'");
    pValue = pValue.toString().replace("\"", "\\\"");
    pValue = pValue.toString().replace("\n", "\n");
    pValue = pValue.toString().replace("\r", "\r");
    return pValue;
}

function trimEnd(pString, pChar) {
    if (sString.substring(sString.length - 1, sString.length) == pChar) {
        return sString = sString.substring(0, sString.length - 1);
    }
    else {
        return sString;
    }
}

$(document).ready(function() {
    var div = $('#loading_progress').css({ position: 'absolute' });

    $(document).mousemove(function(e) {
        div.css({ top: (e.pageY + 18), left: (e.pageX + 18) });
    });
});


function CarouselHome() {
    //rotation speed and timer
    var speed = 5000;
    var run = setInterval('rotate()', speed);

    //grab the width and calculate left value
    var item_width = $('.box_carousel  li').outerWidth();
    var left_value = item_width * (-4);
    //console.info(left_value);
    var totalUl = $('.box_carousel  li').length * $('.box_carousel  li').outerWidth();

    //move the last item before first item, just in case user click prev button
    $('.box_carousel  li:first').before($('.box_carousel  li:last'));

    //set the default item to the correct position
    $('.box_carousel  ul').css({ 'left': left_value - 39, 'width': totalUl });

    //if user clicked on prev button
    $('#prev').click(function() {

        //get the right position
        var left_indent = parseInt($('.box_carousel  ul').css('left')) + item_width;

        //slide the item
        $('.box_carousel  ul').animate({ 'left': left_indent }, function() {
            //console.info(left_indent);
            //move the last item and put it as first item            	
            $('.box_carousel  li:first').before($('.box_carousel  li:last'));

            //set the default item to correct position
            $('.box_carousel  ul').css({ 'left': left_value - 39 });
        });

        //cancel the link behavior            
        return false;

    });


    //if user clicked on next button
    $('#next').click(function() {

        //get the right position
        var left_indent = parseInt($('.box_carousel  ul').css('left')) - item_width;

        //slide the item
        $('.box_carousel  ul').animate({ 'left': left_indent }, function() {

            //move the first item and put it as last item
            $('.box_carousel  li:last').after($('.box_carousel  li:first'));

            //set the default item to correct position
            $('.box_carousel  ul').css({ 'left': left_value - 39 });

        });

        //cancel the link behavior
        return false;

    });

    //if mouse hover, pause the auto rotation, otherwise rotate it
    $('.box_carousel').hover(
	        function() {
	            clearInterval(run);
	        },
	        function() {
	            run = setInterval('rotate()', speed);
	        }
	    );
}

function getFacebookLikeIframe(url) {
    return "<iframe src='http://www.facebook.com/plugins/like.php?locale=pt_BR&amp;app_id=138472696229247&amp;href=" + encodeURIComponent(url) + "&amp;send=false&amp;layout=button_count&amp;width=81&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font=arial&amp;height=21' scrolling='no' frameborder='0' style='border:none; overflow:hidden; width:84px; height:21px;' allowTransparency='true'></iframe >";
    //return "<iframe id='f141bc9b61feb48' name='f156f13a1998616'  src='http://www.facebook.com/plugins/like.php?locale=pt_BR&amp;href=" + encodeURIComponent(url) + "&amp;send=false&amp;layout=button_count&amp;width=81&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font=arial&amp;height=21' scrolling='no' frameborder='0' style='border:none; overflow:hidden; width:82px; height:21px;' allowTransparency='true'></iframe>";
    //return "<iframe id='f141bc9b61feb48' name='f156f13a1998616' src='http://www.facebook.com/plugins/like.php?api_key=113869198637480&amp;channel_url=http%3A%2F%2Fstatic.ak.fbcdn.net%2Fconnect%2Fxd_proxy.php%3Fversion%3D3%23cb%3Df2ad73d8d6e2cd%26origin%3Dhttp%253A%252F%252Fdevelopers.facebook.com%252Ff3dfbf6e4728a22%26relation%3Dparent.parent%26transport%3Dpostmessage&amp;font=arial&amp;href=" + encodeURIComponent(url) + "layout=button_count&amp;locale=pt_BR&amp;node_type=link&amp;sdk=joey&amp;send=false&amp;show_faces=false&amp;width=90' allowTransparency='true'></iframe>";
}
