$(document).ready(function(){
	/* efeito para retirar os valores default dos campos input e textarea ao dar foto*/
	$('input[type=text],input[type=password],textarea').each(function(){
		var input = $(this);
		if(input.attr('testDV') == 'true'){
			$(this).focus(function(){
				if(this.value === this.defaultValue){
					if((this.type == 'text') && (this.id.indexOf('_PW') > -1)){
						input.css('display','none');
						var elms = document.getElementsByName(this.name.substr(0,this.name.length-1));
						if(elms.length == 1){
							$(elms[0]).css('display','').focus();
						}
					} else {
						this.value = '';
					}
				}
			});
			$(this).blur(function(){
				if(this.value == ''){
					if((this.type == 'password') && (this.id.indexOf('_PW') > -1)){
						input.css('display','none');
						var elms = document.getElementsByName(this.name+'2');
						if(elms.length == 1){
							$(elms[0]).css('display','');
						}
					} else {
						this.value = this.defaultValue;
					}
				}
			});
		}
	});

	var prev = "";
	$('#submenu div.bt_menu span.botao').mouseover(function(){
		clearTimeout(prev);
		prev = '';
		$('#submenu div.bt_menu div').hide();
		$(this).parent().find('div').show(20);
	});
	
	$(this).mouseover(function(event){
		if($(event.target).parents('div.bt_menu').length == 0){
			if(prev == '')
				prev = setTimeout(function(){$('#submenu div.bt_menu div').hide()},200);
		} else {
			clearTimeout(prev);
			prev = '';
		}
	});
	
	checkCookie();
});

var trocaFundo = function (bg){	
	$("#main").css('background','url(img/bg'+bg+'.jpg) top center no-repeat');
	$("body").css('background','url(img/bgzinho'+bg+'.jpg) top left');	
	setCookie("bgtipo",bg,365);
}


var getCookie = function(c_name){
	var i,x,y,ARRcookies=document.cookie.split(";");
	for (i=0;i<ARRcookies.length;i++){
		x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
		y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
		x=x.replace(/^\s+|\s+$/g,"");
		if (x==c_name){
			return unescape(y);
		}
	}
}

var setCookie = function (c_name,value,exdays){
	var exdate=new Date();
	exdate.setDate(exdate.getDate() + exdays);
	var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
	document.cookie=c_name + "=" + c_value;
}

var checkCookie = function (){
	var bgtipo=getCookie("bgtipo");
	if (bgtipo!=null && bgtipo!=""){
		trocaFundo(bgtipo);
	}else{
		trocaFundo('trilha');
	}
}


