	// JavaScript Document
	
	
	var current_project = 0;
	var number_of_projects = 0;
	var current_slide = new Array();
	var slides = new Array();
	var time_between_projects = 4000; //miliseconds
	var current_banner = 0;
	var time_between_banner_slides = 5000; //miliseconds
	var rotation;
	
	
	
	
	function MM_validateForm() { //v4.0
	  if (document.getElementById){
		var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
		for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
		  if (val) { nm=val.name; if ((val=val.value)!="") {
			if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
			  if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
			} else if (test!='R') { num = parseFloat(val);
			  if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
			  if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
				min=test.substring(8,p); max=test.substring(p+1);
				if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
		  } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
		} if (errors) alert('The following error(s) occurred:\n'+errors);
		document.MM_returnValue = (errors == '');
	} }
	
	Array.prototype.max = function() {
	var max = this[0];
	var len = this.length;
	for (var i = 1; i < len; i++) if (this[i] > max) max = this[i];
	return max;
	}
	Array.prototype.min = function() {
	var min = this[0];
	var len = this.length;
	for (var i = 1; i < len; i++) if (this[i] < min) min = this[i];
	return min;
	}

	function align(clase){
		//align the table columns
		clase = "."+clase;
		var columns = $(clase);
		var box = new Array();
		var max_boxes = new Array();
		for(i = 0; i < columns.length ; i++)
		{
			box[i] = $(columns[i]).children(".box");
			max_boxes.push(box[i].length);
		}
		var boxes_number = max_boxes.max();
		for(j = 0; j < boxes_number; j ++)
		{
			var heights = new Array();
			for(i = 0; i < columns.length ; i++)
			{
				//if(box[i].length > j)
				//{	
					if (j < ( box[i].length - 1))
					{
						heights.push($(box[i][j]).height());
					}
				//}
			}
			var max_height = heights.max() + "px";
			for(i = 0; i < columns.length ; i++)
			{
				if (j < ( box[i].length - 1))
				{
					$(box[i][j]).css({"height":max_height});
				}
			}
		}
		var heights = new Array();
		for(i = 0; i < columns.length ; i++)
		{
			heights.push($(columns[i]).height());
		}
		
		var max_height = heights.max();
		//making every last box heigh enough to align all tables
		
		for(i = 0; i < columns.length ; i++)
		{
			var difference = max_height - $(columns[i]).height();
			var current_height = $(box[i][( box[i].length - 1 )]).height();
			var new_height = ( current_height + difference ) + "px";
			$(box[i][( box[i].length - 1 )]).css({"height" : new_height});
		}
		
		$(".cb-corner").css({"bottom":"0px"});
	}

	function start_banner(){
	// Banner
		
		$("#banner .cover").fadeTo(0,0);
		$("#banner .cover").css({"display":"none"});
		$("#banner .controls .button").click(function(){
		
			change_banner($(this).html()-1);
		
		});
		var banner_slides = $("#banner .content .slide");
		for(i = 0; i < banner_slides.length; i ++)
		{
			var display = (i == 0) ? "block" : "none";
			$(banner_slides[i]).css({"display":display});
		}
		
		rotation = setTimeout("rotate_banner();",time_between_banner_slides);
	
	
	
		// Align columns by making both paragraphs the same height.
		var heights = new Array();
		
		heights.push($("#paragraph-A").height());
		heights.push($("#paragraph-B").height());
		// Function max() is defined in //scripts/functions.js
		var Max = heights.max() + "px";
		$("#paragraph-A").css({"height":Max});
		$("#paragraph-B").css({"height":Max});

		//Get the number of boxes to align (gets the column with more boxes, in case in a later time, one column has more boxes than the other)
		var boxes_number = new Array();
		var cols = $(".content-col");
		boxes_number.push($(cols[0]).children(".index-box").size());
		boxes_number.push($(cols[1]).children(".index-box").size());
		var boxes_number = boxes_number.max();
		
		//Name the columns
		var colA = $(cols[0]).children(".index-box");
		var colB = $(cols[1]).children(".index-box");
		// For each row, adjust height in both boxes.
		for(i = 0; i < boxes_number; i++)
		{
			//same as with paragraphs
			heights = new Array();
			
			heights.push($(colA[i]).height());
			heights.push($(colB[i]).height());
			var Max = heights.max() + "px";
			$(colA[i]).css({"height":Max});
			$(colB[i]).css({"height":Max});
		}
		
		var projects = $("#featured-project").children(".project");
		heights = new Array();
		number_of_projects = projects.length;
		
		for(i = 0; i < number_of_projects; i ++){
			//Hide all but the first project
			var display = (i == 0) ? "block" : "none";
			$(projects[i]).css({"display":display});
			
			var pr_slides = $(projects[i]).children(".slideshow").children(); //get number of slides for every panel
			for(j = 0; j < pr_slides.length; j++)
			{
				display = (j == 0) ? "block" : "none";
				var fade = (j == 0) ? 1 : 0;
				$(pr_slides[j]).css({"display":display});
				$(pr_slides[j]).fadeTo(0,fade);
			}
			
			current_slide.push(0); // for every panel
			slides.push(pr_slides.length); 
			heights.push($(projects[i]).height());
		}
		// Adjust the height of the div to the max height of its children elements
		var cover_height = (heights.max())+"px";
		$("#featured-project #cover").css({"height":cover_height});
		$("#featured-project #cover").fadeTo(0,0);
		var Max = (heights.max() + 25)+"px";
		$("#featured-project").css({"height":Max});
		setTimeout("change_slide();",time_between_projects);	
	}
	
		function change_slide(){
		//Get the current project and its slides
		var projects = $(".project");
		var project = projects[current_project];
		var pr_slides = $(project).children(".slideshow").children();
		//Check if the current project current slide is the last, if it isn't, then change the slide; otherwise change the project
		if(current_slide[current_project] < slides[current_project] - 1)
		{
		//Current slide is not the last one
			//fade slide
			$(pr_slides[current_slide[current_project]]).fadeTo(400,0,function(){
				//hide after fading and show next slide
				$(pr_slides[current_slide[current_project]]).css({"display":"none"});
				$(pr_slides[current_slide[current_project]+1]).css({"display":"block"});
				//fade in next slide
				$(pr_slides[current_slide[current_project]+1]).fadeTo(400,1);
				//change current_slide value
				current_slide[current_project] = (current_slide[current_project] + 1) % slides[current_project];
				//call the function again
				setTimeout("change_slide();",time_between_projects);
			});
			
		}
		else
		{
		//Current slide is the last one
			//Fade out whole panel
			$("#featured-project #cover").fadeTo(400,1,function(){
				//Reset panel
				$(pr_slides[current_slide[current_project]]).css({"display":"none"});
				$(pr_slides[current_slide[current_project]]).fadeTo(0,0);
				$(pr_slides[0]).css({"display":"block"});
				$(pr_slides[0]).fadeTo(0,1);
				current_slide[current_project] = 0;
				//Hide Panel
				$(projects[current_project]).css({"display":"none"});
				//Change current project value
				current_project = (current_project + 1) % number_of_projects;
				//Fade in next panel
				$(projects[current_project]).css({"display":"block"});
				$("#featured-project #cover").fadeTo(400,0);
				//call the function again
				setTimeout("change_slide();",time_between_projects);
			});
		}
	}
	function rotate_banner()
	{
		var number_of_banners = $("#banner .content .slide").size();
		var next_banner = (current_banner + 1) % number_of_banners;
		change_banner(next_banner);
	}
	
	function change_banner(number)
	{
		if(number != current_banner)
		{
			clearTimeout(rotation);
			current_banner = number;
			var b_slides = $("#banner .content .slide");
			var b_buttons = $("#banner .controls .button");
			for(i = 0; i < b_slides.length; i++){
				(i == number) ? $(b_buttons[i]).addClass("activated") : $(b_buttons[i]).removeClass("activated");
			}
			$("#banner .cover").stop(true);
			$("#banner .cover").css({"display":"block"});
			$("#banner .cover").fadeTo(400,1,function(){
				for (i = 0; i < b_slides.length; i++)
				{
					var display = (i == number) ? "block" : "none";
					$(b_slides[i]).css({"display":display});
				}
				$("#banner .cover").fadeTo(400,0,function(){
					$("#banner .cover").css({"display":"none"});
					rotation = setTimeout("rotate_banner();",time_between_banner_slides);
				});
			});
		}
	}
	
	function page_setup(){};
	
	//Setup
	$(document).ready(function(){
			
		//Fill Colorboxes
		if($(".color-box").size() > 0)
		{
			var Boxes = $(".color-box");
			for (i = 0 ; i < Boxes.length ; i ++)
			{
				var text = $(Boxes[i]).html();
				var text = text + ' <div class="cb-corner cbc-bl"></div><div class="cb-corner cbc-br"></div><div class="cb-corner cbc-tl"></div><div class="cb-corner cbc-tr"></div>';
				
				if( ($(Boxes[i]).hasClass("autoborder-off")) == false )
				{
					$(Boxes[i]).html(text);
				}
				
			}
		}
		
		page_setup();

	});
