function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	}
	else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}
function findPosX(obj) {
	var curleft = 0;
	if(obj.offsetParent) {
		while(1) {
			curleft += obj.offsetLeft;
			if(!obj.offsetParent)
			break;
			obj = obj.offsetParent;
		}
	}
	else {
		if(obj.x)
		curleft += obj.x;
	}
	return curleft;
};
function findPosY(obj) {
	var curtop = 0;
	if(obj.offsetParent) {
	while(1) {
		curtop += obj.offsetTop;
		if(!obj.offsetParent)
		break;
		obj = obj.offsetParent;
		}
	}
	else {
		if(obj.y)
		curtop += obj.y;
	}
	return curtop;
};
var _POPUP_FEATURES = 'width=790,height=525,scrollbars=no';
function raw_popup(url, target, features) {
	if (isUndefined(features)) features = _POPUP_FEATURES;
	if (isUndefined(target)) target   = '_blank';
	if (url.indexOf('?') != -1) {
		symbol = "&";
	} else {
		symbol = "?";
	}
	var theWindow = window.open(url + symbol + "js=true", target, features);
	theWindow.focus();
	return theWindow;
}
function link_popup(src, features) {
	return raw_popup(src.getAttribute('href'), src.getAttribute('target') || '_blank', features);
}
function isUndefined(v) {
	var undef;
	return v===undef;
}
function printpage() {
	if (window.print) { window.print(); }
	else {
		alert ("To print this page please select the 'Print' option from your browser's 'File' menu.")
	}
	return;
}
function addClass(target, classValue) {
	if (!hasClass(target, classValue)) {
		if (target.className == "") {
			target.className = classValue;
		} else {
			target.className += " " + classValue;
		}
	}
	return true;
};
function removeClass(target, classValue) {
	var removedClass = target.className;
	var pattern = new RegExp("(^| )" + classValue + "( |$)");
	removedClass = removedClass.replace(pattern, "$1");
	removedClass = removedClass.replace(/ $/, "");
	target.className = removedClass;
	return true;
};
function hasClass(target, classValue) {
	if(target != null)
	{
		var pattern = new RegExp("(^| )" + classValue + "( |$)");
		if (target.className.match(pattern)) {
			return true;
		}
		return false;
	}
};


(function($) {
	// ------------------------------------------------------
	// Events to load on "document.ready"
	$(document).ready(function() {

		// Slide swapper
		if ( $('.flashGallery').length > 0 ) { 
			
			setInterval(function(){ChangeSlide();}, 4000);
		} 

		function ChangeSlide() {
	
			var $active = $('.flashGallery li.active');
			
			if ( $active.length == 0 ) $active = $('.flashGallery li:last');
		
			// use this to pull the images in the order they appear in the markup
			var $next =  $active.next().length ? $active.next()
			: $('.flashGallery li:first');
	
			$active.addClass('last-active');
		
			$next.css({opacity: 0.0})
			.addClass('active')
			.animate({opacity: 1.0}, 1000, function() {
				$active.removeClass('active last-active');
			});
		}
		
	});
})(jQuery);
