function Portfolio() {
	this.init();
};

Portfolio.prototype = {
	
	portfolioContainer : null,
	portfolioPieces : null,
	currentPiece : null,
	portfolioWidth : null,
	backArrow : null,
	nextArrow : null,
	
	blurb : null,
	
	init : function() {
		//console.log('Portfolio Initialized');
		
		this.portfolioContainer = $('#portfolioList');
		this.portfolioWidth = this.portfolioContainer.innerWidth();
		this.portfolioPieces = $('#portfolio li');
		
		this.createArrows();
		this.createBlurb();
		
		var thisPortfolio = this;
		
		this.portfolioPieces.each(function() {
			var piece = $(this);
			piece.css('position','absolute');
			var title = piece.find('h4').hide().text();
			var desc = piece.find('p').hide().text();
			piece.find('img').hover(function(e) {
					thisPortfolio.blurb.find('h4').text(title);
					thisPortfolio.blurb.find('p').text(desc);
				})
			piece.find('a').click(function(e) {
					e.preventDefault();
					window.open(this.href);
				})
										   
			piece.hide();
		});
		
		$('#portfolio').hover(function(e) {
				thisPortfolio.blurb.show();
			}, function(e) {
				thisPortfolio.blurb.hide();
			})
		
		this.currentPiece = this.portfolioPieces.first().show();
		var title = this.currentPiece.find('h4').text();
		var desc = this.currentPiece.find('p').text();
		this.blurb.find('h4').text(title);
		this.blurb.find('p').text(desc);
	},
	
	slideMe : function(isNext) {
		var thisPortfolio = this;
		var nextPiece = isNext ? this.currentPiece.next('li') : this.currentPiece.prev('li');
		if(!nextPiece.length) {
			nextPiece = isNext ? this.portfolioPieces.first() : this.portfolioPieces.last();
		}
		var currentGoTo = isNext ? -this.portfolioWidth.toString() : this.portfolioWidth.toString();
		var nextInit = isNext ? this.portfolioWidth + 'px' : -this.portfolioWidth + 'px';
		var speed = 1000;
		
		/*console.log('\ncurrent piece: ' + this.currentPiece.find('h4').text());
		console.log('next piece: ' + nextPiece.find('h4').text());
		console.log('currentGoTo: ' + currentGoTo);*/
		
		var title = nextPiece.find('h4').text();
		var desc = nextPiece.find('p').text();
		this.blurb.find('h4').text(title);
		this.blurb.find('p').text(desc);
		
		this.currentPiece.css('left', '0px')
			.animate({
				left: currentGoTo,
			  },speed,'easeOutElastic', function() {
				$(this).hide();
			  });
		
		nextPiece.css('left', nextInit).show()
			.animate({
				left: '0',
			  },speed,'easeOutElastic', function() {
				//console.log('DONE current piece: ' + thisPortfolio.currentPiece.find('h4').text());
				
			  });
			
			
			
		thisPortfolio.currentPiece = nextPiece;
	},
	
	createArrows : function() {
		var thisPortfolio = this;
		
		this.backArrow = $('<div class="portfolioArrow"/>').insertBefore(this.portfolioContainer);
		this.backArrow.css({'background':'transparent url(imgs/portArrowLeft.png) no-repeat',
							'left':'-75px'})
				.hover(function() {
					$(this).css('background','transparent url(imgs/portArrowLeftOv.png) no-repeat');
				}, function() {
					$(this).css('background','transparent url(imgs/portArrowLeft.png) no-repeat');
				})
				.click(function() {
					thisPortfolio.slideMe(false);
				});
		
		this.nextArrow = $('<div class="portfolioArrow"/>').insertBefore(this.portfolioContainer);
		this.nextArrow.css({'background':'transparent url(imgs/portArrowRight.png) no-repeat',
							'left': (this.portfolioWidth + 15) + 'px'})
				.hover(function() {
					$(this).css('background','transparent url(imgs/portArrowRightOv.png) no-repeat');
				}, function() {
					$(this).css('background','transparent url(imgs/portArrowRight.png) no-repeat');
				})
				.click(function() {
					thisPortfolio.slideMe(true);
				});
	},
	
	createBlurb : function() {
		this.blurb = $('<div class="portfolioBlurb" />').insertBefore(this.portfolioContainer)
			.append('<h4 />')
			.append('<p />').hide();
	}
};
