Array.prototype.find = function(searchStr) {
	var returnArray = false;
	for (i=0; i<this.length; i++) {
	if (typeof(searchStr) == 'function') {
		if (searchStr.test(this[i])) {
			if (!returnArray) { returnArray = []; }
				returnArray.push(i);
	}
	} else {
		if (this[i]===searchStr) {
			if (!returnArray) { returnArray = []; }
			returnArray.push(i);
			}
		}
	}
	return returnArray;
}

function opacity(id, opacStart, opacEnd, millisec) {
	//speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++)
			{
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
	var object = document.getElementById(id).style; 
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}

function shiftOpacity(id, millisec) {
	//if an element is invisible, make it visible, else make it ivisible
	if(document.getElementById(id).style.opacity == 0) {
		opacity(id, 0, 100, millisec);
	} else {
		opacity(id, 100, 0, millisec);
	}
}

function blendimage(divid, imageid, imagefile, millisec) {
	var speed = Math.round(millisec / 100);
	var timer = 0;
	
	//set the current image as background
	document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";
	
	//make image transparent
	changeOpac(0, imageid);
	
	//make new image
	document.getElementById(imageid).src = imagefile;

	//fade in image
	for(i = 0; i <= 100; i++) {
		setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
		timer++;
	}
}

function currentOpac(id, opacEnd, millisec) {
	//standard opacity is 100
	var currentOpac = 100;
	
	//if the element has an opacity set, get it
	if(document.getElementById(id).style.opacity < 100) {
		currentOpac = document.getElementById(id).style.opacity * 100;
	}

	//call for the function that changes the opacity
	opacity(id, currentOpac, opacEnd, millisec);
}

var currentKey = 0;
var thumbActive = "thumb_" + galleryPics[0].slice(0,-4);

function galleryThumbOver(id) {document.getElementById(id).style.top = "-54px";}
function galleryThumbOut(id) 
{
	try
	{
		if (thumbActive != id || document.getElementById('cover').style.display == ""){ document.getElementById(id).style.top = "0px";}
	}
	catch(err)	{}
	
}
function galleryThumbClick(id)
{
	var speed = 1000;
	if (document.getElementById('cover') && document.getElementById('cover').style.display == "")
	{
		opacity('cover', 100, 0, 1000);
		document.getElementById('cover').style.display = "block";
		interval = setInterval("document.getElementById('cover').style.display = 'none'; clearInterval(interval);", 1000);
		if (sectionBackButtonHTML != ""){document.getElementById('sectionCopy').innerHTML += sectionBackButtonHTML;}
		speed = 1;
	}
	
	document.getElementById(thumbActive).style.top = "0px";
	thumbActive = "thumb_"+id;
	document.getElementById(thumbActive).style.top = "-54px";
	currentKey = parseInt(galleryPics.find(id+".jpg"));
	blendimage("picDiv", "picInfront", "images/gallery/"+id+".jpg", speed);
}
function galleryPrevious()
{
	if (currentKey == 0){galleryThumbClick(galleryPics[galleryPics.length-1].slice(0,-4));}
	else {galleryThumbClick(galleryPics[(currentKey-1)].slice(0,-4));}
}
function galleryNext()
{	
	if (currentKey == galleryPics.length-1) {galleryThumbClick(galleryPics[0].slice(0,-4));}
	else {galleryThumbClick(galleryPics[(currentKey+1)].slice(0,-4));}
}

function linkTab(id)
{
	this.id = id;
	this.bgy = -35;
	this.timer;
	this.over = function() {
		if (this.bgy+5 <= 0)
		{
			this.bgy = this.bgy + 5;
			document.getElementById(this.id+"Link").style.backgroundPosition = "0px "+this.bgy+"px";
			this.timer = setTimeout(this.id+".over()", 50);
		}
		else {clearTimeout(this.timer);}
	}
	
	this.out = function() {
		if (this.bgy-5 >= -35)
		{
			this.bgy = this.bgy - 5;
			document.getElementById(this.id+"Link").style.backgroundPosition = "0px "+this.bgy+"px";
			this.timer = setTimeout(this.id+".out()", 50);
		}
		else {clearTimeout(this.timer);}
	}
}

var story = new linkTab('story');
var home = new linkTab('home');
var portfolio = new linkTab('portfolio');
var design = new linkTab('design');
var production = new linkTab('production');
var distribution = new linkTab('distribution');
var packaging = new linkTab('packaging');
var offices = new linkTab('offices');
var giving = new linkTab('giving');
var news = new linkTab('news');



function mouseOverLink(tab)
{
	clearTimeout(tab.timer);
	tab.over();
}

function mouseOutLink(tab)
{
	clearTimeout(tab.timer);
	tab.out();
}

function showCover()
{
	document.getElementById('cover').style.display = "";
	opacity('cover', 0, 100, 1000);
	document.getElementById('sectionCopy').removeChild(document.getElementById('sectionBackButton'));
	document.getElementById(thumbActive).style.top = "0px";
}

function overButton()
{
	document.getElementById('buttonBack').src = "images/buttonBack1.jpg";
}

function outButton()
{
	document.getElementById('buttonBack').src = "images/buttonBack0.jpg";
}


function pageLoad(section)
{
		changeOpac (0, 'right');
    	changeOpac (0, 'center');
    	
    	shiftOpacity('right', 1000);
    	shiftOpacity('center', 1000)
}

function showPop(id)
{
	document.getElementById('popContent').innerHTML = document.getElementById(id).innerHTML;
	changeOpac(0, 'coverBack');
	changeOpac(0, 'coverContainer');
	document.getElementById('coverContainer').style.display = "block";
	document.getElementById('coverContainer').style.visibility = "visible";
	document.getElementById('coverBack').style.display = "block";
	document.getElementById('coverBack').style.visibility = "visible";
	opacity('coverBack', 0, 70, 500);
	opacity('coverContainer', 0, 100, 500);
}
function popFadeout()
{
	document.getElementById('popContent').innerHTML = "";
	document.getElementById('coverContainer').style.display = "none";
	document.getElementById('coverContainer').style.visibility = "hidden";
	document.getElementById('coverBack').style.display = "none";
	document.getElementById('coverBack').style.visibility = "hidden";
	changeOpac(0, 'coverBack');
	changeOpac(0, 'coverContainer');
}
function closePop()
{
	
	opacity('coverBack', 70, 0, 500);
	opacity('coverContainer', 100, 0, 500);
	setTimeout('popFadeout()', 500);
}