﻿var ajax=null;
var fto=1;
var fpago=1;
var wprod=132;
var ant=0;

function ref_desc(){
ajaxfLoader('datos','includes/descargas.php','reg=1',ajax,0);
}

window.onkeypress = function(elEvento) {
  var evento = elEvento || window.event;
  var codigo = evento.keyCode;    
  if(codigo > 36 & codigo < 41)
   return false;
}

function goToByScroll(id){
	$('html,body').animate({scrollTop: $("#"+id).offset().top-141},1000);
}

function focusIn(id)
{
	if(document.getElementById(id).value=='Buscar' || document.getElementById(id).value=='Usuario' || document.getElementById(id).value=='Contraseña')
	{
		document.getElementById(id).value='';
		document.getElementById(id).style.color='#000';
		//alert(document.getElementById(id).innerHTML);
	}	
}
function focusOut(id)
{
	if(document.getElementById('buscar').value == ''){ document.getElementById('buscar').value='Buscar'; document.getElementById('buscar').style.color='#999';}
	if(document.getElementById('user').value == ''){ document.getElementById('user').value='Usuario'; document.getElementById('user').style.color='#999';}
	if(document.getElementById('pass').value == ''){ document.getElementById('pass').value='Contraseña'; document.getElementById('pass').style.color='#999';}
}

function enviar_email()
{
	document.getElementById("formulario").submit();
	document.getElementById("visor").innerHTML='Enviando...';
}
function estado(msg)
{
	document.getElementById("visor").innerHTML='<b>'+msg+'</b>';
}
function carga_noticia(id)
{
	if(ant!=0) cerrar_noticia2(ant,id);
	else
	{
		goToByScroll("n"+id);
		document.getElementById("s"+id).innerHTML="&nbsp;&nbsp;x&nbsp;&nbsp;";
		$('#d'+id).animate({height: document.getElementById("t"+id).offsetHeight},1000,function(){document.getElementById("s"+id).attributes["onclick"].value="cerrar_noticia("+id+");";});
	}
	ant=id;
}
function cerrar_noticia2(ant,id)
{
	$('#d'+ant).animate({height: 140},1000,function(){
		document.getElementById("s"+ant).innerHTML="&nbsp;&nbsp;+&nbsp;&nbsp;";
		document.getElementById("s"+id).innerHTML="&nbsp;&nbsp;x&nbsp;&nbsp;";
		document.getElementById("s"+ant).attributes["onclick"].value="carga_noticia("+ant+");"; 
		goToByScroll("n"+id);
		$('#d'+id).animate({height: document.getElementById("t"+id).offsetHeight},1000,function(){document.getElementById("s"+id).attributes["onclick"].value="cerrar_noticia("+id+");";});
		});
}
function cerrar_noticia(id)
{
	$('#d'+id).animate({height: 140},1000,function(){
		document.getElementById("s"+id).attributes["onclick"].value="carga_noticia("+id+");";
		});
	document.getElementById("s"+id).innerHTML="&nbsp;&nbsp;+&nbsp;&nbsp;";
	ant = 0;
}

function mover(id)
{
	$('#'+id).animate({
    right: 3
     }, (300), function() {});
}
function move(id)
{
	$('#'+id).animate({
    bottom: 0
     }, (300), function() {});
}

function closem(id)
{
	$('#'+id).animate({
    bottom: -10
     }, (300), function() {});
	}
function prensa1(){
	$('#datos').animate({
    opacity: '0'
     }, (300), function() {});
	$('#tf_bg0').animate({
    opacity: '0',
	backgroundColor: "#ffffff"
     }, (300), function() {
		 document.getElementById('tf_bg0').innerHTML='';
		 ajaxfLoader('datos',"includes/publcaciones.php",'cant='+parseInt(($(window).width()-300)/250),ajax,2)
		});
	}
function prensa2(){
	ajaxfLoader('datos','includes/descargas.php','',ajax,0);
	}

function menu_notic(){
	 $('#datos').animate({
    opacity: '0'
     }, (300), function() {});
	$('#tf_bg0').animate({
    opacity: '0',
	backgroundColor: "#ffffff"
     }, (300), function() {
		 document.getElementById('tf_bg0').innerHTML='';
		 ajaxfLoader('datos',"includes/noticias.php",'',ajax,2);
		});
	}
function show_mn(){
	 $('#tf_bg0').animate({
			 opacity: '1',
			 }, (300), function() {});
	$('#datos').animate({
			 opacity: '1',
			 }, (600), function() {});
	}

function menu_filos(){
	$('#nameprod').animate({
    opacity: '0'
     }, (300), function() {});
	 $('#desp').animate({
    opacity: '0'
     }, (300), function() {});
	 $('#datos').animate({
    opacity: '0'
     }, (300), function() {});
	$('#tf_bg0').animate({
    opacity: '0'
     }, (300), function() {
		 document.getElementById('tf_bg0').innerHTML='';
		 ajaxfLoader('datos',"includes/filo.php",'',ajax,1)
		});
	}
	
function show_mf(){
	 $('#tf_bg0').animate({
			 opacity: '1',
			 backgroundColor: "#f1f1f3"
			 }, (300), function() {});
	$('#datos').animate({
			 opacity: '1',
			 }, (600), function() {});
}

function menu_cont(){
	$('#nameprod').animate({
    opacity: '0'
     }, (300), function() {});
	 $('#desp').animate({
    opacity: '0'
     }, (300), function() {});
	 $('#datos').animate({
    opacity: '0'
     }, (300), function() {});
	$('#tf_bg0').animate({
    opacity: '0'
     }, (300), function() {
		 document.getElementById('tf_bg0').innerHTML='';
		 ajaxfLoader('datos',"includes/cont.php",'',ajax,3)
		});
	}
	
function show_mc(){
	 $('#tf_bg0').animate({
			 opacity: '1',
			 backgroundColor: "#f1f1f3"
			 }, (300), function() {});
	$('#datos').animate({
			 opacity: '1',
			 }, (600), function() {});
}

function off_desp(tam,num){
	if(num==1)
		{
		ch_tam(tam,0,'desp_prod',0.3);
		ch_tam(tam,0,'desp_not',0.3);
		ch_tam(tam,0,'desp_prensa',0.3);	
		}
	else if(num==2)
		{
		
		}
	else{
		
		}				
	}
function ch_tam(w,h,id,seg){
	$('#'+id).animate({
    height: h,
	width: w,
     }, (seg*1000), function() {});
	}

function ini(){
	 $('#tf_bg0').animate({
	 width: $(window).width(),
	 height: $(window).height()-80
	 }, (50), function() {});
	 
	 resize($('#tf_bg0img'));
	 
	 $('#tf_bg0').animate({
	 opacity: '1',
	 }, (800), function() {});	
}
function resize($img){
	var w_w	= $(window).width(),
		w_h	= $(window).height(),
		i_w	= $img.width(),
		i_h	= $img.height(),
		r_i	= i_h / i_w;
	w_f=(i_w*$(window).height())/i_h;
	if(w_f<$(window).width())
		{
		w_f=$(window).width();
		h_f=(i_h*$(window).width())/i_w;
		left=0;
		top=($(window).height()-h_f)/2;
		}
	else
		{
		h_f=$(window).height();
		left=($(window).width()-w_f)/2;
		top=0;	
		}
		
	$img.animate({
		width	: w_f,
		height	: h_f,
		top		: top,
		left	: left
	},50);
}

function ajaxfLoader(control,url,valores,objetoajax,func){
objetoajax = new XMLHttpRequest();
objetoajax.open("GET",url+ "?" + valores, true);
objetoajax.onreadystatechange=function()
{
if (objetoajax.readyState == 1){
	
}
if (objetoajax.readyState == 4)
{
	if (objetoajax.status == 200) 
	{
		document.getElementById(control).innerHTML=objetoajax.responseText;
		if(func==0)FB.XFBML.parse();
		if(func==1)ajaxfLoader('datos','includes/producto.php',valores,ajax,0);
		if(func==2)ajaxfLoader('carrito','includes/mod_carrito.php','',ajax,0);
		if(func==3)BannerIni();
		if(func==4)goToByScroll('n'+ant);
	}
	else 
	{
		alert("Error al cargar datos.");
	}
}
}
objetoajax.send(null);
}

function next_img(){
	tmp=ides.split(',');
	if(fto<tmp.length-1)
	{
		 document.getElementById('tf_bg1img').src=tmp[fto+1];
		 
		 $('#tf_bg1').animate({
		 opacity: '0'
		 }, (50), function() {
		$('#tf_bg1').animate({
		 width: $(window).width(),
		 height: $(window).height()-80,
		 left:$(window).width() 
		 }, (50), function() {
			 resize($('#tf_bg1img'));
			 $('#tf_bg1').animate({
		 opacity: '1'
		 }, (50), function() {
			 
			 $('#tf_bg0').animate({
			 left: $(window).width()*-1
			 }, (1000), function() {});
			 fto++;
			 document.getElementById('pg').innerHTML=fto;
			 $('#tf_bg1').animate({
			 left: 0
			 }, (1000), function() {
				 
				document.getElementById("tf_bg1").setAttribute("id","tmp0");
				document.getElementById("tf_bg0").setAttribute("id","tf_bg1");
				document.getElementById("tmp0").setAttribute("id","tf_bg0");
				document.getElementById("tf_bg1img").setAttribute("id","tmp0");
				document.getElementById("tf_bg0img").setAttribute("id","tf_bg1img");
				document.getElementById("tmp0").setAttribute("id","tf_bg0img");
				 });
			 });});});
	}
	}

function prev_img(){
	tmp=ides.split(',');
	if(fto>1)
	{
		document.getElementById('tf_bg1img').src=tmp[fto-1];
		
		$('#tf_bg1').animate({
		 opacity: '0'
		 }, (50), function() {
		$('#tf_bg1').animate({
		 width: $(window).width(),
		 height: $(window).height()-80,
		 left:(-1*$(window).width()) 
		 }, (50), function() {
			 resize($('#tf_bg1img'));
			 $('#tf_bg1').animate({
		 opacity: '1'
		 }, (50), function() {
			 
			 $('#tf_bg0').animate({
			 left: $(window).width()
			 }, (1000), function() {});
			 fto--;
			 document.getElementById('pg').innerHTML=fto;
			 $('#tf_bg1').animate({
			 left: 0
			 }, (1000), function() {
				 
				document.getElementById("tf_bg1").setAttribute("id","tmp0");
				document.getElementById("tf_bg0").setAttribute("id","tf_bg1");
				document.getElementById("tmp0").setAttribute("id","tf_bg0");
				document.getElementById("tf_bg1img").setAttribute("id","tmp0");
				document.getElementById("tf_bg0img").setAttribute("id","tf_bg1img");
				document.getElementById("tmp0").setAttribute("id","tf_bg0img");
				 });
			 });});});	
	}
}

var img=1;
var temp;
function BannerGo()
{
	if(document.getElementById('banner')) document.getElementById('banner').style.background = 'url(images/inicio'+(img)+'.jpg)';
	temp=setTimeout("img++;if(img==4) img=1;BannerGo();",6000);
}
function BannerIni()
{
	clearTimeout(temp);
	BannerGo();
}

function handleChange(evt){
	if(evt.pathNames[0]){
		//if(evt.pathNames[0]=='aux')history.back();
		if(evt.pathNames[0]=='' || evt.pathNames[0]=='inicio')
		{
			document.location = 'http://www.mutdesign.com';
		}
		else if(evt.pathNames[0]=='filosofia')
		{
			ajaxfLoader('datos','includes/filo.php','',ajax,0);
			ch_tam(wprod,0,'desp_nosotros',0.3);ch_tam(wprod,0,'desp_prensa',0.3);ch_tam(wprod,0,'desp_prod',0.3);ch_tam(wprod,0,'desp_grf',0.3);
		}
		else if(evt.pathNames[0]=='estudio')
		{
			ajaxfLoader('datos','includes/estudio.php','',ajax,0);
			ch_tam(wprod,0,'desp_nosotros',0.3);ch_tam(wprod,0,'desp_prensa',0.3);ch_tam(wprod,0,'desp_prod',0.3);ch_tam(wprod,0,'desp_grf',0.3);
		}
		else if(evt.pathNames[0]=='amigos')
		{
			ajaxfLoader('datos','includes/amigos.php','',ajax,0);
			ch_tam(wprod,0,'desp_nosotros',0.3);ch_tam(wprod,0,'desp_prensa',0.3);ch_tam(wprod,0,'desp_prod',0.3);ch_tam(wprod,0,'desp_grf',0.3);
		}
		else if(evt.pathNames[0]=='noticias') ajaxfLoader('datos','includes/noticias.php','id='+evt.pathNames[1],ajax,0);
		else if(evt.pathNames[0]=='producto')
		{
			ajaxfLoader('datos','includes/producto.php','id='+evt.pathNames[1],ajax,0);
			ch_tam(wprod,0,'desp_nosotros',0.3);ch_tam(wprod,0,'desp_prensa',0.3);ch_tam(wprod,0,'desp_prod',0.3);ch_tam(wprod,0,'desp_grf',0.3);
		}
		else if(evt.pathNames[0]=='grafico')
		{
			ajaxfLoader('datos','includes/grafico.php','id='+evt.pathNames[1],ajax,0);
			ch_tam(wprod,0,'desp_nosotros',0.3);ch_tam(wprod,0,'desp_prensa',0.3);ch_tam(wprod,0,'desp_prod',0.3);ch_tam(wprod,0,'desp_grf',0.3);
		}
		else if(evt.pathNames[0]=='publicaciones')
		{
			ajaxfLoader('datos','includes/publicaciones.php','',ajax,0);
			ch_tam(wprod,0,'desp_nosotros',0.3);ch_tam(wprod,0,'desp_prensa',0.3);ch_tam(wprod,0,'desp_prod',0.3);ch_tam(wprod,0,'desp_grf',0.3);
		}
		else if(evt.pathNames[0]=='descargas')
		{
			ajaxfLoader('datos','includes/descargas.php','',ajax,0);
			ch_tam(wprod,0,'desp_nosotros',0.3);ch_tam(wprod,0,'desp_prensa',0.3);ch_tam(wprod,0,'desp_prod',0.3);ch_tam(wprod,0,'desp_grf',0.3);
		}
		else if(evt.pathNames[0]=='contacto') ajaxfLoader('datos','includes/cont.php','',ajax,0);
	}
}
