// FUNÇÕES JAVASCRIPT - VIAMAX
jQuery(document).ready(function() {
	
	jQuery.face_popup.settings.opacity = 0.5;
	
	// --------------- ACESSANDO AOS LINKS DAS PÁGINAS
	if(jQuery('div.li-box-programacao-01-dir, div.li-box-programacao-03-esq, div.li-box-programacao-01-esq')) {
		jQuery('div.li-box-programacao-01-dir, div.li-box-programacao-03-esq, div.li-box-programacao-01-esq').mouseover(function() {
			jQuery(this).attr('title',jQuery(this).find('a').attr('title'));
		});
	}
	
	if(jQuery('div.desc-box-prog-01')) {
		jQuery('div.desc-box-prog-01').mouseover(function() {jQuery(this).attr('title',jQuery(this).find('span').text());});
	}
	if(jQuery('div.li-box-programacao-01-dir, div.li-box-programacao-01-esq, div.li-box-programacao-02-esq, div.li-box-programacao-03-esq')) {
		jQuery('div.li-box-programacao-01-dir, div.li-box-programacao-01-esq, div.li-box-programacao-02-esq, div.li-box-programacao-03-esq').hover(function() {
			jQuery(this).addClass('opt-selected');		
		}, function() {
			jQuery(this).removeClass('opt-selected');
		});
		
		jQuery('div.li-box-programacao-01-dir').click(function() {
			window.location = jQuery(this).find('a').attr('href');
		});
		jQuery('div.li-box-programacao-01-esq').click(function() {
			window.location = jQuery(this).find('a').attr('href');
		});
		jQuery('div.li-box-programacao-03-esq').click(function() {
			window.location = jQuery(this).find('a').attr('href');
		});
		jQuery('div.li-box-programacao-02-esq').click(function() {
			window.location = 'http://www.viamax.com.br/planos.php?cd_cid=1';
		});
	}
	
	if(jQuery('div.div-promocao-home')) {
		jQuery('div.div-promocao-home').mouseover(function() {jQuery(this).attr('title','Planos feitos à sua medida'); });
	}
	
	if(jQuery('div.desc-box-prog-03')) {
		jQuery('div.desc-box-prog-03').mouseover(function() {jQuery(this).attr('title',jQuery(this).find('span').text());});
	}
	
	// PROPRIEDADES VISUAIS
	if(!jQuery.browser.msie) {
		if(jQuery('div.content-desc-box-prog')) jQuery('div.content-desc-box-prog').css('vertical-align','middle');
	}
	
	// BLOCO ENQUENTE
	if(jQuery('div#div-enquente')) {
		// PROPRIEDADE INICIAL DE POSICIONAMENTO DO BLOCO DE ENQUENTE
		jQuery('div#div-enquente').css({top:(jQuery(window).height() - jQuery('div#div-enquente').height())/2});
		
		jQuery('div#div-enquente').hover(function(){
			jQuery('div#div-enquente').toggleClass('opt-selected');
		}, function() {
			jQuery('div#div-enquente').toggleClass('opt-selected');
		});
	}
});

// FUNÇÃO PARA OBTER A POSIÇÃO ATUAL DO SCROLL
function getPageScroll() {
    var xScroll, yScroll;
    if (self.pageYOffset) {
        yScroll = self.pageYOffset;
        xScroll = self.pageXOffset;
    } else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
        yScroll = document.documentElement.scrollTop;
        xScroll = document.documentElement.scrollLeft;
    } else if (document.body) {// all other Explorers
        yScroll = document.body.scrollTop;
        xScroll = document.body.scrollLeft;
    }
    arrayPageScroll = new Array(xScroll, yScroll);
    return arrayPageScroll;
}

function getPageSize() {
    var xScroll, yScroll;
    if (window.innerHeight && window.scrollMaxY) {
        xScroll = window.innerWidth + window.scrollMaxX;
        yScroll = window.innerHeight + window.scrollMaxY;
    } else if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac
        xScroll = document.body.scrollWidth;
        yScroll = document.body.scrollHeight;
    } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
        xScroll = document.body.offsetWidth;
        yScroll = document.body.offsetHeight;
    }
    var windowWidth, windowHeight;
    if (self.innerHeight) {	// all except Explorer
        if (document.documentElement.clientWidth) {
            windowWidth = document.documentElement.clientWidth;
        } else {
            windowWidth = self.innerWidth;
        }
        windowHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
        windowWidth = document.documentElement.clientWidth;
        windowHeight = document.documentElement.clientHeight;
    } else if (document.body) { // other Explorers
        windowWidth = document.body.clientWidth;
        windowHeight = document.body.clientHeight;
    }
    // for small pages with total height less then height of the viewport       
    if (yScroll < windowHeight) {
        pageHeight = windowHeight;
    } else {
        pageHeight = yScroll;
    }
    // for small pages with total width less then width of the viewport
    if (xScroll < windowWidth) {
        pageWidth = xScroll;
    } else {
        pageWidth = windowWidth;
    }
    arrayPageSize = new Array(pageWidth, pageHeight, windowWidth, windowHeight);
    return arrayPageSize;
}

// CRIANDO A MÁSCARA PARA O FORMULÁRIO DE CONTATO
function criaMascara() {
    $("body").append("<div id='mask-form' class='mascara'></div>");
    if ($("#mask-form")) {
        $("#mask-form").hide();
        overlayMask("mask-form");
    }
}

// FUNÇÃO PARA APLICAR A MÁSCARA
function overlayMask(objeto) {
    // FUNÇÃO PARA PODER FAZER APARECER A MÁSCARA
    if ($("#" + objeto)) {
        $("#" + objeto).css('display', 'block');
        $("#" + objeto).css({ height: $(document).height(), width: $(window).width() });
        $("#" + objeto).fadeIn(1000);
        $("#" + objeto).fadeTo("slow", 0.5);
    }
}

// FUNÇÃO PARA CRIAR O QUADRO DE DIÁLOGO FACEBOOK
function criaFacebook() {
    var htmlFacebook01 = '<div id="frame-facebook"> \
                <table border="0" cellpadding="0" cellspacing="0" width="100%" align="center"> \
                    <tbody><tr><td class="btl-facebook"></td><td class="bh-facebook"></td><td class="btr-facebook"></td></tr> \
                    <tr><td class="bv-facebook"></td> \
                    <td style="background-color:white;"><div class="body-msg-facebook"><div id="box-title-facebook"><span>Enviando Mensagem...</span></div> \
                            <div class="body-txt-msg-facebox"><div id="txt-msg-facebox"><span>Aguarde por favor</span></div> \
                                <div class="img-loading-facebox"><img alt="Loading de envio de mensagem" src="imagens/icones/horizontal_loader.gif" /></div> \
                                <div id="btn-facebook"><a href="#" title="Fechar"><img alt="Fechar" src="imagens/facebox/closelabel.png" /></a></div> \
                            </div></div></td> \
                    <td class="bv-facebook"></td></tr><tr>'
    var htmlFacebook02 = '<td class="bbl-facebook"></td><td class="bh-facebook"></td><td class="bbr-facebook"></td> \
                    </tr></tbody></table></div>'
    $("body").append(htmlFacebook01 + htmlFacebook02);
    if ($("#frame-facebook")) {
        $("#frame-facebook").hide();
        overlayFacebook("frame-facebook");
    }
}

function overlayFacebook(nomeObj) {
    if ($("#" + nomeObj)) {
        $("#btn-facebook").hide();
        $("#" + nomeObj).css({ left: ($(document).width() - $("#" + nomeObj).width()) / 2, top: getPageScroll()[1] + (getPageSize()[3] / 5) });
        $("#" + nomeObj).fadeIn(750);
        $("#btn-facebook").click(function() { fechaFacebook('mask-form', nomeObj); });
        $(window).scroll(function() {
            $("#" + nomeObj).css({ top: getPageScroll()[1] + (getPageSize()[3] / 5) });
        });
    }
}

// FUNÇÃO PARA ELIMINAR A MÁSCARA E ELIMINAR A JANELA DO FACEBOOK
function fechaFacebook(nomeMask, nomeFacebook) {
    if ($("#" + nomeMask + ",#" + nomeFacebook)) {
        $("#" + nomeMask + ",#" + nomeFacebook).fadeOut(function() {
            $("#" + nomeMask + ",#" + nomeFacebook + ",#btn-facebook").remove();
        });
    }
}

// FUNÇÃO PARA OBTER A MENSAGEM DO SERVIDOR
/** * Função limpa espaço * @param str String * @return nada **/
function getTrim(str) {
	if (typeof (str) !== "undefined") {
		return str.replace(/^\s+|\s+$/g, "");
    } else {
    	return "";
    }
}
