function formatTweet(json)
{
	    for (var j=0;j<json.length;j++)
	    {
  		myjson = json[j];
  		var ind = j + 1;
  		var myDiv = document.getElementById('tweet-'+ind);
  		myDiv.innerHTML = "<a href=\"http://twitter.com/#!MzaMusic\" target=\"_blank\">" + myjson.text + "</a>";
	}
}

function changeHistory(elm){
	window.history.pushState('novapa', 'titulo', elm);
}

function setJSfix(){
	$("#servicos-mza .scroll-txt .inner").scrollable({ vertical: true, mousewheel: true });
    $("#servicos-mza .list-photos li a").fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'titlePosition' 	: 'over'
	});	
}

function fixCtServ(){
	setTimeout(setJSfix,4000)
}


function cghash(){
	var vl = anc+"_pag";
	window.location.hash=vl;
}


function mngHASH(elm){
	var anchor = elm.split("_")[0];
	anchor = anchor.replace("#","");
	$('html, body').stop().animate({
		scrollLeft: $('#'+anchor).offset().left
	}, 1000);
	$('ul li a[href="#'+anchor+'"]').parent("li").addClass("on").siblings().removeClass("on"); 
	//alert(elm);
}

var slidehselct = 0;


function slideHome(){

	if(slidehselct == 1){
		var elm = $('.list-videos li a:eq(1)');
		slidehselct = 2;
	}else if(slidehselct == 2){
		var elm = $('.list-videos li a:eq(2)');
		slidehselct = 3;
	}else{
		var elm = $('.list-videos li a:eq(0)');
		slidehselct = 1;
	}

	elm.parent().addClass('on').siblings().removeClass("on");
	if ( elm.attr('rel') == 'video') {
		$('.video a.link-video-int img').attr('src','');
		$('.video a.link-video-int').attr('href','');
		$('.video a.link-video-int').hide();
		$('.video a.link-video-ext').show();
		$('.video a.link-video-ext img').show();
		$('.video a.link-video-ext').attr('href','http://www.youtube.com/embed/' + elm.attr('href') + '/?wmode=Opaque');
		$('.video a.link-video-ext img').attr('src','http://img.youtube.com/vi/' + elm.attr('href') + '/0.jpg');
		$(".video a.link-video-ext").fancybox({
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'titlePosition' 	: 'over'
		});	
	} else {
		$('.video a.link-video-ext').attr('href','');
		$('.video a.link-video-ext img').attr('src','');
		$('.video a.link-video-ext').hide();
		$('.video a.link-video-int').show();
		$('.video a.link-video-int img').show();
		$('.video a.link-video-int img').attr('src',elm.attr('href'));
		$('.video a.link-video-int').attr('href',elm.attr('name'));
	}

	temposlidehome = setTimeout(slideHome, 8000);

}



var anc = "";
var getanc = "";

$(document).ready(function(){


	$(window).bind('hashchange', function(e) {
		e.preventDefault();
	});


//	$('#menu li a.linkpush').click(function() {
//		changeHistory($(this).attr("href"));
//	});


	// begin Form Contato
	$('#bt_contato').click(function() {

		var txtContatoEmail_aux 	= $("#txtContatoEmail").val();
		var txtContatoAssunto_aux 	= $("#txtContatoAssunto").val();
		var txtContatoMsg_aux		= $("#txtContatoMsg").val();

		var msg_aux = null;

		if(txtContatoEmail_aux == "Seu e-mail" || txtContatoEmail_aux == "" || txtContatoAssunto_aux == "Assunto" || txtContatoAssunto_aux == "" || txtContatoMsg_aux == "") {
			msg_aux = "Por favor, preencha todos os campos para enviar o contato";
			alert(msg_aux);
		}

		if(msg_aux == null || msg_aux == "") {
			$.post("action/contato_act.asp", {txtContatoEmail: txtContatoEmail_aux, txtContatoAssunto: txtContatoAssunto_aux, txtContatoMsg: txtContatoMsg_aux},function(retorno){
				//e.preventDefault();
				if(retorno != "") {				
					//exibe msg
					$("#layer-contato").slideToggle("slow");
					alert(retorno);	

				}					
			});
		}

	});

	$('.list-photos ul').jcarousel();

	$('input:text').blur(function(){
		if( $(this).val().length === 0 ) {
			var tit = $(this).attr("title");
			$(this).attr("value",tit);
		}
	});

	$('input:text').focus(function(){
		var tit = $(this).attr("title");
		if( $(this).val() == tit ) {
			$(this).attr("value","");
		}
	});

	$('textarea').focus(function(){
		var tit = "Mensagem";
		if( $(this).html() == tit ) {
			$(this).html("");
		}
	});

	$('textarea').blur(function(){
		if( $(this).html() == "" ) {
			var tit = "Mensagem";
			$(this).html(tit);
		}
	});



	// begin galeria home
	var valor_rel = $('.list-videos li a:eq(0)').attr('rel');
	var valor_src = $('.list-videos li a:eq(0)').attr('href');
	var valor_alt = $('.list-videos li a:eq(0)').attr('title');

	if ( valor_rel == 'video') {
		$('.video a.link-video-int').hide();
		$('.video a.link-video-int img').hide();
	}else{
	//	$('<img src="' +valor_src+ '" alt="' +valor_alt+ '" />').appendTo('.video');
		$('.video a.link-video-ext').hide();
		$('.video a.link-video-ext img').hide();
	}

	$(".video a.link-video-ext").fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'titlePosition' 	: 'over',
		'showNavArrows'		: false
	});	

	$('.list-videos li a').mouseover(function(event) {
		event.preventDefault();
		$(this).parent().addClass('on').siblings().removeClass("on");
		if ( $(this).attr('rel') == 'video') {
			$('.video a.link-video-int img').attr('src','');
			$('.video a.link-video-int').attr('href','');
			$('.video a.link-video-int').hide();
			$('.video a.link-video-ext').show();
			$('.video a.link-video-ext img').show();
			$('.video a.link-video-ext').attr('href','http://www.youtube.com/embed/' + $(this).attr('href') + '/?wmode=Opaque');
			$('.video a.link-video-ext img').attr('src','http://img.youtube.com/vi/' + $(this).attr('href') + '/0.jpg');
			slidehselct = $(this).attr('title');
			clearTimeout(temposlidehome);
			$(".video a.link-video-ext").fancybox({
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'titlePosition' 	: 'over',
				'showNavArrows'		: false
			});	
			temposlidehome = setTimeout(slideHome, 8000);
		} else {
			$('.video a.link-video-ext').attr('href','');
			$('.video a.link-video-ext img').attr('src','');
			$('.video a.link-video-ext').hide();
			$('.video a.link-video-int').show();
			$('.video a.link-video-int img').show();
			$('.video a.link-video-int img').attr('src',$(this).attr('href'));
			$('.video a.link-video-int').attr('href',$(this).attr('name'));
			slidehselct = $(this).attr('title');
			clearTimeout(temposlidehome);
			temposlidehome = setTimeout(slideHome, 8000);
		}
	});
	// end galeria home


	temposlidehome = setTimeout(slideHome, 8000);


	// begin verificar Largura da tela
	var windowWidth = $(window).width();
	$('.stage').width(windowWidth);
	var larguraBody = windowWidth * 7; /* largura da tela * qtd de secao*/
	$('#main').width(larguraBody);

	$(window).resize(function() {
		var windowWidth = $(window).width();
		$('.stage').width(windowWidth);
		var larguraBody = windowWidth * 7; /* largura da tela * qtd de secao*/
		$('#main').width(larguraBody);

		getanc = window.location.hash;
		if(getanc != null && getanc != ""){
			teste = mngHASH(getanc);
			window.setInterval(teste, 1500);
		}

	});

	// begin scrollling page
	$('#menu li a.anchor, h1 a, .sidebar-nossos-servicos a, .box-promocoes a, .lista-nossos-servicos li a.anchor').bind('click',function(event){
		

		$("#menu li").removeClass("on");
		$(".lista-nossos-servicos li").removeClass("on");
		$('#contato').fadeOut();

		$("#music iframe").attr("src","music.asp");
		$("#web-talentos iframe").attr("src","web-talentos.htm");
		$("#promocoes iframe").attr("src","promocoes.asp?ViewOK=1");
		$("#area-de-imprensa iframe").attr("src","area-de-imprensa.asp");
		
		/*$("#servicos-consultoria-mza iframe").attr("src","servicos-consultoria.asp");*/
		
		$("#servicos-consultoria-mza").load('servicos-consultoria.asp', fixCtServ());
		
		$("#servicos-mza").load('servicos.asp', fixCtServ());


		var $anchor = $(this);
		$('html, body').stop().animate({
			scrollLeft: $($anchor.attr('href')).offset().left
		}, 1000);
		event.preventDefault();
		$(this).parent("li").addClass("on").siblings().removeClass("on");

		anc = $anchor.attr('href');
		changeHistory($(this).attr("href"));
		window.setInterval(cghash, 500);


	});

	
	getanc = window.location.hash;
	if(getanc != null && getanc != ""){
		//teste = mngHASH(getanc);
		window.setInterval(teste, 1500);
	}

$('a[href$="' + window.location.hash + '"]').parent("li").addClass("on");


	

	$("html, body").mousewheel(function(event, delta) {
	  this.scrollLeft -= (delta * 80);
	  event.preventDefault();
	});


	$(".scroll-txt .inner").scrollable({ vertical: true, mousewheel: true });
    $(".list-photos li a").fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'titlePosition' 	: 'over'
	});	

	// begin Form Contato
	$('#bt_contato').click(function() {

		var txtContatoEmail_aux 	= $("#txtContatoEmail").val();
		var txtContatoAssunto_aux 	= $("#txtContatoAssunto").val();
		var txtContatoMsg_aux		= $("#txtContatoMsg").val();

		var msg_aux = null;

		if(txtContatoEmail_aux == "Seu e-mail" || txtContatoEmail_aux == "" || txtContatoAssunto_aux == "Assunto" || txtContatoAssunto_aux == "" || txtContatoMsg_aux == "") {
			msg_aux = "Por favor, preencha todos os campos para enviar o contato";
			alert(msg_aux);
		}

		if(msg_aux == null || msg_aux == "") {
			$.post("action/contato_act.asp", {txtContatoEmail: txtContatoEmail_aux, txtContatoAssunto: txtContatoAssunto_aux, txtContatoMsg: txtContatoMsg_aux},function(retorno){
				//e.preventDefault();
				if(retorno != "") {
					//exibe msg
					$("#layer-contato").slideToggle("slow");
					alert(retorno);

				}
			});
		}

	});

	//$("#servicos-mza").load('servicos.asp', fixCtServ());

});


if (navigator.userAgent.match(/like Mac OS X/i)) {
	//window.onscroll = function() {
	 // document.getElementById('header').style.left =
	//	 (window.pageXOffset + window.innerWidth - 25) + 'px';
	//};
}


function mangHash(variavel){
	window.location.hash = window.location.hash + "/" + variavel;
}

