

jQuery.noConflict();
jQuery(document).ready(function() {
    jQuery('#mycarousel').jcarousel({
        scroll: 1,
		easing: 'BounceEaseOut',
		auto: 10,
        animation: 450,
		wrap: 'both',
		initCallback: mycarousel_initCallback
    });
});

jQuery.easing['BounceEaseOut'] = function(p, t, b, c, d) {
	if ((t/=d) < (1/2.950)) {
		return c*(7.5625*t*t) + b;
	} else if (t < (2/2.950)) {
		return c*(7.5625*(t-=(1.5/2.950))*t + .950) + b;
	} else if (t < (2.5/2.950)) {
		return c*(7.5625*(t-=(2.25/2.950))*t + .93950) + b;
	} else {
		return c*(7.5625*(t-=(2.625/2.950))*t + .9843950) + b;
	}
};


function mycarousel_initCallback(carousel)
{
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });
	
	jQuery('#mycarousel-next').bind('click', function() {
        carousel.next();
        return false;
    });

    jQuery('#mycarousel-prev').bind('click', function() {
        carousel.prev();
        return false;
    });

    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};


function loadSound()
{

	$('som').innerHTML = '';
	$('som').style.display = 'block';
	$('som').innerHTML = '<embed src="http://204.188.192.66:8000/" id="sound1" type="application/x-mplayer2" width="0" height="0" autostart="true" enablejavascript="true" />';
}


function unloadSound()
{
	$('som').style.display = 'none';
	$('som').innerHTML = '';
}

var enviando = 0;
function enviaMsg()
{
	if(enviando != 0)
	{
		alert('Enviando...');
		return;
	}
	var nome = $('nome').value;
	var assunto = $('assunto').value;
	var telefone = $('telefone').value;
	var email = $('email').value;
	var para = $('para').value;
	
	if(email.search(/@/) == -1)
	{
		$('debug').innerHTML = '<font color="red">Preencha o e-mail corretamente.</font>';	
		return;
	}
	var mensagem = $('mensagem').value;
	var parametros = 'nome=' + nome + '&assunto=' + assunto + '&telefone=' + telefone + '&email=' + email + '&mensagem=' + mensagem + '&para=' + para;
	enviando = 1;
	result = ajaxOperate('envia_mensagem.php',parametros);
	if(result)
	{
		enviando = 0;
		$('nome').value = '';
		$('assunto').value = '';
		$('telefone').value = '';
		$('email').value = '';
		$('mensagem').value = '';
	}
}


function atualizaOrdem(ordem)
{
	
	new Ajax.Request
	(
	 	'salva_ordem.php',
			{
				method:'POST',
				parameters:ordem,
				onSuccess: function(transport) {},
				onFailure: function() {}
			}
	);
	
}
///////////////////////////////////////////////////////////////
/*var index = -1;
var eventos =  new Array(2);
eventos[0] = {'foto_url':'imagens/flash_festajunina.jpg'};
eventos[1] = {'foto_url':'imagens/flash_momento.jpg'};*/


var index2 = 0;	
function proximaPublicidade()
{
	
	if($('lv_overlay').style.display == 'none')
	{
		
		index2 += 1;
		if(typeof(publicidade[index2]) != 'undefined') 
		{
			
			var arquivo = publicidade[index2]['foto_url'];
			var t1 = publicidade[index2]['extensao'].split('.');
			var extensao = t1[1];
			
			if(extensao == 'jpg' || extensao == 'bmp')
			{
				
				$('p_flash').style.display = 'none';
				$('p_imagem').style.display = 'block';
				$('p_imagem').src = publicidade[index2]['foto_url'];
				$('p_link').href = publicidade[index2]['link'];
			}
			else if(extensao == 'swf')
			{
				
				$('flash-content').innerHTML = '';
				$('p_imagem').style.display = 'none';
				$('flash-content').innerHTML = '<embed width="265" height="240" src="' + publicidade[index2]['foto_url'] + '" name="p_flash" id="p_flash"></embed>';
				$('p_link').href = publicidade[index2]['link'];
				//alert($('flash-content').innerHTML);
				
			}
		}
		else
		{
			index2=0;
			proximaPublicidade();
		}
	
	}
}
function voltaPublicidade()
{
	index2 -= 1;
	if(typeof(publicidade[index2]) != 'undefined') 
	{
		$('p_imagem').src = publicidade[index2]['foto_url'];
		$('p_link').href = publicidade[index2]['link'];
		
	}
	else
	{
		index2 = i2+1;
		voltaPublicidade();
	}
}


function iframeBusca()
{
	$('div_conteudo').style.width='700px';
	$('div_conteudo').innerHTML = '<iframe src="cms/usuarios/perfil.php" width="679" height="698" frameborder="0" scrolling="no"></iframe>';
	$('div_conteudo').scrollTo();
}

function ajaxBusca(pagina) 
{
	var obj = new Ajax.Request
	(
		pagina,
			{
				method:'GET',
				evalJS:true,
				asynchronous:false,
				onSuccess:function(transport)
				{
					
					if(pagina=='programacao.html')
					{
						$('div_conteudo').style.height = '3500px';
					}
					else if(pagina=='todas_galerias.php')
					{
						$('div_conteudo').style.height = '1800px';
					}
					else
					{
						$('div_conteudo').style.height = 'auto';
					}
					
					$('div_conteudo').style.background = '#E5E5E5';
					//$('div_conteudo').style.border = '1px #000 solid';
					$('div_conteudo').style.width = '700px';
					
					
					
					$('div_conteudo').innerHTML = transport.responseText;
					
					$('div_conteudo').scrollTo();
					evaljs();
				},
				onFailure:function(transport)
				{
					$('div_conteudo').innerHTML = transport.status;	
				},
				on404: function(transport)
				{
					$('div_conteudo').innerHTML = 'Página não encontrada';	
				},
				onCreate: function()
				{
					$('div_conteudo').innerHTML = '<img src="imagens/loading.gif" border="0" />';
				}
			}
	);
	if(pagina == 'contato.html')
	{
		var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1");
		var sprytextfield2 = new Spry.Widget.ValidationTextField("sprytextfield2");
		var sprytextfield3 = new Spry.Widget.ValidationTextField("sprytextfield3", "email");
		var sprytextfield4 = new Spry.Widget.ValidationTextField("sprytextfield4");
		var sprytextarea1 = new Spry.Widget.ValidationTextarea("sprytextarea1", {maxChars:300, counterType:"chars_remaining", counterId:"countsprytextarea1"});	
	}
	
}



function recados()
{
	Lightview.show({href:'cms/recados/envia_recados.php',rel:'iframe',options:{width:600,height:300}});
}
function todos_recados()
{
	Lightview.show({href:'todos_recados.php',rel:'iframe',options:{width:750,height:500}});
}
function promocoes()
{
	Lightview.show({href:'todas_promocoes.php',rel:'iframe',options:{width:750,height:500}});
}
function galerias()
{
	Lightview.show({href:'todas_galerias.php',rel:'iframe',options:{width:750,height:500}});
}


Event.observe(window,'load',function (){
	
	proximaPublicidade();
	setInterval('proximaPublicidade()',23000);
	loadSound();
});



var hpanel = new Object;
var div_conteudo = 'div_conteudo';

Spry.Utils.addLoadListener(function(){
	Spry.Widget.HTMLPanel.evalScripts = true;
	var Obs = new Object;

	Obs.onPostUpdate = function(notifier,data)
	{
		jQuery.scrollTo(jQuery('#div_conteudo'),1000);
		window.document.body.style.cursor = 'default';
		//$('div_conteudo').style.border = '1px #000 solid';
		$('div_conteudo').style.width = '700px';
	}

	
	Obs.onPreLoad = function(notifier,data)
	{
		$('div_conteudo').style.background = '#E5E5E5';
		if(data.url.search(/index/) != -1)
		{
			$('div_conteudo').style.background = '#CCC';
			$('div_conteudo').style.height = 'auto';
			$('div_conteudo').style.width = '700px';
		}
		else if(data.url.search(/todas_galerias/) != -1)
		{
			$('div_conteudo').style.height = '1800px';	
		}
		
		window.document.body.style.cursor = 'wait';
		window.document.getElementById(div_conteudo).innerHTML = '<div style="text-align:left;"><img src="imagens/loading.gif" /></div>';
	
	}
	
	hpanel = new Spry.Widget.HTMLPanel(div_conteudo,{evalScripts:true});
	hpanel.addObserver(Obs);
});
