/*********************Preload Menu ***************/
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//////////////////////////////////////////
var LbLogin = "";
var liveSite = "";
var UID = "";
var nombreUsuario="";
function validarNro(e){
	var key;
	if(window.event) // IE
	{
		key = e.keyCode;
	}else if(e.which) // Netscape/Firefox/Opera
	{
		key = e.which;
	}
	if (key < 48 || key > 57)
	{
		return false;
	}
	return true;
}

function mostrarAlerta(msj)
{
	var Contenido = "<div id='msj_alerta'>"+msj+"</div>";
	
	var detalle_combo = new light_box({lightBoxOpacity:0.7, tema:'alerta' });
	detalle_combo.abrirLightBox(Contenido);
	enviando = false;
}
function mostrarLogin(msj)
{
	var Contenido = "<div id='msj_login'>"+msj+"</div>";
	
	var detalle_combo = new light_box({lightBoxOpacity:0.7, tema:'login', heightContent:500, widthContent: 500 });
	detalle_combo.abrirLightBox(Contenido);
	enviando = false;
}
function abrirLogin()
{
	light_login = new frame_box({lightBoxOpacity:0.5, tema:'login' });
	light_login.onClose = function(){top.location.href = top.location.href;}
	light_login.abrirLightBox(liveSite+"login");
}
function cerrarLogin(){
	top.light_login.cerrarLight();
}
function goRegistro(){
	top.light_login.cerrarLight();
	top.location= "http://www.pastasdoria.com/registro/";
}

var elemento_formulario = "";
var enviando = false;

function enviarFormulario(formulario){
	if (!enviando){
		enviando = true;
		$('loading').setStyle("display", "block");
		elemento_formulario = formulario;
		elemento_formulario.set('send', { method: 'post',evalScripts:true, onComplete: mostrarRespuesta});
		elemento_formulario.send();
	}
}

function mostrarRespuesta(texto){
	$('loading').setStyle("display", "none");
	enviando = false;

	if (texto == "ok"){
		elemento_formulario.reset();
		if(elemento_formulario.name =="login_form")
			window.top.newRequest(liveSite+'?opcion=login&a=mostrarFormularioPre', 'container_formulario');
	}	
}
function newRequest(url_request,id_div){
	new Request(
			{
			method: 'post',
			url: url_request,
			//onCreate:mostrarCargador(),
			//onLoading:cargando(),
			onSuccess: function(texto){
			//$("cargando").tween("opacity", "1", "0");	
			$(id_div).innerHTML = texto;
			},
			evalScripts:true
			}).send();
	
}
function popup(page, height, width)
{
  var url = page;
  var h = height;
  var w = width;
  var left=(screen.width)?(screen.width - width)/2:100;
  var top=(screen.height)?(screen.height - height)/2:100;

 var popup = window.open(url,'popUp','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=' + w + ',height=' + h + ',left='+left+',top='+top);
 popup.focus();
}
function verTerminos()
{
	popup("php/html/terminos.html", screen.height-150 , 570);
}
function validarFocus(div, texto, tipo){
	if(tipo == '1' && $(div).value == texto)
		$(div).value = '';
	else if(tipo == '0' && $(div).value == '')
		$(div).value = texto;
}
function overlay(visible, i){
	if(visible == '1'){
		$('overlay_'+i).setStyle('display', 'block');
	}else
		$('overlay_'+i).setStyle('display', 'none');
}
function validarBusqueda(){
	var texto = /^\S/;
	var buscar = $('buscar').value;
	if (!(buscar.match(texto))|| buscar == '' || buscar == 'buscar'){
		mostrarAlerta('Debe escribir un criterio de busqueda');
		$('buscar').focus();	
		return false;
	}else
		return true;
	return false;
}
function verFlotante(visible){
	if(visible == '0'){
		var over = $('novedades_off');
		var morph = over.get('morph', {link: 'cancel', duration: 500, transition: Fx.Transitions.Sine.easeIn});
		morph.start({'right': [over.getStyle('right'), 0]});
		
		var over2 = $('novedades');
		var morph2 = over2.get('morph', {link: 'cancel', duration: 500, transition: Fx.Transitions.Sine.easeIn});
		morph2.start({'right': [over2.getStyle('right'), -250]});
	}else{
		var over = $('novedades_off');
		var morph = over.get('morph', {link: 'cancel', duration: 500, transition: Fx.Transitions.Sine.easeIn});
		morph.start({'right': [over.getStyle('right'), -50]});
		
		var over2 = $('novedades');
		var morph2 = over2.get('morph', {link: 'cancel', duration: 500, transition: Fx.Transitions.Sine.easeIn});
		morph2.start({'right': [over2.getStyle('right'), 0]});
	}
}
function shareFB(url){
    var surl = "http://www.facebook.com/sharer.php?u="+encodeURIComponent(url);
	popup(surl, 300, 756);
}
var foto_actual = 1;
function cambiarNombre(direccion){
	$('overlay_banner'+foto_actual).setStyle('display', 'none');
	if(direccion == '1'){
		foto_actual+=1;
	}else{
		if(foto_actual > 1)
			foto_actual-=1;
	}
	$('overlay_banner'+foto_actual).setStyle('display', 'block');
}
function tween(id, estilo, valor, duracion){
	var over = $(id);
	var morph = over.get('morph', {link: 'cancel', duration: duracion, transition: Fx.Transitions.Sine.easeIn});
	if(estilo == "opacity")
		morph.start({'opacity': [over.getStyle(estilo), valor]});
	else if(estilo == "left")
		morph.start({'left': [over.getStyle(estilo), valor]});
	else if(estilo == "right")
		morph.start({'right': [over.getStyle(estilo), valor]});
	else if(estilo == "width")
		morph.start({'width': [over.getStyle(estilo), valor]});
	else if(estilo == "height")
		morph.start({'height': [over.getStyle(estilo), valor]});
	
}
var carrusel = "";


function iniciarEventos(){
	carrusel = new CarruselFotos({container_carrusel: "carrusel", ancho_fotos: 518});
	$('over_receta').addEvents({
		'mouseenter':overServicio.bindWithEvent(),
		'mouseleave':outServicio.bindWithEvent()
		//'click': clickServicio.bindWithEvent($('event_serv_'+i),i)
	});	
}

function overServicio(e, id){
	var over = $('overlay_banner');
	$('overlay_banner').innerHTML = $("img_"+carrusel.foto_actual).alt;
	
	var morph = over.get('morph', {link: 'cancel', duration: 500, transition: Fx.Transitions.Sine.easeIn});
	morph.start({'opacity': [over.getStyle('opacity'), 1]});
}


function outServicio(e, id){
	var over = $('overlay_banner');
	var morph = over.get('morph', {link: 'cancel', duration: 500, transition: Fx.Transitions.Sine.easeIn});
	morph.start({'opacity': [over.getStyle('opacity'), 0]});
}

function mostrarScroll(content,scrollbar,handle,horizontal,ignoreMouse){
	
	var steps = (horizontal?(content.getScrollSize().x - content.getSize().x):(content.getScrollSize().y - content.getSize().y))
	var slider = new Slider(scrollbar, handle, {	
		steps: steps,
		mode: (horizontal?'horizontal':'vertical'),
		onChange: function(step){
//Scrolls the content element in x or y direction.
			var x = (horizontal?step:0);
			var y = (horizontal?0:step);
			content.scrollTo(x,y);
		}
	}).set(0);
	if( !(ignoreMouse) ){
		// Scroll the content element when the mousewheel is used within the 
		// content or the scrollbar element.
		$$(content, scrollbar).addEvent('mousewheel', function(e){	
			e = new Event(e).stop();
			var step = slider.step - e.wheel * 30;	
			slider.set(step);					
		});
	}
	// Stops the handle dragging process when the mouse leaves the document body.
	$(document.body).addEvent('mouseleave',function(){slider.drag.stop()});
}
