/*Todos os direitos reservados à ELO IDEIAS LTDA ME*/
$(window).resize(function(){
});
$(function(){
	/* Brazilian initialisation for the jQuery UI date picker plugin. */
	$.datepicker.regional['pt-BR'] = {
		clearText: 'Limpar', clearStatus: '',
		closeText: 'Fechar', closeStatus: '',
		prevText: '&#x3c;Anterior', prevStatus: '',
		prevBigText: '&#x3c;&#x3c;', prevBigStatus: '',
		nextText: 'Pr&oacute;ximo&#x3e;', nextStatus: '',
		nextBigText: '&#x3e;&#x3e;', nextBigStatus: '',
		currentText: 'Hoje', currentStatus: '',
		monthNames: ['Janeiro','Fevereiro','Mar&ccedil;o','Abril','Maio','Junho',
		'Julho','Agosto','Setembro','Outubro','Novembro','Dezembro'],
		monthNamesShort: ['Jan','Fev','Mar','Abr','Mai','Jun',
		'Jul','Ago','Set','Out','Nov','Dez'],
		monthStatus: '', yearStatus: '',
		weekHeader: 'Sm', weekStatus: '',
		dayNames: ['Domingo','Segunda-feira','Ter&ccedil;a-feira','Quarta-feira','Quinta-feira','Sexta-feira','Sabado'],
		dayNamesShort: ['Dom','Seg','Ter','Qua','Qui','Sex','Sab'],
		dayNamesMin: ['Dom','Seg','Ter','Qua','Qui','Sex','Sab'],
		dayStatus: 'DD', dateStatus: 'D, M d',
		dateFormat: 'dd/mm/yy', firstDay: 0,
		initStatus: '', isRTL: false};
	$.datepicker.setDefaults($.datepicker.regional['pt-BR']);
});
function atualiza_agenda(){

	$(".dia .cw").each(function(){
		var load = $(this).attr('load');
		$(this).load('/json/sm/'+load + ' #content');
	});
	$(".toggle_over").mouseover(function(){
		$(this).find(".visible").hide();
		$(this).find(".hidden").show();
	}).mouseout(function(){
		$(this).find(".visible").show();
		$(this).find(".hidden").hide();
	});
}
function form_confirma_gostei(){
	
	$(".btn_toggle").each(function(){
		var status = $(this).attr("status");
		$(this).attr("src", $(this).attr( status ) );
		if(status=='off'){
			$(this).mouseover(function(){
				var on = $(this).attr("on");
				$(this).attr("src", on );
			});
			$(this).mouseout(function(){
				var off = $(this).attr("off");
				$(this).attr("src", off );
			});
		}
	});
	

	$(".toggle .open").click(function(){
		$(this).parents().parent(".toggle").find(".visible").hide("slow");
		$(this).parents().parent(".toggle").find(".hidden").show("slow");
		$(this).parents().parent(".toggle").find(".hidden :input:first").select();
		return false;
	});

	$(".toggle .visible").show();
	$(".toggle .hidden ").hide();
	
	$(".toggle .close").click(function(){
		$(this).parents().parent(".toggle").find(".hidden").hide("slow");
		$(this).parents().parent(".toggle").find(".visible").show("slow");
		$(this).parents().parent(".toggle").find(".visible :input:first").select();
		return false;
	});

	$(".toggle_fast .open").click(function(){

		$(this).parents().parent(".toggle_fast").find(".visible").hide();
		$(this).parents().parent(".toggle_fast").find(".hidden").show();
		$(this).parents().parent(".toggle_fast").find(".hidden :input:first").select();
		return false;
	});

	$(".toggle_fast .close").click(function(){
		$(this).parents().parent(".toggle_fast").find(".hidden").hide();
		$(this).parents().parent(".toggle_fast").find(".visible").show();
		$(this).parents().parent(".toggle_fast").find(".visible :input:first").select();
		return false;
	});
	$('.login_go').click(function(){
		var a = $('html .login_gone:first');
			a.show();
			a.find('h2').hide();
			a.dialog();
		return false;
	});
	
	
}
$(function() {
	
	$(".branco").each(function(){
		$(this).mouseover(function(){
			$(this).find(".b_over.hidden").show();
		}).mouseout(function(){
			$(this).find(".b_over.hidden").hide();
		});
	});
	$('.login_go').click(function(){
		var a = $('html .login_gone:first');
			a.show();
			a.find('h2').hide();
			a.dialog();
		return false;
	});
	$("[show_over]").each(function(){
		var t = $(this);
		var cl = t.attr("show_over");
		$("."+cl).each(function(){
			$(this).mouseover(function(){
				$(this).find("[show_over]:first").show();
			}).mouseout(function(){
				$(this).find("[show_over]:first").hide();
			});
		});
	});
	
	$("a[confirm]").click(function(){
		var t = $(this);
		var msg = t.attr("confirm");
		if(confirm(msg)){
			var del_class = t.attr("del_class");
			if(del_class){
				t.parents("."+del_class).hide("slow");
				$.get(t.attr("href"));
				return false;
			} else {
				return false;
			}
		} else {
			return false;
		}
	});
	
	$(".info").each(function(){
		var t = $(this); var txt = $(this).find("font");
		txt.hide(); t.mouseover(function(){
			txt.show("");
		}).mouseout(function(){
			txt.hide("");
		});
	});
	
	var legend =  $("#show_legend").html();
	$("#p_tb_opt #p_tr_opt a").mouseover(function(){
		var t = $(this).attr("legend");
		if(t) $("#show_legend").html(t); 
	}).mouseout(function(){
		if(legend) $("#show_legend").html(legend);
	});
	
	$(".link_form").each(function(){
		var form = $(this);
		$(this).find(".del").click(function(){
			form.find(".deleted").val(1);
			form.hide("slow");
			return false;
		});
		
	});
		
	$("#quadro1").each(function(){
		var q = $(this);
		q.find(".qclose").click(function(){
			q.hide("slow"); return false;
		});
	});	
	
	$("#pf_link_edit").click(function(){
		$("#pf_link_panel").show();
		$("#pf_link_panel").dialog({
			height: 360,
			width: 480,
			modal: true,
			resizable: true,
			buttons: {
				'Salvar Alterações': function() {
					{
						$("#pf_link_form").submit();
					}
				},
				'Cancelar': function() {
					$(this).dialog('close');
				}
			},
			close: function() {
				$(".link_form").each(function(){
					var form = $(this);
					form.find(".deleted").val(0);
					form.show();
				});
			}
		});
	});

	form_confirma_gostei();
	
	$(".form input").addClass("form_box");
	$(".button")
		.removeClass("form_box")
		.button()
		.css("-webkit-border-radius","4px")
		.css("-moz-border-radius","4px");
	$(".button.ss")
		.css("padding","5px")
		.css("padding","5px");
	
	$(".galeria .img").lightBox({
		imageLoading: '/css/images/lightbox-ico-loading.gif',
		imageBtnClose: '/css/images/closelabel.gif',
		imageBtnPrev: '/css/images/prevlabel.gif',
		imageBtnNext: '/css/images/nextlabel.gif',
		imageBlank: '/css/images/blank.gif',
		txtImage: 'Imagem',
		txtOf: 'de'
	});
	
	$(".perfil .icon ").mouseover(function(){
		var src = $(this).attr("src");
		if(src.search("_off")>0){
			src = src.replace("0","1");
			src = src.replace("_off","_on");
			$(this).attr("src",src);
			$(this).attr("change",true);
		}
	}).mouseout(function(){
		if($(this).attr("change")){
			var src = $(this).attr("src");
			src = src.replace("1","0");
			src = src.replace("_on","_off");
			$(this).attr("src",src);
		}
	});
	
	var comment_dft = "Digite aqui sua mensagem..";
	$(".comment").each(function(){
		if($(this).attr("value")=="") {
			$(this).attr("value",comment_dft);
			$(this).parent().find(".comment_ok").attr("disabled",true);
			$(this).parent().find(".comment_ok").hide();
		}
	});
	$(".comment").blur(function(){
		if($(this).attr("value")=="") {
			$(this).attr("value",comment_dft);
			$(this).parent().find(".comment_ok").attr("disabled",true);
			$(this).parent().find(".comment_ok").hide();
		}
	});
	$(".comment").focus(function(){
		if($(this).val()==comment_dft) {
			$(this).val("");
			$(this).parent().find(".comment_ok").attr("disabled",false);
			$(this).parent().find(".comment_ok").show();
		}
	});
	
	function mt_nav_on(id){
		$(".mt_nav img").each(function(){
			if($(this).attr("mt")==id) {
				$(this).attr("src",$(this).attr("on"));
			}
			else {
				$(this).attr("src",$(this).attr("off"));
			}
		});
	}
	function mt_slide(id){
		$(".mt_slide").each(function(){
			if($(this).attr("id")=="mt_"+id) {
				$(this).css("position","absolute").fadeIn(600);
			}
			else {
				$(this).css("position","absolute").fadeOut(600);
			}
		});
	}
	var nav_id = 1;
	var nav_idt = 1;
	function update_mt_nav(){
		mt_slide(nav_id);
		mt_nav_on(nav_id);
		nav_id++; if(nav_id>5) nav_id = 1; if(nav_idt<=8) nav_idt++;
	}
	var time_out = setInterval(function(){ update_mt_nav(); },2000+(nav_idt*100));
	mt_nav_on(1);
	$(".mt_slide:first").show();
	$(".mt_slide").click(function(){
		document.location.href = $(this).attr("url");
	});
	$(".mt_nav img").click(function(){
		var id = $(this).attr("mt");
		mt_slide(id);
		mt_nav_on(id);
		clearTimeout(time_out);  return false;
	});
	
	  /* Bind an event to window.onhashchange that, when the hash changes, gets the
	     hash and adds the class "selected" to any matching nav link.*/
	  $(window).bind( 'hashchange', function(){
	    var hash = location.hash.replace('#','');
	    /* Iterate over all nav links, setting the "selected" class as-appropriate.*/
	    if(hash){
	    	$("#evento_show").load('/json/ev/'+hash+' #content',function(){
	    		
	    		$('html, body').animate({scrollTop: $("#evento_show").offset().top - 12}, 1200);
	    		$(".evento_img").click(function(){
	    			var dir = $(this).attr("folder");
	    			var img = $(this).attr("img");
	    			var branco = $("#evento_show .b5 table:first");
	    			branco.hide();
	    			branco.parent().append("<div id=img_return><img src='"+dir+"image_"+img+".jpg' style='cursor:pointer;' title='Voltar' width=100%></div>");
	    			$("#evento_show #img_return").click(function(){
	    				$(this).remove();
		    			branco.show();
			    		$('html, body').animate({scrollTop: $("#evento_show").offset().top + 533 }, 1200);
	    			});
		    		$('html, body').animate({scrollTop: $("#evento_show").offset().top + 533 }, 1200);
	    			return false;
	    		});
	    		
	    		form_confirma_gostei();
	    		
	    	});
	    }
	  });
	  
	  /*Since the event is only triggered when the hash changes, we need to trigger
	    the event now, to handle the hash the page may have loaded with.*/ 
	  $(window).trigger( 'hashchange' );
		  

	var effect = "slide";
	var speed  = {};
	$("#prev").click(function(){
		$(".dia .cw").each(function(){
			var load = $(this).attr('load');
			var num = eval(load)-5;
			if (num<0) var novo = num; else var novo = '+'+num;
			$(this).hide(effect,speed);
			$(this).attr('load',novo);
			$(this).find('span').html("<font size=1>Carregando...</font>");
			$(this).find('div.week_div div').html("&nbsp;");
			$(this).show(effect,speed);
		});
		atualiza_agenda();
	});
	$("#next").click(function(){
		$(".dia .cw").each(function(){
			var load = $(this).attr('load');
			var num = eval(load)+5;
			if (num<0) var novo = num; else var novo = '+'+num;
			$(this).hide(effect,speed);
			$(this).attr('load',novo);
			$(this).find('span').html("<font size=1>Carregando...</font>");
			$(this).find('div.week_div div').html("&nbsp;");
			$(this).show(effect,speed);
		});
		atualiza_agenda();
	});
	atualiza_agenda();
	
	$("table[click_url]").each(function(){
		$(this).css("cursor","pointer");
		$(this).click(function(){
			document.location.href = $(this).attr("click_url");
		});
	});
	
	$("div[class_over]").mouseover(function(){
		$(this).addClass($(this).attr("class_over"));
	}).mouseout(function(){
		$(this).removeClass($(this).attr("class_over"));
	});
	
	$("input[default],textarea[default]").each(function(){
		var t = $(this); 
		var dfv = t.attr("default");
		var ofv = "";
		if(t.val()=='') {
			t.val(dfv); t.removeClass("cd"); t.addClass("cl");
		}
		t.focus(function(){ 
			if(t.val()==dfv) {
				t.val(ofv); t.removeClass("cl"); t.addClass("cd");
			}  
		});
		t.blur(function(){ 
			if(t.val()==ofv) {
				t.val(dfv); t.removeClass("cd"); t.addClass("cl");
			}
		});
	});
	
	var lfa_txt = "Cole aqui seus links novos."; 
	
	$(".link_form_add textarea").each(function(){
		var t = $(this);
		if(t.val()=='') t.val(lfa_txt);
		t.focus(function(){
			if(t.val()==lfa_txt) t.val("");			
		}).blur(function(){
			if(t.val()=="") t.val(lfa_txt);			
		});
	});
	
	$(".accordion").accordion({
		event: "click",			
		collapsible: true,
		active: false,
		icons: {
			header: "ui-icon-circle-arrow-e",
			headerSelected: "ui-icon-circle-arrow-s"
		}
	});

	$("#day_show").button().click(function(){
		$("#day_select").toggle("blind");
		$(this).addClass('ui-state-active');
	});
	$("#day_drop").button({
		text: false,
		icons: {
			primary: "ui-icon-triangle-1-s"
		}
	}).click(function(){
		$(this).addClass('ui-state-active');
		$("#day_select").toggle("blind");
	}).parent().buttonset();
	$("#day_select").datepicker({
		altField: '#agenda_date',
		dateFormat: 'yy-mm-dd',
		onSelect: function(){ 
			$(this).hide('slow');
			document.location.href = '/agenda/' + $("#agenda_date").attr("value");
		}
	}).hide();
	
	$(".datepicker").datepicker({			
		showOn: 'button',
		buttonImage: '/css/images/calendar.png',
		buttonImageOnly: true

	});

	
	$(".dialog").dialog({
		modal: true,
		resizable: false,
		width: 420,
		buttons: {
			Ok: function() {
				$(this).dialog('close');
				$('form input[value=]:first').focus(); 
			}
		}
	});

	$("#dialog_refresh").dialog({
		modal: true,
		resizable: false,
		width: 420,
		buttons: {
			Ok: function() {
				$(this).dialog('close');
				if($("#dialog_refresh").attr('alt')!=''){
					document.location.href = ($("#dialog_refresh").attr('alt'));
				} else {
					document.location.href = document.location.href;
				}
			}
		}
	});
	$(".click").find("#title").click(function(){
		$(this).parent().find("#content").toggle('fast');
		return false;
	});

	$(".toggle .open").click(function(){
		$(this).parents().parent(".toggle").find(".visible").hide("slow");
		$(this).parents().parent(".toggle").find(".hidden").show("slow");
		$(this).parents().parent(".toggle").find(".hidden :input:first").select();
		return false;
	});

	$(".toggle .visible").show();
	$(".toggle .hidden ").hide();
	
	$(".toggle .close").click(function(){
		$(this).parents().parent(".toggle").find(".hidden").hide("slow");
		$(this).parents().parent(".toggle").find(".visible").show("slow");
		$(this).parents().parent(".toggle").find(".visible :input:first").select();
		return false;
	});

	$(".toggle_fast .open").click(function(){

		$(this).parents().parent(".toggle_fast").find(".visible").hide();
		$(this).parents().parent(".toggle_fast").find(".hidden").show();
		$(this).parents().parent(".toggle_fast").find(".hidden :input:first").select();
		return false;
	});

	$(".toggle_fast .close").click(function(){
		$(this).parents().parent(".toggle_fast").find(".hidden").hide();
		$(this).parents().parent(".toggle_fast").find(".visible").show();
		$(this).parents().parent(".toggle_fast").find(".visible :input:first").select();
		return false;
	});
	

	$(".toggle_over").mouseover(function(){
		$(this).find(".visible").hide();
		$(this).find(".hidden").show();
		$(this).find(".hidden :empty").select();
	});
	$(".toggle_over").mouseout(function(){
		$(this).find(".visible").show();
		$(this).find(".hidden").hide();
		$(this).find(".visible :empty").select();
	});
	
	setTimeout(function(){ $(".info_box").each(function(){

		$(this).find("font").hide("slow");
		$(this).find(".icon ").show("slow");
		
	}); }, 5000);
	$(".info_box").find("font").hide().show("slow");
	$(".info_box").click(function(){
		$(this).find("font").toggle("slow");
		$(this).find(".icon").toggle("slow");
	});
	
});

function reload() {
	document.location.href = document.location.href;
}
