/*jslint browser: true, cap: false, confusion: true, continue: true, css: true, debug: false, devel: false, eqeq: true, evil: false, forin: false, fragment: true, maxerr: 3, newcap: false, plusplus: true, sub: false, undef: false, unparam: true, vars: false, white: true */
/*globals $, document, webroot, borrarActividades, FB */

/*!
 * Funciones JS | <Nombre Proyecto>
 *
 * Andain, Desarrollo y Diseño Web
 * http://www.andain.cl/ <contacto@andain.cl>
 */

//<![CDATA[

//------------------------ JQUERY
$(document).ready(function()
{
	var $container 	= $('#am-container'),
		$imgs		= $container.find('img').hide(),
		totalImgs	= $imgs.length,
		cnt			= 0;
	
	$imgs.each(function(i) {
		var $img	= $(this);
		$('<img/>').load(function() {
			++cnt;
			if( cnt === totalImgs ) {
				$imgs.show();
				$container.montage({
					fillLastRow				: true,
					alternateHeight			: false,
					fixedHeight 			: 200,
					liquid                  : true, 
					alternateHeightRange	: {
						min	: 200,
						max	: 300
					},
					margin : 5,
					//fillLastRow : true
				});
			}
		}).attr('src',$img.attr('src'));
	});
	
	$('.submit').live(
	{
		keydown	: function(evento)
		{
			if ( evento.keyCode === 13 )
			{
				$(this).parents('form').submit();
			}
			return false;
		},
		click	: function()
		{
			$(this).parents('form').submit();
			return false;
		}
	});
	
	//---------- carrusel de proyectos
	$(".contenedor-carrusel").jCarouselLite(
	{
		btnNext: '.btn-next-carrusel',
		btnPrev: '.btn-prev-carrusel',
		visible: 5,
		circular: false,
		scroll: 1,
		speed: 600
		//easing: "backout"
	});
	
	
	// =================================================== PROYECTOS
	$('a.img-proyecto').click(function(evento)
	{
		evento.preventDefault();
		var	id			= $(this).data('id'),
			imagen		= $(this).data('img'),
			proyecto	= $(this).data('proyecto'),
			servicio	= $(this).data('servicio'),
			agencia		= $(this).data('agencia'),
			ano			= $(this).data('ano'),
			link		= $(this).data('link'),
			contenedor	= '.lb-proyecto .contenedor .proyecto';
			
		$('.lb-proyecto').data('id', id).fadeIn();
		$('.media', contenedor).html('<img alt="" src="' + webroot + 'img/' + imagen + '" />');
		$('.nombre', contenedor).html('<b class="strong">Proyecto</b>' + proyecto);
		$('.servicio', contenedor).html('<b class="strong">Servicio</b>' + servicio);
		$('.agencia', contenedor).html('<b class="strong">Agencia</b>' + agencia);
		$('.ano', contenedor).html('<b class="strong">Año</b>' + ano);
		if(link == '#')
		{
			$('.online', contenedor).attr('href', link);
			$('.online', contenedor).hide();
		}
		else
		{
			$('.online', contenedor).attr('href', link);
			$('.online', contenedor).show();
		}
	});
	
	//------ siguiente proyecto
	$('.proyecto .next a').click(function(evento)
	{
		evento.preventDefault();
		var	id		= $(this).parents('.lb-proyecto').data('id'),
			sig		= $('.campana a.img-proyecto[data-id="' + id + '"]').parents('.campana').next().find('a.img-proyecto');
			
			if( sig.size() )
			{
				sig.click();
			}
			else
			{
				//alert('NO HAY');
				return false;
			}
	});
	
	//------ anterior proyecto
	$('.proyecto .prev a').click(function(evento)
	{
		evento.preventDefault();
		var	id		= $(this).parents('.lb-proyecto').data('id'),
			ant		= $('.campana a.img-proyecto[data-id="' + id + '"]').parents('.campana').prev().find('a.img-proyecto');
			
			if( ant.size() )
			{
				ant.click();
			}
			else
			{
				//alert('NO HAY');
				return false;
			}
	});
	
	
	// =================================================== EQUIPO
	$('.footer .mapsite a.btn-equipo').click(function(evento)
	{
		evento.preventDefault();
		$('.lb-equipo').fadeIn();
	});
	
	
	// =================================================== QUE HACEMOS
	$('.menu a.quehacemos').click(function(evento)
	{
		evento.preventDefault();
		$('.lb-que_hacemos').fadeIn();
		$('.contenedor .que .contenido-interior').scrollTop(0);
	});
	
	
	//---------- menu que hacemos	
	$('.submenu a.btn-que').click(function(evento)
	{
		evento.preventDefault();
		
		var id				= $(this).data('id'),
			nombre			= $(this).data('nombre'),
			descripcion		= $(this).data('descripcion'),
			contenedor		= '.lb-que_hacemos .contenedor .que .contenido-interior';
			
		$('.submenu a.btn-que').removeClass('current');
		$('.submenu a.qh' + id).addClass('current');
		$('.contenedor .que .contenido-interior').scrollTop(0);
		
		$('.titulo', contenedor).html(nombre);
		$('.informacion', contenedor).html(descripcion);
	});
	
	
	// =================================================== CONTACTO
	$('.menu a.contacto').click(function(evento)
	{
		evento.preventDefault();
		$('.lb-contacto').fadeIn();
	});
	
	
	// =================================================== CERRAR
	//cierra todos los lb
	$('.cerrar a').click(function(evento)
	{
		evento.preventDefault();
		$('.lb').fadeOut();
	});
	
	
});

//]]>

