$(document).ready(function(){
			
	$('#sucursales_contenedor ul').css("width", $('#sucursales_contenedor li').length * 220);
	
	$('#sucursales_contenedor').serialScroll({
		items: 'div',
		interval: 5000,
		axis: 'x',
		duration: 1000,
		step: 1,
		start: 0,
		cycle: true,
		force: true
	});
	
	$("a[rel^='prettyPhoto']").prettyPhoto({
		show_title: false,
		modal: true,
		allow_resize: false,
		theme: 'facebook'
	});
	
});
jQuery.ajaxSetup({
	cache: false
});
function buscaSugs(inputString) {
	if(inputString.length == 0) {
		// Hide the suggestion box.
		$('#suggestions').hide();
	} else {
		if(inputString.length >= 4) {
			$.post("autoCompletado.php", {query: ""+inputString+""}, function(data){
				if( data == "" ) { $('#autoSuggestionsList').html('<p align="center">No se encontraron resultados...</p>'); } else { $('#autoSuggestionsList').html(data); }
				$('#suggestions').show();
			});
		} else { $('#suggestions').hide(); }
	}
} // lookup

function cierraSugs(thisValue) {
	setTimeout("$('#suggestions').hide();", 200);
}
function catalogoVirtual(url, ancho, alto, title, description)
{
	$.prettyPhoto.open(url+'&width='+ancho+'&height='+alto,title,description);
	return false;
}
function preCarrito(producto)
{
	$.prettyPhoto.open('precarrito.php?id='+producto+'&iframe=true&width=715&height=300','','');
	return false;
}
function carrito()
{
	$.prettyPhoto.open('carrito.php?iframe=true&width=900&height=550','','');
	return false;
}
function loginAjax()
{
	var fields = new Array("usuario_input", "pass_input");
	var info = "";
	for( var i = 0; i <= fields.length-1; i++ )
	{
		var valor = jQuery.trim($('#'+fields[i]).val());
		if( valor == "" ) {
			$('#loginAjaxResponse').html('Llena todos los campos...');
			return false;
		}
		info += ( info == "" ) ? fields[i]+'='+valor : '&'+fields[i]+'='+valor;
	}
	$.ajax({
		type: "POST",
		url: "login.php",
		cache: false,
		data: info,
		success: function(datos){
			if( datos.substr(0, 5) == "Error" )
			{
				$('#loginAjaxResponse').html(datos.substr(7));
			} else {
				window.location.reload();
			}
		}
	});
}
//function to check valid email address
function isValidEmail(strEmail){
  validRegExp = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
   // search email text for regular exp matches
    if (strEmail.search(validRegExp) == -1) 
   {
      return false;
    } 
    return true; 
}

function agregarBoletin()
{
	var email = jQuery.trim($('input#news_email').val());
	$.ajax({
			type: "POST",
			url: "newsletter.php",
			cache: false,
			data: "email="+email,
			success: function(datos){
				alert(datos);
		  }
	});
}
