/*
 * [a] Stijn Van Minnebruggen
 * [c] Do Not Fold
 * [s] www.donotfold.be
 * 
*/

var currPortfolio;
var currImages;
var currImage = 1;
var arrayPageSize;
var yScroll;
var imgW;
var imgH;

function showPortfolio(name, images) {
	
	// start vars
		currImage = 1;
		currPortfolio = name;
		currImages = images;
	
	// get window vars
		getPageSize();
		getPageScroll();
	
	// show portfolio
		$('overlay').style.height = arrayPageSize[1]+'px';
		new Effect.Appear('overlay', { duration: 1, from: 0.0, to: 0.6, afterFinish: showPortfolioDetail });
	
}

function showPortfolioDetail() {
	
	// reset image
		$('prevBtn').style.display = 'none';
		$('nextBtn').style.display = 'none';
		$('detail_img').innerHTML = '';
	
	// show portfolio block
		$('detail').style.display = 'block';
		$('detail').style.top = yScroll+(arrayPageSize[3] / 15)+'px';
	
	// load image
		imgPreloader = new Image();
		imgPreloader.onload = function(){
			imgW = imgPreloader.width+20;
			imgH = imgPreloader.height+20;
			new Effect.Morph('detail', { style: 'width:'+imgW+'px; height:'+imgH+'px; margin-left: -'+(imgW/2)+'px;', duration:0.5, afterFinish: showPortfolioImage });
			showButtons();
		}
		imgPreloader.src = 'img/portfolio/'+currPortfolio+currImage+'.jpg';
	
}

function showPortfolioImage() {
	$('detail_img').innerHTML = '<img src="img/portfolio/'+currPortfolio+currImage+'.jpg" alt="" />';
	new Effect.Appear('detail_img');
}

function showButtons() {
	$('prevBtn').style.width = (imgW/2)+'px';
	$('prevBtn').style.height = (imgH-20)+'px';
	$('nextBtn').style.width = (imgW/2)+'px';
	$('nextBtn').style.height = (imgH-20)+'px';
	$('nextBtn').style.marginLeft = (imgW/2)+'px';
	if(currImage > 1) $('prevBtn').style.display = 'block';
	if(currImage < currImages) $('nextBtn').style.display = 'block';
	blur();
}

function hidePortfolio() {
	new Effect.Fade('detail', { afterFinish: resetPortfolio });
	new Effect.Fade('overlay');
}

function resetPortfolio() {
	$('detail_img').innerHTML = '';
}

function showNextItem() {
	
	if(currImage < currImages) currImage++;
	showPortfolioDetail();
}

function showPrevItem() {
	if(currImage > 1) currImage--;
	showPortfolioDetail();
}


// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez

function getPageSize() {
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth; yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth; yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth; yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth; windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth; windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth; windowHeight = document.body.clientHeight;
	}
	
	// for small pages with total height less then height of the viewport
		if(yScroll < windowHeight) pageHeight = windowHeight;
		else pageHeight = yScroll;
	
	// for small pages with total width less then width of the viewport
		if(xScroll < windowWidth) pageWidth = windowWidth;
		else pageWidth = xScroll;
	
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);

}


// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.org

function getPageScroll() {

	if(self.pageYOffset) yScroll = self.pageYOffset;
	else if(document.documentElement && document.documentElement.scrollTop) yScroll = document.documentElement.scrollTop; // Explorer 6 Strict
	else if(document.body) yScroll = document.body.scrollTop; // all other Explorers

}

