function changeLinks(){
	$("a").each(function(){
        var linkType = $(this).attr("href").substring(0,1);  
        var linkTypeB = $(this).attr("href").substring(0,4);  
        if(linkType == "/" && linkTypeB != "/img"){
            if(!$(this).attr("target")){
                $(this).attr("href","javascript:exibir('"+$(this).attr("href")+"');");  
            }
        }
    });
	xp();
}
function exibir(url){
    $('#content').hide('fade');
	$("#MENU").load(url+" #MENU #menu_content",function(){
		changeLinks();
		$("#content").load(url+" #content",function(){
			$('#content').show('fade',500,function(){changeLinks();});
			
		});
	});
}

function xp(){

	$(".img_slide").each(function(){
		var islide = $(this);
		eval('var imgs = ['+islide.attr('imgs')+'];');
		//alert(imgs);
		var mygallery=new simpleGallery({
			wrapperid: islide.attr('id'), 
			dimensions: [islide.attr('w'), islide.attr('h')], 
			imagearray: imgs,
			autoplay: [true, 2500, 1], 
			persist: false, 
			fadeduration: 1000, 
			oninit:function(){ 
				
			},
			onslide:function(curslide, i){ 
				
			}
		});
	});
	
	$(".dialog_open").each(function(){
		//how to: <button class='hc_add dialog_open' h=240 target='#open_$i'></bt>
		$(this).click(function(){
			var target = $(this).attr("target");
			var h = $(this).attr("h"); if(!h) h = 340;
			var w = $(this).attr("w"); if(!w) w = 480;
			$(target).dialog({ width:w, height:h, modal:true});//!
			return false;
		});
		
	});
	
	$(".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;
				}
			}
		}
	});
	
	
	
	$(".galeria.a .img.a[target='']").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'
	});
	
	$(".galeria.b .img.a").click(function(){ return false; });
	
	$(".img").css("cursor","-moz-zoom-in, pointer;");
	
	$(".sav_border .get_over[show]").each(function(){
		var tag = $(this).attr("show");
		var speed = $(this).attr("speed");
		if(!speed) speed = "";
		$(this).mouseover(function(){
			$(this).find(tag).show('');
		}).mouseout(function(){
			$(this).find(tag).hide('');
		});
	});
	
	$(".sav_border .get_over[hide]").each(function(){
		var tag = $(this).attr("hide");
		var speed = $(this).attr("speed");
		if(!speed) speed = "";
		$(this).mouseover(function(){
			$(this).find(tag).hide('');
		}).mouseout(function(){
			$(this).find(tag).show('');
		});
	});
	
	$(".over[show]").each(function(){
		var tag = $(this).attr("show");
		var speed = $(this).attr("speed");
		if(!speed) speed = "";
		$(this).mouseover(function(){
			$(this).find(tag).show('');
		}).mouseout(function(){
			$(this).find(tag).hide('');
		});
	});
	
	$(".over[hide]").each(function(){
		var tag = $(this).attr("hide");
		var speed = $(this).attr("speed");
		if(!speed) speed = "";
		$(this).mouseover(function(){
			$(this).find(tag).hide('');
		}).mouseout(function(){
			$(this).find(tag).show('');
		});
	});
	
	$(".toggle .open").click(function(){
		$(this).parents().parent(".toggle").find(".visible").hide("fade");
		$(this).parents().parent(".toggle").find(".hidden").show("fade");
		$(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("fade");
		$(this).parents().parent(".toggle").find(".visible").show("fade");
		$(this).parents().parent(".toggle").find(".visible :input:first").select();
		return false;
	});	
	
	$("input[default],textarea[default]").each(function(){
		var t = $(this); 
		var dfv = t.attr("default");
		var dfcolor = t.css("color");
		var ofv = "";
		if(t.val()=='') {
			t.val(dfv); t.css("color","silver");
		}
		t.focus(function(){ 
			if(t.val()==dfv) {
				t.val(ofv); t.css("color",dfcolor);
			}  
		});
		t.blur(function(){
			if(t.val()==ofv) {
				t.val(dfv); t.css("color","silver");
			}
		});
	});
	
	$(".button").button();

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