window.addEvent('domready', function() {
	hoverImg();
});

function hoverImg(){
	$$('.borde-imagenes img').addEvents({
	mouseenter: function(){
		this.fade(0.6);
	},
	mouseleave: function(){
	   this.fade(1);
	}
	});
}

function aunNoDisponible(){
	alert("En construcción.\n\nEn breve estaremos actualizando esta sección. Disculpe las molestias.");
	return false;
}

function get_portfolio(page){
	if (page==""){
		var page = Cookie.read('page');
		if (!page) page = 1;		
	}
	laurl = "portfolio_page_"+page+".html";
	
	new Request({
		url: laurl,
		method: 'get',
		onRequest: function(){
			$('html_portfolio_page').set('html', '<img src="imagenes/ajax-loader.gif" />');
		},
		onSuccess: function(txt){
			$('html_portfolio_page').set('html', txt);
			hoverImg();
			Cookie.write('page', page, {duration: 1});
		},
		onFailure: function(){
			$('html_portfolio_page').set('text', 'Ha fallado el requerimiento..');
			Cookie.dispose('page');
		}
	}).send();	
}


function get_caso(uncaso){
	Url = window.location.href;
	if (Url.indexOf("portfolio.html") != -1){
		window.location.href = "casos_de_estudio.html#"+uncaso;
	}
	
	if (uncaso==""){		
		variable = Url.split ("#");
		if (variable.length != 1)
		{
			uncaso=variable[1];
		}
	}
	
	switch (uncaso) {
		case "absa":laurl = "portfolio/absa.html";eltextoh1="<b>Caso:</b> Aguas Bonaerenses";break;			
		case "alfil":laurl = "portfolio/alfilazul.html";eltextoh1="<b>Caso:</b> Alfil Azul";break;
		case "aloise":laurl = "portfolio/aloise.html";eltextoh1="<b>Caso:</b> Aloise Hogar";break;
		case "banco":laurl = "portfolio/banco.html";eltextoh1="<b>Caso:</b> Banco Alimentario";break;			
		case "cedlas":laurl = "portfolio/cedlas.html";eltextoh1="<b>Caso:</b> CEDLAS";break;
		case "corallo":laurl = "portfolio/corallo.html";eltextoh1="<b>Caso:</b> Perfumer&iacute;as Corallo";break;
		case "deptostemp":laurl = "portfolio/deptostemp.html";eltextoh1="<b>Caso:</b> Departamentos Temporales";break;
		case "dormusic":laurl = "portfolio/dormusic.html";eltextoh1="<b>Caso:</b> Dormusic";break;
		case "dunkue":laurl = "portfolio/dunkue.html";eltextoh1="<b>Caso:</b> Dunkue-bar";break;	
		case "electhom":laurl = "portfolio/electhom.html";eltextoh1="<b>Caso:</b> Electhom";break;			
		case "fibrosis":laurl = "portfolio/fibrosis.html";eltextoh1="<b>Caso:</b> Fibrosis Quística";break;
		case "frank":laurl = "portfolio/frankville.html";eltextoh1="<b>Caso:</b> Hostel Frankville";break;
		case "instrumento":laurl = "portfolio/instrumento.html";eltextoh1="<b>Caso:</b> Instrumento Electoral";break;
		case "journal":laurl = "portfolio/journal.html";eltextoh1="<b>Caso:</b> Revista Económica";break;
		case "natalia":laurl = "portfolio/natalia.html";eltextoh1="<b>Caso:</b> Natalia Nogueira";break;
		case "nestor":laurl = "portfolio/nestor.html";eltextoh1="<b>Caso:</b> Nestor Garnica";break;
		case "pm70":laurl = "portfolio/pm70.html";eltextoh1="<b>Caso:</b> PM70 Arquitectos";break;
		case "portalba":laurl = "portfolio/portalba.html";eltextoh1="<b>Caso:</b> PortalBA";break;
		case "orquesta":laurl = "portfolio/orquesta.html";eltextoh1="<b>Caso:</b> Orquesta De Camara";break;
		case "sedlac":laurl = "portfolio/sedlac.html";eltextoh1="<b>Caso:</b> SEDLAC";break;
		case "sintesis":laurl = "portfolio/absa-sintesis.html";eltextoh1="<b>Caso:</b> Sintesis de Medios - ABSA";break;
		case "weizur":laurl = "portfolio/weizur.html";eltextoh1="<b>Caso:</b> Laboratorio Weizur";break;
		default :laurl = "portfolio/absa.html";eltextoh1="<b>Caso:</b> Aguas Bonaerenses";break;
	}
	
	
	new Request({
		url: laurl,
		method: 'get',
		onRequest: function(){
			$('html_casodeestudio').set('html', '<img src="imagenes/ajax-loader.gif" />');
		},
		onSuccess: function(txt){
			$('html_casodeestudio').set('html', txt);
			$('tituloCasoEstudio').set('html', eltextoh1);	
			(new JFeedMoo('img.img_portfolio','btn_portfolio_Prev','btn_portfolio_Next')).playing(5000,false);
		},
		onFailure: function(){
			$('html_casodeestudio').set('text', 'Ha fallado el requerimiento..');
		}
	}).send();	
}

function get_novedades(){
	new Request({
		url: 'div_novedades.html',
		method: 'get',
		onRequest: function(){
			$('div_casosestudio').set('html', '<img src="imagenes/ajax-loader.gif" />');
		},
		onSuccess: function(txt){
			$('div_novedades').set('html', txt);
			new JFeedMoo('div.novedades','btnNovPrev','btnNovNext');
		},
		onFailure: function(){
			$('div_novedades').set('text', 'Ha fallado el requerimiento..');
		}
	}).send();	
}

function get_testimonios(){
	new Request({
		url: 'div_testimonios.html',
		method: 'get',
		onRequest: function(){
			$('div_testimonios').set('html', '<img src="imagenes/ajax-loader.gif" />');
		},
		onSuccess: function(txt){
			$('div_testimonios').set('html', txt);
			new JFeedMoo('div.testimonios','btnTestiPrev','btnTestiNext').playing(10000,true);	
		},
		onFailure: function(){
			$('div_testimonios').set('text', 'Ha fallado el requerimiento..');
		}
	}).send();	
}

function get_casosestudio(){
	new Request({
		url: 'div_casosestudio.html',
		method: 'get',
		onRequest: function(){
			$('div_casosestudio').set('html', '<img src="imagenes/ajax-loader.gif" />');
		},
		onSuccess: function(txt){
			$('div_casosestudio').set('html', txt);
			new JFeedMoo('div.casosestudio','btnCasoPrev','btnCasoNext');
		},
		onFailure: function(){
			$('div_casosestudio').set('text', 'Ha fallado el requerimiento..');
		}
	}).send();
}

function get_clientes(){
	new Request({
		url: 'div_clientes.html',
		method: 'get',
		onRequest: function(){
			$('div_clientes').set('html', '<img src="imagenes/ajax-loader.gif" />');
		},
		onSuccess: function(txt){
			$('div_clientes').set('html', txt);
			(new JFeedMoo('img.clientes','btnClientesPrev','btnClientesNext')).playing(4000,false);
		},
		onFailure: function(){
			$('div_clientes').set('text', 'Ha fallado el requerimiento..');
		}
	}).send();	
}

function get_contacto(){
	var req = new Request({
		url: 'div_contacto.html',
		method: 'get',
		onRequest: function(){
			$('div_contacto').set('text', '');
		},
		onSuccess: function(txt){
			$('div_contacto').set('html', txt);
			$("resultado_div_contacto").fade('hide');
			$("resultado_div_contacto").style.display = "none";
			set_contacto_rapido();
		},
		onFailure: function(){
			$('div_contacto').set('text', 'Ha fallado el requerimiento..');
		}
	});
	req.send();	
}

function set_contacto_rapido(){
	respOk = "<p style='padding:10px;'><br /><img src='imagenes/imgCheck.png'/><br /><br />El mensaje ha sido enviado.<br />En breve le estaremos respondiendo.<br /><br />Muchas Gracias</p>";
	respNotOk1 = "<p style='padding:10px;'><br /><img src='imagenes/imgError.png'/><br /><br />Por favor, complete todos los campos del formulario.</p>";
	respNotOk2 = "<p style='padding:10px;'><br /><img src='imagenes/imgError.png'/><br /><br />Por favor, ingrese un email valido.</p>";	
	$("form_contacto_rapido").addEvent('submit', function(e) {
		e.stop();
		this.set('send', {
			 onRequest: function(){
				$('loading_div_contacto').set('html', '<img src="imagenes/ajax-loader.gif" />');
			},
			onSuccess: function(respuesta) { 
				$('loading_div_contacto').set('html', '');
				
				$("resultado_div_contacto").style.display = "";
				
				if (respuesta=="0"){
					$('resultado_div_contacto').set('html', respOk);
					$("form_contacto_rapido").reset();
				}
				if (respuesta=="1"){
					$('resultado_div_contacto').set('html', respNotOk1);
				}
				if (respuesta=="2"){
					$('resultado_div_contacto').set('html', respNotOk2);
				}				
				
				$("tabla_contacto").style.display = "none";
				$("resultado_div_contacto").fade(1);
				
				setTimeout(function() { $("resultado_div_contacto").fade('hide');$('resultado_div_contacto').style.display = "none";$("tabla_contacto").style.display = "";$("tabla_contacto").fade('hide');$("tabla_contacto").fade(1); },3000);				
			}
		});
		this.send();
	});	
}

function set_contacto(){
	respOk = "<p style='font-size:13pt;'>El mensaje ha sido enviado. En breve le estaremos respondiendo.<br /><br />Muchas Gracias</p>";
	respNotOk1 = "<p style='color:#d40000;'>Por favor, complete los campos requeridos del formulario.</p>";
	respNotOk2 = "<p style='color:#d40000;'>Por favor, ingrese un email valido.</p>";	
	$("form_contacto").addEvent('submit', function(e) {
		e.stop();
		this.set('send', {
			 onRequest: function(){
				$('loading_div_contacto').set('html', '<img src="imagenes/ajax-loader.gif" />');
			},
			onSuccess: function(respuesta) { 
				
				if (respuesta=="0"){
					$('loading_div_contacto').set('html', respOk);
					$("form_contacto").reset();
				}
				if (respuesta=="1"){
					$('loading_div_contacto').set('html', respNotOk1);					
				}
				if (respuesta=="2"){
					$('loading_div_contacto').set('html', respNotOk2);
					$('email').focus();
				}				
				
				setTimeout(function() {$('loading_div_contacto').set('html', ""); },5000);				
			}
		});
		this.send();
	});	
}
