// JavaScript Document
var str = window.location.href;
	var len = window.location.href.length;
	var less = 8;
	var start = len - 7;
	
	if(str.substr(start) == "a/1.cfm") {
		//alert('yo');
		var startpos = $('#sidebar h3').position();
		$('#glower').css( {
			top: startpos.top,
			left: startpos.left,
			position: "absolute",
			display: "block"
						 }).animate( {opacity: 0}, 3000);
			
		
		//$('#sidebar h3').animate( {opacity: "url(i/Shared/bg-side-title-glow.jpg) no-repeat scroll left top"}, 3000 );
		/*$('#sidebar h3').css( {background: 'url(/i/Shared/bg-side-title-glow.jpg) no-repeat scroll left top'} ).animate( {opacity: .25}, 2000)
		.queue( function() {
			$('#sidebar h3').css( {background: 'url(/i/Shared/bg-side-title2.jpg) no-repeat scroll left top'} ).animate( {opacity: 1}, 0);
			$('#sidebar h3').dequeue();
		 });
		*/
		//$('#sidebar h3').css( {background: 'url(/i/Shared/bg-side-title-glow.jpg) no-repeat scroll left top'} );
		/*
		$('#sidebar h3').animate( {opacity: 1},4000)
		.queue(function() {
			$(this).css( {background: 'url(/i/Shared/bg-side-title2.jpg) no-repeat scroll left top'} );
			$(this).dequeue();
		})
		.animate( {opacity: 1},4000);
		*/
	}
if( document.addEventListener ) document.addEventListener( 'DOMContentLoaded', cmxform, false );

function cmxform(){
	// Hide forms
	$( 'form.cmxform' ).hide().end();
	
	// Processing
	$( 'form.cmxform' ).find( 'li>label' ).not( '.nocmx' ).each( function( i ){
		
		var labelContent = this.innerHTML;
		var labelWidth = document.defaultView.getComputedStyle( this, '' ).getPropertyValue( 'width' );
		var labelSpan = document.createElement( 'span' );
			labelSpan.style.display = 'block';
			labelSpan.style.width = labelWidth;
			labelSpan.innerHTML = labelContent;
		this.style.display = '-moz-inline-box';
		this.innerHTML = "";
		this.appendChild( labelSpan );
		} ).end();	
	
	// Show forms
	$( 'form.cmxform' ).show().end();
}

function changebus() {
	var dobus = $(".radbus:checked").val();
	if ( dobus == 'None') {
		$(".busyes").hide("normal");
		$(".busno").show("normal");
		$("#changelist").removeOption("");
		$("#changelist").removeOption("Sutherland Campus, Peterborough");
		$("#changelist").removeOption("Frost Campus, Lindsay");
		$("#changelist").removeOption("McRae Campus, Peterborough");
		$("#changelist").removeOption("Haliburton Campus, Haliburton");
		$("#changelist").removeOption("Cobourg Campus, Cobourg");
		$("#changelist").removeOption("Eastern Ontario Fire Academy, Norwood");
		var myOptions = {
			"" : "----  select location ----",
			"Sutherland Campus, Peterborough" : "Sutherland Campus, Peterborough",
			"McRae Campus, Peterborough" : "McRae Campus, Peterborough",
			"Frost Campus, Lindsay" : "Frost Campus, Lindsay",
			"Haliburton Campus, Haliburton" : "Haliburton Campus, Haliburton",
			"Cobourg Campus, Cobourg" : "Cobourg Campus, Cobourg",
			"Eastern Ontario Fire Academy, Norwood" : "Eastern Ontario Fire Academy, Norwood"
			}
		$("#changelist").addOption(myOptions, false);
		}
	else {
		$(".busno").hide("normal");
		$(".busyes").show("normal");
		$("#changelist").removeOption("");
		$("#changelist").removeOption("Sutherland Campus, Peterborough");
		$("#changelist").removeOption("Frost Campus, Lindsay");
		$("#changelist").removeOption("McRae Campus, Peterborough");
		$("#changelist").removeOption("Haliburton Campus, Haliburton");
		$("#changelist").removeOption("Cobourg Campus, Cobourg");
		$("#changelist").removeOption("Eastern Ontario Fire Academy, Norwood");
		var myOptions = {
			"" : "----  select location ----",
			"Sutherland Campus, Peterborough" : "Sutherland Campus, Peterborough",
			"McRae Campus, Peterborough" : "McRae Campus, Peterborough",
			"Frost Campus, Lindsay" : "Frost Campus, Lindsay"
			}
		$("#changelist").addOption(myOptions, false);
	}
}

// Change dates on Welcome Days Registration
function changeDates() {
	
	var dodate = $("#CAMPUS").val();
	if ( (dodate == 'Sutherland Campus, Peterborough') || (dodate == 'McRae Campus, Peterborough') || (dodate == '')) {
		
		if (dodate == 'McRae Campus, Peterborough')
			$('#mcrae-notice').show("normal");
		else
			$('#mcrae-notice').hide();
			
		$("#EVENT_DATE").removeOption(/./);
		var myOptions = {
			"" : "----  select date ----",
			"07/12/10" : "Monday July 12",
			"07/13/10" : "Tuesday July 13",
			"07/14/10" : "Wednesday July 14",
			"07/15/10" : "Thursday July 15",
			"07/16/10" : "Friday July 16"
			}
		$("#EVENT_DATE").addOption(myOptions, false);
	}
	else {
		$('#mcrae-notice').hide();
		
		$("#EVENT_DATE").removeOption(/./);
		var myOptions = {
			"" : "----  select date ----",
			"07/12/10" : "Monday July 12",
			"07/13/10" : "Tuesday July 13",
			"07/15/10" : "Thursday July 15",
			"07/16/10" : "Friday July 16"
			}
		$("#EVENT_DATE").addOption(myOptions, false);
	}
}
// Change ACCUPLACER times on Welcome Days Registration
function changeAccuplace() {
	
	var dodate = $("#CAMPUS").val();
	if ( (dodate == 'Sutherland Campus, Peterborough') || (dodate == 'McRae Campus, Peterborough') || (dodate == '')) {
		
		$('#rabies_opt').hide();
		
		$("#ACCUPLACER").removeOption(/./);
		var myOptions = {
			"" : "----  select appointment ----",
			"11:30" : "11:30",
			"12:30" : "12:30",
			"1:30" : "1:30",
			"2:30" : "2:30"
			}
		$("#ACCUPLACER").addOption(myOptions, false);
	}
	else {
		$('#rabies_opt').show();
		
		$("#ACCUPLACER").removeOption(/./);
		var myOptions = {
			"" : "----  select appointment ----",
			"12:00" : "12:00",
			"1:00" : "1:00",
			"3:00" : "3:00"
			}
		$("#ACCUPLACER").addOption(myOptions, false);
	}
}
// Change ACCUPLACER times on Welcome Days Registration
function changeWDSession() {
	
	var dodate = $("#CAMPUS").val();
	if ( (dodate == 'Sutherland Campus, Peterborough') || (dodate == 'McRae Campus, Peterborough') || (dodate == '')) {
		
		$('#wd_session_br').show();
		$('#wd_session_fr').hide();
	}
	else {
		$('#wd_session_br').hide();
		$('#wd_session_fr').show();
		
	}
}
function changeWDForm() {
		changeDates();
		changeAccuplace();
		changeWDSession();
	}
	
function clearInput(input) {
	if (input.defaultValue==input.value) {
	input.value = "";
	$(input).css("color","black");
	}
}
function setInput(input,val) {
	if (input.value=="") {
		input.value = val;
		$(input).css("color","");
	}
	else {
		$(input).css("color","black");
	}		
}
var alertRules =  function () {
	alert('Please read and accept the Contest Rules');
	return false;
};

function checkTermsAccept() {
	if($("#terms").attr("checked")) {		
		$("#submitwithterms").removeAttr("disabled");
		$("#submitwithterms").unbind("click", alertRules );
	}
	else {
		$("#submitwithterms").attr("disabled","disabled");
		$("#submitwithterms").bind("click", alertRules);
		
	}
}

$("#terms").click( function () {
	checkTermsAccept();
});

checkTermsAccept();

function hideLoad(msg) {
	$('#PIN').val(msg).attr('readonly','readonly');
	$('#loadPin').remove();
}
	

$(document).ready(function(){ 
						   
	/* This eliminates the background-image flicker bug in IE6 */
	try {
	  document.execCommand('BackgroundImageCache', false, true);
	} catch(e) {}

	// create a dropshadow on images within the program pages
	$('#program-overview img').each(function() {
		$(this).after('<div class="clear"></div>').wrap('<div class="program-img-shadow"></div>');		
	});
	
	// HOME PAGE BANNER ROTATION
	/* Disabled and replaced  below with a sinble flash file
		//banner object template
		function banner(html) {
			this.html = html;
		}
		var bannerArr = new Array();
		
		// array of banner objects
		//NOTE: the first array object will be the same as the default banner in the markup.
		bannerArr[0] = new banner($('#feat').html());
		bannerArr[1] = new banner('<div style="width:770px;margin:0px 10px;"><a href="http://'+location.hostname+'/index.cfm/go/programs/sub/display/code/SAG.cfm" title="Sustainable Agriculture"><img src="/i/Home/banner-Sustainable-Agriculture-0609.jpg" width="770" height="220" alt="Sustainable Agriculture" /></a></div>');
		bannerArr[2] = new banner('<div style="width:770px;margin:0px 10px;"><a href="http://'+location.hostname+'/index.cfm/go/programs/sub/display/code/EMP.cfm" title="Emergency Management"><img src="/i/Home/banner-Emergency-Management-0609.jpg" width="770" height="220" alt="Emergency Management" /></a></div>');
		bannerArr[3] = new banner('<div style="width:770px;margin:0px 10px;"><a href="http://'+location.hostname+'/index.cfm/go/programs/sub/display/code/WDF.cfm" title="Web Design Fundamentals"><img src="/i/Home/banner-Web-Developer-0609.jpg" width="770" height="220" alt="Web Design Fundamentals" /></a></div>');
		
		$('#feat').html(''); // clears the banner container of the default banner so it's bot repeated in rotation
		var x=0;	
		while(x < bannerArr.length) {
			$('#feat').append(bannerArr[x].html);
			x++;
		}	
		// begin rotation of banners
		$('#feat').cycle({ 
			fx:    'fade', 
			pause: 1,
			timeout: 4000
		});	
	*/
	
	// preload images from css
	//$.preloadCssImages();
	// END HOME PAGE BANNER ROTATION
	
	/*										
	$('.sf-menu').supersubs({ 
            minWidth:    12,   // minimum width of sub-menus in em units 
            maxWidth:    27,   // maximum width of sub-menus in em units 
            extraWidth:  1     // extra width can ensure lines don't sometimes turn over 
                               // due to slight rounding differences and font-family 
		}).superfish({ 
            animation: {height:'show'},   // slide-down effect without fade-in 
            delay:     1200,              // 1.2 second delay on mouseout 
			autoArrows: false
	  }); 
	*/
	// HOME PAGE FEATURE REPLACEMENT
	//banner= '<div style="width:770px;margin:0px;z-index: 0;"><scr'+'ipt src="js/AC_RunActiveContent.js" type="text/javascript" language="javascript"></scr'+'ipt><div style="width:770px;margin:0px 10px;z-index: 0;"><object style="z-index: 0;" height="220" align="middle" width="770" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" name="fadeimagesequence" id="IDS" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0"><param name="wmode" value="transparent" /> <param value="/Home/News/Media/fadeimagesequence.swf" name="movie"/> <param value="high" name="quality"/> <param value="sameDomain" name="allowscriptaccess"/> <param value="false" name="allowfullscreen"/> <embed height="220" align="middle" width="770" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" allowfullscreen="false" allowscriptaccess="sameDomain" name="banner_IDS" quality="high" src="/Home/News/Media/fadeimagesequence.swf" id="IDS" wmode="transparent" /></object></div>';
	//banner= '<div style="width:770px;margin:0px;z-index: 0;"><scr'+'ipt src="js/AC_RunActiveContent.js" type="text/javascript" language="javascript"></scr'+'ipt><div style="width:770px;margin:0px 10px;z-index: 0;"><object style="z-index: 0;" height="220" align="middle" width="770" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" name="preview" id="IDS" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0"><param name="wmode" value="transparent" /> <param value="/Home/preview.swf" name="movie"/> <param value="high" name="quality"/> <param value="sameDomain" name="allowscriptaccess"/> <param value="false" name="allowfullscreen"/> <param value="/Home/banner/xml/banner.xml" name="xmlPath"/> <embed height="220" align="middle" width="770" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" allowfullscreen="false" allowscriptaccess="sameDomain" name="banner_IDS" quality="high" src="/Home/preview.swf" id="IDS" wmode="transparent" xmlPath="/Home/banner/xml/banner.xml" /></object></div>';
	//banner = '<div style="width:770px;margin:0px;z-index: 0;"><div id="FlabellComponent" style="width:100%;height:100%;"></div></div>';
	// PARAMS
		$('#feat').html(''); // clears the banner container of the default banner
		
		var params = {};
		    params.bgcolor = "#FFFFFF";
		    params.menu = "false";
		    params.scale = 'noScale';
		    params.wmode = "opaque";
		    params.allowfullscreen = "true";
		    params.allowScriptAccess = "always";
		    
		    // ATTRIBUTES
		    var attributes = {};
		    attributes.id = 'feat';
		    attributes.name = 'feat'
		    
		    // JAVASCRIPT VARS 
			// cache buster
			var cacheBuster = Date.parse(new Date());		    
		    
		    // stage dimensions
		    var stageW = 790;
			var stageH = 220; 
		    
		    /** FLASH VARS **/
		    var flashvars = {};
		    
		    // component dimensions inside the SWF file
		    flashvars.componentWidth = stageW;
			flashvars.componentHeight = stageH;
			
			// path to files (can be "")
			flashvars.pathToFiles = "/Home/banner/";
			
			// path to content XML
			flashvars.xmlPath = "/xml/banner.xml";
			
		    /** EMBED THE SWF**/        
            swfobject.embedSWF('/Home/preview.swf', 'feat', stageW, stageH, '9.0.45', '/js/expressinstall.swf', flashvars, params, attributes);
        
	//$('#feat').append(banner).css({paddingLeft: '0px', zIndex: '0'});
	
	$('#feature-fb').append('<div id="logo-replace">&nbsp;</div>').click(function(){ window.location = 'http://www.facebook.com/pages/Peterborough-ON/Fleming-College/5690608258'});
	$('#feature-fb').append('<div id="name-replace">&nbsp;</div>').click(function(){ window.location = 'http://www.facebook.com/pages/Peterborough-ON/Fleming-College/5690608258'});
	
	$('.sf-menu').superfish({ 
            animation: {height:'show'},   // slide-down effect without fade-in 
            delay:     1200,              // 1.2 second delay on mouseout 
			autoArrows: false
	  });
	
	//$("#news").newsticker(8000);
	
	$.localScroll( { lazy: true });

	$('.rounded').corner({
	  tl: { radius: 6 },
	  tr: { radius: 6 },
	  bl: { radius: 6 },
	  br: { radius: 6 },
	  antiAlias: true,
	  autoPad: true });
	
	$('ul.striped-list li:even').addClass('list-stripe');
	
	/* Home Page */
	
	$("#home_search").focus(function() {
		if($(this).val() == "Type a topic, phrase or question . . .") {
			$(this).val("");
		}
	});
	$("#home_search").blur(function() {
		if($(this).val() == "") {
			$(this).val("Type a topic, phrase or question . . .");
		}
	});
	
	function closeContestForm() {
		var pos = $('#feature-contest').position();  
		$('#contestWrapper').animate({
			left: pos.left,
			width: '0px'}, 300);
		
		$('#contest-entry-trigger')
			.bind('click',function() {
				showContestForm();
				return false;
			});
		
	if(($.browser.msie) || ($.browser.opera) ) {
		$('#contest-entry-trigger').bind('mouseup',function() {
				showContestForm();
				return false;
			});
		}
	}
	
	banner= '<a style="display:block;" id="contest-entry-trigger" href="/index.cfm/go/contest/sub/register.cfm"><div style="width:220px;height:118px;z-index: 0;"><object style="z-index: 0;" height="118" align="middle" width="220" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" name="btnCampaign" id="btnCampaign" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0"><param name="wmode" value="transparent" /> <param value="/contest/btnCampagin.swf" name="movie"/> <param value="high" name="quality"/> <param value="sameDomain" name="allowscriptaccess"/> <param value="false" name="allowfullscreen"/> <embed height="118" align="middle" width="220" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" allowfullscreen="false" allowscriptaccess="sameDomain" name="btnCampaign" quality="high" src="/contest/btnCampagin.swf" id="btnCampaign" wmode="transparent" /></object></div></a><div id="contest-details"><a href="index.cfm/go/contest.cfm">Click here for more information</a></div>';
	
	$('#feature-contest').html(''); // clears the banner container of the default banner
	$('#feature-contest').html(banner);
	$('#contest-entry-trigger').bind('click', function() {
		showContestForm();
				
		return false;
	});
	
	if(($.browser.msie) || ($.browser.opera) ) {
		$('#contest-entry-trigger').bind('mouseup', function() {
			showContestForm();
			return false;
		});
	}
	
	function contestTermsAccept(ele) {
		if($(ele).attr("checked")) {		
			$('#termsAlert').remove();
			$('#termsWrapper').remove();
			$('#submitit').unbind('click');
			$('#contestWrapper').animate({height: '113px'}, 800);	
			
			$('#submitit').bind('click', function() {				
				$('#contest-regfrm').ajaxSubmit( {
					url: '/Contest/act_contestSubmit.cfm?ajax=true',
					beforeSubmit: function() {
						//$('#AlumniUpdate input[type="submit"]').attr({disabled:"disabled",value:"Working..."});
					},
					success: function(msg,txt) {
					 var rtn = $.trim(msg).split(',');
					  if(rtn[0] == 'FAILED') {
						if(rtn[1] == 'pin') {
							  window.location = 'http://' + top.location.host +'/index.cfm/go/contest/sub/register/alert/pin.cfm';
						}
						else if (rtn[1] == 'terms') {
							window.location = 'http://' + top.location.host +'/index.cfm/go/contest/sub/register/alert/terms.cfm';
						}
						else {
							window.location = 'http://' + top.location.host +'/index.cfm/go/contest/sub/register/alert/true.cfm';
						}
					  }
					  else if(rtn[0] == 'SUCCESS'){
						window.location = 'http://' + top.location.host +'/index.cfm/go/contest/sub/registerconfirm.cfm'; 
					  }
					}
				});
				return false;				
			});
		}
		else {
			$('#submitit').bind('click', function() {
				alertReadTerms();
				return false;
			});
		}
	}
	
	function alertReadTerms() {
		//$.prompt('Please read and accept the Terms and Conditions before entering the contest.');
		$('#termsWrapper').remove();
		$('#contestWrapper').append('<div id="termsAlert"><p class="notice">You must read and accept the Terms and Conditions before entering the contest.</p></div>');
		$('#contestWrapper').animate({height: '153px'}, 800);
								
	}
	var inputVal = new Array();
	inputVal['NAME'] = 'First Name...';
	inputVal['EML'] = 'E-Mail...';
	inputVal['PHONE'] = 'Phone...';
	inputVal['STREET'] = 'Street...';
	inputVal['CITY'] = 'City...';
	inputVal['POSTAL'] = 'Postal Code...';
	inputVal['PIN'] = '';
	
	function setInputVal(input) {
		var id = (input).attr('id');
		for (i in inputVal)
		{
			if ((i == id) && ($('#'+id).val() == ''))
			{				
				$('#'+id).val(inputVal[i]);
			}
		}
	}
	function clearInputVal(input) {
		input.select();
		
		//var id = (input).attr('id');
		/*
		for (i in inputVal)
		{
			if ((i == id) && ($('#'+id).val() == inputVal[i]))
			{
				$('#'+id).select();
				//$('#'+id).val('');
			}
		}
		*/
	}
	
	function showContestForm() {
		// get the start position for the form
		var pos = $('#feature-contest').position();  
		
		$.ajax({
			type: 	'GET',
			url:	'/contest/frm_contest.cfm',
			success: function(msg) {
				// disable the trigger so you can't open mulitple forms
				
				$('#contest-entry-trigger')
					.unbind('click').bind('click', function() {
							closeContestForm();
							return false;
						});
				if(($.browser.msie) || ($.browser.opera) ) {
					$('#contest-entry-trigger').unbind('mouseup').bind('mouseup', function() {
						closeContestForm();
						return false;
					});
				}
				
				// create a container for the form and position it
				$('body').prepend('<div id="contestWrapper">&nbsp;</div>');
				$('#contestWrapper').css({top: pos.top+33, left: pos.left-1, width: '1px', height: '113px', overflow:'hidden'}).html(msg + '<div class="clear"></div>');
				//remove static page styles
				$('#contest-form-nojs').removeClass('contest-form');
				$('.button_rollover').remove();
				$('#contest-regfrm').removeClass('cmxform');
				for (i in inputVal)	{
					$('#'+i).val(inputVal[i]).bind('blur', function() { setInputVal($(this)); } ).bind('focus', function() { clearInputVal(this); } );
					$('#'+i).removeClass('error');
				}
				
				//$('#submitit').val('');
				$('#submitit').bind('click', function() {
					alertReadTerms();
					return false;
				});
				$('#TERMS').attr('checked',false);
				
				$('#PIN').keypress(function(e) {
					var len = $('#PIN').val();
					if(len.length >= 3) {
						$('#showEntry').trigger('click');						
					}
				});
				
				// create the trigger and animation to show 'Step 2'
				$('#pinInput').append('<span id="showEntry" class="trigger"><img src="/i/Contest/pinSubmit-bg.gif" /></span>');
				$('#showEntry').bind('click',function() {
					$('#contestWrapper').animate({
						left: pos.left-550,
						width: '550px'},
						1500, 'easeOutBounce');								  
				});				
				
				
				// do the animation to show 'Step 1'
				$('#contestWrapper').animate({
					left: pos.left-148,
					width: '149px'},
					800, 'easeOutBounce');
				
				// create the rules section and the animation to show it
				$('#termsCond').bind('click',function() {													  
					$.ajax({
						type: 	'GET',
						url:	'/contest/dsp_contestRules.cfm',
						success: function (msg) {
							$('#termsAlert').remove();		
							$('#contestWrapper').append('<div id="termsWrapper"><div id="terms" class="hide">'+msg+'</div><div id="termsClose" class="trigger"><img src="/i/Contest/termsClose.gif" /></div></div>');
							$('#contestWrapper').animate({height: '500px'}, 800);
							$('#terms').show();
							
							$('#termsClose').bind('click',function() {
								$('#contestWrapper').animate({height: '113px'}, 800);
								$('#termsWrapper').remove();
								
							});
							
						}
					});
					
					
					return false;
				});
				
				// bind the submit button to the value of the Terms checkbox
				$('#TERMS').bind('click', function() { contestTermsAccept($(this)); });
				
				
				$('#genPin').bind('click',function() {
					$.ajax({
						type: 	'GET',
						url:	'/contest/act_genPin.cfm?ajax=true',
						beforeSend: function() {
							$('#page').append('<div id="loadPin" class="hide"><div id="loadPinMsg"><p>Please wait a moment while we generate your PIN number.</p><img src="/i/Shared/loadingAnimation.gif"></div></div>');
							if($('#colC').length > 0) {
								position = $('#colB').position();
							}
							else {
								position = $('#content').position();
							}
							$('#loadPin').css({top: position.top, left: position.left-20}).show();
						},							
						success: function (msg) {
							$('#genPin').unbind('click').bind('click', function() { return false; });
							$('#showEntry').trigger('click');
							setTimeout('hideLoad("'+msg+'")',1500);							
						}
					 });
					return false;
				 });
				// hide the 'Required fields' notice in the markup
				$('#frm-notice').hide();
			}
		});	
	}
	
	if($('#facebook-fan-static').length > 0) {
		$('#facebook-fan-static').remove();
	}
	
	if($('#contest-form-nojs').length > 0) {
		for (i in inputVal)	{
			if($('#'+i).val() == '') {
				thisval = inputVal[i];
			}
			else {
				thisval = $('#'+i).val();
			}
			$('#'+i).val(thisval).bind('blur', function() { setInputVal($(this)); } ).bind('focus', function() { clearInputVal(this); } );
			
		}
		
		$('#genPin').bind('click',function() {
			$.ajax({
				type: 	'GET',
				url:	'/contest/act_genPin.cfm?ajax=true',
				beforeSend: function() {
					$('#page').append('<div id="loadPin" class="hide"><div id="loadPinMsg"><p>Please wait a moment while we generate your PIN number.</p><img src="/i/Shared/loadingAnimation.gif"></div></div>');
					$('#loadPin').show();
				},							
				success: function (msg) {
					$('#genPin').unbind('click').bind('click', function() { return false; });
					$('#showEntry').trigger('click');
					setTimeout('hideLoad("'+msg+'")',1500);	
					$('#showEntry').hide();
				}
			 });
			return false;
		 });
		
	}
	
	if($('#ebull-frm').length > 0) {
		var eml = $('#EML').val();
		if(eml != '') {
			$('#ebull-frm').replaceWith('<p id="ebull-subscribe" class="trigger" title="Subscribe '+eml+' to Fleming\'s E-Bulletin" >Click Here to Sign up for Fleming\'s E-Bulletin</p>');
		}
		$('#ebull-subscribe').bind('click', function() {
			$.ajax({
				type: 	'GET',
				url:	'/contest/act_ebull.cfm?eml='+eml+'&ajax=true',
				success: function(msg) {
					$('#ebull-subscribe').text(eml + ' has been added to Fleming\'s E-Bulletin');
					$('#ebull-subscribe').unbind();
					$('#ebull-subscribe').removeClass('trigger');
					$('#ebull-subscribe').addClass('notice');
				}
			});
		});				
	}
	
	$('.inline-eml').defuscate();
	
	/* page navigation */
	$('.current-page a').click(function() {
		return false;
	});
	
	/* Course Cart */
	$('#cart-button').hover(function() {
		$(this).attr('src', '/i/Shared/cart-button-ovr.gif')
		},
		function() {
		$(this).attr('src', '/i/Shared/cart-button.gif')
		}				 
	);
	
	var sideImg = Math.floor(Math.random()*9);	
	//$('#side-ftr').css( {background: 'url(/i/Shared/bg-side-paper-ftr-'+sideImg+'.jpg) top left no-repeat'} );	
	
	//setInterval("rotateSide('sideImg')",10000);
	
	/* FAQ pages - hide answers and format page */
	$('dl.faq dt').addClass('question');
	$('dl.faq dd').hide();
	$('dl.faq dt').click(function() {
		$(this).next('dd').toggle('normal');
	});
	
	/* make logo clickable and send users to homepage */
	$("#nav h1").click(function() {
		var server = top.location.host;
		location.href = 'http://' + server + '/';
	});
	
	$(".program-content").each(function() {
		$(this).hide();
		$("#program-overview").show();
		
	});
	
	$("#proginfo").click(function(){
		$("#program-overview").show("fast");
		$("#program-curriculum").hide("fast");
		$("#program-coursedescription").hide("fast");
		$("#program-miscinfo").hide("fast");
		$("#proginfo").addClass("selectedtab");
		$("#progcirc").removeClass("selectedtab");
		$("#crsedesc").removeClass("selectedtab");
		$("#progmisc").removeClass("selectedtab");
		
		if($("#program-overview:visible")) {
			return false;
		};
	});
	$("#progcirc").click(function(){
		$("#program-curriculum").show("fast");
		$("#program-overview").hide("fast");
		$("#program-coursedescription").hide("fast");
		$("#program-miscinfo").hide("fast");
		$("#progcirc").addClass("selectedtab");
		$("#proginfo").removeClass("selectedtab");
		$("#crsedesc").removeClass("selectedtab");
		$("#progmisc").removeClass("selectedtab");
		
		if($("#program-overview:visible")) {
			return false;
		};
	});	
	$("#crsedesc").click(function(){
		$("#program-coursedescription").show("fast");
		$("#program-overview").hide("fast");
		$("#program-curriculum").hide("fast");
		$("#program-miscinfo").hide("fast");
		$("#crsedesc").addClass("selectedtab");
		$("#proginfo").removeClass("selectedtab");
		$("#progcirc").removeClass("selectedtab");
		$("#progmisc").removeClass("selectedtab");
		
		if($("#program-overview:visible")) {
			return false;
		};
	});
	$("#progmisc").click(function(){
		$("#program-miscinfo").show("fast");
		$("#program-overview").hide("fast");
		$("#program-curriculum").hide("fast");
		$("#program-coursedescription").hide("fast");
		$("#progmisc").addClass("selectedtab");
		$("#proginfo").removeClass("selectedtab");
		$("#progcirc").removeClass("selectedtab");
		$("#crsedesc").removeClass("selectedtab");
		
		if($("#program-overview:visible")) {
			return false;
		};
	});
	
	$(".crselink").click(function() {
		var ele = $(this).attr("id")
		ele = ele.substring(1,ele.length);
		$("#program-overview").hide("fast");
		$("#program-curriculum").hide("fast");
		$("#program-miscinfo").hide("fast");
		$("#crsedesc").addClass("selectedtab");
		$("#proginfo").removeClass("selectedtab");
		$("#progcirc").removeClass("selectedtab");
		$("#progmisc").removeClass("selectedtab");
		
		$("#program-coursedescription").show("fast",function() { 
			$.scrollTo("#a"+ele);
		});

		return false;
	});
	$(".desclink").click(function() {
		var ele = $(this).attr("id")
		ele = ele.substring(1,ele.length);
		$("#program-overview").hide("fast");
		$("#program-coursedescription").hide("fast");
		$("#program-miscinfo").hide("fast");
		$("#progcirc").addClass("selectedtab");
		$("#proginfo").removeClass("selectedtab");
		$("#crsedesc").removeClass("selectedtab");
		$("#progmisc").removeClass("selectedtab");
		
		$("#program-curriculum").show("fast",function() { 
			$.scrollTo("#curr-top");
		});

		return false;
	});
	
	$("#side-common ul#ul-side-common li ul.side-sublist li").hover(
		function() {
			$(this).css("background","#96B7C8");
			$(this).children().css("color","#fff");
		},
		function() {
			$(this).css("background","#fff");
			$(this).children().css("color","#666");
		}
	);
	$('input[name="BIRTHDATE"]').datepicker({yearRange: '-80:+0',dateFormat: 'dd/mm/yy'});
	
	// prepare Options Object 
	var ptsreg_submit = { 
		target:     '#reply', 
		url:        'Programs/act_ptsreg.cfm',
		success:    function() { 
			$('#submitit').attr({disabled: "true"});
			$('#reply').show("normal");
			}
		} 	
	
	/* Ajax Validation and Submission of Alumni Profile Update */	
	$('#AlumniUpdate').validate({
	   submitHandler: function(form) {
		$(form).ajaxSubmit( {
			target: '#response',
			url: '/Alumni/act_alumni_update.cfm?ajax=true',
			beforeSubmit: function() {
				$('#AlumniUpdate input[type="submit"]').attr({disabled:"disabled",value:"Working..."});
			},
			success: function() {
		   	 	$(form).hide();
		 		$('#response').show();
				$.scrollTo( 'h1', 800 );
			}
		});
		return false;
	   },
	   errorClass: "invalid"
	});
	
	/* Ajax Validation and Submission of Alumni Locator Tool */	
	$('#AlumniLocate').validate({
	   submitHandler: function(form) {
		$(form).ajaxSubmit( {
			target: '#response',
			url: '/Alumni/act_alumni_locate.cfm?ajax=true',
			beforeSubmit: function() {
				$('#AlumniLocate input[type="submit"]').attr({disabled:"disabled",value:"Working..."});
			},
			success: function() {
				$('#question').hide();
				$.scrollTo( 'h1', 800 );
			}
		});
		return false;
	   },
	   errorClass: "invalid"
	});
	
	/* Announcement regarding photo-id on Financial/dsp_home.cfm - remove when announcement no longer needed */
	$("#osapid").click(function(){
		$("#fin_alert").toggle("normal");
		return false;			
	});
	
	/* Budget Calculator */	
	$("#BudgetCalc input").focus(function() {
		if($(this).val() == 0) {
			$(this).val('');
		}
	});
	$("#BudgetCalc input").blur(function() {
		DoCalc();
		if($(this).val() == '') {
			$(this).val('0');
		}
	});
	$("#BudgetCalc input, #BudgetCalc select").change(function() {
		DoCalc();
	});
	$("#BudgetCalc #submitform").click(function() {
		DoCalc();
		return false;
	});
	$("#BudgetCalc #submitform, #submitform_instruction").hide();
	/* Budget Calculator Validation */	
	$('#BudgetCalc').validate({
 		errorElement: "div",
		errorClass: "calc-error",
		errorPlacement: function(error, element) {
    		error.insertAfter( element.prev() );
  		 }
	});	
	
	/* Bursary page - toggle eligibility notice */
	/* hide all on page load */
	$('.elignote').each(function() {
		$(this).hide();
	});
						
	$('.notetrig').click(function() {
		var itm = $(this).attr('id');
		$('#a'+itm).toggle("normal");
	});
	
	/* write the summary statement */
	var summtxt = $('input[name="ELIGIBILITY"]:checked').parent().text();
	$('#filter-eligibility').html(summtxt);
	
	/* filter results using form elements */
	$('.filter-opts').click(function() {
		var itmval = $(this).children().children().val();
		var itmtxt = $(this).text();
		$('.burs-elg').each(function() {
			var type = $(this).attr("title");
			switch(itmval) {
				case 'A':
					$(this).parents('dl').show();
					break;
				case 'R':
					if( type == 'R' || type == 'A') {
						$(this).parents('dl').show();
					}
					else {
						$(this).parents('dl').hide();
					}
					break;
				case 'E':
					if( type == 'E' || type == 'A') {
						$(this).parents('dl').show();
					}
					else {
						$(this).parents('dl').hide();
					}
					break;
			}
		});
		$('#filter-eligibility').html(itmtxt);
	});	
	$('select[name="CATEGORYID"]').change(function() {
		var itmval = $(this).val();
		var itmtxt = '';
		$('.bursaries').each(function() {
			if(itmval == 0) {
				$(this).show();
			}
			else {
				if($(this).attr('id') != 'g-'+itmval && $(this).attr('id') != 'g-3') {
					$(this).hide();
				}
				else {
					$(this).show();
				}
			}
		});	
		$('select[name="CATEGORYID"] option:selected').each(function () {
			itmval = $(this).val();
			itmtxt += $(this).text() + ' Bursaries';
			
			if(itmval == 0) {
				$('#filter-bursary').text('Displaying: All Bursaries');
			}
			else  {
				$('#filter-bursary').html('Displaying: <a href="'+ location.href + '#g-' + 3 + '">General Bursaries</a>');
			}
			
			if(itmval != 0 && itmval != 3)
				$('#filter-program').html(' &amp; <a href="'+ location.href + '#g-' + itmval + '">' + itmtxt + '</a>');
			else
				$('#filter-program').html('');
		 });
		
	});
	
	/* phonelist striping */
	$('.phonelist p').each(function(i) {
		if (i % 2 == 0) {
			$(this).addClass('odd');
		}
	});
	$('.phonelist p').hover(
		function () {
			$(this).addClass("ovr");
		  },
		  function () {
			$(this).removeClass("ovr");
		  }	
	);
	
	//Job Posting
	/* Ajax Validation and Submission of job post submission */	
	$('#jobpost-regfrm').validate({
		submitHandler: function(form) {
			$(form).ajaxSubmit( {
				target: '#response',
				url: '/Services/act_jobSubmit.cfm?ajax=true',
				beforeSubmit: function() {
					$(form).find('input[type="submit"]').attr({disabled:"disabled",value:"Sending Submission..."});
				},
				success: function() {
				   $('.registration-form').hide();
				   $('#response').show();
					$.scrollTo( 'h1', 800 );
				}
			});
			return false;
		},
		errorClass: "invalid",
		errorElement: "p",
		errorPlacement: function(error, element) {
			error.appendTo( element.parent("li") );
		}		
	});
	
	/* Begin Virtual Visit */
	/* Ajax Validation and Submission of PAL Application */	
	$('#virtual-visit-regfrm').validate({
		submitHandler: function(form) {
			$(form).ajaxSubmit( {
				target: '#virtual-visit',
				url: '/Liaison/act_registrationSubmit.cfm?ajax=true',
				beforeSubmit: function() {
					$(form).find('input[type="submit"]').attr({disabled:"disabled",value:"Sending Registration..."});
				},
				success: function() {
				   //$('#virtual-visit').html('yo');
				}
			});
			return false;
		},
		errorClass: "invalid",
		errorElement: "span",
		errorPlacement: function(error, element) {
			error.appendTo( element.parent("li") );
		}		
	});
	
	/* Begin Open House */
	
	/* Ajax Validation and Submission of Open House registration */	
	$('#openhouse-regfrm').validate({
		submitHandler: function(form) {
			$(form).ajaxSubmit( {
				target: '#response',
				url: '/openhouse/act_registerSubmit.cfm?ajax=true',
				beforeSubmit: function() {
					$(form).find('input[type="submit"]').attr({disabled:"disabled",value:"Sending Registration..."});
				},
				success: function() {
				   $(form).hide();
				   $('#response').show();
					$.scrollTo( 'h1', 800 );
				}
			});
			return false;
		},
		errorClass: "invalid",
		errorElement: "p",
		errorPlacement: function(error, element) {
			error.appendTo( element.parent("li") );
		}		
	});	
	
	// set the default bus fields
	changebus();
	
	
	
	$(".radbus").click(changebus);	
	
	/* End Open House */
	
	// WELCOME DAYS
	/* Ajax Validation and Submission of Welcome Days registration */	
	$('#welcomedays-regfrm').validate({
		submitHandler: function(form) {
			$(form).ajaxSubmit( {
				target: '#response',
				url: '/welcomedays/act_registerSubmit.cfm?ajax=true',
				beforeSubmit: function() {
					$(form).find('input[type="submit"]').attr({disabled:"disabled",value:"Sending Registration..."});
				},
				success: function() {
				   $(form).hide();
				   $('#response').show();
					$.scrollTo( 'h1', 800 );
				}
			});
			return false;
		},
		errorClass: "invalid",
		errorElement: "p",
		errorPlacement: function(error, element) {
			error.appendTo( element.parent("li") );
		}		
	});
	
	changeWDForm();
	
	$('#welcomedays-regfrm #CAMPUS').change(changeWDForm);
	
	/* end WELCOME DAYS */
	
	// OCFMA CONFERENCE
	/* Ajax Validation and Submission of Welcome Days registration */	
	$('#ocfma-regfrm').validate({
		submitHandler: function(form) {
			$(form).ajaxSubmit( {
				target: '#response',
				url: '/ocfma/act_registerSubmit.cfm?ajax=true',
				beforeSubmit: function() {
					$(form).find('input[type="submit"]').attr({disabled:"disabled",value:"Sending Registration..."});
				},
				success: function() {
				   $(form).hide();
				   $('#response').show();
					$.scrollTo( 'h1', 800 );
				}
			});
			return false;
		},
		errorClass: "invalid",
		errorElement: "p",
		errorPlacement: function(error, element) {
			error.appendTo( element.parent("li") );
		}		
	});
	$('#ocfma-regopts > li').hover(function() {
			$(this).css('backgroundColor','#f1f1f1');
							   },
			function() {
			$(this).css('backgroundColor','#ffffff');
							   });			   
	/* HOME PAGE */
	$('#feature-media').click(function(){
		location.href='http://'+ location.hostname + '/index.cfm/go/media.cfm';
	});
	
	// PAL Program
	/* Ajax Validation and Submission of PAL Nomination */	
	$('#palnom-regfrm').validate({
		submitHandler: function(form) {
			$(form).ajaxSubmit( {
				target: '#response',
				url: '/pal/act_nominationSubmit.cfm?ajax=true',
				beforeSubmit: function() {
					$(form).find('input[type="submit"]').attr({disabled:"disabled",value:"Sending Nomination..."});
				},
				success: function() {
				   $(form).hide();
				   $('#response').show();
					$.scrollTo( 'h1', 800 );
				}
			});
			return false;
		},
		errorClass: "invalid",
		errorElement: "p",
		errorPlacement: function(error, element) {
			error.appendTo( element.parent("li") );
		}		
	});
	
	/* Ajax Validation and Submission of PAL Application */	
	$('#palapply-regfrm').validate({
		submitHandler: function(form) {
			$(form).ajaxSubmit( {
				target: '#response',
				url: '/pal/act_applySubmit.cfm?ajax=true',
				beforeSubmit: function() {
					$(form).find('input[type="submit"]').attr({disabled:"disabled",value:"Sending Application..."});
				},
				success: function() {
				   $(form).hide();
				   $('#response').show();
					$.scrollTo( 'h1', 800 );
				}
			});
			return false;
		},
		errorClass: "invalid",
		errorElement: "p",
		errorPlacement: function(error, element) {
			error.appendTo( element.parent("li") );
		}		
	});
	
	/* Ajax Validation and Submission of PAL Application */	
	$('#palreq-regfrm').validate({
		submitHandler: function(form) {
			$(form).ajaxSubmit( {
				target: '#response',
				url: '/pal/act_findSubmit.cfm?ajax=true',
				beforeSubmit: function() {
					$(form).find('input[type="submit"]').attr({disabled:"disabled",value:"Sending Application..."});
				},
				success: function() {
				   $(form).hide();
				   $('#response').show();
					$.scrollTo( 'h1', 800 );
				}
			});
			return false;
		},
		errorClass: "invalid",
		errorElement: "p",
		errorPlacement: function(error, element) {
			error.appendTo( element.parent("li") );
		}		
	});
	
	/* Ajax Validation and Submission of PAL Application */	
	$('#ementor-regfrm').validate({
		submitHandler: function(form) {
			$(form).ajaxSubmit( {
				target: '#response',
				url: '/pal/act_ementorSubmit.cfm?ajax=true',
				beforeSubmit: function() {
					$(form).find('input[type="submit"]').attr({disabled:"disabled",value:"Sending Application..."});
				},
				success: function() {
				   $(form).hide();
				   $('#response').show();
					$.scrollTo( 'h1', 800 );
				}
			});
			return false;
		},
		errorClass: "invalid",
		errorElement: "p",
		errorPlacement: function(error, element) {
			error.appendTo( element.parent("li") );
		}		
	});
	
	//ORIENTATION pages
	
	$('#br-orientation-detail').hide();
	$('ul#br-orientation')
		.append('<li><span class="trigger"><strong>Click here for details and intinerary at Sutherland Campus</strong></span></li>')
			.bind('click',function() {
				if($('#br-orientation-detail').is(':hidden')) {
					$('#br-orientation-detail').show('normal');
					$('ul#br-orientation .trigger strong').text('Click here to hide details');
				}
				else {
					$('#br-orientation-detail').hide('normal');
					$('ul#br-orientation .trigger strong').text('Click here for details and intinerary at Sutherland Campus');
				}
			});
	
	$('#mc-orientation-detail').hide();
	$('ul#mc-orientation')
		.append('<li><span class="trigger"><strong>Click here for details and intinerary at McRae Campus</strong></span></li>')
			.bind('click',function() {
				if($('#mc-orientation-detail').is(':hidden')) {
					$('#mc-orientation-detail').show('normal');
					$('ul#mc-orientation .trigger strong').text('Click here to hide details');
				}
				else {
					$('#mc-orientation-detail').hide('normal');
					$('ul#mc-orientation .trigger strong').text('Click here for details and intinerary at McRae Campus');
				}
			});
	
	$('#fr-orientation-detail').hide();
	$('ul#fr-orientation')
		.append('<li><span class="trigger"><strong>Click here for more details and intinerary at Frost Campus</strong></span></li>')
			.bind('click',function() {
				if($('#fr-orientation-detail').is(':hidden')) {
					$('#fr-orientation-detail').show('normal');
					$('ul#fr-orientation .trigger strong').text('Click here to hide details');
				}
				else {
					$('#fr-orientation-detail').hide('normal');
					$('ul#fr-orientation .trigger strong').text('Click here for more details and intinerary at Frost Campus');
				}
			});
			
	// myFleming
	$('.myfleming-hide').hide();
	$('.br, .fr').not('.myfleming-nav').hide();
	
	$('#athletics').show();
	$('.br').show();
	if($('.myfleming-nav').length > 0) {
		$('.myfleming-nav').find('a').click(function() {
			var myclass = $(this).attr('class').split(' ');
			var id = myclass[0].substr(2);
			var campus = myclass[1].substr(2);
			
			$('.myfleming-hide').hide();
			$('.br, .fr').not('.myfleming-nav').hide();
			
			$('.'+campus).show();
			$('#'+id).show("slow");
			
			return false;
		});
	}
	//countdown widget
	function timer() {
		if ($('#countdown').attr('title')) {
		var ctr = $('#countdown').attr('title').split(';');
		ctr = '+'+ctr[1]+'S';
		return ctr;
	}}
	$('#countdown').countdown(
		{	until: '+'+timer()+'s',
			format: 'S',
			onExpiry: function() {
				var url = $('#countdown').attr('title').split(';');
				url = url[0];
				window.location = url;
			}
		});
	
});


