
// global

var d = document;

// onload

window.onload = function() {
	$("input,textarea").focus(function() {
		$(this).css({ "border-color":"#999","color":"#000" });
	});
	$("input,textarea").blur(function() {
		$(this).css({"border-color":"#ccc","color":"#333"});
	});
	setTimeout(function() {
		$("#coverArtwork a").animate({width:"207px"},300);
	},500);
	$(".new").fadeIn(300);
	setTimeout(function() {
		$(".formSuccess").fadeOut(1000);
	},4000);
	$(".required").fadeIn(300);
}

// xhr

var xHRObject = false;
if (window.XMLHttpRequest) {
	xHRObject = new XMLHttpRequest();
} else if (window.ActiveXObject) {
	xHRObject = new ActiveXObject("Microsoft.XMLHTTP");
}

// return request data

function returnData() {
	if (xHRObject.readyState == 4 && xHRObject.status == 200) {
		var serverText = xHRObject.responseText;
		if (serverText.indexOf('|' != -1)) {
			element = serverText.split('|');
			d.getElementById(element[0]).innerHTML = element[1];
			if (element[2] != null) {
				d.getElementById(element[2]).innerHTML = element[3];
			}
		}
	}
	$(window).load();
}

// newsletter subscribe

function subscribe() {
	$("#subscribe .required").remove();
	$("#subscribe .loading").animate({width:"24px"},300);
	var subscribeName = d.getElementById('subscribeName').value;
	var subscribeEmail = d.getElementById('subscribeEmail').value;
	setTimeout(function() {
		xHRObject.open(
					   "POST",
					   "/php/subscribe.php?subscribeName="+encodeURIComponent(subscribeName)+
					   "&subscribeEmail="+encodeURIComponent(subscribeEmail),
					   true
					   );
		xHRObject.onreadystatechange = returnData;
		xHRObject.send(null);
	},500);
}

// send online message

function sendMessage() {
	$("#getInTouch .required").remove();
	$("#getInTouch .loading").animate({width:"24px"},300);
	var sendMessageName = d.getElementById('sendMessageName').value;
	var sendMessageEmail = d.getElementById('sendMessageEmail').value;
	var sendMessageURL = d.getElementById('sendMessageURL').value;
	var sendMessageMessage = d.getElementById('sendMessageMessage').value;
	var data = "sendMessageName="+encodeURIComponent(sendMessageName)+
		"&sendMessageEmail="+encodeURIComponent(sendMessageEmail)+
		"&sendMessageURL="+encodeURIComponent(sendMessageURL)+
		"&sendMessageMessage="+encodeURIComponent(sendMessageMessage);
	setTimeout(function() {
		xHRObject.open("POST","/php/send_message.php",true);
		xHRObject.setRequestHeader("Content-type","application/x-www-form-urlencoded");
		xHRObject.onreadystatechange = returnData;
		xHRObject.send(data);
	},500);
}

// post musing comments

function postComment() {
	$("#postComment .required").remove();
	$("#postComment .loading").animate({width:"24px"},300);
	var postCommentMuse = d.getElementById('postCommentMuse').value;
	var postCommentName = d.getElementById('postCommentName').value;
	var postCommentURL = d.getElementById('postCommentURL').value;
	var postCommentComment = d.getElementById('postCommentComment').value;
	var data = "postCommentMuse="+encodeURIComponent(postCommentMuse)+
		"&postCommentName="+encodeURIComponent(postCommentName)+
		"&postCommentURL="+encodeURIComponent(postCommentURL)+
		"&postCommentComment="+encodeURIComponent(postCommentComment);
	setTimeout(function(){
		xHRObject.open("POST","/php/post_comment.php",true);
		xHRObject.setRequestHeader("Content-type","application/x-www-form-urlencoded");
		xHRObject.onreadystatechange = returnData;
		xHRObject.send(data);
	},500);
}
