/*////////////////////////////////////////////////////////////
JavaScript Code Library
Developed by GrafX Design Division Pty Ltd
http://www.grafx.com.au

Last Checked In By : Richard Czeiger
Public Revision No : 1.0

The software and related user documentation are
protected under copyright laws and remain the sole
property of GrafX Design Division. Full license is
available on the GrafX Design Division web site or
in the original download.

Technical support is available via the GrafX web site at
http://www.grafx.com.au
////////////////////////////////////////////////////////////*/




// Get the hacked stylesheet
document.write('<style type="text/css">@import url("/styles/hacks.css");</style>');




// Suppress JavaScript Errors
// window.onerror = new Function("return true")




// Set the Status Bar Message
var statusMsg = 'YMCA Sydney';
window.defaultStatus = statusMsg;




// Fixes IE6 CSS Rendering Bug
if (document.all && window.attachEvent) window.attachEvent("onload", fixWinIE);
function fixWinIE() {
	if (document.body.scrollHeight < document.body.offsetHeight) { document.body.style.display = 'block'; }
}




// Spam Suppression for Emails
function stopSpam(name, domain, subject) {
	var symbol = '@';
	// Took out the Subject due to MS fault in Outlook Express (Source - http://support.microsoft.com/kb/q182985/ )
	// document.write('<a href="mailto:' + name + symbol + domain + '&subject=' + subject + '">' + name + symbol + domain + '</a>');
	document.write('<a href="mailto:' + name + symbol + domain + '">' + name + symbol + domain + '</a>');
}




// sHover for Navigation
sfHover = function() {
	if (document.getElementById("navigation")) {
		var sfEls = document.getElementById("navigation").getElementsByTagName("LI");
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				this.className+=" sfhover";
			}
			sfEls[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp("sfhover\\b"), "");
			}
		}
	}
}



// XHTML External Link Script
function externalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName('a');
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute('href') && anchor.getAttribute('rel') == 'external') {
			anchor.target = '_blank';
		}

		/*
		if (anchor.getAttribute('href') && ( (anchor.parentNode.getAttribute('class') == 'current') || (anchor.parentNode.getAttribute('className') == 'current') ) ) {
		// if ( anchor.getAttribute('href') && (anchor.parentNode.getAttribute('class') == 'current') ) {
			// Get the parent
			if (anchor.parentNode.parentNode.parentNode.nodeName == 'LI') {
				var programs = document.getElementById('programs').getElementsByTagName('UL')[0];
				programs.setAttribute('class', 'inactive');
				anchor.parentNode.parentNode.parentNode.setAttribute('class', 'active');
			}
		}
		*/
	}
}
// For Colorbox popups
$(document).ready(function(){
	// $(".popup").colorbox();
	$(".popup").colorbox({width:"500px", height:"400px", title:true, scrolling:false, opacity:0.75, iframe:true});
});



// Selected to use server-side script and jQuery Corners
// http://jquery.malsup.com/corner/
$(document).ready(function(){
	if ( $('#navigation div').length ) {
		$("#navigation div").corner("bottom");
	}
});

// Make Global Nav Scroll
/*////////////////////////////////////////////////////////////
$(function() {
	$(window).scroll(function(){
		var scrollTop = $(window).scrollTop();
		if(scrollTop != 0)
			$('#global').stop().animate({'opacity':'0.3'},400);
		else
			$('#global').stop().animate({'opacity':'1'},400);
	});

	$('#global').hover(
		function (e) {
			var scrollTop = $(window).scrollTop();
			if(scrollTop != 0){
				$('#global').stop().animate({'opacity':'1'},400);
			}
		},
		function (e) {
			var scrollTop = $(window).scrollTop();
			if(scrollTop != 0){
				$('#global').stop().animate({'opacity':'0.3'},400);
			}
		}
	);
});
////////////////////////////////////////////////////////////*/
/*////////////////////////////////////////////////////////////
// CSS Styles for this to happen
#global {
	position: fixed; top: 0; z-index: 1000; width: 960px;
}
#masthead {
	margin: 33px 0 0 0;
}
#navigation {
	top: 235px;
}
////////////////////////////////////////////////////////////*/



// Add to Favourites (Bookmarking Script)
function bookmark() {
	var url 	= document.location.href;
	var title 	= document.title;

	if ((navigator.appName == 'Microsoft Internet Explorer') && (parseInt(navigator.appVersion) >= 4)) {
		window.external.AddFavorite(url,title);
	} else if (navigator.appName == 'Netscape') {
		window.sidebar.addPanel(title,url,'');
	} else {
		alert("Press Ctrl-D (Netscape) or Ctrl-T (Opera) to bookmark");
	}
}
// jQuery Version
$(document).ready(function(){
	$("a.bookmark").click(function(e){
		e.preventDefault(); // this will prevent the anchor tag from going the user off to the link
		var bookmarkUrl 	= document.location.href;
		var bookmarkTitle 	= document.title;

		if (window.sidebar) { // For Mozilla Firefox Bookmark
			window.sidebar.addPanel(bookmarkTitle, bookmarkUrl,"");
		} else if( window.external || document.all) { // For IE Favorite
			// window.external.AddFavorite( bookmarkUrl, bookmarkTitle);
			alert("Press Ctrl-D to bookmark");
			return false;
		} else if(window.opera) { // For Opera Browsers
			$("a.jQueryBookmark").attr("href",bookmarkUrl);
			$("a.jQueryBookmark").attr("title",bookmarkTitle);
			$("a.jQueryBookmark").attr("rel","sidebar");
		} else { // for other browsers which does not support
			alert("Press Ctrl-D (Netscape) or Ctrl-T (Opera) to bookmark");
			return false;
		}
	});
});



// Validation for "Find Your Y"
function checkSearch() {
	selectLocation = document.find.location;
	myLocation = selectLocation.options[selectLocation.selectedIndex].value;

	selectSuburb = document.find.suburb;
	suburb = selectSuburb.options[selectSuburb.selectedIndex].value;

	if ( (myLocation=='') && (suburb=='') ) {
		alert('Please select a location or suburb from the drop-down list.');
		return false;
	} /* else {
		if (suburb=='') {
			selectLocation[0].selected=true;
			document.location.href = myLocation;
		} else {
			selectSuburb[0].selected=true;
			document.location.href = suburb;
		}
	}
	return false; */
	return true;
}

// Change value of select elements
function setSelect(SelectName, Value) {
	eval("SelectObject = document.getElementById('" + SelectName + "');");
	for(index = 0; index < SelectObject.length; index++) {
		if (SelectObject[index].value == Value) {
			SelectObject.selectedIndex = index;
		}
	}
}




// Toggle Function
function toggle(obj) {
	obj = document.getElementById(obj);
	if (obj.style.display == "none") {
		obj.style.display = "";
	} else {
		obj.style.display = "none";
	}
}




// Pop Up Window
function popUp(picURL, picTitle, w, h) {
	window.open(sPicURL+'?'+picTitle, 'popUp', 'resizable=1,width='+w+',height='+h+', scrollbars=no');
}




// Actions for CSS Classes
function cssClass(action,object,class1,class2) {
	// swap 		replaces class class1 with class class2 in object.
	// add 			adds class class1 to the object.
	// remove 	removes class class1 from the object.
	// check 		test if class class1 is already applied to object and returns true or false.
	switch (action) {
		case 'swap':
		object.className=!cssClass('check',object,class1)?object.className.replace(class2,class1): object.className.replace(class1,class2);
	break;
	case 'add':
		if(!cssClass('check',object,class1)){object.className+=object.className?' '+class1:class1;}
	break;
	case 'remove':
		var rep=object.className.match(' '+class1)?' '+class1:class1;
		object.className=object.className.replace(rep,'');
	break;
	case 'check':
		return new RegExp('\\b'+class1+'\\b').test(object.className);
	break;
	}
}




// Focus on Input Fields
// inputFocus = function () {
function inputFocus() {
	var focusEl = document.getElementsByTagName("input");
	for (var i=0; i<focusEl.length; i++) {
		if ((focusEl[i].getAttribute("type") == "text")||(focusEl[i].getAttribute("type") == "password")) {
			focusEl[i].onfocus=function() {
				this.className+="sffocus";
			}
			focusEl[i].onblur=function() {
				this.className=this.className.replace(new RegExp("sffocus\\b"), "");
			}
		}
	}
	var focusTx = document.getElementsByTagName("TEXTAREA");
	for (var i=0; i<focusTx.length; i++) {
		focusTx[i].onfocus=function() {
			this.className+="sffocus";
		}
		focusTx[i].onblur=function() {
			this.className=this.className.replace(new RegExp("sffocus\\b"), "");
		}
	}
}
// if (window.attachEvent) window.attachEvent("onload", inputFocus);




// Global Cookie Function
function setCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function getCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	setCookie(name,'',-1);
}




/*
// Event-Manager Script by Keith Gaughan
// For implementations that don't include the push() methods for arrays.
if (!Array.prototype.push) {
	Array.prototype.push = function(elem) {
		this[this.length] = elem;
	}
}

var EventManager = {
	_registry: null,

	Initialise: function() {
		if (this._registry == null) {
			this._registry = [];
			// Register the cleanup handler on page unload.
			EventManager.Add(window, "unload", this.CleanUp);
		}
	},

	// Registers an event and handler with the manager.
	Add: function(obj, type, fn, useCapture) {
		this.Initialise();
		// If a string was passed in, it's an id.
		if (typeof obj == "string")
			obj = document.getElementById(obj);
		if (obj == null || fn == null)
			return false;
		// Mozilla/W3C listeners?
		if (obj.addEventListener) {
			obj.addEventListener(type, fn, useCapture);
			this._registry.push({obj: obj, type: type, fn: fn, useCapture: useCapture});
			return true;
		}
		// IE-style listeners?
		if (obj.attachEvent && obj.attachEvent("on" + type, fn)) {
			this._registry.push({obj: obj, type: type, fn: fn, useCapture: false});
			return true;
		}
		return false;
	},

	// Cleans up all the registered event handlers.
	CleanUp: function() {
		for (var i = 0; i < EventManager._registry.length; i++) {
			with (EventManager._registry[i]) {
				// Mozilla/W3C listeners?
				if (obj.removeEventListener)
					obj.removeEventListener(type, fn, useCapture);
				// IE-style listeners?
				else if (obj.detachEvent)
					obj.detachEvent("on" + type, fn);
			}
		}
		// Kill off the registry itself to get rid of the last remaining references.
		EventManager._registry = null;
	}
};
// EventManager.Add(window,'load', sfHover);
// EventManager.Add(window,'load', externalLinks);
*/




// Multiple Onload Functions to be called
$(document).ready(function(){ sfHover(); });
$(document).ready(function(){ externalLinks(); });