var J = jQuery.noConflict();

J(document).ready(function(){ 
							   
							   			
							      
// Events INIT

J(".event_description").addClass("hide");
J(".events_wrap").removeClass("set_height");

J(".event_toggle").click(function() {
	J(this).parents(".events_wrap").toggleClass("event_open");
	J(this).next(".event_description").slideToggle("fast")
	J(this).toggleClass("event_open");
});

J(".events_wrap h3").click(function() {
	J(this).parents(".events_wrap").toggleClass("event_open");
	J(this).siblings(".event_description").slideToggle("fast")
	J(this).siblings(".event_toggle").toggleClass("event_open");
});

J(".event_date").click(function() {
	J(this).parents(".events_wrap").toggleClass("event_open");
	J(this).siblings(".events_content").children(".event_description").slideToggle("fast")
	J(this).siblings(".events_content").children(".event_toggle").toggleClass("event_open");
});

						   
// attach link to activities li click

J("ul.activities_wrap li").click(function() {
	
	window.location = J(this).find('a:first').attr('href');
	return false;
	
});
		
	// add icons
					 
					 J("a[href$='.pdf']").addClass("pdf");
					 J("a[href$='.doc']").addClass("doc");
					 J("a[href$='.ppt']").addClass("ppt");
					 
		
		// FANCYBOX
		
		
						J.fn.getTitle = function() {
			var arr = J("a.fancybox");
			J.each(arr, function() {
				var title = J(this).children("img").attr("alt");
				if (title =="") {title = J(this).next().children("p").html()}; // create title from PWA + PHP captions
				if (title == "") {title = J(this).attr("title")}; // if nothing else, set title to that of the page
				J(this).attr('title',title);
			})
		}

		// Supported file extensions
		var thumbnails = 'a:has(img)[href$=".bmp"],a:has(img)[href$=".gif"],a:has(img)[href$=".jpg"],a:has(img)[href$=".jpeg"],a:has(img)[href$=".png"],a:has(img)[href$=".BMP"],a:has(img)[href$=".GIF"],a:has(img)[href$=".JPG"],a:has(img)[href$=".JPEG"],a:has(img)[href$=".PNG"]';

	
		J(thumbnails).addClass("fancybox").attr("rel","fancybox").getTitle();

		//J(thumbnails).addClass("fancybox").attr("rel","fancybox");

			J("a.fancybox").fancybox({
			'imageScale': true,
			'padding': 10,
			'zoomOpacity': true,
			'zoomSpeedIn': 500,
			'zoomSpeedOut': 500,
			'zoomSpeedChange': 300,
			'overlayShow': true,
			'overlayColor': "#666666",
			'overlayOpacity': 0.3,
			'enableEscapeButton': true,
			'showCloseButton': true,
			'hideOnOverlayClick': true,
			'hideOnContentClick': false,
			'frameWidth':  560,
			'frameHeight':  340,
			'callbackOnStart': null,
			'callbackOnShow': null,
			'callbackOnClose': null,
			'centerOnScroll': false,
			'title'			: this.title,
			'titlePosition'	:	'over'
		});
		
				J("a.iframe_map").fancybox({
		'hideOnContentClick': false,
		'width'				: 660,
		'height'			: '75%',
        'autoScale'     	: false,
        'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe'
	});	
						

		// XHTML TARGET FIX
J('a.newwin').attr('target', '_blank');


}); // end doc ready

// allows tabs to be selected from a url PARAM
	
function gup( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}	
	
