var portfolioImageDir = "wp-content/themes/chadbaudoin.com/portfolio_carousel/images/"
var curWork = null;
var works;

$(document).ready(function(){
	works = new Array();
	
	//first 
	var workOne = new Work();
	workOne.title = "hhof.tv";
	workOne.description = "A press site for Hallmark Hall of Fame to promote upcoming movies. Developed the site from scratch using agile Java technologies and created a custom CMS. Implemented the design using HTML, CSS and Javascript (scriptaculous).";
	workOne.images.push("hhof1.png", "hhof2.png");
	
	//second
	var workTwo = new Work();
	workTwo.title = "ourremembrance.com";
	workTwo.description = "A social networking site for people grieving family and friends who have passed. Developed the site from scratch using core Java technologies (Spring, Hibernate) with a small team. Implemented the technical front end components of the site using AJAX (DWR, scriptaculous and self build libraries).";
	workTwo.images.push("or1.png", "or2.png");
	
	//third
	var workThree = new Work();
	workThree.title = "barclaycardus.com";
	workThree.description = "A consumer site for BarclayCard US so customers can manage and view their credit cards. Worked on a number of cross browser support issues, built interfaces using YUI, intensely worked with Javascript and CSS.";
	workThree.images.push("barc1.png", "barc2.png");
	
	//fourth
	var workFour = new Work();
	workFour.title = "sonicdrivein.com";
	workFour.description = "Main consumer site for the Sonic Drive In chain of restaurants. Developed core search functionality using Apache Lucene and also implemented minor enhancements.";
	workFour.images.push("sonic1.png");
	
    works.push(workOne, workTwo, workThree, workFour);
	
	setWorkUIById(0);

	$('.portfolio_less_button').click(function() {
		setWorkUIById($(this).attr("id"));
		return false;
	});
	
	$('.portfolio_more_button').click(function() {
		setWorkUIById($(this).attr("id"));
		return false;
	});
});

function setWorkUIById(id){
	id = parseInt(id);
    if(id == -1)
		return;
	
	if(id == 0)
		$('.portfolio_less_button').attr('id', -1);
	else if(id > 0)
		$('.portfolio_less_button').attr('id', id - 1);

	if(id == (works.length - 1))
		$('.portfolio_more_button').attr('id', -1);
	else if(id < works.length)
		$('.portfolio_more_button').attr('id', id + 1);
	
	setWorkUI(works[id]);
}

function setWorkUI(work){
	curWork = work;
	
	$(".portfolio_portal").fadeOut(function(){
		if(work.images.length > 0)
			setImageFocus(work.images[0]);

		$(".portfolio_description_title").text(work.title);
		$(".portfolio_description_text").text(work.description);
		
		$(".portfolio_portal").fadeIn();
		
		//set the images navigation
		$(".portfolio_image_nav").html("");
		for(i=0;i<work.images.length;i++){
			$(".portfolio_image_nav").append($("<a>"+(i+1)+"</a>").click(function(){setImageFocus(curWork.images[$(this).attr("id")]);}).attr('href','').attr('class','portfolio_change_work_image').attr('id',i).attr('onClick','return false;'));
		}
	});
}

function setImageFocus(img){
	var mg = $("<img></img>").attr('src',portfolioImageDir+img);
	$(".portfolio_image_container").fadeOut("slow", function(){
		$(".portfolio_image_container").html(mg);
		$(".portfolio_image_container").fadeIn("slow");
	});
}
