/* 2008 (C) All Rights Resverved www.kalelmedia.com */

var slide = {
	next: function(){
		['part-1', 'part-2'].each(Element.toggle);
		
		if($('part-1').visible()){
			$('linkText').update('Next Page');
		} else if ($('part-2').visible()){
			$('linkText').update('Previous Page');
		}
	}
}

function showAlbumInfo(idx){
	
	//if($('newmusic'+idx)){
		//Effect.Appear('greyScreen',{ to: 0.9});
		//Effect.Appear('newmusic'+idx);
	//} else {
	
		// set working element.
		var ele = $("music"+idx);
		
		//load innerHTML
		var content = ele.innerHTML;
		
		// Rename all elements within ele
		// to avoid conflictt in JS
		ele.descendants().each(function(s){
			s.id = s.id + "old";
		});
		
		
		// get current class
		var sClass = ele.readAttribute('class');
		
		// override positioning styles to make center screen.
		var dimentions = ele.getDimensions();
		var top = (document.height - dimentions.height) / 2;
		var left = (document.width - dimentions.width) / 2;
		
		
		// build our new div for content.
		var newDiv = document.createElement('div');
		newDiv.id = "newmusic"+idx;
		newDiv.className = sClass;
		
		// set the new html. also set a close cross.
		var cross = "<span style='position: absolute; top: 10px; right: 10px;'>[ <a href='#' onClick='hideAlbumInfo("+idx+");'>Close</a> ]</span>";
		newDiv.innerHTML = cross + content;
		
		// if we are in IE force positions.
		if(Prototype.Browser.IE){
			// set style for div 
			newDiv.style.position = "absolute";
			newDiv.style.top = "100px";
			newDiv.style.left = "400px";
		} else {
			// set style for div 
			newDiv.style.position = "absolute";
			newDiv.style.top = "" + top.toString() + "px";
			newDiv.style.left = "" + left.toString() + "px";
		}
		
		// create grey div.
		var greyDiv = document.createElement('div');
		greyDiv.id = "greyScreen";
		
		// Set the style for the greyDiv
		greyDiv.style.width = "100%";
		greyDiv.style.height = "100%";
		greyDiv.style.position = "absolute";
		greyDiv.style.top = "0px";
		greyDiv.style.left = "0px";
		greyDiv.style.opacity = 0.9;
		greyDiv.style.backgroundColor = "#999";
		greyDiv.style.overflow = "hidden";
		
		// make both hidden so we can fade them in.
		greyDiv.style.display = "none";
		newDiv.style.display = "none";
		
		// append our new content and grey div
		document.body.appendChild(greyDiv);
		document.body.appendChild(newDiv);
		
		Effect.Appear('greyScreen',{ to: 0.9});
		Effect.Appear('newmusic'+idx);
	//}
}

function hideAlbumInfo(idx){	
	Effect.Fade('newmusic'+idx);
	Effect.Fade('greyScreen');
}

function contactShow(){

	if($('newcontactpage')){
		Effect.Appear('greyScreen',{ to: 0.9});
		Effect.Appear('newcontactpage');
	} else {

		// set working element.
		var ele = $("contactPage");
		
		//load innerHTML
		var content = ele.innerHTML;
		
		var des = ele.descendants().each(function(s){
			s.id = s.id + "2";
			s.name = s.name + "2";
		});
		
		// get current class
		var sClass = ele.readAttribute('class');
		
		// override positioning styles to make center screen.
		var dimentions = ele.getDimensions();
		var top = (document.height - dimentions.height) / 2;
		var left = (document.width - dimentions.width) / 2;
		
		
		// build our new div for content.
		var newDiv = document.createElement('div');
		newDiv.id = "newcontactpage";
		newDiv.className = sClass;
		
		// set the new html. also set a close cross.
		var cross = "<span style='position: absolute; top: 10px; right: 10px;'>[<a href='#' onClick='contactHide();'>Close</a>]</span>";
		newDiv.innerHTML = cross + content;
		
		if(Prototype.Browser.IE){
			// set style for div 
			newDiv.style.position = "absolute";
			newDiv.style.top = "100px";
			newDiv.style.left = "400px";
		} else {
			// set style for div 
			newDiv.style.position = "absolute";
			newDiv.style.top = "" + top.toString() + "px";
			newDiv.style.left = "" + left.toString() + "px";
		}
			
		// create grey div.
		var greyDiv = document.createElement('div');
		greyDiv.id = "greyScreen";
		
		// Set the style for the greyDiv
		greyDiv.style.width = "100%";
		greyDiv.style.height = "100%";
		greyDiv.style.position = "absolute";
		greyDiv.style.top = "0px";
		greyDiv.style.left = "0px";
		greyDiv.style.opacity = 0.9;
		greyDiv.style.backgroundColor = "#999";
		greyDiv.style.overflow = "hidden";
		
		// make both hidden so we can fade them in.
		greyDiv.style.display = "none";
		newDiv.style.display = "none";
		
		// append our new content and grey div
		document.body.appendChild(greyDiv);
		document.body.appendChild(newDiv);
		
		Effect.Appear('greyScreen',{ to: 0.9});
		Effect.Appear('newcontactpage');
	}
}

function showImage(img,cap,width){
	
	//set image
	var content = "<div id='imageBox'><img src='"+img+"' width='"+width+"'/><div id='imageCaption' class='caption'>"+cap+"</div></div>";
	
	// If bigimage is set, just replace content and fade in
	if($('bigImage')){
	
		$('imageBox').innerHTML = content;
		Effect.Appear('greyScreen',{ to: 0.9});
		Effect.Appear('bigImage');
	
	} else {
	
		// override positioning styles to make center screen.
		var top = (document.height - 500) / 2;
		var left = (document.width - 500) / 2;
		
		
		// build our new div for content.
		var newDiv = document.createElement('div');
		newDiv.id = "bigImage";
		newDiv.style.width = width +"px";
		newDiv.style.padding = "25px";
		newDiv.style.backgroundColor = "#fff";
		
		// set the new html. also set a close cross.
		var cross = "<span style='position: absolute; top: 2px; right: 10px; background-color: #fff;'>[<a href='#' onClick='hideImage();'>Close</a>]</span>";
		
		newDiv.innerHTML = cross + content;
		
		if(Prototype.Browser.IE){
			// set style for div 
			newDiv.style.position = "absolute";
			newDiv.style.top = "10px";
			newDiv.style.left = "400px";
		} else {
			// set style for div 
			newDiv.style.position = "absolute";
			newDiv.style.top = "" + top.toString() + "px";
			newDiv.style.left = "" + left.toString() + "px";
		}
			
		// create grey div.
		var greyDiv = document.createElement('div');
		greyDiv.id = "greyScreen";
		
		// Set the style for the greyDiv
		greyDiv.style.width = "100%";
		greyDiv.style.height = "100%";
		greyDiv.style.position = "absolute";
		greyDiv.style.top = "0px";
		greyDiv.style.left = "0px";
		greyDiv.style.opacity = 0.9;
		greyDiv.style.backgroundColor = "#999";
		greyDiv.style.overflow = "hidden";
		
		// make both hidden so we can fade them in.
		greyDiv.style.display = "none";
		newDiv.style.display = "none";
		
		// append our new content and grey div
		document.body.appendChild(greyDiv);
		document.body.appendChild(newDiv);
		
		// run the effect on each to make them
		// fade in.
		Effect.Appear('greyScreen',{ to: 0.9});
		Effect.Appear('bigImage');
	}
}

function hideImage(){	
	Effect.Fade('bigImage');
	Effect.Fade('greyScreen');
}


function contactHide(){	
	Effect.Fade('newcontactpage');
	Effect.Fade('greyScreen');
}

function nextSlide(first, last){
	
	$('text').getElementsBySelector('[gallery="1"]').each(function(s){
		//find current.
		if(s.visible()){
			if((parseInt(s.id) + 1) > last){
				alert('Sorry, there are no more pages to view.');
			} else {
				s.hide();
				var ele = $('' + (parseInt(s.id) + 1));
				ele.show();
				
				throw $break;
			}
		}
	});
}

function previousSlide(first, last){	
	$('text').getElementsBySelector('[gallery="1"]').each(function(s){
		//find current.
		if(s.visible()){
			if((parseInt(s.id) - 1) < first){
				alert('Sorry, you are on the first page.');
			} else {
				s.hide();
				var ele = $('' + (parseInt(s.id) - 1));
				ele.show();
				
				throw $break;
			}
		}
	});
}

function nextPage(first, last){
	
	$('text').getElementsBySelector('[apage="1"]').each(function(s){
		//find current.
		if(s.visible()){
			if((parseInt(s.id) + 1) > last){
				alert('Sorry, there are no more pages to view.');
			} else {
				s.hide();
				var ele = $('' + (parseInt(s.id) + 1));
				ele.show();
				
				throw $break;
			}
		}
	});
}

function previousPage(first, last){	
	$('text').getElementsBySelector('[apage="1"]').each(function(s){
		//find current.
		if(s.visible()){
			if((parseInt(s.id) - 1) < first){
				alert('Sorry, you are on the first page.');
			} else {
				s.hide();
				var ele = $('' + (parseInt(s.id) - 1));
				ele.show();
				
				throw $break;
			}
		}
	});
}

function nextReview(idx, ele2, first, last){
	
	$(ele2).getElementsBySelector('[areview="1"]').each(function(s){
		//find current.
		if(s.visible()){
			if((parseInt(s.id) + 1) > last){
				alert('Sorry, there are no more pages to view.');
			} else {
				alert(s.id);
				alert(parseInt(s.id));
				s.hide();
				var ele = $('' + (parseInt(s.id) + 1) + 'r' + idx);
				ele.show();
				
				throw $break;
			}
		}
	});
}

function previousReview(idx, ele2, first, last){	
	$(ele2).getElementsBySelector('[areview="1"]').each(function(s){
		//find current.
		if(s.visible()){
			if((parseInt(s.id) - 1) < first){
				alert('Sorry, you are on the first page.');
			} else {
				alert(s.id);
				alert(parseInt(s.id));
				s.hide();
				var ele = $('' + (parseInt(s.id) - 1) + 'r' + idx);
				ele.show();
				
				throw $break;
			}
		}
	});
}

function updateSong(id){

	var ele = document.getElementById('file' + id);
	var cur = ele.innerHTML;
	var hide = "<div style='display: none;' id='hidden"+id+"'>"+cur+"</div>";
	var sNew = "<input type='file' name='track"+id+"' /><a href='#' onClick='revert("+id+");'>R</a>";
	
	ele.innerHTML = hide + sNew;
}

function revert(id){
	var ele = document.getElementById('file'+id);
	var ele2 = document.getElementById('hidden'+id);
	
	ele.innerHTML = ele2.innerHTML;
}

function ajaxForm(ele){
	$(ele).request({
		method: 'post',
		onSuccess: function(){
			alert('Message Sent');
		},
		onFailure: function(){
			alert('Sorry, there was an error');
		}

	});
}

function ajaxForm2(ele){
	$('formBit').hide();
	$('formAlert').show();
	$('formAlert').innerHTML = "Sending...";
	$(ele).request({
		method: 'post',
		onSuccess: function(){
			$('formAlert').innerHTML = "Message Sent";
		},
		onFailure: function(){
			$('formAlert').innerHTML = "Sorry there was an error";
		}

	});
}

function magicBox(t){
	var ele = $('magicBox');
	var newName = t.name;
	var text = $('reviewText').innerHTML;
	
	var out = "<textarea style='width: 200px; height: 100px;' on id='"+newName+"' onblur='mirrors(this)' name='"+newName+"'>"+text+"</textarea>";
	
	ele.innerHTML = out;
	$(newName).focus();
}

function mirrors(t){
	var ele = $('magicBox');
	var text = t.value;
	var mirror = $('reviewText');
	
	mirror.innerHTML = text;
	
	// limit length to 25
	var sText = text.substring(0,25);
	
	var newBox = "<input type='text' name='"+t.name+"' class='hidden' onFocus='magicBox(this);' value='"+sText+"' />";
	
	ele.innerHTML = newBox;
}

function editReview(id){
	
	var text = $('text' + id);
	var box = $('review' + id);
	var cross = $('cross' + id);
	
	text.hide();
	box.show();
	cross.show();
}

function updateBox(id){

	var text = $('text' + id);
	var box = $('review' + id);
	var cross = $('cross' + id);
	
	var newText = box.innerHTML;
	newText = newText.toString();
	newText = newText.substring(0,25);
	
	var edit = " [ <a href='#' onClick='return editReview("+id+");'>E</a> ]</span>"
	
	text.innerHTML = newText + edit;
	
	text.show();
	box.hide();
	cross.hide();	
}

function makeEdit(idx,cap,img){
	// hide add
	$('addBay').hide();
	// fill fields
	$('caption').value = cap;
	$('idx').value = idx;
	
	$('image').innerHTML = "<img src='." +img+ "' width='60' height='60' />";
	// show edit
	$('editBay').show();
}

function backAdd(){
	$('editBay').hide();
	$('addBay').show();
}

function makeEdit2(idx, title){
	// hide add
	$('addBay').hide();
	// fill fields
	$('title').value = title;
	$('idx').value = idx;
	$('contentBox').innerHTML = $('t' + idx).innerHTML;
	
	
	$('editBay').show();
}

function makeLinks(idx){
	var link1 = "<a href='./edit-tracks.php?Idx="+idx+"'>Edit Tracks</a>";
	var link2 = "<a href='./edit-reviews.php?Idx="+idx+"'>Edit Reviews</a>";
	
	$('link1').innerHTML = link1;
	$('link2').innerHTML = link2;
}

function playSound(s,d){
	Sound.play(s,{replace:true});
}

function stopSound(){
	Sound.play("",{replace:true});
}

function loadReview(album,review){
	var cont = $('review'+album+review+'old');
	$('quoteText'+album).innerHTML = cont.innerHTML;
}