// NEWSLETTER FORM
function removeValue() 
{
	this.value = "";
}

function reveal()
{
	$("newsletterForm").className = 'reveal';
}


// IMAGE ROLLOVERS
// opacity rollover effect
function opacityOver() 
{
	var link = this.getAttribute('id');
	$(link).className = 'opacityOver';
}

function opacityNormal() 
{
	var link = this.getAttribute('id');
	$(link).className = 'opacityNormal';
}

// navigation images
function mouseover() 
{
	var src_normal = this.getAttribute('src');
	if(src_normal.search('_over') == -1) {
		var src_over   = src_normal.substring(0, src_normal.lastIndexOf('.'));
		src_over      += '_over.gif';	
		this.setAttribute('src', src_over); 
	}
}

function mouseout() 
{
	var src_over   = this.getAttribute('src');
	var src_normal = src_over.substring(0, src_over.lastIndexOf('_'));  
    src_normal 	  += '.gif';
}

// background artist pics
function infoReveal() 
{
	var link  = this.getAttribute('id');
	link += 'Info';
	$(link).className = 'revealArtistInfo';
	//show teeth on doctor rex
	$("drRex").className = 'drOver';
}

function infoHide() 
{
	var link  = this.getAttribute('id');
	link += 'Info';
	$(link).className = 'artistInfo';
	//hide teeth on doctor rex
    $("drRex").className = 'drNormal';
}


// LABELS PAGE
// reveal individual label info
function labelReveal() 
{
	
	//hide labels home div
	$('labelsHome').className = 'hidden';
	
	//reveal current artist div
	var label = this.getAttribute('id');
	var labelDiv = label+'Info';
	$(labelDiv).className = 'reveal';
	
	//hide all artist images
	var images = $$('#labelsInfo li');
	for (var i = 0; i < images.length; i++) {
		images[i].className = 'hidden';
	}

	//reset current artist images to reveal thumbnails and first image
	$(label+'_image1').className = 'reveal';
	var thumbs = $$('#'+label+'Thumbnails li');
	for (var i = 0; i < thumbs.length; i++) {
		thumbs[i].className = 'reveal';
	}
	
		
}

function backToLabels() 
{
	//hide all divs
	var divs = $$('#labelsInfo div');
	for (var i = 0; i < divs.length; i++) {
		divs[i].className = 'hidden';
	}
	
	//reveal main div/info
	$('labelsHome').className = 'reveal';
}


// STORE GALLERY PAGE  
function artistReveal() 
{
	//hide gallery div
	$('storeGallery').className = 'hidden';
	//hide all artist divs
	var artistDivs = $$('#storeGalleryArtists div');
	for (var i = 0; i < artistDivs.length; i++) {
		artistDivs[i].className = 'hidden';
	}
	
	//reveal current artist div
	var artist = this.getAttribute('id');
	var artistDiv = artist+'Info';
	$(artistDiv).className = 'reveal';
	
	//hide all artist images
	var images = $$('#storeGalleryArtists li');
	for (var i = 0; i < images.length; i++) {
		images[i].className = 'hidden';
	}
	//reset current artist images to reveal thumbnails and first image
	$(artist+'_image1').className = 'reveal';
	var thumbs = $$('#'+artist+'Thumbnails li');
	for (var i = 0; i < thumbs.length; i++) {
		thumbs[i].className = 'reveal';
	}
}

function showImage() 
{
	//reveal selected image
	var thumbnail = this.getAttribute('id');
	var image = thumbnail.replace('thumbnail', 'image');
	$(image).className = 'reveal';	

	//hide the other images
	var index  = thumbnail.lastIndexOf('_');
	var artist = thumbnail.substring(0, index);
	artist.replace('_', '');
	var images = $$('#'+artist+'Images li');
	for (var i = 0; i < images.length; i++) {
		var img = images[i].getAttribute('id');
		if(img != image) {
			$(img).className = 'hidden';	
		}
	}
}

function backToGallery() 
{
	//hide all divs
	var divs = $$('#storeGalleryArtists div');
	for (var i = 0; i < divs.length; i++) {
		divs[i].className = 'hidden';
	}
	//reveal gallery menu
	$('storeGallery').className = 'reveal';
	
}

function galleryNext() 
{
	//show next artist results if more than 4
	var artistList = $$('#storeGallery li');
	for (var i = 0; i < artistList.length; i++) {
		var listItem  = artistList[i].getAttribute('id');
		var linkStart = listItem.lastIndexOf('_');
		var linkCount = listItem.substring(linkStart).replace('_', '');
		if(linkCount <= 4) {
			$(listItem).className = 'hidden';
		} else {
			$(listItem).className = 'reveal';
		}
	}
	$("galleryNext").innerHTML = '';
	$("galleryHome").innerHTML = 'Back';
}

function galleryBack() 
{
	//hide artist results if more than 4
	var artistList = $$('#storeGallery li');
	for (var i = 0; i < artistList.length; i++) {
		var listItem  = artistList[i].getAttribute('id');
		var linkStart = listItem.lastIndexOf('_');
		var linkCount = listItem.substring(linkStart).replace('_', '');
		if(linkCount > 4) {
			$(listItem).className = 'hidden';
		} else {
			$(listItem).className = 'reveal';
		}
	}
	$("galleryNext").innerHTML = 'Next';
	$("galleryHome").innerHTML = '';
}





/** MAIN LOADER FUNCTION **/
function loader() 
{
	/** FLYOVER EFFECT **/
	var scroll = new Fx.Scroll('contentWrapper', {
		wait: false,
		duration: 2500,
		offset: {'x': -150, 'y': -50},
		transition: Fx.Transitions.Quad.easeInOut
	});
	
	function flyover() 
	{
		if(this==$('link1')) {scroll.toElement('content1');}
		if(this==$('link2')) {scroll.toElement('content2');}
		if(this==$('link3')) {scroll.toElement('content3');}
		if(this==$('link4')) {scroll.toElement('content4');}
		if(this==$('link5')) {scroll.toElement('content5');}
		
		if(this==$('peteDjPic') || this==$('miseryPic') || this==$('otisPic') || this==$('peteGirlPic') || this==$('owlPic') || this==$('arloPic') || this==$('simonPic')) {scroll.toElement('content3');}
		      
	}
		
	/** TEST JAVASCRIPT FUNCTIONS BEFORE RUNNING SCRIPTS **/
	if(document.getElementById || document.getElementsByTagName) {
	
		// run FLYOVER function when nav link clicked
		var links = $$('#navList a');
		for (var i = 0; i < links.length; i++) {
			links[i].onclick = flyover;
		}
		
		// run FLYOVER function when wall pic clicked
		if($('contentInner')) {
			var pics = $$('#contentInner div.wallPics');
			for (var i = 0; i < pics.length; i++) {
				var link = $(pics[i]).getFirst();
				link.onclick = flyover;
			}
		}
		
		// REVEAL JOIN NEWSLETTER FORM
		if($("joinUp")) {
			$("joinUp").onclick = reveal;
			if($("newsletterInput")) { $("newsletterInput").onclick = removeValue; }
		}
	
		// ROLLOVER EFFECTS
		//pre-cache all rollover images
		var images = $$('#container img');
		for (var i = 0; i < images.length; i++) {
			var img = images[i];
			var source = img.src;
			
			//gifs - retreive path name minus extension
			var img_name = source.substring(0, source.lastIndexOf('.'));
			img_name    += "_over.gif";
			//pre-cache gifs
			var image = new Image();
			image.src = img_name;
			images_loaded = true;
		
			//jpegs - retreive path name minus extension
			var pic_name = source.substring(0, source.lastIndexOf('.'));
			pic_name    += "_over.jpg";
			//pre-cache jpegs
			var pic = new Image();
			pic.src = pic_name;
			pics_loaded = true;
		}
	
   		// nav mouseover
		var images = $$('#navList img');
		for (var i = 0; i < images.length; i++) {
			images[i].onmouseover = mouseover;
			images[i].onmouseout  = mouseout;
		}
		
		if($("contentInner")) {
			// artist background wall pics mouseover
			var links = $$('.wallPics a');
			for (var i = 0; i < links.length; i++) {
				links[i].onmouseover = infoReveal;
				links[i].onmouseout  = infoHide;
			}
		}
		
		// LABELS PAGE
		if($('labelsList')) {
			
			// change content onclick
			var labelLinks = $$('#labelsList a.labelsLink');
			for (var i = 0; i < labelLinks.length; i++) {
				labelLinks[i].onclick 	  = labelReveal;
			}
			
			// change image on thumbnail click
			var thumbnailLinks = $$('#labelsInfo a.labelThumbnail');
			for (var i = 0; i < thumbnailLinks.length; i++) {
				thumbnailLinks[i].onclick = showImage;
			}
			
			// go back to labels
			var backBtn = $$('#labelsInfo a.labelsBack');
			for (var i = 0; i < backBtn.length; i++) {
				backBtn[i].onclick = backToLabels;
			}
		}
		
	
		// ARTISTS PAGE
		if($("storeGallery")) {
			
			// change content onclick
			var artistLinks = $$('#storeGallery a.titleImage');
			for (var i = 0; i < artistLinks.length; i++) {
				artistLinks[i].onclick = artistReveal;
			}
			
			// change image on thumbnail click
			var thumbnailLinks = $$('#storeGalleryArtists a.artistThumbnail');
			for (var i = 0; i < thumbnailLinks.length; i++) {
				thumbnailLinks[i].onclick = showImage;
			}
			
			var backBtn = $$('#box3 a.galleryBack');
			for (var i = 0; i < backBtn.length; i++) {
				backBtn[i].onclick = backToGallery;
			}
	
			//hide artist results if more than 4
			var artistList = $$('#storeGallery li');
			for (var i = 0; i < artistList.length; i++) {
				var listItem  = artistList[i].getAttribute('id');
				var linkStart = listItem.lastIndexOf('_');
				var linkCount = listItem.substring(linkStart).replace('_', '');
				if(linkCount >= 5) {
					$(listItem).className = 'hidden';
					$("galleryNext").innerHTML = 'Next';
				}
			}
			
			// access next 4 artists with NEXT button
			if($("galleryNext")) {
				$("galleryNext").onclick = galleryNext;
			}
			// go back to gallery
			if($("galleryHome")) {
				$("galleryHome").onclick = galleryBack;
			}
		}
		
			
		
		
	}

	if($('contentInner')) {
		/** CONTENT - fade content boxes in/out **/
		var fx1  = $('box1').effects({duration: 1000, transition: Fx.Transitions.Quart.easeOut});
		var fx2  = $('box2').effects({duration: 1000, transition: Fx.Transitions.Quart.easeOut});
		var fx3  = $('box3').effects({duration: 1000, transition: Fx.Transitions.Quart.easeOut});
		var fx4  = $('box4').effects({duration: 1000, transition: Fx.Transitions.Quart.easeOut});
		var fx5  = $('box5').effects({duration: 1000, transition: Fx.Transitions.Quart.easeOut});
	}	
	
	
	// create array of all li tags with the class "start"
	var navLink = $$('#navList li.start');
	
	navLink.addEvent('click', function() {
	
		if(this==$('start1')) {
			//close all other boxes - first test whether they are open
			if(($('box2').getStyle('height').toInt()) >= 1) { fx2.start({'height': 0,'opacity': 0}); }
			if(($('box3').getStyle('height').toInt()) >= 1) { fx3.start({'height': 0,'opacity': 0}); }
			if(($('box4').getStyle('height').toInt()) >= 1) { fx4.start({'height': 0,'opacity': 0}); }
			if(($('box5').getStyle('height').toInt()) >= 1) { fx5.start({'height': 0,'opacity': 0}); }
			//open 'home' box
			fx1.start().chain(function() {
				this.start.delay(900, this, {'opacity': .9, 'width': 400, 'height': 380});
			});
		}
		
		if(this==$('start2')) {
			//close all other boxes - first test whether they are open
			if(($('box1').getStyle('height').toInt()) >= 1) { fx1.start({'height': 0,'opacity': 0}); }
			if(($('box3').getStyle('height').toInt()) >= 1) { fx3.start({'height': 0,'opacity': 0}); }
			if(($('box4').getStyle('height').toInt()) >= 1) { fx4.start({'height': 0,'opacity': 0}); }
			if(($('box5').getStyle('height').toInt()) >= 1) { fx5.start({'height': 0,'opacity': 0}); }
			//open 'labels' box
			fx2.start().chain(function() {
				this.start.delay(900, this, {'opacity': .9, 'width': 400, 'height': 350});
			});
		}
		
		if(this==$('start3')) {
			//close all other boxes - first test whether they are open
			if(($('box2').getStyle('height').toInt()) >= 1) { fx2.start({'height': 0,'opacity': 0}); }
			if(($('box1').getStyle('height').toInt()) >= 1) { fx1.start({'height': 0,'opacity': 0}); }
			if(($('box4').getStyle('height').toInt()) >= 1) { fx4.start({'height': 0,'opacity': 0}); }
			if(($('box5').getStyle('height').toInt()) >= 1) { fx5.start({'height': 0,'opacity': 0}); }
			//open 'gallery' box
			fx3.start().chain(function() {
				this.start.delay(900, this, {'opacity': .9, 'width': 400, 'height': 350});
			});
		}
		
		if(this==$('start4')) {
			//close all other boxes - first test whether they are open
			if(($('box2').getStyle('height').toInt()) >= 1) { fx2.start({'height': 0,'opacity': 0}); }
			if(($('box3').getStyle('height').toInt()) >= 1) { fx3.start({'height': 0,'opacity': 0}); }
			if(($('box1').getStyle('height').toInt()) >= 1) { fx1.start({'height': 0,'opacity': 0}); }
			if(($('box5').getStyle('height').toInt()) >= 1) { fx5.start({'height': 0,'opacity': 0}); } 
			//open 'blog' box
			fx4.start().chain(function() {
				this.start.delay(900, this, {'opacity': .9, 'width': 400, 'height': 350});
			});
		}
		
		if(this==$('start5')) {
			//close all other boxes - first test whether they are open
			if(($('box2').getStyle('height').toInt()) >= 1) { fx2.start({'height': 0,'opacity': 0}); }
			if(($('box3').getStyle('height').toInt()) >= 1) { fx3.start({'height': 0,'opacity': 0}); }
			if(($('box4').getStyle('height').toInt()) >= 1) { fx4.start({'height': 0,'opacity': 0}); }
			if(($('box1').getStyle('height').toInt()) >= 1) { fx1.start({'height': 0,'opacity': 0}); }
			//open 'about' box
			fx5.start().chain(function() {
				this.start.delay(900, this, {'opacity': .9, 'width': 400, 'height': 350});
			});
		}
		
	});
	
	
	
	// create array of all div tags with the class "wallPics"
	var wallPicLink = $$('#contentInner div.wallPics');
	
	wallPicLink.addEvent('click', function() {
		
		//close all other boxes - first test whether they are open
		if(($('box2').getStyle('height').toInt()) >= 1) { fx2.start({'height': 0,'opacity': 0}); }
		if(($('box1').getStyle('height').toInt()) >= 1) { fx1.start({'height': 0,'opacity': 0}); }
		if(($('box4').getStyle('height').toInt()) >= 1) { fx4.start({'height': 0,'opacity': 0}); }
		if(($('box5').getStyle('height').toInt()) >= 1) { fx5.start({'height': 0,'opacity': 0}); }
		//open 'gallery' box
		fx3.start().chain(function() {
			this.start.delay(900, this, {'opacity': .9, 'width': 400, 'height': 350});
		});
	});
	
}

window.onload = loader;
