	/****************************************************
	* ROAD RUNNER RECORDS
	* application.js
	* Additional functions not provided by Indierock Media
	* by Andrew Carpenter
	* 
	* Functions found in this file utilize the
	* Mootools JS library. http://www.mootools.net
	* Documentation found at http://docs.mootools.net
	*****************************************************/
	
	// For main picture fader
	var mainPhotoArray = new Array();
	var photoDimmer;
	
	function showHideCommentedComments(theID, scrollWhat){
		var comments_area = "comments_commented_area-" + theID;
		var comment_form = "comment_commented_form-" + theID;
		var news_entry = "news_commented_entry-" + theID;
		var scroll = new Fx.Scroll(window, {
	  	wait: false,
	  	duration: 1000,
	  	transition: Fx.Transitions.Quad.easeInOut
	  });
	  $(comments_area).getElements('a[class=add_comment]').addEvent('click', function(event) {
	  	event = new Event(event).stop();
	  	scroll.toElement(comment_form);
	  });
		$(comments_area).getElements('a[class=close_it]').addEvent('click', function(event) {
	  	event = new Event(event).stop();
	  	scroll.toElement(news_entry);
	  	document.getElementById("comments_commented_area-" + theID).style.display = "none";
	  });
		if (document.getElementById(comments_area).style.display == "none"){
			document.getElementById(comments_area).style.display = "block";
			resizeNews("commented");	
		}else{
			document.getElementById("comments_commented_area-" + theID).style.display = "none";
			resizeNews("commented");	
		}

	}
	
	function showHideArchiveComments(theID, scrollWhat){
		var comments_area = "comments_archive_area-" + theID;
		var comment_form = "comment_archive_form-" + theID;
		var news_entry = "news_archive_entry-" + theID;
		var scroll = new Fx.Scroll(window, {
	  	wait: false,
	  	duration: 1000,
	  	transition: Fx.Transitions.Quad.easeInOut
	  });
	  $(comments_area).getElements('a[class=add_comment]').addEvent('click', function(event) {
	  	event = new Event(event).stop();
	  	scroll.toElement(comment_form);
	  });
		$(comments_area).getElements('a[class=close_it]').addEvent('click', function(event) {
	  	event = new Event(event).stop();
	  	scroll.toElement(news_entry);
	  	document.getElementById("comments_archive_area-" + theID).style.display = "none";
	  });
		if (document.getElementById(comments_area).style.display == "none"){
			document.getElementById(comments_area).style.display = "block";
			resizeNews("commented");	
		}else{
			document.getElementById("comments_archive_area-" + theID).style.display = "none";
			resizeNews("commented");	
		}

	}
	
	/****************************************************
	*	AJAX NEWS  PAGE LOADER
	* Loads content from other sources
	****************************************************/
	function loadPageContent(moduleName, contentDiv, pageNum, tagName, needsUpdate){
			
			if(!needsUpdate){
				needsUpdate = false;
			}
			
			var date = new Date();
			var url = "content.aspx?t=" + moduleName + "&PageNum=" + pageNum;
			if(tagName != ""){
				url += "&TagName=" + tagName;
			}
			url +="&" + date.getTime();
			
			var scroll = new Fx.Scroll(contentDiv, {
				wait: false,
				duration: 1000,
				transition: Fx.Transitions.Quad.easeInOut
			});
			
			new Ajax(url, {
				method: 'get',
				onRequest: function(){
					$('waiting_bar').setStyle('display', 'inline');
					var scrollTop = new Fx.Scroll(window, {
						wait: false,
						duration: 0,
						transition: Fx.Transitions.Quad.easeInOut
					});
					scrollTop.toElement("main_module");
					scroll.toTop();
				},
				onComplete: function(){
					$('waiting_bar').setStyle('display', 'none');
					if(needsUpdate){
						var news_module = $("news_module");
						var active_tab = $("archive_content");
						var tab_header = $("news_module_top");
						var safeFixedHeight = active_tab.getSize().size.y + tab_header.getSize().size.y + 25;
						news_module.effect("height",{duration: 500}).start(safeFixedHeight);
					}
				},
				update: $(contentDiv)
			}).request();
	}
	
	/****************************************************
	*	AJAX NEWS  SEARCH HANDLER
	* Loads content from other sources
	****************************************************/
	function searchNews(){
		var sBox = $("SearchText");
		loadPageContent('archive_module','archive_content', 1 , escape(sBox.value), true);
		/*var news_module = $("news_module");
		var active_tab = $("archive_content");
		var tab_header = $("news_module_top");
		var safeFixedHeight = active_tab.getSize().size.y + tab_header.getSize().size.y + 25;
		news_module.effect("height",{duration: 500}).start(safeFixedHeight);*/
	}
	
	function doSearchSubmit(event){
		var key =  event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
		if(key == 13){
			searchNews();
			return false;
		}
	}
	
	function goToCommentForm(ID){
		var storyHolder = $("singleitem_content");
		var scroll = new Fx.Scroll(window, {
			wait: false,
			duration: 1000,
			transition: Fx.Transitions.Quad.easeInOut
		});
		var scrollTop = new Fx.Scroll(storyHolder, {
			wait: false,
			duration: 0,
			transition: Fx.Transitions.Quad.easeInOut
		});
		scrollTop.toBottom();
		scroll.toElement("comment_story_form-"+ID);
	}
	
	/****************************************************
	*	AJAX MAIN PHOTO LOADER
	* Loads content from other sources
	****************************************************/
	function loadMainPhoto(filename, origPhotoElement){
		var origPhoto = $(origPhotoElement);
		var newPhoto = $("waiting_image");
		var loadingPhoto = $("waiting_bar_photo");
		newPhoto.src = origPhoto.src;
		newPhoto.setOpacity(1);
		loadingPhoto.style.display = "block";
		newPhoto.style.display = "block";
		var tempImg = new Image();
		tempImg.src = filename;	
		
		tempImg.onload = function(){
			origPhoto.src = this.src;
			loadingPhoto.style.display = "none";
			
			var fadePic = newPhoto.effect('opacity', {duration: 1500});
			fadePic.addEvent('onComplete', function() {
					newPhoto.style.display = "none";
					});
			fadePic.start(0);
			//newPhoto.style.display = "none";
		}
	}
	
	function loadMainPhoto2(fileID, origPhotoElement){
		if(photoDimmer){
			photoDimmer.stop();
		}
		var origPhoto = $(origPhotoElement);
		var newPhoto = $("waiting_image");
		
		var ua = navigator.userAgent;
		if(ua.indexOf("Windows") > -1 && ua.indexOf("Firefox/2") > -1){
			origPhoto.src = mainPhotoArray[fileID].src;																		
		}
		else{
			newPhoto.src = origPhoto.src;
			newPhoto.setOpacity(1);
			newPhoto.style.display = "block";
			origPhoto.src = mainPhotoArray[fileID].src;
			photoDimmer = newPhoto.effect('opacity', {duration: 1500});
			photoDimmer.addEvent('onCancel', function() {
					newPhoto.style.display = "none";
					});
			photoDimmer.addEvent('onComplete', function() {
					newPhoto.style.display = "none";
					});
			photoDimmer.start(0);
			//newPhoto.style.display = "none";
		}
	}
	
	function preloadMainPhoto(photoArray){
		if(photoArray){
			for (var i=0; i<photoArray.length; ++i ){
				var tempImg = new Image();
				tempImg.src = photoArray[i].url;
				mainPhotoArray[photoArray[i].id] = tempImg;
			}
		}
	}
	
	function pausecomp(millis){
		var date = new Date();
		var curDate = null;

		do { curDate = new Date(); }
		while(curDate-date < millis);
	} 
	
	function goToTopNews(){
		var scroll = new Fx.Scroll(window, {
			wait: false,
			duration: 1000,
			transition: Fx.Transitions.Quad.easeInOut
		});
		scroll.toElement("news_module");
	}
	
	function showSendToFriend(elem, newsitemID){
		var form = $("send_form");
		var coords = $(elem).getCoordinates();
		form.setStyle("top", coords.top + coords.height);
		form.setStyle("left", coords.left);
		form.setStyle("display", "block");
		$("send_post_id").value = newsitemID;
		$("send_to").value = "";
		$("send_from").value = "";
		$("send_name").value = "";
		$("send_form_waiting").style.display = "none";
		$("send_form_error").style.display = "none";
		$("send_form_form").style.display = "block";
	}
	
	function sendToFriend(){
		$("send_form_waiting").style.display = "block";
		$("send_form_error").style.display = "none";
		var date = new Date();
		var form = $("send_form_form")
		var request = new Ajax("content.aspx?t=send_to_friend&d=" + date.getTime(),
				{onComplete: updateFriend, method: "post", data: form} );
		request.request();
	}
	
	function updateFriend(request){
		$("send_form_waiting").style.display = "none";
		var x = eval("("+request+")");
		if(x.success == true){
			$("send_form_form").style.display = "none";
		}
		var messageDiv = $("send_form_error");
		messageDiv.style.display = "block";
		messageDiv.innerHTML = x.msg;
	}
	
	function reportAbuse(commentID){
		var date = new Date();
		var request = new Ajax("/artists/reportabuse.aspx?d=" + date.getTime(),
				{onComplete: notifyClient, method: "post", data: "commentID="+commentID} );
		request.request();
	}
	
	function notifyClient(request){
		alert("Thanks for the alert. We'll deal with it in short order.");
	}
