// Javscript Copyright Corey Campbell 2010
// Helper Functions
// Moves Sliders according to their ID and grabs buttons according to their title
function loadEvent() {
		var loadingID = $('loading');
		loadingID.innerHTML = '<h1><span class="highlight">Ah...</span><span class="indent">All Done.</span></h1>';
		window.setTimeout(function() {
 		new Effect.Fade(loadingID, { duration: 1.5 }); }, 500);
}

function move()
{
	var move, mid, currentPage, pageSize, totalPages, moveNext, movePrev, shiftclass, 
	idmove, i, m, shiftclassmove, showhide, popupimg, a, a_length, aa, b, b_length,
	bb, popupref, popuplink, resetshift, marginfix, marginstring, marginwidth = null;
	mid = $('mid-container').getElementsByClassName('mid');
	for(m = 0; m < mid.length; m++) 
	{
		currentPage = 1;
		pageSize = 1;
		move = mid[m].getDimensions().width;
		totalPages = mid[m].getElementsByClassName('slide').length;
		mid[m].getElementsByClassName('shift')[0].setStyle({width: totalPages*move + "px"});
		moveNext = mid[m].getElementsByClassName('moveToNext');
		for(i = 0; i < moveNext.length; i++) 
		{
			moveNext[i].observe('click',function() 
			{
				totalPages2 = this.up('.mid').getElementsByClassName('slide').length;
				if(currentPage < totalPages2-pageSize)
				{
					if(this.up('.shift') == null) {
						new Effect.Move(this.up(0).next('.shift'), { x: -move, y: 0, duration: 0.5, transition: Effect.Transitions.sinoidal, queue: 'end' });
						currentPage++;
						this.up(0).down('.page').down('.currentpage').innerHTML = currentPage+1;
						
					} else {
						new Effect.Move(this.up('.shift'), { x: -move, y: 0, duration: 0.5, transition: Effect.Transitions.sinoidal, queue: 'end' });
						currentPage++;
					}
				}	
			});
		}
		movePrev = mid[m].getElementsByClassName('moveToPrev');
		for(i = 0; i < movePrev.length; i++) 
		{
			movePrev[i].observe('click',function() 
			{
				if(currentPage > 0)
				{
					if(this.up('.shift') == null) {
						new Effect.Move(this.up(0).next('.shift'), { x: move, y: 0, duration: 0.5, transition: Effect.Transitions.sinoidal, queue: 'end' });
						currentPage--;
						this.up(0).down('.page').down('.currentpage').innerHTML = currentPage+1;
					} else {
						new Effect.Move(this.up('.shift'), { x: move, y: 0, duration: 0.5, transition: Effect.Transitions.sinoidal, queue: 'end' });
						currentPage--;
					}
				}
			});
		}
		popuplink = $('mid').getElementsByClassName('lightboxpop');
		for(i = 0; i < popuplink.length; i++) 
		{	
			popuplink[i].observe('click',function() 
			{
				if(this.hasClassName('thumb')){
					popupimg = this.getElementsByTagName('img')[0].src;
					marginfix = $('mid-container').getElementsByClassName('project_display');
					for(i = 0; i < marginfix.length; i++) 
					{	
						marginfix[i].getElementsByClassName('shift')[0].setStyle({left: '0px', margin: '0px'});
						marginfix[i].getElementsByClassName('currentpage')[0].innerHTML = "1";
					}
					currentPage = 0; // PROBLEM::: Current page is reset but the position shift remains the same
				} else {
					popupimg = this.identify();
				}
				a = popupimg.split("/");
				a_length = a.length-1;
				aa = a[a_length];
				b = aa.split("-");
				b_length = b.length;
				popupref = b[0];
				//new Effect.Move(shiftclassmove, { x: move, y: 0, duration: 0.4, transition: Effect.Transitions.sinoidal, queue: 'end' });
				//popupref.setStyle({display: 'block'});
				new Effect.Appear(popupref, { from: 0, to: 1.0, duration: 0.7 });
				//document.getElementById(popupref).style.display='block';
				new Effect.Appear('fade', { from: 0, to: .8, duration: 0.5 });
				$('fade').observe('click',function() 
				{
					new Effect.Fade(popupref, { duration: 0.2 });
					new Effect.Fade('fade', { duration: 0.2 });
					marginstring = $("project").getStyle('left');
					a = marginstring.split("px");
					marginwidth = a[0];
					if(marginwidth/900 == 1) {
						currentPage = 0;
					} else {
						currentPage = 2;
					}
				});
			});
		}
	}
}
// Formats type to have a gradiant and softer edge
function clearType()
{
	var renderH1 = document.getElementsByTagName('h1');
	
	for(var i = 0; i < renderH1.length; i++) {
		var innerH1 = renderH1[i].innerHTML;
		renderH1[i].innerHTML = '<span class="overlap">'+innerH1+'</span>'+innerH1;
	}
}
// Formats type to have a gradiant and softer edge
function blockquoteQuotes()
{
	var renderBQ = document.getElementsByTagName('blockquote');
	
	for(var i = 0; i < renderBQ.length; i++) {
		var innerBQ = renderBQ[i].innerHTML;
		renderBQ[i].innerHTML = '<span class="quote">'+innerBQ+'</span>';
	}
}