/* browser specific stylesheets
----------------------------------------------------------------------------*/

if (browser.isWin && browser.isIE){
	loadStylesheet("ie_win.css");
	if (browser.versionMajor==6)
		loadStylesheet("ie_win_6.css");
	else if (browser.versionMajor==7)
		loadStylesheet("ie_win_7.css");
} else if (browser.isSafari){
	loadStylesheet("safari.css");
	if (browser.versionMajor==3)
		loadStylesheet("safari_3.css");
}

/* homepage projects
----------------------------------------------------------------------------*/

var projectIndex=0;
var numProjects;
var projectWidth=415;

function previousProject(){
	//if first project ignore
	if (projectIndex==0)
		return;
	//if last project show next arrow
	var showNextButton=false;
	if (projectIndex==numProjects-1){
		$('nextProject').setStyle({visibility:"visible"});
		showNextButton=true;		
	}
	projectIndex--;
	if (showNextButton)
		new Effect.Parallel(
			[
				new Effect.Opacity($('nextProject'), {from:0, to:1, duration:2}),
				new Effect.MoveBy($('projects-inner'), 0, projectWidth, {duration:2, queue:"end",
					afterFinish:function(obj){showProjectFeatures(projectIndex)}})
			]				
		)
	else
		new Effect.MoveBy($('projects-inner'), 0, projectWidth, {duration:2, queue:"end", 
			afterFinish:function(obj){showProjectFeatures(projectIndex)}});	
	//if first project hide previous arrow
	if (projectIndex==0)
		new Effect.Opacity($('previousProject'), {from:1, to:0, duration:2, queue:"end",
			afterFinish:hide});
}

function nextProject(){	
	//if last project ignore
	if (projectIndex==numProjects-1)
		return;
	//if first project show previous arrow
	var showPreviousButton=false;
	if (projectIndex==0){
		$('previousProject').setStyle({visibility:"visible"});
		showPreviousButton=true;
	}
	projectIndex++;
	if (showPreviousButton)
		new Effect.Parallel(
			[
			 	new Effect.Opacity($('previousProject'), {from:0, to:1, duration:2}),
				new Effect.MoveBy($('projects-inner'), 0, -1*projectWidth, {duration:2, queue:"end",
					afterFinish:function(obj){showProjectFeatures(projectIndex)}})
			]				
		)
	else
		new Effect.MoveBy($('projects-inner'), 0, -1*projectWidth, {duration:2, queue:"end",
			afterFinish:function(obj){showProjectFeatures(projectIndex)}});
	//if last project hide next arrow
	if (projectIndex==numProjects-1)
		new Effect.Opacity($('nextProject'), {from:1, to:0, duration:2, queue:"end", 
			afterFinish:hide});		
}

function hide(obj){
	obj.element.setStyle({visibility:"hidden"});
}

function showProjectFeatures(projectIndex){
	//reset features
	var liElems=getChildElems($('features'),"li");
	for (var i=1;i<liElems.length;i++)
		liElems[i].className="";	
	//highlight features
	for(var i=0;i<projectFeatures[projectIndex].length;i++)
		$(projectFeatures[projectIndex][i]).className="inProject";
}

/* init
----------------------------------------------------------------------------*/

function main_init(){
	if (getBodyElem().className.indexOf("home")!=-1)
		home_init();	
}

function home_init(){
	$("projects").setStyle({overflow:"hidden", height:"12.5em"});
	$("nextProject").setStyle({visibility:"visible"});
	showProjectFeatures(0);	
	numProjects=getChildElems($('projects-inner'),"div").length;
	new Effect.Opacity($('previousProject'), {from:0, to:0, duration:0});	
}

runOnLoad(main_init);

