addDOMLoadEvent=(function(){var e=[],t,s,n,i,o,d=document,w=window,r='readyState',c='onreadystatechange',x=function(){n=1;clearInterval(t);while(i=e.shift())i();if(s)s[c]=''};return function(f){if(n)return f();if(!e[0]){d.addEventListener&&d.addEventListener("DOMContentLoaded",x,false);/*@cc_on@*//*@if(@_win32||@_win64)d.write("<script id=__ie_onload defer src=//0><\/scr"+"ipt>");s=d.getElementById("__ie_onload");s[c]=function(){s[r]=="complete"&&x()};/*@end@*/if(/WebKit/i.test(navigator.userAgent))t=setInterval(function(){/loaded|complete/.test(d[r])&&x()},10);o=w.onload;w.onload=function(){x();o&&o()}}e.push(f)}})();

function main()
{

	$("a.inline").fancybox();

	$("#chkfrm").validate({
	  rules: {
		email: "required",
		email2: {
		  equalTo: "#email"
		}
	  }
	});

	var ie8 = false;
	var ie7 = false;
	var ie6 = false;

	if (/MSIE (\d+\.\d+);/.test(navigator.userAgent))
	{ //test for MSIE x.x;
		var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
		if (ieversion>=8)
			ie8 = true;
		else if (ieversion>=7)
			ie7 = true;
		else if (ieversion>=6)
			ie6 = true;
	}

	//alert (ie7);
	if (ie6 == false) 
	{
		$("form.jqtransform").jqTransform();
	}
	 
	if (ie6 == true)
	{
		$('#aboutList').accordion(
		{
			autoheight: false,
			active: false,
			alwaysOpen: false
		});
	} 
	 
	downloadSteps();
	clickTabs();
	document.getElementById("langs").onchange = langChange;
	
	$('#aboutList').accordion(
	{
		autoheight: false,
		active: false,
		alwaysOpen: false
	});
	
	$('#faqList').accordion(
	{
		header: 'a.title',
		autoheight: false,
		active: false,
		alwaysOpen: false,
		navigation: true
	});
		
	$(window).resize(function()
	{ 
		//alert(sectionActiva);
		webMov();
		webEvents();
		langChange();
	});
	
	webMov();
	webEvents();
}

addDOMLoadEvent(main);

function downloadSteps()
{
	var steps = document.getElementById("insteps");
	if(!steps) return;
	
	var estepes = ["insteps","instepse"], f = estepes.length, sli, n;
	
	var stepsImg =
	{
		'insteps'	: ["firefox_step1.png","firefox_step2.png","firefox_step3.png","firefox_step3.png"],
		'instepse'	: ["explorer_step1.png","explorer_step2.png","explorer_step3.png","explorer_step3.png"]
		
	};
	
	while(f--)
	{
		steps = document.getElementById(estepes[f]);
		sli = steps.getElementsByTagName("A");
		n = sli.length;
		steps._total = n -1;
		
		while(n--)
		{
			sli[n]._total = sli;
			sli[n]._actual = n;
			sli[n].onclick = function()
			{
				var a,k = this._total.length, b;
				while(k--)
				{
					a = this._total[k].id;
					
					document.getElementById(a + "_section").className = "";
					document.getElementById(a).parentNode.className = "";
				}
				
				this.parentNode.className = "active";
				document.getElementById(this.id + "_section").className = "active";
				
				b = this.parentNode.parentNode.id;
				a = document.getElementById(b + "_img");
				k = a.src.substring(0, a.src.lastIndexOf("/") + 1);
				
				a.src = k + stepsImg[b][this._actual];
				
				return false;
			}
		}
	}
	
	stepsTimer();
}

function stepsTimer()
{
	var clicks = ["insteps","instepse"], n = clicks.length, a, b;
	
	while(n--)
	{
		a = document.getElementById(clicks[n]);
		
		a._pas = a._pas || 0;
		
		b = a.getElementsByTagName("A");
		
		b[a._pas].onclick();
		
		a._pas++;
		if(a._pas > a._total) a._pas = 0;
	}
	
	setTimeout(stepsTimer,4000);
	
}

function clickTabs()
{
	$("ul.tabs").each(function()
	{
		$("ul.tabs li.tab").click(function()
		{
			var tab = $(this);
			tab.parent().children().removeClass("showing");
			tab.parent().children().removeClass("active");
			
			$(this).addClass("active");
			$("#" + this.id + "_cont").addClass("showing");
			
			return false;
		});
	});
}

function getUrlParams(u)
{
	u = u || window.location.href;
	u = u.substring(u.indexOf("?") + 1).split("&");
	
	var k,o = {}, n = u.length;
	while(n--)
	{
		k = u[n].split("=");
		o[k[0]] = k[1];
	}
	
	return o;
}

// -----------------------------------------------------------------------

function webMov()
{
	
	var ample = $("#main").innerWidth();
	var alt = $("#nonFooter").innerHeight();
	
	if(ample < 955) ample = 955;
	if(alt < 600) ample = 600;
	
	var blocks = $(".block"),k = blocks.length;
	
	var costat = k;
	
	var pos = new Array(costat), n = costat;
	
	while(n--)
	{
		pos[n] = {x: 0 , y: n * ample};
	}
	
	n = 0;
	blocks.each(function(){
		var a = pos[n++], jo = $(this);
		jo.css({'top': a.x + 'px','left': a.y + 'px','width': ample + 'px','height': alt + 'px', 'position' : 'absolute'});
		jo.data('x',a.x);
		jo.data('y',a.y);
		
		var menu = $("#menu_" + jo.children(':first-child').attr("id"));
		menu.data('x',a.x);
		menu.data('y',a.y);
		
	});
	
	$(".block").css({
		'display': 'none'
		});
	
	
	$("#nonFooter").css({
		'overflow-x': 'hidden',
		'overflow-y': 'scroll',
		'height' : 600 + 'px'
	 });
	
	$("#content").css({
		'width' : ample + 'px',
		'height': 100 + '%',
		'overflow': 'hidden',
		'visibility': 'visible',
		'top' : '0px',
		'display': 'block'
	 });
	 
	n = $("#menu li.selected a, #footer a.selected");
	
	$("#slider").css({
		'width' : ample * costat + 'px',
		'overflow': 'visible',
		'top': '0px',
		'left': '0px'
	});	
	
	$(".menu_home_block").css({
		'display': 'block',
		'height': 400 + 'px'
	});
	
};

function webEvents()
{
	
	$("#menu a, #footer a").click(function()
	{
		if(anim.timer) return;
		sectionActiva = '#section_' + this.id.substring(5);
		var activeBlock = $('.' + this.id + '_block');
		var altBlock = $('.' + this.id + '_block' + ' .content').innerHeight();
		
		//alert(sectionActiva);
		
		$("#menu li").removeClass("selected");
		$("#footer a").removeClass("selected");
		
		var jo = $(this);
		
		jo.parent().addClass("selected");
		jo.addClass("selected");		
		
		setTimeout
			(
					function()
					{
					
							var s = $("#slider");
		
							anim.main("slider",parseInt(s.css("top")),parseInt(s.css("left")),jo.data('x'),jo.data('y'));
							
							$(".block").css({
							'display': 'none'
							});
							
							$(activeBlock).css({
							'display': 'block',
							'height': altBlock + 'px'
							});	
					},
					500
			); 
		
		return false;
				
	});
	
	var seccio = window.location.hash;
	if(seccio.indexOf("section") == -1) return;
	seccio = seccio.substring(9);
	
	var sectionHeight = $('#' + seccio + ' .sectionTxt').innerHeight();
	var activeSeccio = $('.' + seccio + '_block');

	
	$(".block").css({
	'display': 'none'
	});
	
	$(activeSeccio).css({
	'display': 'block',
	'height': sectionHeight + 'px'
	});	
	
	seccio = $(".block > #" + seccio).parent();
	
	//$("#slider").css({'left': '-' + seccio.data('y') + 'px'});
	$("#slider").css({'left': (seccio.data('y') === void(0) ? '0px' : ('-' + seccio.data('y') + 'px') ) });
}

var sectionActiva = 'index';

function langChange()
{
	var url = window.location.href;
	
	var combo = document.getElementById('langs');
	var langValor = combo.selectedIndex;
	var langValue = combo.options[combo.selectedIndex].value;
		
	var sufijo = url.indexOf('#');
	var sufijo2 = sectionActiva.indexOf('#')
	
	//alert(sufijo2);
	
	if (sufijo != -1 && sufijo2 == -1 && substitution != '/#' && substitution != '/#de' && substitution != '/#en' && substitution != '/#es' && substitution != '/#fr' && substitution != '/#it' && substitution != '/de/#' && substitution != '/en/#' && substitution != '/es/#' && substitution != '/fr/#' && substitution != '/it/#') {
		var sectionVieja = url.substring(sufijo);
		sectionActiva = sectionVieja;
	}
	
	var substitutionNum = url.indexOf('/',10);
	var substitution = url.substring(substitutionNum);
	
	if (substitution == '/') {
	url = url + langValue + '/' + sectionActiva;
	window.location.href = url;
	return;
	}
	
	if (substitution == '/#') {
	url = url.replace('/#',"/" + langValue + "/" + sectionActiva);;
	window.location.href = url;
	return;
	}
	
	if (substitution == '/#de') {
	url = url.replace('/#de',"/" + langValue + "/" + sectionActiva);;
	window.location.href = url;
	return;
	}
	
	if (substitution == '/#en') {
	url = url.replace('/#en',"/" + langValue + "/" + sectionActiva);;
	window.location.href = url;
	return;
	}
	
	if (substitution == '/#es') {
	url = url.replace('/#es',"/" + langValue + "/" + sectionActiva);;
	window.location.href = url;
	return;
	}
	
	if (substitution == '/#fr') {
	url = url.replace('/#fr',"/" + langValue + "/" + sectionActiva);;
	window.location.href = url;
	return;
	}
	
	if (substitution == '/#it') {
	url = url.replace('/#it',"/" + langValue + "/" + sectionActiva);;
	window.location.href = url;
	return;
	}
	
	if (substitution == '/de/#') {
	url = url.replace('/de/#',"/" + langValue + "/" + sectionActiva);;
	window.location.href = url;
	return;
	}
	
	if (substitution == '/en/#') {
	url = url.replace('/en/#',"/" + langValue + "/" + sectionActiva);;
	window.location.href = url;
	return;
	}
	
	if (substitution == '/es/#') {
	url = url.replace('/es/#',"/" + langValue + "/" + sectionActiva);;
	window.location.href = url;
	return;
	}
	
	if (substitution == '/fr/#') {
	url = url.replace('/fr/#',"/" + langValue + "/" + sectionActiva);;
	window.location.href = url;
	return;
	}
	
	if (substitution == '/it/#') {
	url = url.replace('/it/#',"/" + langValue + "/" + sectionActiva);;
	window.location.href = url;
	return;
	}
	
	url = url.replace(substitution,"/" + langValue + "/" + sectionActiva);
	window.location.href = url;
	
}

//addDOMLoadEvent(langChange);

// -----------------------------------------------------------------------
// M.A. Coma Rivas
var anim =
{
	// pass, begining value, end value, end pass
	calc		: function(t,b,c,d){if((t/=d/2)<1) return c/2*t*t*t*t*t+b; return c/2*((t-=2)*t*t*t*t+2)+b;},
	sx			: 0,
	sy			: 0,
	ex			: 0,
	ey			: 0,

	main		: function(id,sx,sy,ex,ey)
	{
		//alert (ey);
		if(anim.timer) return;
		
		anim.obj = document.getElementById(id);
		
		anim.sx = sx;
		anim.sy = sy;
		anim.ex = -ex - sx;
		anim.ey = -ey - sy;
		
		//alert (anim.ey);
		
		anim.st1 = anim.st2 = 0;
		anim.en1 = anim.en2 = 30;
		

		anim.play();
	},
	
	play		: function()
	{
		anim.timer = setInterval(anim.anim,10);
	},
	
	anim		: function(a)
	{
		a = anim.obj.style;	
		
		//a.top = anim.calc(anim.st1,anim.sx,anim.ex,anim.en1) + "px";
		//a.left = anim.calc(anim.st2,anim.sy,anim.ey,anim.en2) + "px";
		//a.left = anim.calc(anim.st2,anim.sy,(anim.ey === void(0) ? 0 : anim.ey),anim.en2) + "px";
		//a.left = anim.calc(anim.st2,anim.sy,(anim.ey == NaN ? 0 : anim.ey),anim.en2) + "px";
		a.left = anim.calc(anim.st2,anim.sy,(isNaN(anim.ey) ? 0 : anim.ey),anim.en2) + "px";
		
		
		
		anim.st2 = anim.st1 += ( anim.st1 < anim.en1 || anim.stop() );
	},
	
	stop		: function()
	{
		clearInterval(anim.timer);
		anim.timer = null;
	}
};

// Menu changes to gray

var modifyPixel = function(data,i) {
  var average = (data[i]+data[i+1]+data[i+2])/3;
  data[i]   = average;
  data[i+1] = average;
  data[i+2] = average;   
}

var rectangleToGray = function(context,left,top,width,height){
  var imageData = context.getImageData(left,top,width,height);
  var data   = imageData.data;
  var length = data.length;
  for (var i = 0;i<length;i+=4) {
    modifyPixel(data,i);
  }
  context.putImageData(imageData, left, top); 
}

var canvasToGray = function(canvas,deltay) {
  var context = canvas.getContext('2d'); 
  var width  = canvas.width;
  var height = canvas.height;
  var y  = 0;
  deltay = deltay || height;
  var step = function() {
    rectangleToGray(context,0,y,width,deltay); 
    y += deltay;
    if (y<height) {
      var rest = height-y;
      if ( rest < deltay) deltay = rest;
      setTimeout(step,0);
    }
  }
  step();
}

var imageToGray = function(im) {

  var canvas = document.createElement("canvas");  
  
  if(canvas.getContext){
    canvas.width  = im.width  || im.offsetWidth; 
    canvas.height = im.height || im.offsetHeight; 
    canvas.getContext('2d').drawImage(im,0,0); 
    //im.parentNode.replaceChild(canvas,im); 
	//im.style.display = "none";
    im.parentNode.appendChild(canvas); 
    canvasToGray(canvas,10);
  }
  else {
    var nit = 100;     
    for (var j = 0;j<nit;j++)
       im.style.filter = 'progid:DXImageTransform.Microsoft.BasicImage(grayscale=1)';
  }
}

function clickMenu() {

	var menu = document.getElementById('menu');
	var apts = menu.getElementsByTagName('img');
	var aptsLink = menu.getElementsByTagName('a');	
	var aptsColor = menu.getElementsByTagName('canvas');
	
	var aptsLong = apts.length;
	var ind = 0;
	var indice = 0;
	var indice2 = 0;
	var indice3 = 0;
	var navegador = navigator.appName;
	
	var aptActivo = 'section_home';
	var url2 = window.location.href;
	var sufijo2 = url2.indexOf('#');
	var sufijoActivo2 = url2.substring(sufijo2);	
	var compruebaSufijo = sufijoActivo2.substring(0,1);	
	
	while (ind<aptsLong) {
		apts[ind].onclick = function() {
		
			var navegador = navigator.appName;
			
			if (navegador == "Netscape") 
			{
				
				if(resetCanvas(this)) 
				{
				this.style.display = "none";
				}
				else 
				{
				imageToGray(this);
				this.style.display = "none";
				}
				
			} else {
				
				if(resetCanvas(this)) 
				{
				}
				else 
				{
				imageToGray(this);
				}				
			}		
		}
		ind++;
	};	
	
	while (indice3<aptsLong) {
		apts[indice3].onmouseout = function() {
		
			var navegador = navigator.appName;
			
			if (navegador == "Netscape") 
			{				
				resetCanvas(this);
				this.style.display = "none";
				
			} else {			
				resetCanvas(this)
			}		
			
		}
		indice3++;
	};	
	
	while (indice2<aptsLong) {
		apts[indice2].onmouseover = function() {
		
			var navegador = navigator.appName;
			
			if (navegador == "Netscape") 
			{
				
				if(resetCanvas(this)) 
				{
				this.style.display = "none";
				}
				else 
				{
				imageToGray(this);
				this.style.display = "none";
				}
				
			} else {
				
				if(resetCanvas(this)) 
				{
				}
				else 
				{
				imageToGray(this);
				}				
				
			}	
			
		}
		indice2++;
	};	
	
	while (indice<aptsLong) {
		aptsLink[indice].onclick = function() {
			//alert (this.getElementsByTagName('img')[0]);
			var navegador = navigator.appName;
			
			if (navegador == "Netscape") 
			{
				
				if(resetCanvas(this.getElementsByTagName('img')[0])) 
				{
				this.getElementsByTagName('img')[0].style.display = "none";
				}
				else 
				{
				imageToGray(this.getElementsByTagName('img')[0]);
				this.getElementsByTagName('img')[0].style.display = "none";
				}
				
			} 
			else 
			{
				
				if(resetCanvas(this.getElementsByTagName('img')[0])) 
				{
				}
				else 
				{
				imageToGray(this.getElementsByTagName('img')[0]);
				}				
				
			}				
		}
		indice++;
	};
	
	// Activate menu option
	
	if (navegador == "Netscape") 
	{
		
		if (compruebaSufijo != '#')
		{
		imageToGray(apts[0]);
		apts[0].style.display = "none";
		}	
		
		if (sufijoActivo2 == '#section_home')
		{
		imageToGray(apts[0]);
		apts[0].style.display = "none";
		}
		
		if (sufijoActivo2 == '#section_about')
		{
		imageToGray(apts[1]);
		apts[1].style.display = "none";
		}
		
		if (sufijoActivo2 == '#section_sdownload')
		{
		imageToGray(apts[2]);
		apts[2].style.display = "none";
		}
		
		if (sufijoActivo2 == '#section_tell01')
		{
		imageToGray(apts[3]);
		apts[3].style.display = "none";
		}
		
		if (sufijoActivo2 == '#section_faq')
		{
		imageToGray(apts[4]);
		apts[4].style.display = "none";
		}
		
		if (sufijoActivo2 == ''){
		imageToGray(apts[0]);
		apts[0].style.display = "none";
		}
		
	}
	else
	{
	
		if (compruebaSufijo != '#')
		{
		imageToGray(apts[0]);
		}	
		
		if (sufijoActivo2 == '#section_home' || sectionActiva == 0)
		{
		imageToGray(apts[0]);
		}
		
		if (sufijoActivo2 == '#section_about')
		{
		imageToGray(apts[1]);
		}
		
		if (sufijoActivo2 == '#section_sdownload')
		{
		imageToGray(apts[2]);
		}
		
		if (sufijoActivo2 == '#section_tell01')
		{
		imageToGray(apts[3]);
		}
		
		if (sufijoActivo2 == '#section_faq')
		{
		imageToGray(apts[4]);
		}
	}
};
	

addDOMLoadEvent(clickMenu);

function resetCanvas(imagen)
{
	
	var menuColor = document.getElementById('menu');
	var aptsColor = menuColor.getElementsByTagName('img');
	var aptsColorLong = aptsColor.length;
	var indice = 0;
	while (indice<aptsColorLong)
	{
		//apts[indice].style.display = 'block';
		aptsColor[indice].style.display = 'block';
		aptsColor[indice].style.filter = 'progid:DXImageTransform.Microsoft.BasicImage(grayscale=0)';
		indice++;
	}
	
	var canvas = imagen.parentNode.getElementsByTagName("canvas");
	
	if(canvas.length)
	{
		canvas[0].style.display = "block";
		return true;
	}	
	return false;
};
