// JavaScript Document

var mixCurPage=1;
var promoCurPage=1;
var galCurPage=1;
var galCurImageNum=1;
var sH=0;
var loadedBits=0;
var curVid=1;
var thisPage;
function moveStuff (id,leftIt,movepx,type) {
	if (leftIt===1 && sH===0) {
		sH=1; go4=1;
		if (type=='mix') mixCurPage=mixCurPage-1;
		if (type=='promo') promoCurPage=promoCurPage-1;
		if (type=='gal') galCurPage=galCurPage-1;
		new Effect.Move(id, { x: movepx, y: 0, mode: 'relative', transition: Effect.Transitions.spring, afterFinish: function(){sH=0;}});
	}
	else if (sH===0) {
		sH=1; go4=1;
		if (type=='mix') mixCurPage=mixCurPage+1;
		if (type=='promo') promoCurPage=promoCurPage+1;
		if (type=='gal') galCurPage=galCurPage+1;
		new Effect.Move(id, { x: -movepx, y: 0, mode: 'relative', transition: Effect.Transitions.spring, afterFinish: function(){sH=0;}});
	}
	if (go4===1) {
		if (type=='mix') {
			if (mixCurPage >= mixPages) $('arrowMixRight').hide(); else $('arrowMixRight').show();
			if (mixCurPage <2) $('arrowMixLeft').hide(); else $('arrowMixLeft').show();
		}
		if (type=='promo') {
			if (promoCurPage >= promoPages) $('arrowPromoRight').hide(); else $('arrowPromoRight').show();
			if (promoCurPage <2) $('arrowPromoLeft').hide(); else $('arrowPromoLeft').show();
		}
		if (type=='gal') {
			if (galCurPage >= galImPages) $('arrowGalRight').hide(); else $('arrowGalRight').show();
			if (galCurPage <2) $('arrowGalLeft').hide(); else $('arrowGalLeft').show();
		}
	}
}

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) 
	return arrayPageSize;
}

function showDateBox(onOff,id) {
if ((onOff==1) && (sH==0)) {
	var aj1 = new Ajax.Updater('dateImage', 'ajax_stuff.php', {method: 'get', parameters: 'type=dateImage&id='+id, onComplete:showDateBox2});
	var aj2 = new Ajax.Updater('dateDate', 'ajax_stuff.php', {method: 'get', parameters: 'type=dateDate&id='+id, onComplete:showDateBox2});
	var aj3 = new Ajax.Updater('dateLocation', 'ajax_stuff.php', {method: 'get', parameters: 'type=dateLocation&id='+id, onComplete:showDateBox2});
	var aj4 = new Ajax.Updater('dateText', 'ajax_stuff.php', {method: 'get', parameters: 'type=dateText&id='+id, onComplete:showDateBox2});
	
}
else if ((onOff==2) && (sH==0)) {
	sH=1;
	new Effect.BlindUp('dateBoxContent', {duration:0.8, afterFinish: function (){
        new Effect.Fade('dateBoxMain', {duration:0.3, afterFinish: function (){
			$('blackArea').style.display="none";
			if ($('scContLeft') != null) $('scContLeft').style.display="block";
			if ($('vidBox') != null) $('vidBox').style.display="block";
			if ($('scCont1') != null) $('scCont1').style.display="block";
			sH=0;
	 }});}});
}
}

function showDateBox2() {
	loadedBits=loadedBits+1;
	if (loadedBits==4) {
		sH=1;
		var arrayPageSize = getPageSize();
		$('blackArea').style.height = arrayPageSize[1] + 'px';
		$('blackArea').style.display="block";
		if ($('scContLeft') != null) $('scContLeft').style.display="none";
		if ($('vidBox') != null) $('vidBox').style.display="none";
		if ($('scCont1') != null) $('scCont1').style.display="none";
		theNewLeft=arrayPageSize[2]; theNewLeft=(theNewLeft-380)/2;
		$('dateBoxMain').style.left = theNewLeft + 'px';
		new Effect.Appear('dateBoxMain', {duration:0.3, afterFinish: function (){
        	new Effect.BlindDown('dateBoxContent', {duration:0.8, afterFinish: function (){
				sH=0;
				loadedBits=0
	 	}});}});
	}
}

function loadVid(vidID,box) {
	var flashvars = {clip_id: vidID,server: "vimeo.com",show_title: "1",show_byline: "1",show_portrait: "0",fullscreen: "1",color:"ffe200"};
	var params = {allowfullscreen: "true",allowscriptaccess: "always",movie: "http://vimeo.com/moogaloop.swf"};
	var attributes = {clip_id: vidID};
	swfobject.embedSWF("http://vimeo.com/moogaloop.swf", "vidBox", "400", "273", "9.0.0","expressInstall.swf", flashvars, params, attributes);
	changeVidBG (box,1,1);
	oldVid=curVid;
	curVid=box;
	changeVidBG (oldVid,0,1);
}

function nXPrTrack(theDir) {
		if (theDir=='next') { curMix=curMix+1; } else { curMix=curMix-1; }
		var trackID=trackIDs[curMix];
		if (curMix>=totalMix) { $('scNext').setStyle({ zIndex: 1 }); } else { $('scNext').setStyle({ zIndex: 4 }); }
		if (curMix<2) { $('scPrevious').setStyle({ zIndex: 1 }); } else { $('scPrevious').setStyle({ zIndex: 4 }); }
		var flashvars = { url: "http://soundcloud.com/danielhills/"+trackID,color: '0060ff', auto_play:'true'};
		var params = {allowscriptaccess: "always",wmode: "transparent"};
		var attributes = {name: 'player'};
		swfobject.embedSWF("http://player.soundcloud.com/player.swf", "scCont1", "207", "81", "9.0.0","expressInstall.swf", flashvars, params, attributes);
     	var myAjax = new Ajax.Updater('scTrackTitle', 'ajax_stuff.php', {method: 'get', parameters: 'type=trackTitle&permalink='+trackID});
}

function nXPrTrack2(theDir) {
		if (theDir=='next') { curMix=curMix+1; } else { curMix=curMix-1; }
		var trackID=trackIDs[curMix];
		if (curMix>=totalMix) { $('scNext').innerHTML='<img src="images/sc_next_off.png" alt="" />'; } else { $('scNext').innerHTML='<a href="#" onclick="nXPrTrack2(\'next\'); return false;" class="scNext"></a>'; }
		if (curMix<2) { $('scPrevious').innerHTML='<img src="images/sc_previous_off.png" alt="" />'; } else { $('scPrevious').innerHTML='<a href="#" onclick="nXPrTrack2(\'prev\'); return false;" class="scPrevious"></a>'; }
		var flashvars = { url: "http://soundcloud.com/danielhills/"+trackID,color: '0060ff', auto_play:'true'};
		var params = {allowscriptaccess: "always",wmode: "transparent"};
		var attributes = {name: 'player'};
		swfobject.embedSWF("http://player.soundcloud.com/player.swf", "scCont1", "468", "81", "9.0.0","expressInstall.swf", flashvars, params, attributes);
     	var myAjax = new Ajax.Updater('scTrackTitle', 'ajax_stuff.php', {method: 'get', parameters: 'type=trackTitle&permalink='+trackID});
}

function changeVidBG (box,over,forGood) {
	if (box!=curVid) {
		if (over===1) {
			$('vidBox'+box).className='vidBoxOn';
			$('vidBoxTextT'+box).className='vidBoxTextTOn';
			$('vidBoxTextB'+box).className='vidBoxTextBOn';
			$('vidText'+box).className='videoTextBOn';
		}
		else {
			$('vidBox'+box).className='vidBox';
			$('vidBoxTextT'+box).className='vidBoxTextT';
			$('vidBoxTextB'+box).className='vidBoxTextB';
			$('vidText'+box).className='videoTextT';
		}
	}
}

function signUP () {
	if (($('name').value != '') && ($('email').value != '') && ($('name').value != 'NAME') && ($('email').value != 'EMAIL')) {
		var name=$('name').value;
		var email=$('email').value;
		var aj1 = new Ajax.Request('ajax_stuff.php', {method: 'get', parameters: 'type=signUP&name='+escape($F('name'))+'&email='+escape($F('email')), onSuccess:emailRec});
	}
	else {
		$('signUpResponse').innerHTML='Something missing?';
	}
}

function contactDH () {
	if (($('name').value != '') && ($('email').value != '') && ($('comments').value != '')) {
		var name=$('name').value;
		var email=$('email').value;
		var telephone=$('telephone').value;
		var comments=$('comments').value;
		var aj1 = new Ajax.Request('ajax_stuff.php', {method: 'get', parameters: 'type=contactDH&name='+escape($F('name'))+'&email='+escape($F('email'))+'&telephone='+escape($F('telephone'))+'&comments='+escape($F('comments')), onSuccess:emailSent});
	}
	else {
		$('emailResponse').innerHTML='Please enter at least your name, email &amp; comments.';
	}
}

function emailRec() {
	$('signUpResponse').innerHTML='Email added';
	setTimeout(resetEmailRec,3000);
}
function resetEmailRec() {
	$('signUpResponse').innerHTML='';
	$('name').value='NAME';
	$('email').value='EMAIL';
}

function emailSent() {
	$('emailResponse').innerHTML='Thanks, your email has been sent';
	setTimeout(resetEmailSent,3000);
}
function resetEmailSent() {
	$('emailResponse').innerHTML='';
	$('name').value='';
	$('email').value='';
	$('telephone').value='';
	$('comments').value='';
}

function removecue(obj,type,focused){
	if (focused==1) {
  		if ((obj.value=='NAME') || (obj.value=='EMAIL')) {
  			obj.value='';
  		}
	}
	else {
		if ((type=='name') && (obj.value=='')) {
			obj.value='NAME';
		}
		if ((type=='email') && (obj.value=='')) {
			obj.value='EMAIL';
		}
	}
}

function selectDate(num,onOff) {
	if (onOff=='on') {
		$('image'+num).setStyle({ borderColor: '#a314fd' });
		$('location'+num).setStyle({ color: '#a314fd' });
		$('dateText'+num).setStyle({ color: '#ffffff' });
		$('dateBox'+num).setStyle({ cursor: 'pointer' });
	}
	else {
		$('image'+num).setStyle({ borderColor: '#484949' });
		$('location'+num).setStyle({ color: '#ffffff' });
		$('dateText'+num).setStyle({ color: '#a314fd' });
	}
}

function loadImage(id) {
    var aj1 = new Ajax.Updater('mainImage', 'ajax_stuff.php', {method: 'get', parameters: 'type=galImage&id='+id});
	var aj2 = new Ajax.Updater('titleText', 'ajax_stuff.php', {method: 'get', parameters: 'type=galTitle&id='+id});
	var aj3 = new Ajax.Updater('descText', 'ajax_stuff.php', {method: 'get', parameters: 'type=galText&id='+id});
	galCurImageNum = galleryImagePos[id];
	imageOpacity (galleryImagePos[id],1);
	if (Math.ceil(galCurImageNum/5) > galCurPage) {
	moveStuff('gallArea',0,605,'gal');
	}
	if (Math.ceil(galCurImageNum/5) < galCurPage) {
	moveStuff('gallArea',1,605,'gal');
	}
	loadGallery ();
}
function nextImage(){
	var newPos = galCurImageNum+1;
	if (galleryImageID[newPos] != null) {
		loadImage(galleryImageID[newPos])
	}
}
function loadGallery () {
	i=1;
	imageExists = true;
	while (imageExists) {
		if ($('gal'+i) != null) {
		
			imageOpacity (i,0);
		
		}
		else {
			
			imageExists = false;
			
		}
		i=i+1;
	}
	
}
function imageOpacity (id,onOff) {

	if (onOff==1) {

		$('gal'+id).setStyle({ opacity: 1.0 });
		
	}
	else {
	
		if (galCurImageNum != id) $('gal'+id).setStyle({ opacity: 0.5 });
		
	}

}

