// Making the Article page my marionette with Mouvement...
	
	var mainMenu = Array();
	// Mouvement launch sequence
	Page.onReady = function() {
		// Set up input watching for the comment field. (Mobile browsers only - this variable is fed through PHP).
		var hifi = false;
		var OSString = navigator.appVersion;
		if (OSString.indexOf("Win") != -1 || OSString.indexOf("Mac") != -1 || OSString.indexOf("X11") != -1 || OSString.indexOf("Linux") != -1) {
			hifi = true;
		}

		if (hifi) { /* High-fidelity mode activates only on a desktop browser as these effects are more resource intensive */
			// Shine the logo if we're in high fidelity mode!
			kLogo = Page.preShine('kashmaniacLogo', true);
			
			var menuBtns = Array("mainHomeBtn", "mainBlogBtn", "mainPortfolioBtn", "mainKashiBtn", "mainContactBtn");
			var thisPage = 1;
			var i = menuBtns.length;
			while (i--) {
				var currentBtn = Page.grabItem(menuBtns[i]);
				currentBtn.display.alpha = 0;
				if (i !== thisPage) {
					Page.hoverFade(currentBtn, 100, 0, 0.25, 0.5);
					var menuImage = Page.grabItem(currentBtn.domElement.firstChild);
					menuImage.placeHolder = true;
					menuImage.move("nowhere", 76, 0.5);

					var slide = function(e) {
						var menuItem = (e.currentTarget !== undefined) ? e.currentTarget : e.srcElement;
						if (menuItem.tagName === 'IMG') {
							var mouveItem = Page.grabItem(menuItem);
						} else if (menuItem.tagName === 'DIV') {
							var mouveItem = Page.grabItem(menuItem.nextSibling);
						} else {
							var mouveItem = Page.grabItem(menuItem.lastChild);
						}
						
						if (e.type === "mouseover") {
							mouveItem.move("nowhere", 0, 0.5);
						} else {
							mouveItem.move("nowhere", 76, 0.5);
						}
					}
				
					if (currentBtn.domElement.addEventListener != undefined) {
						currentBtn.domElement.addEventListener('mouseover', slide, false);
						currentBtn.domElement.addEventListener('mouseout', slide, false);
					} else {
						currentBtn.domElement.attachEvent('onmouseover', slide);
						currentBtn.domElement.attachEvent('onmouseout', slide);
					}
				} else {
					currentBtn.display.alpha = 0;
					currentBtn.alpha(100, 0.5);
				}
			}
			
			var name = new CheckField('nameField');
			name.regExpression = /^[a-z0-9\s\!\.]+$/i;
			var email = new CheckField('emailField');
			email.regExpression = /^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+(?:[A-Z]{2}|com|edu|org|net|gov|mil|biz|info|mobi|name|aero|jobs|museum)\b$/i; //'
			// Thank you to regular-expressions.info for the email regular expressions pattern 
			
			email.minLength = 8;
			var website = new CheckField('webField');
			website.regExpression = /^(http\:\/\/|https\:\/\/|www\.){0,2}[A-Za-z0-9-]{2,}\.[A-Za-z0-9-\.]{0,10}[\.]{0,1}[a-zA-Z]{2,3}[a-zA-Z\/\.\-_0-9\?\!\$\&\(\)\'%\#\=\+\;\:\,]{0,100}[^.]$/i; //'
			website.minLength = 0;
			
			website.okImg = "../images/blogCommentText220BackCorrect.png";
			website.invalidImg = "../images/blogCommentText220BackIncorrect.png";
			website.idleImg = "../images/blogCommentText220BackIdle.png";
			
			var blogId = new CheckField('blogId');
			blogId.minLength = 0;
			blogId.progressiveCheck = false;
			
			var commentBody = new CheckField('commentField');
			commentBody.progressiveCheck = false;
			
			for (i = 0; i < fields.length; i++) {
				fields[i].watchField();
			}
			
			bCommForm = Page.grabItem("blogCommentForm");
			bCommForm.resize(bCommForm.display.originalWidth, document.getElementById('sendBtn').offsetTop - 16,0.5);

		}

		// Animate the statements into view and save them as objects.
		statements = new Array();
		statementDivs = document.getElementById('blogRight');
		statementDivs = statementDivs.getElementsByTagName('p');
		
		if (statementDivs != undefined && (statementDivs.length > 0)) {
			for (i = 0; i < statementDivs.length; i++) {
				statements[i] = Page.grabItem(statementDivs[i]);

				statements[i].alpha(100,Math.round(45 * (i/statementDivs.length))/100 + 0.2,0.1 + (0.15*(i+1)), 0);
				statements[i].alpha(50,Math.round(45 * (i/statementDivs.length))/100 + 0.5,0.3 + (0.15*(i+1)), 100);
				
				statements[i].move(statements[i].display.originX - 9, statements[i].display.originY - 4, Math.round(45 * (i/statementDivs.length))/100 + 0.2, 0.1 + (0.15*(i+1)), undefined, 0);
				Page.hoverFade(statements[i], 100, 50, 0.25, 0.5);
			}
		}
		
		// Animate the "Blog Home" link
		homePageLink = Page.grabItem("blogHomeBtn");

		lastPage = document.referrer;
		if (lastPage.indexOf('blog/older') != -1) {
			homePageLink.domElement.href = lastPage;
		}
		if (this.isIE) {// Oh Microsoft... IE9 better be worth it!
			homePageLink.domElement.childNodes[0].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src=" + homePageLink.domElement.childNodes[0].src + ",sizingMethod='image')";
		}
		
		homePageLink.move("nowhere", homePageLink.display.originY + 64, 0.45);
		homePageLink.alpha(50, 0.1);
		homePageLink.alpha(100, 0.1, 0.1, 50);
		homePageLink.alpha(75, 0.5, 0.2, 100);

		Page.hoverFade(homePageLink, 100, 75, 0.1, .25);
		setTimeout(function() {Page.play();}, Page.heartbeat);
	}
	
	// Lastly, the comments mechanism...
	commentDiv = document.getElementById('blogCommentForm');
	function comment(e) {
		var wrap = function(text) {
			commentDiv.innerHTML = '<div class="response">'  + text + '</div>';
		}
		
		var process = function(response) {
			var bCommForm = Page.grabItem("blogCommentForm");
			if (response === "success") {
				wrap('Thank you for your comment, please refresh the page and you\'ll see it appear above.');
				bCommForm.resize(bCommForm.display.originalWidth, 24,0.5);
			} else if (response === "duplicate") {
				wrap('This comment has already been submitted. Please refresh the page if you can\'t see it.');
				bCommForm.resize(bCommForm.display.originalWidth, 24,0.5);
			} else {
				commentDiv.innerHTML = response;
			}
		}
		switch (e.target.readyState) { 
			case 1 : wrap("Sending...");
					 break;
			case 2 : wrap("Processing...");
					 break;
			case 3 : wrap("Receiving...");
					 break;
			case 4 : process(e.target.responseText);
					 break;
			default: wrap("Error!");
		}
		
		
	}