/*
 * Projects module
 *
 * Copyright (c) 2011 Senscape s.r.l. (senscape.net)
 *
 */

var projLong = ['Asylum', 'Beyond Worlds', 'Dagon'];
var projShort = ['asylum', 'beyond', 'dagon'];
var projDetail = ["<p style='text-align:center'><img src='images/logo_asylum.png'/></p>" +
	"<p>Decay surrounds you, dread around every corner. You feel imprisoned while traversing the endless hallways... <b>Asylum</b> is a chilling journey through the intricate floors of the Hanwell Mental Institute, in which unimaginable atrocities have occurred in the past. This horror adventure aims to marry cutting edge visuals with thrilling storytelling to give you the ultimate experience in fear.</p>" +
	"<a href='http://www.FaceTheHorror.com' target='_blank'><b>Visit the website &raquo;</b></a><br/>" +
	"<a href='forum/viewforum.php?f=6'><b>Discuss in forum &raquo;</b></a><br/>" +
	"<a href='http://www.Slightly-Deranged.com/?tag=asylum' target='_blank'><b>Read the blog &raquo;</b></a>",
	"<p style='text-align:center'><img src='images/logo_beyond.png'/></p>" +
	"<p>A unique take in social games, <b>Beyond Worlds</b> is a science fiction story that unfolds in episodic form. Explore countless of planets, gathering valuable resources, strange alien artifacts and even encountering new civilizations. For once your decisions truly matter and your discoveries can have a profound impact on the story. Blending elements of role-playing games and adventures, this is social gaming for the rest of us.</p>" +
	"<a href='http://www.Beyond-Worlds.com' target='_blank'><b>Visit the website &raquo;</b></a><br/>" +
	"<a href='forum/viewforum.php?f=19'><b>Discuss in forum &raquo;</b></a><br/>",
	"<p style='text-align:center'><img src='images/logo_dagon.png'/></p>" +
	"<p>The backbone of our flagship project <b>Asylum</b>, <b>Dagon</b> is a game engine especially tailored for adventure games and based on open technologies. Featuring a deceptively simple scripting language, blazing fast performance and high portability supporting Windows, Linux, Mac OS X and iOS devices, the project aims to become a referendum of the genre.</p>" +
	"<a href='http://www.senscape.net/forum/viewforum.php?f=16'><b>Discuss in forum &raquo;</b></a><br/>"];

var btnMargin = 17;
var btnWidth = 250;

var projActive = '';
var displace = '';

function switchProject(back) {
	if (back) {
		$('#'+projActive+'_shine').fadeIn(1000);
		$('#'+projActive+'_detail').fadeOut(1000);
		$('#back').fadeOut(1000);
		$('#'+projActive).animate({
			marginLeft: displace,
		  }, 1500, function() {
			for (i = 0; i < projShort.length; i++) {
				$('#' + projShort[i]).fadeIn(1000);
				$('#' + projShort[i] + '_shine').show();
			}
  		});
  		projActive = '';
  		displace = '';
	}
	else {
		$('#'+projActive+'_shine').fadeOut(1000);
		$('#back').fadeIn(1000);
		for (i = 0; i < projShort.length; i++) {
			if (projShort[i] != projActive)
				$('#' + projShort[i]).fadeOut(1000);
		}
		displace = $('#'+projActive).css('margin-left');
		
		$('#'+projActive).animate({
			marginLeft: '20px',
		  }, 1500, function() {
			$('#' +projActive+'_detail').fadeIn(1000);
  		});
	}
}

function switchProjectInstant(project) {
	if (projActive != project) {
		if (displace != '')
			$('#'+projActive).css('margin-left', displace);

		projActive = project;
		displace = $('#'+projActive).css('margin-left');
	}

	for (i = 0; i < projShort.length; i++) {
		$('#' + projShort[i] + '_shine').hide();
		if (projShort[i] != projActive) {
			$('#' + projShort[i]).hide();
			$('#' + projShort[i] + '_detail').hide();
		}
	}
		
	$('#'+projActive).show();
	$('#'+projActive).css('margin-left', '20px');
	$('#'+projActive+'_detail').show();
	$('#back').show();
}

var sep = btnMargin;
for (i = 0; i < projShort.length; i++) {
	$('#projects_full').append("<div id='"+projShort[i]+"' style='margin-left:"+sep+"px'>" + 
		"<img src='images/btn_"+projShort[i]+".png' alt='"+projLong[i]+"' title='"+projLong[i]+"' style='margin-top:29px; position:absolute' />" +
		"<span id='"+projShort[i]+"_shine' class='shine' style='margin-top:29px'/><span id='"+projShort[i]+"_logo' class='project_logo'><img src='images/logo_"+projShort[i]+".png'/></span></div>");
		
	$('#'+projShort[i]+'_logo').hide();
	
	$('#'+projShort[i]).mouseover(function() {
		if (projActive == '') 
			$('#'+this.id+'_logo').fadeIn(250);
		this.style.cursor='pointer';
	});
	$('#'+projShort[i]).mouseout(function() { 
		if (projActive == '') 
			$('#'+this.id+'_logo').hide();
	});
	$('#'+projShort[i]).click(function() {
		if (projActive == '') {
			projActive = this.id;
			$('#'+projActive+'_logo').hide();
			switchProject(0);
		}
		else {
			switchProject(1);
		}
	});
	
	$('#projects_full').append("<div id='"+projShort[i]+"_detail' style='width:500px; height:250px; overflow:hidden; display:none; float:right'>" + 
		projDetail[i] +
		"</div>");

	sep += btnWidth + btnMargin;
}

$('#projects_full').append("<img id='back' style='position:absolute; margin-left:95px; bottom:64px; display:none' src='images/btn_back.png'/>");

$('#back').click(function() { switchProject(1); });
$('#back').mouseover(function() { 
	this.style.cursor='pointer'; 
	document.getElementById('back').setAttribute('src','images/btn_back_lit.png');
});
$('#back').mouseout(function() { document.getElementById('back').setAttribute('src','images/btn_back.png'); });

