function init() {
	fill(fillWith(), "content");
	setMailingListTheme();
}
//Funciones
function fillWith() {

	var path = location.href;
	var selectedSection = path.substring(path.lastIndexOf('?')+1, path.length);
	
	if (selectedSection == "estudio" || selectedSection == "galeria" || selectedSection == "shop") {
		changeSourceById('imgTop', 'images/' + selectedSection + 'Top.jpg');
		return "php/"+selectedSection+".php";
	} else {
		return "php/main.php";
	}
	
}
function setMailingListTheme() {
	var eEmail = document.getElementById("email");
	eEmail.value = 'Subscríbete';
	eEmail.style.color = 'gray';
	document.getElementById("submitNewsletter").disabled = true;
}
function resetMailingListTheme(eEmail) {
	if (eEmail.value == 'Subscríbete' && eEmail.style.color == 'gray') { 
		eEmail.value = '';
		eEmail.style.color ='black';
		document.getElementById("submitNewsletter").disabled = false;
	}
}
function changeSourceById(id, src) {
	document.getElementById(id).src = src;
}
function scrollUp(object) {
	object.scroll(0,0);
}
function gotoEstudio() {
	fill('php/estudio.php', 'content');
	changeSourceById('imgTop', 'images/estudioTop.jpg');
}
function gotoGaleria() {
	fill('php/galeria.php', 'content');
	changeSourceById('imgTop', 'images/galeriaTop.jpg');
}
function gotoShop() {
	fill('php/shop.php', 'content');
	changeSourceById('imgTop', 'images/shopTop.jpg');
}
function gotoMain() {
	fill('php/main.php', 'content');
	changeSourceById('imgTop', 'images/top.jpg');
}
//Ajax | Cloro
function ajaxObject() {
	var request = null;
	if(window.XMLHttpRequest){
		request = new XMLHttpRequest();
	} else if(window.ActiveXObject) {
		request = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		document.getElementById("content").innerHTML = "Lo sentimos, su browser no soporta ajax.  Por favor descargue un browser mas actualizado.  <br />Gracias";
	}
	return request;
}

function fill(file, place, method) {

	var request = ajaxObject();
	
	request.onreadystatechange = function() {
		if(request.readyState == 4) {
			document.getElementById(place).innerHTML = request.responseText;
			document.body.style.cursor = 'auto';
		}
	}
	document.body.style.cursor = 'wait';
	request.open ("GET", file, true);
	request.send (null);
}
//Estudio
function showProject(id) {
	if (id != "") {
		fill("php/estudio.php?ID=" + id, "portafolio");
	}
}
//Galeria
function showGaleryProject(id) {
	if (id != "") {
		fill("php/galeria.php?ID=" + id, "portafolio");
	}
}
function galeria(folder, imageArray) {
	var images = "<div id='innerPortfolio' ><div class='hr'><hr /></div><div id='scroll'><table id='innerPortafolioTable' ><tr>";
	for (var i = 0; i < imageArray.length;i++) {
		images += "<td style='margin:10px'><img src='../trabajos/"+folder+"/"+imageArray[i]+"'></td>";
	}
	images += "</tr></table></div></div>";
	document.getElementById('portafolio').innerHTML = images;
	//customResizeParentById(450, "iFrame");
}
function refreshBlog() {
	document.getElementById('blog').src = "php/wordpress/index.php";
}