$(".main_image .desc").show(); //Show Banner
$(".main_image .block").animate({ opacity: 0.85 }, 1 ); //Set Opacity

$(".image_thumb ul li:first").addClass('active'); //Add the active class (highlights the very first list item by default)
$(".image_thumb ul li").click(function(){
	//Set Variables
	var imgAlt = $(this).find('img').attr("alt"); //Get Alt Tag of Image
	var imgTitle = $(this).find('a').attr("href"); //Get Main Image URL
	var imgDesc = $(this).find('.block').html();  //Get HTML of the "block" container
	var imgDescHeight = $(".main_image").find('.block').height(); //Find the height of the "block"

	if ($(this).is(".active")) {  //If the list item is active/selected, then...
		return false; // Don't click through - Prevents repetitive animations on active/selected list-item
	} else { //If not active then...
		//Animate the Description
		$(".main_image .block").animate({ opacity: 0, marginBottom: -imgDescHeight }, 250 , function() { //Pull the block down (negative bottom margin of its own height)
			$(".main_image .block").html(imgDesc).animate({ opacity: 0.85,	marginBottom: "0" }, 250 ); //swap the html of the block, then pull the block container back up and set opacity
			$(".main_image img").attr({ src: imgTitle , alt: imgAlt}); //Switch the main image (URL + alt tag)
		});
	}
	//Show active list-item
	$(".image_thumb ul li").removeClass('active'); //Remove class of 'active' on all list-items
	$(this).addClass('active');  //Add class of 'active' on the selected list
	return false; 

}) .hover(function(){ //Hover effects on list-item 
	$(this).addClass('hover'); //Add class "hover" on hover 
	}, function() {
	$(this).removeClass('hover'); //Remove class "hover" on hover out
});


/*
 * Url preview script 
 * powered by jQuery (http://www.jquery.com)
 * 
 * written by Alen Grakalic (http://cssglobe.com)
 * 
 * for more info visit http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery
 *
 */
 
this.screenshotPreview = function(){	
	/* CONFIG */
		
		xOffset = 10;
		yOffset = 50;
		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
		
	/* END CONFIG */
	$("a.screenshot").not(".picturespage .screenshot, .noscreenshot .screenshot, .latestpics a").hover(function(e){
		this.t = this.title;
		this.title = "";	
		var c = (this.t != "") ? "<br/>" + this.t : "";
		$("body").append("<p id='screenshot'><img src='"+ this.rel +"' alt='Loading preview...' />"+ c +"</p>");								 
		$("#screenshot")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");						
	},
	function(){
		this.title = this.t;	
		$("#screenshot").remove();
	});	
	$("a.screenshot").mousemove(function(e){
		$("#screenshot")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};




this.tooltip = function(){	
	/* CONFIG */		
		xOffset = 10;
		yOffset = 20;		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result		
	/* END CONFIG */		
	$("a.tooltip").hover(function(e){											  
		this.t = this.title;
		this.title = "";									  
		$("body").append("<p id='tooltip'>"+ this.t +"</p>");
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");		
	},
	function(){
		this.title = this.t;		
		$("#tooltip").remove();
	});	
	$("a.tooltip").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};



// starting the script on page load
$(document).ready(function(){
	tooltip();
	$(".image_thumb").css("zoom", "1");
	
	screenshotPreview();
	
	if ( $.browser.msie && $.browser.version < 7 ) {
		$.getScript(basePath + "scripts/DD_belatedPNG_0.0.7a.js", function(){
			$("img").each(function() {
				DD_belatedPNG.fixPng(this);		
			});
			
			
		});
	}
		
	$(".picturespage ul, .newsgallery ul, .latestpics ul").each(function(i) {
		$("a", this).attr("rel", "gallery["+i+"]")
	});
	

  
	/*****************************/
	/******  menu			*****/
	/*****************************/	
	$("#globalnav ul li").fadeMenu(500, "div#globalnav ul li:hover ul");		  
   // $("#menu1 ul li").fadeMenu(500, "div#menu1 ul li:hover ul");
	
	
	
	
	
	/*****************************/
	/****** tool tips		*****/
	/*****************************/
	$("#smallgallerylinks li a").easyTooltip();
	
	/*****************************/
	/****** css fixes		*****/
	/*****************************/
	//$("#smallgallerylinks li a").easyTooltip();
	$(".picturespage .newsitem:last").next().css("clear", "both");
	$(".mini:nth-child(4n)").css("clear", "left"); //not ie
	$(".mini:nth-child(4n)").before("<br style='clear:both;' />"); //ie
		

	/*****************************/
	/******   calendar	   *****/
	/*****************************/
	if(window.eventDates) {
		$('.calendar')  .empty()
						.addClass("activatedcalendar")
						.fullCalendar({
							draggable: false,
							events: eventDates,
							rightToLeft: false
						});
	}
	$("button").click(function(){return false;});
	
	/*****************************/
	/******   lightbox      ******/
	/*****************************/
	window.lightboxSettings = {
		animationSpeed: 'normal', /* fast/slow/normal */
		padding: 40, /* padding for each side of the picture */
		opacity: 0.35, /* Value betwee 0 and 1 */
		showTitle: true, /* true/false */
		allowresize: true, /* true/false */
		counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
		theme: 'dark_square', /* light_rounded / dark_rounded / light_square / dark_square */
		callback: function(){}
	};
	$(".thickbox, #wrap .screenshot, [rel='prettyPhoto[iframes]']").prettyPhoto(window.lightboxSettings);
	$("[rel='prettyPhoto[ajax]']").prettyPhoto(window.lightboxSettings);
	


	/*****************************/
	/******   on air		 *****/
	/*****************************/
	
	//Show and hide the schedule table
	/*$(".onairtablewrapper").hide();
	$("#showschedule").click(
		function(e) {
			e.preventDefault();
			
			$(".newsitem").hide();
			$(".onairtablewrapper").show();
			
			$("<a href='#' class='button jsbutton'>Back</a>")
			.appendTo(".onairtablewrapper")
			.click(function(e) {
				e.preventDefault();
				$(".onairtablewrapper").hide();
				$(".newsitem").show();
				$(this).remove();
			});
		}
	);*/
	
	//biobutton	
	$("#biography").hide();
	
	$(".biobutton").toggle(
		function(e) {
			e.preventDefault();
			$(".notbio").hide();   
			$("#biography").show();
			$(this).text(" > Show Details");
		}, function(e) {
			e.preventDefault();
			$(".notbio").show();   
			$("#biography").hide();
			$(this).text(" > Biography");
		}
	);
	
	
	
	
	
	
}); //EO PAGE LOAD



   
/*****************************/
/******   libs		   *****/
/*****************************/
$.fn.fadeMenu = function (t, selector) {	  
	//ss(selector).remove();  
	
	return this.each(function() {
				
		var $ul = $(this).find('ul:first');
		$ul.show().css({opacity: 0});
		$(this).hover(function(e){		   
				$ul.show()  
				   .animate({opacity: 1}, { queue: false, duration: t });  
			},function(e){
				$ul.hide();  
				  // .animate({opacity: 0}, { queue: false, duration: t });   
				
		});
	});
};		



/*
 * 	Easy Tooltip 1.0 - jQuery plugin
 *	written by Alen Grakalic	
 *	http://cssglobe.com/post/4380/easy-tooltip--jquery-plugin
 *
 *	Copyright (c) 2009 Alen Grakalic (http://cssglobe.com)
 *	Dual licensed under the MIT (MIT-LICENSE.txt)
 *	and GPL (GPL-LICENSE.txt) licenses.
 *
 *	Built for jQuery library
 *	http://jquery.com
 *
 */
 
(function($) {

	$.fn.easyTooltip = function(options){
	  
		// default configuration properties
		var defaults = {	
			xOffset: 10,		
			yOffset: 25,
			tooltipId: "easyTooltip",
			clickRemove: false,
			content: "",
			useElement: ""
		}; 
			
		var options = $.extend(defaults, options);  
		var content;
				
		this.each(function() {
			
			
			var title = $(this).attr("title");				
			$(this).hover(function(e){											 							   
				content = (options.content != "") ? options.content : title;
				content = (options.useElement != "") ? $("#" + options.useElement).html() : content;
				$(this).attr("title","");									  				
				if (content != "" && content != undefined){			
					$("body").append("<div id='"+ options.tooltipId +"'>"+ content +"</div>");		
					$("#" + options.tooltipId)
						.css("position","absolute")
						.css("top",(e.pageY - options.yOffset) + "px")
						.css("left",(e.pageX + options.xOffset) + "px")						
						.css("display","none")
						.fadeIn("fast")
				}
			},
			function(){	
				$("#" + options.tooltipId).remove();
				$(this).attr("title",title);
			});	
			$(this).mousemove(function(e){
				$("#" + options.tooltipId)
					.css("top",(e.pageY - options.yOffset) + "px")
					.css("left",(e.pageX + options.xOffset) + "px")					
			});	
			if(options.clickRemove){
				$(this).mousedown(function(e){
					$("#" + options.tooltipId).remove();
					$(this).attr("title",title);
				});				
			}
		});
	  
	};

})(jQuery);

/*!
 * FullCalendar v1.2.1
 * http://arshaw.com/fullcalendar/
 *
 * use fullcalendar.css for basic styling
 * requires jQuery UI core and draggables ONLY if you plan to do drag & drop
 *
 * Copyright (c) 2009 Adam Shaw
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 *
 * Date: 2009-05-31 13:56:02 -0700 (Sun, 31 May 2009)
 * Revision: 23
 */
 
(function($) {

	$.fn.fullCalendar = function(options) {
	
	
		//
		// Calls methods on a pre-existing instance
		//
		
		if (typeof options == 'string') {
			var args = Array.prototype.slice.call(arguments, 1);
			var res;
			this.each(function() {
				var r = $.data(this, 'fullCalendar')[options].apply(this, args);
				if (typeof res == 'undefined') res = r;
			});
			if (typeof res != 'undefined') {
				return res;
			}
			return this;
		}
		
		
		
		//
		// Process options
		//
		
		options = options || {};
		
		var r2l = options.rightToLeft;
		var dis, dit; // day index sign / translate
		if (r2l) {
			dis = -1;
			dit = 6;
			this.addClass('r2l');
		}else{
			dis = 1;
			dit = 0;
		}
		
		var showTime = typeof options.showTime == 'undefined' ? 'guess' : options.showTime;
		var bo = typeof options.buttons == 'undefined' ? true : options.buttons;
		var weekStart = (options.weekStart || 0) % 7;
		var timeFormat = options.timeFormat || 'gx';
		var titleFormat = options.titleFormat || (r2l ? 'Y F' : 'F Y');
		
		
		
		//
		// Rendering bug detection variables
		//
		
		var tdTopBug, trTopBug, tbodyTopBug, sniffBugs = true;
		
		
		
		this.each(function() {
		
		
			//
			// Instance variables
			//
			
			var date = options.year ? // holds the year & month of current month
				new Date(options.year, options.month || 0, 1) :
				new Date();
			var start, end; // first & last VISIBLE dates
			var today;
			var numWeeks;
			var ignoreResizes = false;
			
			var events = [];
			var eventSources = options.eventSources || [];
			if (options.events) eventSources.push(options.events);
			
			
			
			//
			// Month navigation functions
			//
		
			function refreshMonth() {
				clearEventElements();				
				render();
				//$("[rel='prettyPhoto[ajax]']").prettyPhoto(window.lightboxSettings);
			}
		
			function prevMonth() {
				addMonths(date, -1);
				refreshMonth();
				$("[rel='prettyPhoto[ajax]']").prettyPhoto(window.lightboxSettings);
			}
		
			function nextMonth() {
				addMonths(date, 1);
				refreshMonth();
				$("[rel='prettyPhoto[ajax]']").prettyPhoto(window.lightboxSettings);
			}
			
			function gotoToday() {
				date = new Date();
				refreshMonth();
				$("[rel='prettyPhoto[ajax]']").prettyPhoto(window.lightboxSettings);
			}
		
			function gotoMonth(year, month) {
				date = new Date(year, month, 1);
				refreshMonth();
				$("[rel='prettyPhoto[ajax]']").prettyPhoto(window.lightboxSettings);
			}
			
			function prevYear() {
				addYears(date, -1);
				refreshMonth();
				$("[rel='prettyPhoto[ajax]']").prettyPhoto(window.lightboxSettings);
			}
			
			function nextYear() {
				addYears(date, 1);
				refreshMonth();
				$("[rel='prettyPhoto[ajax]']").prettyPhoto(window.lightboxSettings);
			}
			
			
			
			//
			// Publicly accessible methods
			//
			
			$.data(this, 'fullCalendar', {
				refresh: refreshMonth,
				prevMonth: prevMonth,
				nextMonth: nextMonth,
				today: gotoToday,
				gotoMonth: gotoMonth,
				prevYear: prevYear,
				nextYear: nextYear,
				
				
				//
				// Event CRUD
				//
			
				addEvent: function(event) {
					events.push(normalizeEvent(event));
					clearEventElements();
					renderEvents();
				},
			
				updateEvent: function(event) {
					event.start = $.fullCalendar.parseDate(event.start);
					event.end = $.fullCalendar.parseDate(event.end);
					var startDelta = event.start - event._start;
					var msLength = event.end - event.start;
					event._start = cloneDate(event.start);
					for (var i=0; i<events.length; i++) {
						var e = events[i];
						if (e.id === event.id && e !== event) {
							e.start = new Date(e.start.getTime() + startDelta);
							e._start = cloneDate(e.start);
							e.end = new Date(e.start.getTime() + msLength);
							for (var k in event) {
								if (k && k != 'start' && k != 'end' && k.charAt(0) != '_') {
									e[k] = event[k];
								}
							}
						}
					}
					clearEventElements();
					renderEvents();
				},
			
				removeEvent: function(eventId) {
					if (typeof eventId == 'object') {
						eventId = eventId.id;
					}
					
					// remove from the 'events' array
					var newEvents = [];
					for (var i=0; i<events.length; i++) {
						if (events[i].id !== eventId) {
							newEvents.push(events[i]);
						}
					}
					events = newEvents;
					
					// remove from static event sources
					for (var i=0; i<eventSources.length; i++) {
						var src = eventSources[i];
						if (typeof src != 'string' && !$.isFunction(src)) {
							var newSrc = [];
							for (var j=0; j<src.length; j++) {
								if (src[j].id !== eventId) {
									newSrc.push(src[j]);
								}
							}
							eventSources[i] = newSrc;
						}
					}
					
					clearEventElements();
					renderEvents();
				},
			
				getEventsById: function(eventId) {
					var res = [];
					for (var i=0; i<events.length; i++) {
						if (events[i].id === eventId) {
							res.push(events[i]);
						}
					}
					return res;
				},
				
				
			
				//
				// Event Source CRUD
				//
			
				addEventSource: function(src) {
					eventSources.push(src);
					pushLoading();
					fetchEventSource(src, function() {
						popLoading();
						clearEventElements();
						renderEvents();
					});
				},
			
				removeEventSource: function(src) {
			
					// remove from 'eventSources' array
					var newSources = [];
					for (var i=0; i<eventSources.length; i++) {
						if (src !== eventSources[i]) {
							newSources.push(eventSources[i]);
						}
					}
					eventSources = newSources;
				
					// remove events from 'events' array
					var newEvents = [];
					for (var i=0; i<events.length; i++) {
						if (events[i].source !== src) {
							newEvents.push(events[i]);
						}
					}
					events = newEvents;
				
					clearEventElements();
					renderEvents();
				}
				
			});
			
			
			
			
			
			/*******************************************************************/
			//
			//		Header & Table Rendering
			//
			/*******************************************************************/
			
			
			//
			// Build one-time DOM elements (header, month container)
			//
		
			var titleElement, todayButton, monthElement, monthElementWidth;
			var header = $("<div class='full-calendar-header'/>").appendTo(this);
			
			if (bo) { // "button options"
				var buttons = $("<div class='full-calendar-buttons'/>").appendTo(header);
				if (bo == true || bo.today !== false) {
					todayButton = $("<button class='today' />")
						.append($("<span />").html(
							typeof bo.today == 'string' ?
								bo.today : "today"))
						.click(gotoToday);
					buttons.append(todayButton);
				}
				if (bo.prevYear) {
					var b = $("<button class='prev-year' />")
						.append($("<span />")
							.html(typeof bo.prevYear == 'string' ?
								bo.prevYear : "&laquo;"))
						.click(prevYear);
					if (r2l) buttons.prepend(b);
					else buttons.append(b);
				}
				if (bo == true || bo.prevMonth !== false) {
					var b = $("<button class='prev-month' />")
						.append($("<span />")
							.html(typeof bo.prevMonth == 'string' ?
								bo.prevMonth : (r2l ? "&gt;" : "&lt;")))
						.click(prevMonth);
					if (r2l) buttons.prepend(b);
					else buttons.append(b);
				}
				if (bo == true || bo.nextMonth !== false) {
					var b = $("<button class='next-month' />")
						.append($("<span />").html(typeof bo.nextMonth == 'string' ?
							bo.nextMonth : (r2l ? "&lt;" : "&gt;")))
						.click(nextMonth);
					if (r2l) buttons.prepend(b);
					else buttons.append(b);
				}
				if (bo.nextYear) {
					var b = $("<button class='next-year' />")
						.append($("<span />").html(typeof bo.nextYear == 'string'
							? bo.nextYear : "&raquo;"))
						.click(nextYear);
					if (r2l) buttons.prepend(b);
					else buttons.append(b);
				}
			}
			
			if (options.title !== false) {
				titleElement = $("<h2 class='full-calendar-title'/>").appendTo(header);
			}
		
			monthElement = $("<div class='full-calendar-month' style='position:relative'/>")
				.appendTo($("<div class='full-calendar-month-wrap'/>").appendTo(this));
			
			
			//
			// Build the TABLE cells for the current month. (calls event fetching & rendering code)
			//
			
			var thead, tbody, glass;
			
			function render() {
		
				ignoreResizes = true;
				date.setDate(1);
				clearTime(date);
				var year = date.getFullYear();
				var month = date.getMonth();
				var monthTitle = $.fullCalendar.formatDate(date, titleFormat);
				if (titleElement) titleElement.text(monthTitle);
			
				clearTime(date);
				start = cloneDate(date);
				addDays(start, -((start.getDay() - weekStart + 7) % 7));
				end = cloneDate(date);
				addMonths(end, 1);
				addDays(end, (7 - end.getDay() + weekStart) % 7);
				numWeeks = Math.round((end.getTime() - start.getTime()) / 604800000);
				if (options.fixedWeeks != false) {
					addDays(end, (6 - numWeeks) * 7);
					numWeeks = 6;
				}
			
				today = clearTime(new Date());
				if (todayButton) {
					if (today.getFullYear() == year && today.getMonth() == month) {
						todayButton.css('visibility', 'hidden');
					}else{
						todayButton.css('visibility', 'visible');
					}
				}
				
				var dayNames = $.fullCalendar.dayNames;
				var dayAbbrevs = $.fullCalendar.dayAbbrevs;
			
				if (!tbody) {
				
					// first time, build all cells from scratch
				
					var table = $("<table style='width:100%'/>").appendTo(monthElement);
				
					thead = "<thead><tr>";
					for (var i=0; i<7; i++) {
						var j = (i * dis + dit + weekStart) % 7;
						thead +=
							"<th class='" + dayAbbrevs[j].toLowerCase() +
							(i==0 ? ' first' : '') + "'>" +
							(options.abbrevDayHeadings!=false ? dayAbbrevs[j] : dayNames[j]) +
							"</th>";
					}
					thead = $(thead + "</tr></thead>").appendTo(table);
					
					tbody = "<tbody>";
					var d = cloneDate(start);
					for (var i=0; i<numWeeks; i++) {
						tbody += "<tr class='week"+(i+1)+"'>";
						var tds = "";
						for (var j=0; j<7; j++) {
							var s =
								"<td class='day " + dayAbbrevs[(j + weekStart) % 7].toLowerCase() +
								(j==dit ? ' first' : '') +
								(d.getMonth() == month ? '' : ' other-month') +
								(d.getTime() == today.getTime() ? ' today' : '') +
								"'><div class='day-number'>" + d.getDate() + "</div>" +
								"<div class='day-content'><div/></div></td>";
							if (r2l) tds = s + tds;
							else tds += s;
							addDays(d, 1);
						}
						tbody += tds + "</tr>";
					}
					tbody = $(tbody + "</tbody>").appendTo(table);
						
					// a protective coating over the TABLE
					// intercepts mouse clicks and prevents text-selection
					glass = $("<div style='position:absolute;top:0;left:0;z-index:1;width:100%' />")
						.appendTo(monthElement)
						.click(function(ev, ui) {
							if (options.dayClick) {
								buildDayGrid();
								var td = dayTD(ev.pageX, ev.pageY);
								if (td) return options.dayClick.call(td, dayDate(td));
							}
						});
				
				}else{
				
					// NOT first time, reuse as many cells as possible
			
					var diff = numWeeks - tbody.find('tr').length;
					if (diff < 0) {
						// remove extra rows
						tbody.find('tr:gt(' + (numWeeks-1) + ')').remove();
					}
					else if (diff > 0) {
						var trs = "";
						for (var i=0; i<diff; i++) {
							trs += "<tr class='week"+(numWeeks+i)+"'>";
							for (var j=0; j<7; j++) {
								trs +=
									"<td class='day " +
									dayAbbrevs[(j * dis + dit + weekStart) % 7].toLowerCase() +
									(j==0 ? ' first' : '') + "'>" +
									"<div class='day-number'></div>" +
									"<div class='day-content'><div/></div>" +
									"</td>";
							}
							trs += "</tr>";
						}
						if (trs) tbody.append(trs);
					}
				
					// re-label and re-class existing cells
					var d = cloneDate(start);
					tbody.find('tr').each(function() {
						for (var i=0; i<7; i++) {
							var td = this.childNodes[i * dis + dit];
							if (d.getMonth() == month) {
								$(td).removeClass('other-month');
							}else{
								$(td).addClass('other-month');
							}
							if (d.getTime() == today.getTime()) {
								$(td).addClass('today');
							}else{
								$(td).removeClass('today');
							}
							$(td.childNodes[0]).text(d.getDate());
							addDays(d, 1);
						}
					});
			
				}
			
				setCellSizes();
				
				if (sniffBugs) {
					// nasty bugs in opera 9.25
					// position() returning relative to direct parent
					var tr = tbody.find('tr');
					var td = tr.find('td');
					var trTop = tr.position().top;
					var tdTop = td.position().top;
					tdTopBug = tdTop < 0;
					trTopBug = trTop != tdTop;
					tbodyTopBug = tbody.position().top != trTop;
					sniffBugs = false;
				}
				
				fetchEvents(renderEvents);
				
				ignoreResizes = false;
			
				if (options.monthDisplay) {
					options.monthDisplay(date.getFullYear(), date.getMonth(), monthTitle);
				}
			
			}
			
			
			//
			// Adjust dimensions of the cells, based on container's width
			//
			
			function setCellSizes() {
				var tbodyw = tbody.width();
				var cellw = Math.floor(tbodyw / 7);
				var cellh = Math.round(cellw * .85);
				thead.find('th')
					.filter(':lt(6)').width(cellw).end()
					.filter(':eq(6)').width(tbodyw - cellw*6);
				tbody.find('td').height(cellh);
				glass.height(monthElement.height());
				monthElementWidth = monthElement.width();
			}
			
			
			
			
			
			
			/*******************************************************************/
			//
			//		Event Rendering
			//
			/*******************************************************************/
			
			
			//
			// Render the 'events' array. First, break up into segments
			//
			
			var eventMatrix = [];
		
			function renderEvents() {
				eventMatrix = [];
				var i = 0;
				var ws = cloneDate(start);
				var we = addDays(cloneDate(ws), 7);
				while (ws.getTime() < end.getTime()) {
					var segs = [];
					$.each(events, function(j, event) {
						if (event.end.getTime() > ws.getTime() && event.start.getTime() < we.getTime()) {
							var ss, se, isStart, isEnd;
							if (event.start.getTime() < ws.getTime()) {
								ss = cloneDate(ws);
								isStart = false;
							}else{
								ss = cloneDate(event.start);
								isStart = true;
							}
							if (event.end.getTime() > we.getTime()) {
								se = cloneDate(we);
								isEnd = false;
							}else{
								se = cloneDate(event.end);
								isEnd = true;
							}
							ss = clearTime(ss);
							se = clearTime((se.getHours()==0 && se.getMinutes()==0) ? se : addDays(se, 1));
							segs.push({
								event: event, start: ss, end: se,
								isStart: isStart, isEnd: isEnd, msLength: se - ss
							});
						}
					});
					segs.sort(segCmp);
					var levels = [];
					$.each(segs, function(j, seg) {
						var l = 0; // level index
						while (true) {
							var collide = false;
							if (levels[l]) {
								for (var k=0; k<levels[l].length; k++) {
									if (seg.end.getTime() > levels[l][k].start.getTime() &&
										seg.start.getTime() < levels[l][k].end.getTime()) {
											collide = true;
											break;
										}
								}
							}
							if (collide) {
								l++;
								continue;
							}else{
								break;
							}
						}
						if (levels[l]) levels[l].push(seg);
						else levels[l] = [seg];
					});
					eventMatrix[i] = levels;
					addDays(ws, 7);
					addDays(we, 7);
					i++;
				}
				_renderEvents();
			}
		
		
			//
			// Do the REAL rendering of the segments
			//
		
			var eventElements = []; // [[event, element], ...]
		
			function _renderEvents() {
				for (var i=0; i<eventMatrix.length; i++) {
					var levels = eventMatrix[i];
					var tr = tbody.find('tr:eq('+i+')');
					var td = tr.find('td:first');
					var innerDiv = td.find('div.day-content div').css('position', 'relative');
					var top = innerDiv.position().top;
					if (tdTopBug) top -= td.position().top;
					if (trTopBug) top += tr.position().top;
					if (tbodyTopBug) top += tbody.position().top;
					var height = 0;
					for (var j=0; j<levels.length; j++) {
						var segs = levels[j];
						var maxh = 0;
						for (var k=0; k<segs.length; k++) {
							var seg = segs[k];
							var event = seg.event;
							var left1, left2, roundW, roundE;
							if (r2l) {
								left2 = seg.isStart ?
									tr.find('td:eq('+((seg.start.getDay()-weekStart+7)%7*dis+dit)+') div.day-content div') :
									tbody;
								left1 = seg.isEnd ?
									tr.find('td:eq('+((seg.end.getDay()+6-weekStart)%7*dis+dit)+') div.day-content div').position().left :
									tbody.position().left;
								roundW = seg.isEnd;
								roundE = seg.isStart;
							}else{
								left1 = seg.isStart ?
									tr.find('td:eq('+((seg.start.getDay()-weekStart+7)%7)+') div.day-content div').position().left :
									tbody.position().left;
								left2 = seg.isEnd ?
									tr.find('td:eq('+((seg.end.getDay()+6-weekStart)%7)+') div.day-content div') :
									tbody;
								roundW = seg.isStart;
								roundE = seg.isEnd;
							}
							left2 = left2.position().left + left2.width();
							var cl = event.className;
							if (typeof cl == 'string') {
								cl = ' ' + cl;
							}
							else if (typeof cl == 'object') {
								cl = ' ' + cl.join(' ');
							}
							var element = $("<table class='event" + (cl || '') + "' />")
								.append("<tr>" +
									(roundW ? "<td class='nw'/>" : '') +
									"<td class='n'/>" +
									(roundE ? "<td class='ne'/>" : '') + "</tr>")
								.append("<tr>" +
									(roundW ? "<td class='w'/>" : '') +
									"<td class='c'/>" +
									(roundE ? "<td class='e'/>" : '') + "</tr>")
								.append("<tr>" +
									(roundW ? "<td class='sw'/>" : '') +
									"<td class='s'/>" +
									(roundE ? "<td class='se'/>" : '') + "</tr>");
							buildEventText(event, element.find('td.c'));
							if (options.eventRender) {
								var res = options.eventRender(event, element);
								if (typeof res != 'undefined') {
									if (res === false) continue;
									if (res !== true) element = $(res);
								}
							}
							element
								.css({
									position: 'absolute',
									top: top,
									left: left1,
									width: left2 - left1,
									'z-index': 3
								})
								.appendTo(monthElement);
							initEventElement(event, element);
							var h = element.outerHeight({margin:true});
							if (h > maxh) maxh = h;
						}
						height += maxh;
						top += maxh;
					}
					innerDiv.height(height);
				}
			}
			
			
			//
			// create the text-contents of an event segment
			//
			
			function buildEventText(event, element) {
				$("<a class='event-title' rel='prettyPhoto[ajax]' href='" + event.url + "?ajax=true&amp;width=600&amp;height=400' />")
					.text(event.title)
					.appendTo(element);
				var st = typeof event.showTime == 'undefined' ? showTime : event.showTime;
				if (st != false) {
					if (st == true || st == 'guess' &&
						(event.start.getHours() || event.start.getMinutes() ||
						 event.end.getHours() || event.end.getMinutes())) {
							var timeStr = $.fullCalendar.formatDate(event.start, timeFormat);
							var timeElement = $("<span class='event-time' />");
							if (r2l) element.append(timeElement.text(' ' + timeStr));
							else element.prepend(timeElement.text(timeStr + ' '));
						}
				}
			}
		
		
			//
			// Attach event handlers to an event segment
			//
		
			function initEventElement(event, element) {
				element.click(function(ev) {
					if (!element.hasClass('ui-draggable-dragging')) {
						if (options.eventClick) {
							var res = options.eventClick.call(this, event, ev);
							if (res === false) return false;
						}
						//if (event.url) window.location.href = event.url;
					}
				});
				if (options.eventMouseover)
					element.mouseover(function(ev) {
						options.eventMouseover.call(this, event, ev);
					});
				if (options.eventMouseout)
					element.mouseout(function(ev) {
						options.eventMouseout.call(this, event, ev);
					});
				if (typeof event.draggable != 'undefined') {
					if (event.draggable)
						draggableEvent(event, element);
				}
				else if (options.draggable) {
					draggableEvent(event, element);
				}
				eventElements.push([event, element]);
			}
			
			
			//
			// Remove all event segments from DOM
			//
			
			function clearEventElements() {
				for (var i=0; i<eventElements.length; i++)
					eventElements[i][1].remove();
				eventElements = [];
			}
		
		
		
		
		
		
		
			/*******************************************************************/
			//
			//		Drag & Drop		(and cell-coordinate stuff)
			//
			/*******************************************************************/
			
		
			//
			// Attach jQuery UI draggable
			//
		
			var dragStartTD, dragTD;
			var dayOverlay;
		
			function draggableEvent(event, element) {
				element.draggable({
					zIndex: 4,
					delay: 50,
					opacity: options.eventDragOpacity,
					revertDuration: options.eventRevertDuration,
					start: function(ev, ui) {
						// hide other elements with same event
						for (var i=0; i<eventElements.length; i++) {
							var x = eventElements[i];
							var xevent = x[0];
							if (x[1].get(0) != this && (xevent == event ||
								typeof xevent.id != 'undefined' && xevent.id == event.id))
									x[1].hide();
						}
						if (!dayOverlay)
							dayOverlay =
								$("<div class='over-day' style='position:absolute;z-index:2' />")
									.appendTo(monthElement);
						buildDayGrid();
						dragTD = dragStartTD = null;
						eventDrag(this, ev, ui);
						if (options.eventDragStart)
							options.eventDragStart.call(this, event, ev, ui);
					},
					drag: function(ev, ui) {
						eventDrag(this, ev, ui);
					},
					stop: function(ev, ui) {
						if (!dragTD || dragTD == dragStartTD) {
							// show all events
							for (var i=0; i<eventElements.length; i++)
								eventElements[i][1].show();
						}else{
							var delta = dayDelta(dragStartTD, dragTD);
							for (var i=0; i<events.length; i++) {
								if (event == events[i] || typeof event.id != 'undefined' && event.id == events[i].id) {
									addDays(events[i].start, delta, true);
									addDays(events[i].end, delta, true);
									events[i]._start = cloneDate(events[i].start);
								}
							}
							if (options.eventDrop) {
								options.eventDrop.call(this, event, delta, ev, ui);
							}
							clearEventElements();
							renderEvents();
						}
						dayOverlay.hide();
						if (options.eventDragStop) {
							options.eventDragStop.call(this, event, ev, ui);
						}
					}
				});
			}
			
			
			//
			// Called DURING dragging, on every mouse move
			//
		
			function eventDrag(node, ev, ui) {
				var oldTD = dragTD;
				dragTD = dayTD(ev.pageX, ev.pageY);
				if (!dragStartTD) dragStartTD = dragTD;
				if (dragTD != oldTD) {
					if (dragTD) {
						$(node).draggable('option', 'revert', dragTD==dragStartTD);
						dayOverlay.css({
							top: currTDY,
							left: currTDX,
							width: currTDW,
							height: currTDH,
							display: 'block'
						});
					}else{
						$(node).draggable('option', 'revert', true);
						dayOverlay.hide();
					}
				}
			}
		
		
			//
			// Record positions & dimensions of each TD
			//
		
			var dayX, dayY, dayX0, dayY0;
			var currTD, currR, currC;
			var currTDX, currTDY, currTDW, currTDH;
		
			function buildDayGrid() {
				var tr, td, o=monthElement.offset();
				dayX0 = o.left;
				dayY0 = o.top;
				dayY = [];
				tbody.find('tr').each(function() {
					tr = $(this);
					dayY.push(tr.position().top +
						(trTopBug ? tbody.position().top : 0));
				});
				dayY.push(dayY[dayY.length-1] + tr.height());
				dayX = [];
				tr.find('td').each(function() {
					td = $(this);
					dayX.push(td.position().left);
				});
				dayX.push(dayX[dayX.length-1] + td.width());
				currTD = null;
			}
			
			//
			// Returns TD underneath coordinate (optimized)
			//
		
			function dayTD(x, y) {
				var r=-1, c=-1;
				var rmax=dayY.length-1, cmax=dayX.length-1;
				while (r < rmax && y > dayY0 + dayY[r+1]) r++;
				while (c < cmax && x > dayX0 + dayX[c+1]) c++;
				if (r < 0 || r >= rmax || c < 0 || c >= cmax)
					return currTD = null;
				else if (!currTD || r != currR || c != currC) {
					currR = r;
					currC = c;
					currTD = tbody.find('tr:eq('+r+') td:eq('+c+')').get(0);
					currTDX = dayX[c];
					currTDY = dayY[r];
					currTDW = dayX[c+1] - currTDX;
					currTDH = dayY[r+1] - currTDY;
					return currTD;
				}
				return currTD;
			}
			
			//
			// Get a TD's date
			//
		
			function dayDate(td) {
				var i, trs = tbody.get(0).getElementsByTagName('tr');
				for (i=0; i<trs.length; i++) {
					var tr = trs[i];
					for (var j=0; j<7; j++) {
						if (tr.childNodes[j] == td) {
							var d = cloneDate(start);
							return addDays(d, i*7 + j*dis + dit);
						}
					}
				}
			}
			
			//
			// Return the # of days between 2 TD's
			//
		
			function dayDelta(td1, td2) {
				var i1, i2, trs = tbody.get(0).getElementsByTagName('tr');
				for (var i=0; i<trs.length; i++) {
					var tr = trs[i];
					for (var j=0; j<7; j++) {
						var td = tr.childNodes[j];
						if (td == td1) i1 = i*7 + j*dis + dit;
						if (td == td2) i2 = i*7 + j*dis + dit;
					}
				}
				return i2 - i1;
			}
			
			
			
			
			
			
			
			/*******************************************************************/
			//
			//		Event Sources & Fetching
			//
			/*******************************************************************/
			
			
			//
			// Fetch from ALL sources. Clear 'events' array and populate
			//
			
			function fetchEvents(callback) {
				events = [];
				if (eventSources.length > 0) {
					var queued = eventSources.length;
					var sourceDone = function() {
						if (--queued == 0) {
							popLoading();
							if (callback) {
								callback(events);
							}
						}
					};
					pushLoading();
					for (var i=0; i<eventSources.length; i++) {
						fetchEventSource(eventSources[i], sourceDone);
					}
				}
			}
			
			
			//
			// Fetch from a particular source. Append to the 'events' array
			//
			
			function fetchEventSource(src, callback) {
				var y = date.getFullYear();
				var m = date.getMonth();
				var reportEvents = function(a) {
					if (date.getFullYear() == y && date.getMonth() == m) {
						for (var i=0; i<a.length; i++) {
							normalizeEvent(a[i]);
							a[i].source = src;
						}
						events = events.concat(a);
					}
					if (callback) {
						callback(a);
					}
				};
				if (typeof src == 'string') {
					var params = {};
					params[options.startParam || 'start'] = Math.round(start.getTime() / 1000);
					params[options.endParam || 'end'] = Math.round(end.getTime() / 1000);
					params[options.cacheParam || '_'] = (new Date()).getTime();
					$.getJSON(src, params, reportEvents);
				}
				else if ($.isFunction(src)) {
					src(start, end, reportEvents);
				}
				else {
					reportEvents(src);
				}
			}
			
			
			//
			// methods for reporting loading state
			//
			
			var loadingLevel = 0;
			
			function pushLoading() {
				if (!loadingLevel++ && options.loading) {
					options.loading(true);
				}
			}
			
			function popLoading() {
				if (!--loadingLevel && options.loading) {
					options.loading(false);
				}
			}
			
			
			
			
			
			
			/*******************************************************************/
			//
			//		Begin "Main" Execution
			//
			/*******************************************************************/
		
			var e = $(this);
			var _e = this;
			var resizeID = 0;
			$(window).resize(function() {   // re-render table on window resize
				if (!ignoreResizes) {
					var rid = ++resizeID;   // add a delay
					setTimeout(function() {
						if (rid == resizeID) {
							// if calendar is visible
							if (e.css('display') != 'none') {
								// if the month width changed
								if (monthElement.width() != monthElementWidth) {
									clearEventElements();
									setCellSizes();
									_renderEvents();
									if (options.resize) options.resize.call(_e);
								}
							}
						}
					}, 200);
				}
			});
		
			// let's begin...
			if (e.css('display') != 'none') {
				render();
			}
			
			
			
			
		});
		
		return this;
	};
	
	
	
	
	/***************************************************************************/
	//
	//		Utilities
	//
	/***************************************************************************/
	
	
	//
	// event utils
	//
	
	function normalizeEvent(event) {
		if (event.date) {
			event.start = event.date;
			delete event.date;
		}
		event.start = $.fullCalendar.parseDate(event.start);
		event._start = cloneDate(event.start);
		event.end = $.fullCalendar.parseDate(event.end);
		if (!event.end || event.end <= event.start) {
			event.end = addDays(cloneDate(event.start), 1);
		}
		return event;
	}
	
	function segCmp(a, b) {
		return (b.msLength - a.msLength) * 100 + (a.event.start - b.event.start);
	}
	
	
	//
	// string utils
	//
	
	function zeroPad(n) {
		return (n < 10 ? '0' : '') + n;
	}
	
	
	//
	// date utils
	//
	
	function addMonths(d, n, keepTime) {
		d.setMonth(d.getMonth() + n);
		if (keepTime) return d;
		return clearTime(d);
	}
	
	function addYears(d, n, keepTime) {
		d.setFullYear(d.getFullYear() + n);
		if (keepTime) return d;
		return clearTime(d);
	}
	
	function addDays(d, n, keepTime) {
		d.setDate(d.getDate() + n);
		if (keepTime) return d;
		return clearTime(d);
	}
	
	function clearTime(d) {
		d.setHours(0); 
		d.setMinutes(0);
		d.setSeconds(0); 
		d.setMilliseconds(0);
		return d;
	}
	
	function cloneDate(d) {
		return new Date(+d);
	}
	
	
	//
	// globally accessible date formatting & parsing
	//
	
	$.fullCalendar = {
	
		monthNames: ['January','February','March','April','May','June','July','August','September','October','November','December'],
		monthAbbrevs: ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'],
		dayNames: ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'],
		dayAbbrevs: ['Sun','Mon','Tue','Wed','Thu','Fri','Sat'],
	
		formatDate: function(d, format) {
			var f = $.fullCalendar.dateFormatters;
			var s = '';
			for (var i=0; i<format.length; i++) {
				var c = format.charAt(i);
				if (f[c]) {
					s += f[c](d);
				}else{
					s += c;
				}
			}
			return s;
		},
		
		dateFormatters: {
			'a': function(d) { return d.getHours() < 12 ? 'am' : 'pm' },
			'A': function(d) { return d.getHours() < 12 ? 'AM' : 'PM' },
			'x': function(d) { return d.getHours() < 12 ? 'a' : 'p' },
			'X': function(d) { return d.getHours() < 12 ? 'A' : 'P' },
			'g': function(d) { return d.getHours() % 12 || 12 },
			'G': function(d) { return d.getHours() },
			'h': function(d) { return zeroPad(d.getHours() %12 || 12) },
			'H': function(d) { return zeroPad(d.getHours()) },
			'i': function(d) { return zeroPad(d.getMinutes()) },
			'F': function(d) { return $.fullCalendar.monthNames[d.getMonth()] },
			'm': function(d) { return zeroPad(d.getMonth() + 1) },
			'M': function(d) { return $.fullCalendar.monthAbbrevs[d.getMonth()] },
			'n': function(d) { return d.getMonth() + 1 },
			'Y': function(d) { return d.getFullYear() },
			'y': function(d) { return (d.getFullYear()+'').substring(2) },
			'c': function(d) {
				// ISO8601. derived from http://delete.me.uk/2005/03/iso8601.html
				return d.getUTCFullYear() +
					"-" + zeroPad(d.getUTCMonth() + 1) +
					"-" + zeroPad(d.getUTCDate()) +
					"T" + zeroPad(d.getUTCHours()) +
					":" + zeroPad(d.getUTCMinutes()) +
					":" + zeroPad(d.getUTCSeconds()) +
					"Z";
			}
		},
		
		parseDate: function(s) {
			if (typeof s == 'object')
				return s; // already a Date object
			if (typeof s == 'undefined')
				return null;
			if (typeof s == 'number')
				return new Date(s * 1000);
			return $.fullCalendar.parseISO8601(s, true) ||
			       Date.parse(s) ||
			       new Date(parseInt(s) * 1000);
		},
		
		parseISO8601: function(s, ignoreTimezone) {
			// derived from http://delete.me.uk/2005/03/iso8601.html
			var regexp = "([0-9]{4})(-([0-9]{2})(-([0-9]{2})" +
				"(T([0-9]{2}):([0-9]{2})(:([0-9]{2})(\.([0-9]+))?)?" +
				"(Z|(([-+])([0-9]{2}):([0-9]{2})))?)?)?)?";
			var d = s.match(new RegExp(regexp));
			if (!d) return null;
			var offset = 0;
			var date = new Date(d[1], 0, 1);
			if (d[3]) { date.setMonth(d[3] - 1); }
			if (d[5]) { date.setDate(d[5]); }
			if (d[7]) { date.setHours(d[7]); }
			if (d[8]) { date.setMinutes(d[8]); }
			if (d[10]) { date.setSeconds(d[10]); }
			if (d[12]) { date.setMilliseconds(Number("0." + d[12]) * 1000); }
			if (!ignoreTimezone) {
				if (d[14]) {
					offset = (Number(d[16]) * 60) + Number(d[17]);
					offset *= ((d[15] == '-') ? 1 : -1);
				}
				offset -= date.getTimezoneOffset();
			}
			return new Date(Number(date) + (offset * 60 * 1000));
		}
	
	};
	
	// additional FullCalendar "extensions" should be attached to $.fullCalendar

})(jQuery);
//EOI FULL CALENDAR

/* ------------------------------------------------------------------------
	Class: prettyPhoto
	Use: Lightbox clone for jQuery
	Author: Stephane Caron (http://www.no-margin-for-errors.com)
	Version: 2.4.3
------------------------------------------------------------------------- */

var $pp_pic_holder;
var $ppt;

(function($) {
	$.fn.prettyPhoto = function(settings) {
		// global Variables
		var doresize = true;
		var percentBased = false;
		var imagesArray = [];
		var setPosition = 0; /* Position in the set */
		var pp_contentHeight;
		var pp_contentWidth;
		var pp_containerHeight;
		var pp_containerWidth;
		var pp_type = 'image';
	
		// Global elements
		var $caller;
		var $scrollPos = _getScroll();
	
		$(window).scroll(function(){ $scrollPos = _getScroll(); _centerPicture(); });
		$(window).resize(function(){ _centerPicture(); _resizeOverlay(); });
		$(document).keypress(function(e){
			switch(e.keyCode){
				case 37:
					if (setPosition == 1) return;
					changePicture('previous');
					break;
				case 39:
					if (setPosition == setCount) return;
					changePicture('next');
					break;
				case 27:
					close();
					break;
			};
	    });
 
	
		settings = jQuery.extend({
			animationSpeed: 'normal', /* fast/slow/normal */
			padding: 40, /* padding for each side of the picture */
			opacity: 0.80, /* Value between 0 and 1 */
			showTitle: true, /* true/false */
			allowresize: true, /* true/false */
			counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
			theme: 'light_rounded', /* light_rounded / dark_rounded / light_square / dark_square */
			callback: function(){}
		}, settings);
		
		// Fallback to a supported theme for IE6
		if($.browser.msie && $.browser.version == 6){
			settings.theme = "light_square";
		}
	
		$(this).each(function(){
			var hasTitle = false;
			var isSet = false;
			var setCount = 0; /* Total images in the set */
			var arrayPosition = 0; /* Total position in the array */
			
			imagesArray[imagesArray.length] = this;
			$(this).bind('click',function(){
				open(this);
				return false;
			});
		});
	
		function open(el) {
			$caller = $(el);
		
			// Find out if the picture is part of a set
			theRel = $caller.attr('rel');
			galleryRegExp = /\[(?:.*)\]/;
			theGallery = galleryRegExp.exec(theRel);
		
			// Calculate the number of items in the set, and the position of the clicked picture.
			isSet = false;
			setCount = 0;
			
			_getFileType();
			
			for (i = 0; i < imagesArray.length; i++){
				if($(imagesArray[i]).attr('rel').indexOf(theGallery) != -1){
					setCount++;
					if(setCount > 1) isSet = true;

					if($(imagesArray[i]).attr('href') == $caller.attr('href')){
						setPosition = setCount;
						arrayPosition = i;
					};
				};
			};
		
			_buildOverlay();

			// Display the current position
			$pp_pic_holder.find('p.currentTextHolder').text(setPosition + settings.counter_separator_label + setCount);

			// Position the picture in the center of the viewing area
			_centerPicture();
		
			$('#pp_full_res').hide();
			$pp_pic_holder.find('.pp_loaderIcon').show();
		};
	
		showimage = function(width,height,containerWidth,containerHeight,contentHeight,contentWidth,resized){
			$('.pp_loaderIcon').hide();

			if($.browser.opera) {
				windowHeight = window.innerHeight;
				windowWidth = window.innerWidth;
			}else{
				windowHeight = $(window).height();
				windowWidth = $(window).width();
			};

			$pp_pic_holder.find('.pp_content').animate({'height':contentHeight},settings.animationSpeed);

			projectedTop = $scrollPos['scrollTop'] + ((windowHeight/2) - (containerHeight/2));
			if(projectedTop < 0) projectedTop = 0 + $pp_pic_holder.find('.ppt').height();

			// Resize the holder
			$pp_pic_holder.animate({
				'top': projectedTop,
				'left': ((windowWidth/2) - (containerWidth/2)),
				'width': containerWidth
			},settings.animationSpeed,function(){
				$pp_pic_holder.width(containerWidth);
				$pp_pic_holder.find('.pp_hoverContainer,#fullResImage').height(height).width(width);

				// Fade the new image
				$pp_pic_holder.find('#pp_full_res').fadeIn(settings.animationSpeed,function(){
					$(this).find('object,embed').css('visibility','visible');
				});

				// Show the nav elements
				_showContent();
			
				// Fade the resizing link if the image is resized
				if(resized) $('a.pp_expand,a.pp_contract').fadeIn(settings.animationSpeed);
			});
		};
		
		function _showContent(){
			// Show the nav
			if(isSet && pp_type=="image") { $pp_pic_holder.find('.pp_hoverContainer').fadeIn(settings.animationSpeed); }else{ $pp_pic_holder.find('.pp_hoverContainer').hide(); }
			$pp_pic_holder.find('.pp_details').fadeIn(settings.animationSpeed);
			
			// Show the title
			if(settings.showTitle && hasTitle){
				$ppt.css({
					'top' : $pp_pic_holder.offset().top - 22,
					'left' : $pp_pic_holder.offset().left + (settings.padding/2),
					'display' : 'none'
				});
			
				$ppt.fadeIn(settings.animationSpeed);
			};
		}
		
		function _hideContent(){
			// Fade out the current picture
			$pp_pic_holder.find('.pp_hoverContainer,.pp_details').fadeOut(settings.animationSpeed);
			$pp_pic_holder.find('#pp_full_res object,#pp_full_res embed').css('visibility','hidden');
			$pp_pic_holder.find('#pp_full_res').fadeOut(settings.animationSpeed,function(){
				$('.pp_loaderIcon').show();
			
				// Preload the image
				_preload();
			});
			
			// Hide the title
			$ppt.fadeOut(settings.animationSpeed);
		}
	
		function changePicture(direction){
			if(direction == 'previous') {
				arrayPosition--;
				setPosition--;
			}else{
				arrayPosition++;
				setPosition++;
			};

			// Allow the resizing of the images
			if(!doresize) doresize = true;

			_hideContent();
			$('a.pp_expand,a.pp_contract').fadeOut(settings.animationSpeed,function(){
				$(this).removeClass('pp_contract').addClass('pp_expand');
			});
		};
	
		function close(){
			$pp_pic_holder.find('object,embed').css('visibility','hidden');
			
			$('div.pp_pic_holder,div.ppt').fadeOut(settings.animationSpeed);
			
			$('div.pp_overlay').fadeOut(settings.animationSpeed, function(){
				$('div.pp_overlay,div.pp_pic_holder,div.ppt').remove();
			
				// To fix the bug with IE select boxes
				if($.browser.msie && $.browser.version == 6){
					$('select').css('visibility','visible');
				};
				
				settings.callback();
			});
			
			doresize = true;
		};
	
		function _checkPosition(){
			// If at the end, hide the next link
			if(setPosition == setCount) {
				$pp_pic_holder.find('a.pp_next').css('visibility','hidden');
				$pp_pic_holder.find('a.pp_arrow_next').addClass('disabled').unbind('click');
			}else{ 
				$pp_pic_holder.find('a.pp_next').css('visibility','visible');
				$pp_pic_holder.find('a.pp_arrow_next.disabled').removeClass('disabled').bind('click',function(){
					changePicture('next');
					return false;
				});
			};
		
			// If at the beginning, hide the previous link
			if(setPosition == 1) {
				$pp_pic_holder.find('a.pp_previous').css('visibility','hidden');
				$pp_pic_holder.find('a.pp_arrow_previous').addClass('disabled').unbind('click');
			}else{
				$pp_pic_holder.find('a.pp_previous').css('visibility','visible');
				$pp_pic_holder.find('a.pp_arrow_previous.disabled').removeClass('disabled').bind('click',function(){
					changePicture('previous');
					return false;
				});
			};
		
			// Change the current picture text
			$pp_pic_holder.find('p.currentTextHolder').text(setPosition + settings.counter_separator_label + setCount);
		
			$caller = (isSet) ? $(imagesArray[arrayPosition]) : $caller;
			_getFileType();

			if($caller.attr('title')){
				$pp_pic_holder.find('.pp_description').show().html(unescape($caller.attr('title')));
			}else{
				$pp_pic_holder.find('.pp_description').hide().text('');
			};
		
			if($caller.find('img').attr('alt') && settings.showTitle){
				hasTitle = true;
				$ppt.html(unescape($caller.find('img').attr('alt')));
			}else{
				hasTitle = false;
			};
		};
	
		function _fitToViewport(width,height){
			hasBeenResized = false;
		
			_getDimensions(width,height);
			
			// Define them in case there's no resize needed
			imageWidth = width;
			imageHeight = height;

			windowHeight = $(window).height();
			windowWidth = $(window).width();
		
			if( ((pp_containerWidth > windowWidth) || (pp_containerHeight > windowHeight)) && doresize && settings.allowresize && !percentBased) {
				hasBeenResized = true;
				notFitting = true;
			
				while (notFitting){
					if((pp_containerWidth > windowWidth)){
						imageWidth = (windowWidth - 200);
						imageHeight = (height/width) * imageWidth;
					}else if((pp_containerHeight > windowHeight)){
						imageHeight = (windowHeight - 200);
						imageWidth = (width/height) * imageHeight;
					}else{
						notFitting = false;
					};

					pp_containerHeight = imageHeight;
					pp_containerWidth = imageWidth;
				};
			
				_getDimensions(imageWidth,imageHeight);
			};

			return {
				width:imageWidth,
				height:imageHeight,
				containerHeight:pp_containerHeight,
				containerWidth:pp_containerWidth,
				contentHeight:pp_contentHeight,
				contentWidth:pp_contentWidth,
				resized:hasBeenResized
			};
		};
		
		function _getDimensions(width,height){
			$pp_pic_holder.find('.pp_details').width(width).find('.pp_description').width(width - parseFloat($pp_pic_holder.find('a.pp_close').css('width'))); /* To have the correct height */
			
			// Get the container size, to resize the holder to the right dimensions
			pp_contentHeight = height + $pp_pic_holder.find('.pp_details').height() + parseFloat($pp_pic_holder.find('.pp_details').css('marginTop')) + parseFloat($pp_pic_holder.find('.pp_details').css('marginBottom'));
			pp_contentWidth = width;
			pp_containerHeight = pp_contentHeight + $pp_pic_holder.find('.ppt').height() + $pp_pic_holder.find('.pp_top').height() + $pp_pic_holder.find('.pp_bottom').height();
			pp_containerWidth = width + settings.padding;
		}
	
		function _getFileType(){
			if ($caller.attr('href').match(/youtube\.com\/watch/i)) {
				pp_type = 'youtube';
			}else if($caller.attr('href').indexOf('.mov') != -1){ 
				pp_type = 'quicktime';
			}else if($caller.attr('href').indexOf('.swf') != -1){
				pp_type = 'flash';
			}else if($caller.attr('href').indexOf('iframe') != -1){
				pp_type = 'iframe'
			}else if($caller.attr('href').indexOf('ajax') != -1){
				pp_type = 'ajax'
			}else{
				pp_type = 'image';
			}
		}
	
		function _centerPicture(){
			if ($pp_pic_holder){ if($pp_pic_holder.size() == 0){ return; }}else{ return; }; //Make sure the gallery is open

			if($.browser.opera) {
				windowHeight = window.innerHeight;
				windowWidth = window.innerWidth;
			}else{
				windowHeight = $(window).height();
				windowWidth = $(window).width();
			};
		
			if(doresize) {
				$pHeight = $pp_pic_holder.height();
				$pWidth = $pp_pic_holder.width();
				$tHeight = $ppt.height();
				
				projectedTop = (windowHeight/2) + $scrollPos['scrollTop'] - ($pHeight/2);
				if(projectedTop < 0) projectedTop = 0 + $tHeight;
				
				$pp_pic_holder.css({
					'top': projectedTop,
					'left': (windowWidth/2) + $scrollPos['scrollLeft'] - ($pWidth/2)
				});
		
				$ppt.css({
					'top' : projectedTop - $tHeight,
					'left' : (windowWidth/2) + $scrollPos['scrollLeft'] - ($pWidth/2) + (settings.padding/2)
				});
			};
		};
	
		function _preload(){
			// Hide the next/previous links if on first or last images.
			_checkPosition();
		
			if(pp_type == 'image'){
				// Set the new image
				imgPreloader = new Image();
		
				// Preload the neighbour images
				nextImage = new Image();
				if(isSet && setPosition > setCount) nextImage.src = $(imagesArray[arrayPosition + 1]).attr('href');
				prevImage = new Image();
				if(isSet && imagesArray[arrayPosition - 1]) prevImage.src = $(imagesArray[arrayPosition - 1]).attr('href');

				pp_typeMarkup = '<img id="fullResImage" src="" />';				
				$pp_pic_holder.find('#pp_full_res')[0].innerHTML = pp_typeMarkup;

				$pp_pic_holder.find('.pp_content').css('overflow','hidden');
				$pp_pic_holder.find('#fullResImage').attr('src',$caller.attr('href'));

				imgPreloader.onload = function(){
					var correctSizes = _fitToViewport(imgPreloader.width,imgPreloader.height);
					imgPreloader.width = correctSizes['width'];
					imgPreloader.height = correctSizes['height'];
					showimage(imgPreloader.width,imgPreloader.height,correctSizes["containerWidth"],correctSizes["containerHeight"],correctSizes["contentHeight"],correctSizes["contentWidth"],correctSizes["resized"]);
				};
		
				imgPreloader.src = $caller.attr('href');
			}else{
				// Get the dimensions
				movie_width = ( parseFloat(grab_param('width',$caller.attr('href'))) ) ? grab_param('width',$caller.attr('href')) : "425";
				movie_height = ( parseFloat(grab_param('height',$caller.attr('href'))) ) ? grab_param('height',$caller.attr('href')) : "344";

				// If the size is % based
				if(movie_width.indexOf('%') != -1 || movie_height.indexOf('%') != -1){
					movie_height = ($(window).height() * parseFloat(movie_height) / 100) - 100;
					movie_width = ($(window).width() * parseFloat(movie_width) / 100) - 100;
					parsentBased = true;
				}else{
					movie_height = parseFloat(movie_height);
					movie_width = parseFloat(movie_width);
				}
				
				if(pp_type == 'quicktime'){ movie_height+=13; }
				
				// Fit them to viewport
				correctSizes = _fitToViewport(movie_width,movie_height);
				
				if(pp_type == 'youtube'){
					pp_typeMarkup = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+correctSizes['width']+'" height="'+correctSizes['height']+'"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://www.youtube.com/v/'+grab_param('v',$caller.attr('href'))+'" /><embed src="http://www.youtube.com/v/'+grab_param('v',$caller.attr('href'))+'" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="'+correctSizes['width']+'" height="'+correctSizes['height']+'"></embed></object>';
				}else if(pp_type == 'quicktime'){
					pp_typeMarkup = '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab" height="'+correctSizes['height']+'" width="'+correctSizes['width']+'"><param name="src" value="'+$caller.attr('href')+'"><param name="autoplay" value="true"><param name="type" value="video/quicktime"><embed src="'+$caller.attr('href')+'" height="'+correctSizes['height']+'" width="'+correctSizes['width']+'" autoplay="true" type="video/quicktime" pluginspage="http://www.apple.com/quicktime/download/"></embed></object>';
				}else if(pp_type == 'flash'){
					flash_vars = $caller.attr('href');
					flash_vars = flash_vars.substring($caller.attr('href').indexOf('flashvars') + 10,$caller.attr('href').length);

					filename = $caller.attr('href');
					filename = filename.substring(0,filename.indexOf('?'));

					pp_typeMarkup = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+correctSizes['width']+'" height="'+correctSizes['height']+'"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="'+filename+'?'+flash_vars+'" /><embed src="'+filename+'?'+flash_vars+'" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="'+correctSizes['width']+'" height="'+correctSizes['height']+'"></embed></object>';
				}else if(pp_type == 'iframe'){
					movie_url = $caller.attr('href');
					movie_url = movie_url.substr(0,movie_url.indexOf('iframe')-1);

					pp_typeMarkup = '<iframe src ="'+movie_url+'" width="'+(correctSizes['width']-10)+'" height="'+(correctSizes['height']-10)+'" frameborder="no"></iframe>';
				}else if(pp_type == 'ajax'){
					movie_url = $caller.attr('href');
					//movie_url = movie_url.substr(0,movie_url.indexOf('ajax')-1);
                    
                    var ajexHtml = $.ajax({
                        url: movie_url,
                        async: false
                    }).responseText;
                 
					pp_typeMarkup = '<div id="ajaxContent" style="width:'+(correctSizes['width']-10)+'px;height:'+(correctSizes['height']-10)+'px;"> ' + ajexHtml + '</div>';
					
				}
				// Append HTML
				$pp_pic_holder.find('#pp_full_res')[0].innerHTML = pp_typeMarkup;
				
				// Show content
				showimage(correctSizes['width'],correctSizes['height'],correctSizes["containerWidth"],correctSizes["containerHeight"],correctSizes["contentHeight"],correctSizes["contentWidth"],correctSizes["resized"]);
			}
		};
	
		function _getScroll(){
			if (self.pageYOffset) {
				scrollTop = self.pageYOffset;
				scrollLeft = self.pageXOffset;
			} else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
				scrollTop = document.documentElement.scrollTop;
				scrollLeft = document.documentElement.scrollLeft;
			} else if (document.body) {// all other Explorers
				scrollTop = document.body.scrollTop;
				scrollLeft = document.body.scrollLeft;	
			}
			
			return {scrollTop:scrollTop,scrollLeft:scrollLeft};
		};
	
		function _resizeOverlay() {
			$('div.pp_overlay').css({
				'height':$(document).height(),
				'width':$(window).width()
			});
		};
	
		function _buildOverlay(){
			toInject = "";
			
			// Build the background overlay div
			toInject += "<div class='pp_overlay'></div>";
			
			// Define the markup to append, depending on the content type.
			if(pp_type == 'image'){
				pp_typeMarkup = '<img id="fullResImage" src="" />';
			}else{
				pp_typeMarkup = '';
			}
			
			// Basic HTML for the picture holder
			toInject += '<div class="pp_pic_holder"><div class="pp_top"><div class="pp_left"></div><div class="pp_middle"></div><div class="pp_right"></div></div><div class="pp_content"><a href="#" class="pp_expand" title="Expand the image">Expand</a><div class="pp_loaderIcon"></div><div class="pp_hoverContainer"><a class="pp_next" href="#">next</a><a class="pp_previous" href="#">previous</a></div><div id="pp_full_res">'+ pp_typeMarkup +'</div><div class="pp_details clearfix"><a class="pp_close" href="#">Close</a><p class="pp_description"></p><div class="pp_nav"><a href="#" class="pp_arrow_previous">Previous</a><p class="currentTextHolder">0'+settings.counter_separator_label+'0</p><a href="#" class="pp_arrow_next">Next</a></div></div></div><div class="pp_bottom"><div class="pp_left"></div><div class="pp_middle"></div><div class="pp_right"></div></div></div>';
			
			// Basic html for the title holder
			toInject += '<div class="ppt"></div>';
			
			$('body').append(toInject);
			
			// Set my global selectors
			$pp_pic_holder = $('.pp_pic_holder');
			$ppt = $('.ppt');
			
			$('div.pp_overlay').css('height',$(document).height()).bind('click',function(){
				close();
			});

			$pp_pic_holder.css({'opacity': 0}).addClass(settings.theme);

			$('a.pp_close').bind('click',function(){ close(); return false; });

			$('a.pp_expand').bind('click',function(){				
				$this = $(this);
				
				// Expand the image
				if($this.hasClass('pp_expand')){
					$this.removeClass('pp_expand').addClass('pp_contract');
					doresize = false;
				}else{
					$this.removeClass('pp_contract').addClass('pp_expand');
					doresize = true;
				};
			
				_hideContent();
				
				$pp_pic_holder.find('.pp_hoverContainer, #pp_full_res, .pp_details').fadeOut(settings.animationSpeed,function(){
					_preload();
				});
		
				return false;	
			});
		
			$pp_pic_holder.find('.pp_previous, .pp_arrow_previous').bind('click',function(){
				changePicture('previous');
				return false;
			});
		
			$pp_pic_holder.find('.pp_next, .pp_arrow_next').bind('click',function(){
				changePicture('next');
				return false;
			});

			$pp_pic_holder.find('.pp_hoverContainer').css({
				'margin-left': settings.padding/2
			});
		
			// If it's not a set, hide the links
			if(!isSet) {
				$pp_pic_holder.find('.pp_hoverContainer,.pp_nav').hide();
			};


			// To fix the bug with IE select boxes
			if($.browser.msie && $.browser.version == 6){
				$('body').addClass('ie6');
				$('select').css('visibility','hidden');
			};

			// Then fade it in
			$('div.pp_overlay').css('opacity',0).fadeTo(settings.animationSpeed,settings.opacity, function(){
				$pp_pic_holder.css('opacity',0).fadeIn(settings.animationSpeed,function(){
					$pp_pic_holder.attr('style','left:'+$pp_pic_holder.css('left')+';top:'+$pp_pic_holder.css('top')+';');
					_preload();
				});
			});
		};
	};
	
	function grab_param(name,url){
	  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	  var regexS = "[\\?&]"+name+"=([^&#]*)";
	  var regex = new RegExp( regexS );
	  var results = regex.exec( url );
	  if( results == null )
	    return "";
	  else
	    return results[1];
	}
})(jQuery);


function log() {
	try {   
		var args = [];
		for(var i=0; i<arguments.length;i++)
			args.push("arguments["+i+"]");
			
		eval("console.log("+args.join(",")+")");
		   
	}catch(e){}
}

