
var contentOpen = "";
var menuOpen = "";
var speed = 5;
var a = new Array();

window.onload = function() {
	loadAnchors();

	//datos personales
	setOnClick('#personales', function() { show('personales'); });
	setOnClick('#masdatospersonales', function() { showContent('masdatospersonales'); });

	//otros datos
	setOnClick('#otros', function() { show('otros'); });
	setOnClick('#masdatosdiseno', function() { showContent('masdatosdiseno'); });
	setOnClick('#masdatosdesarrollo', function() { showContent('masdatosdesarrollo'); });

	//proyectos
	setOnClick('#proyectos', function() { show('proyectos'); });
	setOnClick('#ruido', function() { showContent('ruido'); });
	setOnClick('#hermandad', function() { showContent('hermandad'); });
	setOnClick('#olierauto', function() { showContent('olierauto'); });
	setOnClick('#modal', function() { showContent('modal'); });
	setOnClick('#blog', function() { showContent('blog'); });
	setOnClick('#prieto', function() { showContent('prieto'); });

	//contacto
	setOnClick('#contacto', function() { show('contacto'); });

	//acerca de...
	setOnClick('#acercade', function() { showAbout('acercade'); });

	loadSection();

	setTimeout('load()', 1000);
};

load = function() {
	bytefx.fade(get('cargando'), 100, 0, speed, function() {
		setStyleClass('cargando', 'hidden');
	});
};

show = function(identificator) {
	if (menuOpen != '')
		hide(menuOpen, function() {
			bytefx.alpha(get(identificator), 0);
			deleteStyleClass(identificator, 'hidden');
			bytefx.fade(get(identificator), 0, 100, speed);
			menuOpen = identificator;
		});
	else {
		bytefx.alpha(get(identificator), 0);
		deleteStyleClass(identificator, 'hidden');
		bytefx.fade(get(identificator), 0, 100, speed);
		menuOpen = identificator;
	}

	if (contentOpen != '')
		hide(contentOpen, function() { contentOpen = ''; });

};

showContent = function(identificator) {
	if (contentOpen != '')
		hide(contentOpen, function() {
			bytefx.alpha(get(identificator), 0);
			deleteStyleClass(identificator, 'hidden');
			bytefx.fade(get(identificator), 0, 100, speed);
			contentOpen = identificator;
		});
	else {
		bytefx.alpha(get(identificator), 0);
		deleteStyleClass(identificator, 'hidden');
		bytefx.fade(get(identificator), 0, 100, speed);
		contentOpen = identificator;
	}
};

showAbout = function(identificator) {
	if (menuOpen != '')
		hide(menuOpen, function() {
			menuOpen = '';
		});
	if (contentOpen != '')
		hide(contentOpen, function() {
			bytefx.alpha(get(identificator), 0);
			deleteStyleClass(identificator, 'hidden');
			bytefx.fade(get(identificator), 0, 100, speed);
			contentOpen = identificator;
		});
	else {
		bytefx.alpha(get(identificator), 0);
		deleteStyleClass(identificator, 'hidden');
		bytefx.fade(get(identificator), 0, 100, speed);
		contentOpen = identificator;
	}
};

hide = function(identificator, callback) {
	bytefx.fade(get(identificator), 100, 0, speed, function() { setStyleClass(identificator, 'hidden'); callback.call(); });
};

setStyleClass = function(identificator, styleClass) {
	if (!hasStyleClass(identificator, styleClass)) {
		var className = new String(get(identificator).className);
		get(identificator).className = className + " " + styleClass;
	}
};

deleteStyleClass = function(identificator, styleClass) {
	if (hasStyleClass(identificator, styleClass)) {
		var className = new String(get(identificator).className);
		var className = className.replace(styleClass, '');
		get(identificator).className = className;
	}
};

hasStyleClass = function(identificator, styleClass) {
	var className = new String(get(identificator).className);
	return className.indexOf(styleClass) != -1;
};

setOnClick = function(identificator, func) {
	get(identificator).onclick = func;
};

get = function(identificator) {
	if (identificator == null || identificator == '')
		return null;

	if (identificator.indexOf('#') == 0) {
		return a[identificator];
	}
	return document.getElementById(identificator);
};

loadSection = function() {
	var loc = new String(document.location);
	if (loc.indexOf('#') != -1) {
		loc = loc.substring(loc.indexOf('#'), loc.length);

		if (loc == '#personales') {
			show('personales');
		} else if (loc == '#otros') {
			show('otros');
		} else if (loc == '#proyectos') {
			show('proyectos');
		} else if (loc == '#contacto') {
			show('contacto');
		} else if (loc == '#masdatospersonales') {
			show('personales');
			showContent('masdatospersonales');
		} else if (loc == '#masdatosdiseno') {
			show('otros');
			showContent('masdatosdiseno');
		} else if (loc == '#masdatosdesarrollo') {
			show('otros');
			showContent('masdatosdesarrollo');
		} else if (loc == '#ruido') {
			show('proyectos');
			showContent('ruido');
		} else if (loc == '#hermandad') {
			show('proyectos');
			showContent('hermandad');
		} else if (loc == '#olierauto') {
			show('proyectos');
			showContent('olierauto');
		} else if (loc == '#modal') {
			show('proyectos');
			showContent('modal');
		} else if (loc == '#blog') {
			show('proyectos');
			showContent('blog');
		} else if (loc == '#prieto') {
			show('proyectos');
			showContent('prieto');
		} else if (loc == '#acercade') {
			showAbout('acercade');
		}

	}
};

loadAnchors = function() {
	var anchors = document.getElementsByTagName('A');
	var name = '';
	for (var i = 0; anchors != null && i < anchors.length; i++) {
		name = new String(anchors[i].href);
		if (name.indexOf('#') != -1) {
			name = name.substring(name.indexOf('#'), name.length);
			a[name] = anchors[i];
		}
	}

};