
/*  -----------------  Common scripts for blueeyesmagazine.com  -------------------------  */

//  Controls the main dhtml menu, dependent on mootools.js

window.addEvent('domready', function() {
	
	var menuClose = new Image();
	menuClose.src = 'http://blueeyesmagazine.com/images/common/button_menu_open.gif';
									 
	var goNav = new Fx.Elements( $$('div.slides'), {
		'onComplete' : function() {
			if (this.state == 0) { 
				this.state = 180;
				$('menu-button-img').setProperty('src', '/images/common/button_menu_close.gif');
			} else {
				this.state = 0;
				$('menu-button-img').setProperty('src', '/images/common/button_menu_open.gif');
			}
		},
		'duration' : 400,
		transition : Fx.Transitions.sineInOut
	});
	
	goNav.state = 0;
	
	menuSlide = function() {
		if (goNav.state == 0) { 
			goal = 180;
		} else { 
			goal = 0;
		}
		goNav.start({
			'0' : { 'top' :  goal},
			'1' : {'top' : goal}
		});			
	}
	
/*// set the inner page to at least the height of the window	
	if ( $('box-content-inner').getSize().size.y <  window.getScrollHeight() ) { 
		$('box-content-inner').setStyle('height', window.getScrollHeight() + 'px');
	}	*/
	
});

/*  --------  Comment scripts, including email/URL validation and dhtml. Dependent on mootools.js  --------- */

var tbox = null;

isU = function isUrl(s) {
	if (s) {
		var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
		return regexp.test(s);
	} else {
		return true;
	}
}

isE = function isValidEmail(str) {
	if (str) {
   		return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
	} else {
		return true;
	}
}

function commentPreview() {
	theirName = $('name').getValue();
	theirEmail = $('email').getValue();
	theirURL = $('url').getValue();
	theirComment = $('comment').getValue();
	if ( theirURL == 'http://' ) { theirURL = ''; }
	if ( isU(theirURL) && isE(theirEmail) && theirComment && theirName ) {
		now = new Date();
		m = now.getMonth() + 1;
		d = now.getDay();
		d < 10 ? d = "0" + d : '';
		y = now.getFullYear() + "";
		console.log(y);
		y = y.substring(2, 4);
		console.log(y);
		//y < 10 ? y = "0" + y : '';
		//console.log(y);
		theirDate = m + "/" + d + "/" + y;
	
		tHeadString = theirDate + '&nbsp;|&nbsp;';
		if (theirEmail) {
			tHeadString += '<a href="' + theirEmail + '">' + theirName + '</a>';
		} else {
			tHeadString += theirName;
		}
	
		if (theirURL) {
			tSpanString = '<a href="' + theirURL + '">Website</a>';
		}
	
		tBox = new Element('div');
		tBox.addClass('box-comment');
		tBox.addClass('comment-preview');
		tBox.injectAfter('comments-start');
	
		var tHead = new Element('h6');
		tHead.setHTML(tHeadString);
		if (theirURL) {
			var tSpan = new Element('p');
			tSpan.addClass('comment-url');
			tSpan.setHTML(tSpanString);
		}	
	
		var tBody = new Element('div');
		tBody.addClass('comment-body');
		tBody.setHTML(theirComment);

		$('commentform-preview').setStyle('display', 'none');
		$('commentform-cancel').setStyle('display', 'inline');
		tBox.effects({duration : 200}).start({'background-color': ['#D3D3D3','#FFFFFF']});
		tHead.injectInside(tBox);
		tSpan ? tSpan.injectInside(tBox) : '';
		tBody.injectInside(tBox);
	} else {
		alert("Name and Comment are required. Email and URL must be valid if provided.");
	}
}

function unPreview() {
	tBox.effects({duration : 100, onComplete : function(){ tBox.remove(); } }).start({'background-color': ['#D3D3D3','#FFFFFF']});
	$('commentform-preview').setStyle('display', 'inline');
	$('commentform-cancel').setStyle('display', 'none');
}
