// JavaScript Document

$(document).ready(function(){
	
	window.setInterval("title()", 1500);
	
	$(document).pngFix();
	
	/*funções load*/
	$().ajaxStart(function(){ loadingMouseOn(); });
	$().ajaxStop(function(){ loadingMouseOff(); });
	//$().ajaxError(function(){ loadingError() });
	
	loading = 1;
	$("#topoBarLogin").load("/loginBar.php");
	$("#content").load("/home.php");
	
	$("#login").modal({
		url: '/login.php',
		backgroundColor: '#000000',
		backgroundOpacity: 0.8,
		position: 'center',
		referencePosition: this,
		top:0,
		left:0,
		closeEsc: true,
		closeClickOut: true,
		autoOpen: false
	});
	
	$("#menuH a").click(function(){
		var url = $(this).attr("rel");
		if((url == '') || (url == '#')){
			return false;
		}else{
			loading = 1;
			$("#content").load(url);
			window.location.href = '#';
			return false;
		}
	});
	
	//$("#menuV").hide();
	$("#menuVTop").toggle(function(){
		$(this).removeClass();
		$(this).addClass("menuVTopOff");
		$("#menuV").hide('slow');
	}, function(){
		$(this).addClass("menuVTopOn");
		$("#menuV").show('slow');
	});
	
	$("#menuV ul").hide();
	$("#menuV div").toggle(function(){
		$(this).addClass("menuVCatOn");
		$(this).next().show('slow');
	}, function(){
		$(this).removeClass();
		$(this).addClass("menuVCatOff");
		$(this).next().hide('slow');
	});
	$("#menuV a").click(function(){
		var ajax = $(this).attr("rel");
		if(ajax == "ajax"){
			var href = $(this).attr("href");
			if((href != "#") && (href != '')){
				loading = 1;
				$("#content").load(href);
				return false;
			}else{
				return false;
			}
		}
	});
	
	$("#rodapeLinks a").click(function(){
		var href = $(this).attr("href");
		if((href != "#") && (href != '')){
			loading = 1;
			$("#content").load(href);
			window.location.href = '#';
			return false;
		}else{
			return false;
		}
	});
	
	$("#bannerCadastro").click(function(){
		loading = 1;
		$("#content").load("/cadastro.php");
	});
	
	/*---- inicio seletores player ----*/
	$("#btnWebRadio").click(function(){
		if(webRadioView == 0){
			webRadio_on();
		}else{
			webRadio_off();
		}
	});
	
	$("#webRadio").hover(function(){
		webRadioHide = 0;
		webRadio_show();
	}, function(){
		webRadioHide = 1;
		window.setTimeout("webRadio_hide()", 5000);
	});
	
	$("#mapMediaPlayer").hover(function(){
		webRadioHide = 0;
		webRadio_show();
	}, function(){
		webRadioHide = 1;
		window.setTimeout("webRadio_hide()", 5000);
	});
	
	$("#playerPlay").click(function(){
		//IE
		try{
			mediaPlayer.play();
		}catch(e){
			//firefox
			$("#mediaPlayer").show();
		}
		webRadioHide = 1;
		webRadioEfeito();
	});
	
	$("#playerStop").click(function(){
		//IE
		try{
			mediaPlayer.stop();
		}catch(e){
			//firefox
			$("#mediaPlayer").hide();
		}
	});
	
	$("#playerMute").toggle(function(){
		//IE
		try{
			mediaPlayer.Volume = -10000;
		}catch(e){
			return false;
		}
	}, function(){
		//IE
		try{
			mediaPlayer.Volume = 0;
		}catch(e){
			return false;
		}
	});
	
	$("#playerVolDown").click(function(){
		//IE
		try{
			mediaPlayer.Volume = mediaPlayer.Volume - 500;
		}catch(e){
			return false;
		}
	});
	
	$("#playerVolUp").click(function(){
		//IE
		try{
			mediaPlayer.Volume = mediaPlayer.Volume + 500;
		}catch(e){
			return false;
		}
	});
	
	/*---- fim seletores player ----*/
});


/*---- inicio configurações do player ----*/
//window.setInterval("webRadioEfeito()", 50000);
window.setTimeout("webRadio_hide()", 4000);
var webRadioView = 1;
var webRadioHide = 1;
var player = $("#mediaPlayer embed");

function webRadio_show(){
	$("#webRadio").animate({opacity: "1"}, 1000);
}

function webRadio_hide(){
	if(webRadioHide == 1){
		$("#webRadio").animate({opacity: "0.15"}, 1000);
	}
}

function webRadioEfeito(){
	if(webRadioHide == 1){
		$("#webRadio").animate({opacity: "1"}, 1000);
		$("#webRadio").animate({opacity: "0.15"}, 1000);
		$("#webRadio").animate({opacity: "1"}, 1000);
		$("#webRadio").animate({opacity: "0.15"}, 1000);
		$("#webRadio").animate({opacity: "1"}, 1000);
		$("#webRadio").animate({opacity: "0.15"}, 1000);
	}
}

function webRadio_on(){
	webRadioView = 1;
	$("#btnWebRadio img").attr("src", "/imagens/btnWebRadio_off.png");
	$("#btnWebRadio").animate({opacity: "1"}, 1000);
	$("#webRadio").animate({top: "140px"}, 2000);
	webRadioEfeito();
}

function webRadio_off(){
	webRadioView = 0;
	$("#btnWebRadio").animate({opacity: "0.4"}, 1000);
	$("#btnWebRadio img").attr("src", "/imagens/btnWebRadio_on.png");
	$("#webRadio").animate({top: "-100px"}, 2000);
	webRadio_hide();
}
/*---- fim configurações do player ----*/

function atualizaMural(){
	loading = 1;
	$("#content").load("/mural.php");
	return true;
}

//função exclusiva para mural de recados da home
function irMuralRecados(){
	loading = 1;
	$("#content").load("/mural.php");
	return true;
}

//função status de carregamento.
function loadingMouseOn(){
	if(loading == 1){
		$("#mouseCursor").show();
		$(".body").mousemove(function(e){
			xOffeset = 20;
			yOffeset = 2;
			$("#mouseCursor").css("top", (e.pageY - yOffeset));
			$("#mouseCursor").css("left", (e.pageX + xOffeset));
		});
	}
}

function title(){
	window.document.title = ".:: Manica Eventos ::.";
}

//função status de carretamento.
function loadingMouseOff(){
	setTimeout("loadingMouseHide()", 500);
}

function loadingMouseHide(){
	loading = 0;
	$("#mouseCursor").hide();
}

function loadingError(){
	loading = 0;
	$("#mouseCursor").hide();
	window.alert("Falha no carregamento...");
}
