/**
 * @author rvalle
 */
var screenWidth=screen.width;
var screenHeight=screen.height;
var browser=navigator.appName;
function fixPositions(){
	var calculado=Number(Number(screenWidth)-895)/2;
	if (browser === "Microsoft Internet Explorer"){
		calculado/=2;
	}
	var target=document.getElementById("alignPictures");
	target.style.marginLeft=calculado+"px";
}
function assignEvents(){
	/*************** PICTURES ******************/
	//document.getElementById("picture1").onclick=function(){alert("ok")}
	document.getElementById("picture1").onclick = function(){
		changeBackground("pictures/bop_customers.jpg", "bigPicture");
		fillContent(null,'content');
		assignEvents();
	}
	document.getElementById("picture2").onclick = function(){
		changeBackground("pictures/phone_call.jpg", "bigPicture");
		fillContent('technology','content');
	}
	document.getElementById("picture3").onclick = function(){
		changeBackground("pictures/renewable_energy.jpg", "bigPicture");
		fillContent('energy','content');
	}
	document.getElementById("picture4").onclick = function(){
		changeBackground("pictures/home.jpg", "bigPicture");
		fillContent('customers','content');
	}
	document.getElementById("picture5").onclick = function(){
		changeBackground("pictures/bottom_of_the_pyramid.jpg", "bigPicture");
		fillContent('pyramid','content');
	}
	/*******************************************/
	/**************** LINKS ********************/
	document.getElementById("energy").onclick=function(){
		changeBackground("pictures/renewable_energy.jpg", "bigPicture");
		fillContent('energy','content');
	}
	document.getElementById("pyramid").onclick=function(){
		changeBackground("pictures/bottom_of_the_pyramid.jpg", "bigPicture");
		fillContent('pyramid','content');
	}
	document.getElementById("customers").onclick=function(){
		changeBackground("pictures/home.jpg", "bigPicture");
		fillContent('customers','content');
	}
	/*******************************************/
	document.getElementById("btSend").onclick=function(){
		sendThis(this);
	}
}
function changeBackground(fileName, idTarget){
	document.getElementById(idTarget).src=fileName;
}
function fillContent(theme, idTarget){
	var content;
	switch(theme){
		case "energy":
			content='Electricity is generated by pedaling from location to location or in one place by dropping a kick stand to elevate the back tire. The electricity is stored in a car battery which takes ten minutes of pedaling for one hour of use.<br /><br /><a href="#video">View Video</a>';
			break;
		case "pyramid":
			content='The bike is sold at cost and a profit is generated from the reselling of national and international minutes to the entrepreneur. The bike costs $1,900 and we are working with banks to give a two year loan with monthly payments of $100.<br /><br /><a href="#video">View Video</a>';
			break;
		case "technology":
			content='Llamadas Pedaleadas is made of old parts such as a car alternator, car battery and computer battery backup UPS to convert the electricty generated into 110V. National calls are made using cell phone chips in fixed cellular terminals and the billing system shows the customer how much the call is costing him and allows the owner to view sales reports online.<br /><a href="#video">View Video</a>';
			break;
		case "customers":
			content='50% of Nicaraguans have cell phones yet everyday they come to phone call shops to place national phone calls at a cheaper rate. Cell phones are mainly used to receive calls and as an address book. Llamadas Pedaleadas allows the customers to get the same price as a call shop but without the long walk.<br /><br /><a href="#video">View Video</a>';
			break;
		default:
			content='Llamadas Pedaleadas is a ready made, <a id="energy" href="javascript:void(0)">renewable energy</a> business for <a id="pyramid" href="javascript:void(0)">bottom of the pyramid</a> entrepreneurs in Nicaragua that doubles the average monthly salary by selling <a id="customers" href="javascript:void(0)">national and international phone calls</a> in the central park or other populous locations.<br /><br /><a href="#video">View Video</a>';
			break;
	}
	document.getElementById(idTarget).innerHTML=content;
}
function sendThis(buttonObject){
	var career="";
	var name=escape(document.getElementById("name").value);
	var email=escape(document.getElementById("email").value);
	var phone=escape(document.getElementById("phone").value);
	var country=escape(document.getElementById("country").value);
	if (document.getElementById("journalist").checked==true){
		career="Journalist";
	}
	if (document.getElementById("entrepreneur").checked==true){
		career="Entrepreneur";
	}
	if (document.getElementById("curious").checked==true){
		career=escape("Curious Person");
	}
	if (career!="" && name!="" && email!="" && phone!="" && country!=""){
		var emailer=myObject();
		if (emailer==null){
			alert("Your browser is not supported");
			return;
		}
		var seed=Math.random()*10;
		var url="sendThis.php?career="+career+"&name="+name+"&email="+email+"&phone="+phone+"&country="+country+"&seed="+seed;
		emailer.open("get",url,true);
		emailer.onreadystatechange=function(){
			if (emailer.readyState==4){
				document.getElementById("name").value="";
				document.getElementById("email").value="";
				document.getElementById("phone").value="";
				document.getElementById("country").value="";
				buttonObject.value="Sent!";
				buttonObject.disabled=true;
			}
		}
		emailer.send(null);
	}
	else{
		alert("Please fill out all the fields of the form");
	}
}
function myObject(){
	var xmlHttp=null;
	try{
	  	// Firefox, Opera 8.0+, Safari
	  	xmlHttp=new XMLHttpRequest();
	}
	catch (e){
	  	// Internet Explorer
	  	try{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
	  	catch (e){
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}