/* Shadowbox */
Shadowbox.init({
	language: 'pt-br',
	handleOversize: 'drag',
	players: ['img', 'html', 'iframe', 'qt', 'wmp', 'swf', 'flv'],
	onFinish: function() {
		$('#sb-wrapper').show();
	}
});

/*

IMPRIMIR TELA

*/

var printingId = "";
var printer = "";

function printDiv(id){
    printingId = id;
    printer = window.open('/calculadora/print.asp','','width=700,height=400,resizable=yes,scrollbars=yes');
}

function getPrintingContent(){
    printer.document.getElementById('conteudo').innerHTML = $("#" + printingId).parent().html();
}


function aumentaFonte(){
	$('.aumentar p,.aumentar h1,.aumentar h2,.aumentar .legenda').each(function(){
		$(this).css('fontSize',parseInt($(this).css('fontSize').replace('px'))+1);
	});
}

function diminuiFonte(){
	$('.aumentar p,.aumentar h1,.aumentar h2,.aumentar .legenda').each(function(){
		$(this).css('fontSize',parseInt($(this).css('fontSize').replace('px'))-1);
	});
}

function favoritos(el){
	var url;
	cod = $(el).metadata().cod;
	if($(el).hasClass('RemoverFavoritos')){
		url="ajax/favoritos.asp?a=r&vCod=" + cod
	}else{
		url="ajax/favoritos.asp?a=a&vCod=" + cod
	}
	$.ajax({
		url: url,
		success: function(data){
			$(el).toggleClass('RemoverFavoritos');
		}
	})
}
$(function(){
	$('.size a').click(function(){
		if($(this).hasClass('less')){
			diminuiFonte();
		}else{
			aumentaFonte();
		}
	});

	$('.Favoritos').click(function(){
		favoritos(this);
		return false;
	});

	$('.mascaraImoveis').scrollable({
		items: '.Cont',
		vertical:true,
		keyboard: false,
		circular: true
	}).autoscroll({interval: 5000});
	$('#RodapeItens .mascara').scrollable({
		items: '.trilho',
		vertical:true,
		circular: true,
		keyboard: false
	}).autoscroll({interval: 5000});
	$('.Filtro .maceio').click(function(){
		$('.maceio, .saoluiz').removeClass('Sel');
		$('.contAbas .Eds').hide();
		$('.contAbas .Eds.maceio').show();
		$(this).addClass('Sel');
		return false;
	});
	$('.Filtro .saoluiz').click(function(){
		$('.maceio, .saoluiz').removeClass('Sel');
		$('.contAbas .Eds').hide();
		$('.contAbas .Eds.saoluiz').show();
		$(this).addClass('Sel');
		return false;
	});
	$('.comunicacaoControles a').click(function(){
//		var indice = $('.comunicacaoControles a').index($(this));
//		$('.comunicacao > div').hide();
//		$('.comunicacao > div:eq(' + indice + ')').show();
		return false;
	});

	// video
	var video = '';
	if(getQuerystring('video','')){
		video = '/swf/' + getQuerystring('video','') + '.mp4';
	}else if($('.listaVideos a').length > 0){
		video = '/swf/' + getQuerystring('video','',$('.listaVideos a:first').attr('href')) + '.mp4';
	}
	if(video != ''){
		jwplayer("video").setup({
			autostart: true,
			flashplayer: "/js/libs/jwplayer/player.swf",
			file: video,
			height: 360,
			width: 540
		});
	}
	
	Cufon.replace('.renderNormal', {
		fontFamily: 'Helvetica Neue',
		textShadow: '1px 1px rgba(0, 0, 0, 0.6)'
	});
	Cufon.replace('.renderBold, #Topo form .Enviar', {
		fontFamily: 'Helvetica Neue Bold',
		textShadow: '1px 1px rgba(0, 0, 0, 0.6)'
	});
	Cufon.replace('.renderTabela', {
		fontFamily: 'Myriad'
	});
	
	$(".comunicacao").scrollable({items:'.comunicacaoAreas', vertical: true, keyboard: false, circular: true }).navigator(".comunicacaoControles").autoscroll({interval: 5000});

	$('.bannerTopo').scrollable({
		items: '.items',
		size: 1,
		prev:'.btAnterior',
		next:'.btProximo',
		keyboard: false,
		circular: true
	}).autoscroll({interval: 15000});

	//máscaras de formulário
	$.mask.options = {
		attr: 'alt', // an attr to look for the mask name or the mask itself
		mask: null, // the mask to be used on the input
		type: 'fixed', // the mask of this mask
		maxLength: 5000, // the maxLength of the mask
		defaultValue: '', // the default value for this input
		textAlign: true, // to use or not to use textAlign on the input
		selectCharsOnFocus: true, //selects characters on focus of the input
		setSize: true, // sets the input size based on the length of the mask (work with fixed and reverse masks only)
		autoTab: false, // auto focus the next form element
		fixedChars : '[(),.:/ -]', // fixed chars to be used on the masks.
		onInvalid : function(){},
		onValid : function(){},
		onOverflow : function(){}
	};
	$.mask.masks = {
		'ddd'     : { mask : '99' },
		'fone'     : { mask : '9999-9999' },
		'foneddd'     : { mask : '(99) 9999-9999' },
		'cpf'       : { mask : '999.999.999-99' },
		'data'      : { mask : '39/19/2999' },
		'cep'       : { mask : '99999-999' },
		'ano'      : { mask : '2999' },
		'semestrais'      : { mask : '99', type : 'reverse', defaultValue : '0' },
		'parcelas'      : { mask : '999', type : 'reverse', defaultValue : '0' },
		'decimal'			: { mask : '99,999.999.999.999', type : 'reverse', defaultValue : '000' }
	};
	$('input:text').setMask();
});

function getQuerystring(key, default_, url){
	if (default_==null) default_="";
	if (url==null) url=window.location.href;
	key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
	var qs = regex.exec(url);
	if(qs == null)
		return default_;
	else
		return qs[1];
}
