var siteGlobal = function () {
	// private
	function validateForm (id) {
		function isEmpty (val) {
			var testExp = /^\w+/i;
			return (testExp.test(val)) ? false : true;
		}
		var errors = [];
		var formEl = ($(id).tagName == 'FORM') ? $(id) : $(id).down('form');
		formEl.select('.req').each(function (el,i) {
			if (el.hasClassName('req')) {
				var elLbl = $(el.id + '_label').innerHTML;
				switch (el.tagName) {
				case 'INPUT' :
					switch (el.type) {
					case 'text' :
						if (isEmpty(el.value)) {
							errors.push(elLbl + ' was left empty.');
						} else {
							if (el.hasClassName('email')) {
								var format = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
								if (!format.test(el.value)) { errors.push(elLbl + ' is formatted wrong.'); }
							}
						}
						break;
					case 'radio' :
						
						break;
					case 'checkbox' :
						
						break;
					}
					break;
				case 'SELECT' :
					if (el.value == '') { errors.push(elLbl + ' was left empty.'); }
					break;
				case 'TEXTAREA' :
					if (isEmpty(el.value)) { errors.push(elLbl + ' was left empty.'); }
					break;
				}
			}
		});
		return errors;
	}
	
	function alertErrors (errEL,errs,type) {
		if (errs.length > 0) {
			var errStr = '';
			errs.each(function(err) { errStr += '<li>' + err + '</li>'; });
			errStr = '<div class="errContent"><h2>The following errors have been detected:</h2><ol>' + errStr + '</ol><div class="close" onclick="javascript:siteGlobal.closeFormMsg(this);"></div></div>';
			var errMsgEL = errEL.next('div.errMsg');
			if (errMsgEL === undefined) {
				var newEL = new Element('div',{'class':'errMsg','style':'display:none;'});
				errEL.insert({'after':newEL});
				errMsgEL = errEL.next('div.errMsg');
			}
			errMsgEL.update(errStr).blindDown({'duration':.5});
		}
	}
	
	//public
	var pub = function () {
		
		return {
			SITE : {},
			CONTENT : {},
			
			emailFriendPop : function (siteID,contentID) {
				if (!$('eFriendPopUp')) {
					var newEL = new Element('div',{'id':'eFriendPopUp','style':'display:none'});
					$('tWrapper').insert({'bottom':newEL});
				}
				
				var eForm = '<div class="wrapper">\
				<div class="form">\
				<h2>E-mail this page to a colleague.</h2>\
				<form id="eFriendForm" action="#" method="post" onsubmit="return siteGlobal.emailFriendSend();">\
				<fieldset>\
				<legend>To:</legend>\
				<div class="cols">\
					<div class="col">\
						<label id="ToName_label" for="ToName">Name</label>\
						<input type="text" class="text req" id="ToName" name="ToName" value="" />\
					</div>\
					<div class="col">\
						<label id="ToEmail_label" for="ToEmail">Email</label>\
						<input type="text" class="text req email" id="ToEmail" name="ToEmail" value="" />\
					</div>\
				</div>\
				</fieldset>\
				<fieldset>\
				<legend>From:</legend>\
				<div class="cols">\
					<div class="col">\
						<label id="FromName_label" for="FromName">Name</label>\
						<input type="text" class="text req" id="FromName" name="FromName" value="" />\
					</div>\
					<div class="col">\
						<label id="FromEmail_label" for="FromEmail">Email</label>\
						<input type="text" class="text req email" id="FromEmail" name="FromEmail" value="" />\
					</div>\
				</div>\
				</fieldset>\
				<fieldset class="formButtons">\
					<input type="submit" class="formButton fSubmit" value="" />\
					<input type="button" class="formButton fCancel" onclick="siteGlobal.emailFriendClose();" />\
				</fieldset>\
				<input type="hidden" name="siteID" value="' + siteID + '" />\
				<input type="hidden" name="contentID" value="' + contentID + '" />\
				</form>\
				</div>\
				</div>';
				
				var formEL = $('eFriendPopUp').update(eForm).appear({'durtion':.5});
				
				
				this.trackPG('view-send-to-friend');
			},
			
			emailFriendSend : function () {
				var formEL = $('eFriendForm');
				var errors = validateForm(formEL);
				
				if (errors.length > 0) {
					alertErrors(formEL,errors);
				} else {
					var ajaxFile = 'ajax/emailFriend.php';
					var ajaxParams = formEL.serialize(true);
					ajaxParams.cmd = 'send';
					var ajaxOpts = {method : 'post',
						parameters : ajaxParams,
						onSuccess : function(resp) {
							//alert(resp.responseText.strip());
							resp = resp.responseText.strip().evalJSON();
							var thanksMSG = '<fieldset>' + resp.msg + '</fieldset><fieldset class="formButtons"><input type="button" class="formButton fClose" onclick="siteGlobal.emailFriendClose();" /></fieldset>';
							formEL.onsubmit = null;
							formEL.update(thanksMSG);
						}
					}
					new Ajax.Request(ajaxFile,ajaxOpts);
					
					this.trackPG('send-to-friend');
				}
				return false;
			},
			
			emailFriendClose : function () {
				var fEL = $('eFriendPopUp');
				fEL.fade({'durtion':.5});
			},
			
			printPage : function (siteID,contentID) {
				this.trackPG('print-page');
				
				var pURL = this.SITE.base + 'printFriendly.php';
				var pCSS = 'printFriendly/site_' + siteID + '/site_' + siteID + '.css';
				Dynalicious.printFriendly({'el':'.printFriendly','url':pURL,'css':pCSS});
			},
			
			siteLogin : function () {
				var formEL = $('loginForm');
				var errors = validateForm(formEL);
				
				if (errors.length < 1) {
					var ajaxFile = 'ajax/front_login.php';
					var ajaxParams = formEL.serialize(true);
					ajaxParams.cmd = 'login';
					var ajaxOpts = {method : 'post',
						parameters : ajaxParams,
						onSuccess : function(resp) {
							//alert(resp.responseText.strip());
							resp = resp.responseText.strip().evalJSON();
							if (resp.errors.length > 0) {
								alertErrors(formEL,resp.errors);
							} else {
								window.location = resp.redir;
							}
						}
					}
					new Ajax.Request(ajaxFile,ajaxOpts);
				} else {
					alertErrors(formEL,errors);
				}
				return false;
			},
			
			closeFormMsg : function (btnEL) {
				$(btnEL).up('.errMsg').blindUp({'duration':.5});
			},
			
			popUpImg : function (img) {
				var newEL = new Element('div',{'id':'imgPopUp','class':'imgPopUp','style':'visibility:hidden;position:absolute;top:0;z-index:999999;left:50%;'}).update('<img src="' + img + '" /><div class="close" onclick="javascript:siteGlobal.closePopUpImg(this);"></div>');
				$('tWrapper').insert({'bottom':newEL});
				var popEL = $('imgPopUp');
				var popImg = popEL.down('img');
				
				new PeriodicalExecuter(function(pe) {
					var imgDims = popImg.getDimensions();
					if (imgDims.width > 0) {
						var divWidth = imgDims.width;
						var divHeight = imgDims.height;
						var divMar = 0 - (divWidth / 2);
						popEL.setStyle({'display':'none','visibility':'visible','marginLeft':divMar + 'px','width':divWidth + 'px','height':divHeight + 'px'});
						popEL.blindDown({'duration':.5});
						pe.stop();
					}
				},.1);
			
			
			
			},
			
			closePopUpImg : function (btnEL) {
				$(btnEL).up('.imgPopUp').blindUp({'duration':.5,'afterFinish':function() { $(btnEL).up('.imgPopUp').remove(); } });
				
			},
			
			trackPG : function (dir) {
				// analytics
				var trackStr = '/' + this.SITE.name + '/' + this.CONTENT.name + '/' + dir + '/';
				if (typeof pageTracker === 'object' || typeof pageTracker === 'function') {
					pageTracker._trackPageview(trackStr);
				}
			},
			
			watchStory : function (id) {
				//alert(this.SITE.baseHTML);
				var story = null;
				var stories = [{'id':1,'name':'WCC_graduation','dir':'Graduation_Video'},{'id':2,'name':'WCC_promotion','dir':'Promotion_Video'},{'id':3,'name':'WCC_preschool','dir':'Preschool_Video'},{'id':4,'name':'WCC_restaurant','dir':'Restaurant_Video'},{'id':5,'name':'WCC_frisbee','dir':'Frisbee_Video'}];
				
				stories.each (function(s) {
					if (s.id == id) { story = s; }
				});
				var winContent = '';
				if (story !== null) {
					var vidSRC = 'videos/' + story.dir + '/' + story.name;
					winContent = '<div id="storyFlaVid">\
					<script language="javascript">\
						if (AC_FL_RunContent == 0) {\
							alert("This page requires AC_RunActiveContent.js.");\
						} else {\
							AC_FL_RunContent (\
								\'codebase\', \'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0\',\
								\'width\', \'440\',\
								\'height\', \'360\',\
								\'src\', \'' + vidSRC + '\',\
								\'quality\', \'high\',\
								\'pluginspage\', \'http://www.macromedia.com/go/getflashplayer\',\
								\'align\', \'middle\',\
								\'play\', \'true\',\
								\'loop\', \'true\',\
								\'scale\', \'showall\',\
								\'wmode\', \'window\',\
								\'devicefont\', \'false\',\
								\'id\', \'' + story.name + '\',\
								\'bgcolor\', \'#000000\',\
								\'name\', \'' + story.name + '\',\
								\'menu\', \'true\',\
								\'allowFullScreen\', \'false\',\
								\'allowScriptAccess\',\'sameDomain\',\
								\'movie\', \'' + vidSRC + '\',\
								\'salign\', \'\'\
								);\
								setTimeout(function () { $(\'storyFlaVid\').update(AC_GLOBAL.flaVid); }, 250);\
						}\
					</script>';
					
					winContent += '<noscript>\
					<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="440" height="360" id="' + story.name + '" align="middle">\
					<param name="base" value="' + this.SITE.baseHTML + '" />\
					<param name="allowScriptAccess" value="sameDomain" />\
					<param name="allowFullScreen" value="false" />\
					<param name="movie" value="' + vidSRC + '.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#000000" />\
					<embed src="' + vidSRC + '.swf" base="' + this.SITE.baseHTML + '" quality="high" bgcolor="#000000" width="440" height="360" name="' + story.name + '" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />\
					</object>\
					</noscript>';
	
					Dynalicious.openOverlayWin(winContent,{'wait':true,'closeWin':true,'w':480,'h':400});
					
					
				}
				
			},
			
			closeDebug : function () {
				$(siteDEBUG).blindUp({'duration':.5});
			},
			
			submitForm : function (fID) {
				var formEL = ($(fID).tagname == 'FORM') ? $(fID) : $(fID).down('form');
				var errors = validateForm(fID);

				if (errors.length > 0) {
					alertErrors(formEL,errors);
					return false;
				} else {
					return true;
				}
			},
			
			popLink : function (id) {
				var wC = '',wW = 400,wH = 500;
				switch (id) {
				case 'accreditation' :
					wH = 100;
					wC = '<p>Waubonsee Community College is accredited by <a href="http://www.ncahlc.org/" target="_blank">The Higher Learning Commission of the North Central Association of Colleges and Schools </a>(NCA) and is recognized by federal and state agenicies administering financial aid.</p>';
					break;
				case 'notices' :
					wC = '<h2>Terms and Conditions</h2>\
					<p>Waubonsee Community College\'s web site\'s purpose is to provide information and promotion to the community. In the event that there is a discrepancy between information found on the official Waubonsee Community College web site and a printed publication, the information found within the printed publication will over ride any information found within the web site.\
					<p>Some of Waubonsee Community College\'s web pages contain links to web pages that are not affiliated with Waubonsee Community College. The offering of these links does not mean that Waubonsee endorses or approves of the content found on these web pages.</p>\
					<p>Waubonsee Community College adheres to all copyright laws. For further information on copyright laws please visit the U.S. Copyright Office website or the Copyright laws of the U.S. website.</p>\
					<p>For further information please contact Jeff Noblitt, Director of Marketing and Communications.</p></p>\
					<h2>Non-discrimination Policy</h2>\
					<p>Waubonsee Community College does not discriminate on the basis of race, color, religion, sex, sexual orientation, age, national origin, veteran\'s status, marital status, disability or any other characteristic protected by law in its programs and activities.\
					<p>For more information on the college\'s nondiscrimination policies, contact the Director of Human Resources at (630) 466-7900, ext. 2367; Waubonsee Community College, Route 47 at Waubonsee Drive, Sugar Grove, IL 60554-9454.</p></p>\
					<h2>Voter Registration</h2>\
					<p>For information on registering to vote, and to download a registration form, visit the Web site of the Illinois State Board of Elections.</p>';
					break;
				}
				wC = '<div style="padding:26px 26px 0 0;">' + wC + '</div>';
				Dynalicious.openOverlayWin(wC,{'closeWin':true,'w':wW,'h':wH});
			}
		}
	}();
	
	return pub;
	
}();