﻿
/* External Plugins */
//
// create closure
//
(function($) {
	var Temp = function(){
		this.add = function(key, value){
			if(typeof this.values == "undefined")
				this.values = {};
			if(typeof this.values[key] == "undefined" || typeof this.values[key] == null)
				this.values[key] = 0;
			this.values[key]+=value;
			return this.values[key];
		};
		this.get = function(key){
			if(typeof this.values == "undefined")
				this.values = {};
			if(typeof this.values^[key] == "undefined")
				this.values[key] = null;
			return this.values[key];
		};
		this.set = function(key, value){
			if(typeof this.values == "undefined")
				this.values = {};
			if(typeof this.values[key] == "undefined")
				this.values[key] = value;
			return this.values[key];
		};

	};

	$.getBaseUri = function(){
		var b = $("base").attr("href");
		if(b) return $("base").attr("href");
		else return "";
	};

	$.fn.faq = function() {
		return this.each(function() {
			var $this = $(this);
			var dl = $('dl', $this);
			dl.addClass('inv');
			var ul = $(" <ul />");
			var dd = $('dt', $this);
			dd.each(
					function(){
						var li = $(" <li />").attr("class", (dd.length > 1) ? "" : "chosen");
						var fakeDt = $(" <div />").attr("class", "dt").text($(this).text());
						var fakeDd = $(" <div />").attr("class", "dd").text($(this).next().text());
						li.append(fakeDt);
						li.append(fakeDd);
						ul.append(li);
					}
					);
			ul.appendTo($this);
			$('.dt', $this).click(
					function(){
						$(this).parent().siblings().each(function(){
							var li = $(this);
							if(li.hasClass('chosen')){
								li.removeClass('chosen');
							}
						});
						$($(this).parent()).addClass('chosen');
					}
					);
			//			debug($(dd[0]).text());
		});
	};
	$.fn.expanders = function(options) {
		var defaults = {
			isAccordion: false
		};
		var options = $.extend({}, defaults, options);
		return this.each(function() {
			var $this = $(this);
			var isAccordion = options.isAccordion || $(this).hasClass('accordion');
			var toExpand =$('.toExpand', this);
			if(toExpand.length > 0){
				if(isAccordion){
					function setChosen(index) {
						return $this.attr("chosen", index);
					}
					function getChosen(reJquery){
						if(reJquery)
							return $this.find(".toExpand[index='"+getChosen()+"']");
						else
							return $this.attr("chosen");
					};
					function getChosenHead(reJquery){
						if(reJquery)
							return $this.find(".toExpand[index='"+getChosen()+"'] .expHead");
						else
							return $this.find(".toExpand[index='"+getChosen()+"'] .expHead")[0];
					}
					function getChosenContent(reJquery){
						if(reJquery)
							return $this.find(".toExpand[index='"+getChosen()+"'] .expContent");
						else
							return $this.find(".toExpand[index='"+getChosen()+"'] .expContent")[0];
					}
					$this.setClassAttributs("chosen");
					toExpand.each(function(i){
						$(this).attr("index", i);
						$('.expHead', this)
								.click(function(){
							if(getChosenHead() != this){
								getChosenContent(true).slideToggle('slow');
								$('.expContent', $(this).parent()).slideToggle('slow');
								getChosen(true).toggleClass('notExpanded');
								setChosen($(this).parent().attr("index"));
							} else {
								getChosenContent(true).slideToggle('slow');
								setChosen(-1);
							}
							$(this).parent().toggleClass('notExpanded');
						});
						if(getChosen(true)[0] != this)
							$(this).addClass("notExpanded");
						if(i != getChosen()){
							$('.expContent', this).css('display', 'none');
						}
					}).addClass('hasJS');
				}else {
					toExpand.each(function(){
						$('.expHead', this)
								.click(function(){
							$('.expContent', $(this).parent()).slideToggle('slow');
							$(this).parent().toggleClass('notExpanded');
						});
						$(this).addClass("notExpanded");
						$('.expContent', this).css('display', 'none');
					}).addClass('hasJS');
				}
			}
		});
	};

	$.fn.video = function() {
		var t = new Temp();
		function getId(name, rfunc){
			var newId = name+(t.add('video', 1));
			if($('#' + newId).length > 0)
				getId(name, rfunc);
			else
				rfunc(newId);
		}
		return this.each(function() {
			var $this = $(this);
			var $parent = $this.parent();
			var img = $('img', $this);
			var dimensions = {
				width: img.width(),
				height: img.height()+20
			};
			if(swfobject.getFlashPlayerVersion().major >= 9) {
				$parent.height($parent.height()+20);
				if(!$this.attr('id')) {
					getId('videoPlayer', function(id){
						$this.attr('id', id);
					});
				};
				var flashvars = {file: $this.attr('href'), "image": img.attr('src')};
				var params = {'allowfullscreen':'true', 'wmode':'transparent'};
				var attributes = {};
swfobject.embedSWF("fileadmin/swf/longtail/player.swf", $this.attr('id'), dimensions.width, dimensions.height, "9.0.0", false, flashvars, params, attributes);
			}
		});
	};
	$.fn.additionalInput = function() {
		return this.each(function() {
			var $this = $(this);
			function checkState(checked){
				if(checked){
					$this[0].disabled = false;
				} else {
					$this[0].disabled = true;
					if($this[0].nodeName == "SELECT") {
						for(var i=0; i<$this[0].options.length; i++){
							if(i==0)
								$this[0].options[i].selected = true;
							else
								$this[0].options[i].selected = false;
						};
					} else if ($this[0].nodeName == "INPUT"){;
						$this[0].value = "";
					}
				}
				return checked;
			}
			var parentInput = $($this.parents()[1]).find("p:first input");
			checkState(parentInput[0].checked);
			$($this.parents()[2]).find('input[name="'+parentInput[0].name+'"]').change(function(){
				checkState(parentInput[0].checked);
			});
		});
	};
	$.fn.externLinks = function() {
		return this.each(function() {
			var t = $(this).text();
			$(this).text("");
			$(this).append("<span>"+t+"</span>");
			$(this).removeClass("extern");
			$(this).addClass("extern2");
		});
	};
	$.fn.datepicker = function() {
		return this.each(function() {
			//			$(this).addClass("hasJs");
			$(this).find("input").each(function(){
				var labels = $($(this).parents()[1]).find("label.inv[for='"+this.id+"']");
				var labelText = jQuery.trim(labels.text());
				$(this).setClassAttributs("default");
				if(this.value == "") {
					this.value = $(this).attr("default").substring(0, $(this).attr("maxlength"));
				}
			});
			//			$(this).click(function(){alert("Function not available!")});
		});
	};
	$.fn.setClassAttributs = function(attributeName) {
		return this.each(function() {
			var $this = $(this);
			var splitting = this.className.split(" ");
			for(var i= 0; i<splitting.length; i++) {
				if(splitting[i].indexOf(attributeName) != -1){
					var value = splitting[i].substring(splitting[i].indexOf("(")+1, splitting[i].indexOf(")"));
					if(value != "") {
						$this.attr(attributeName, value);
					}
					$(this).removeClass(splitting[i]);
				}
			}
		});
	};
	$.fn.slider = function() {
		function initSlider($select){
			$select.setClassAttributs("imagepre");
			var $sliderCont = $('<div class="sliderCont" />');
			$sliderCont.append('<img class="image0" src="'+$.getBaseUri()+'/fileadmin/img/style/'+$select.attr('imagepre')+'_0.png" />');
			$sliderCont.append('<img class="image1" src="'+$.getBaseUri()+'/fileadmin/img/style/'+$select.attr('imagepre')+'_1.png" />');
			var $scaleCont = $('<div class="scaleCont" />');
			var $valuesCont = $('<div class="valuesCont" />');
			var valuesWidth = 100/($select[0].options.length)*2;
			for(var i=0;i<$select[0].options.length+1;i++){
				var $scale = $('<div class="scale" />');
				$scale.css("width", 100/($select[0].options.length)*i+"%");
				$scaleCont.append($scale);
				if($select[0].options[i]){
					var $value = $('<div class="value" />').text($select[0].options[i].text);
					$value.css({"left":(100/($select[0].options.length)*i-valuesWidth/$select[0].options.length-1)+"%", "width": valuesWidth});
					$valuesCont.append($value);
				}
			}
			var $sliderThumb = $('<img class="thumb" src="'+$.getBaseUri()+'/fileadmin/img/style/slider_thumb.png" />')
			var $lastScale = $scaleCont.find('div.scale:last');
			$lastScale.bind('click', function(event){
				$sliderThumb.animate({'left':event.pageX-$(this).offsetParent().offset().left}, 500);
				var v = Math.floor((event.pageX-$(this).offsetParent().offset().left)/$(this).offsetParent().width()*$select[0].options.length);
				selectOption($select[0].options, v );
			});
			$scaleCont.append($valuesCont);
			$scaleCont.append($sliderThumb);
			$sliderCont.append($scaleCont);
			return $sliderCont;

		}
		function selectOption(options, value){
			for(var i=0; i<options.length; i++) {
				options[i].selected = (i==value);
			};
		}
		return this.each(function() {
			var $this = $(this);
			$this.addClass('hasJS');
			var $iSlider = $this.find(".iSliderMod");
			var $select = $this.find("select");
			$select.addClass("inv");
			$iSlider.append(initSlider($select));
			var $thumb = $iSlider.find(".thumb");
			var parentLeft = $thumb.offsetParent().offset().left;
			var parentWidth = $thumb.offsetParent().width();
			var select = $select[0];
			var options = select.options;
			var moving = 0;
			$thumb.bind('drag', function(event){
					moving = event.cursorOffsetX+event.offsetX-parentLeft;
					if(moving >= 0 && moving <= parentWidth){
						$(this).css({
							left: moving
						});
					}
				})
				.bind('dragend', function (){
					var thumbValue =  Math.floor(moving/parentWidth*options.length);
					if(options.selectedIndex != thumbValue)
						selectOption(options, thumbValue);
				})
		});
	};
	$.fn.textMaxlength = function() {
		return this.each(function() {
			var $this = $(this);
			$this.setClassAttributs("maxlength");
			$this.setClassAttributs("translateFrom");
			$this.setClassAttributs("translateCharacter");
			if($this.attr("maxlength") != undefined) {
				function countCharacters(){
					$this.siblings().text("("+$this[0].value.length+" "+$this.attr("translatefrom")+" "+$this.attr("maxlength")+" "+$this.attr("translatecharacter")+")");
				}
				$this.wrap('<div class="textareaMaxlengthMod" />');
				$($this.parents()[0]).append($("<span />"));
				countCharacters();
				this.onkeyup = function(){
					if(this.value.length > $this.attr("maxlength")) {
						this.value = this.value.substring(0, $this.attr("maxlength"));
					}
					countCharacters();
				};
			}
		});
	};
	$.fn.slideshow = function() {
		var t = new Temp();
		if(typeof window.slideshowFlashloaded == "undefined")
			window.slideshowFlashloaded = function(flashObjId){
				function showImage(image){
					flash.setPause();
					flash.showImage(image);
					return image;
				}
				var flash = $('#'+flashObjId)[0];
				flash.loadJSON(t.get(flashObjId));
				var $p = $('#'+flashObjId).parent();
				var items = 0;
				if($p.attr('enableskip') == "true"){
					var current = showImage(0);
					items = $p.attr("items");
					if($p.find("a").length == 0) {;
						var $next = $('<a href="javascript:void(0)" class="next" />');
						$next.append('<img src="'+$.getBaseUri()+'/fileadmin/img/style/icons/arrow_04204E.gif" />');
						$next.bind('click', function(){
							current++;
							if(current >= items) current = 0;
							current = showImage(current);
						});
						$p.append($next);
						var $prev = $('<a href="javascript:void(0)" class="prev" />');
						$prev.append('<img src="'+$.getBaseUri()+'../img/style/icons/arrow_right_dbe2ec.gif" />');
						$prev.bind('click', function(){
							current--;
							if(current < 0) current = items-1;
							current = showImage(current);
						});
						$p.append($prev);
					}
				}
			};
		function getId(name, rfunc){
			var newId = name+(t.add('idCounter', 1));
			if($('#' + newId).length > 0)
				getId(name, rfunc);
			else
				rfunc(newId);
		}

		return this.each(function() {
			var $this = $(this);
			var images = '{"images":[';
			var dimensions = {};
			$this.wrap('<div class="'+ this.className +'" />');
			var $p = $this.parent();
			$p.setClassAttributs("enableSkip");
			$p.setClassAttributs("dimW");
			$p.setClassAttributs("dimH");
			dimensions.width = $p.attr('dimw');
			dimensions.height = $p.attr('dimh');
			var l = $("img", this).each(function(i){
				images+= ((i==0) ? '' : ',') + '{';
				if(i==0){
					if(!dimensions.height) dimensions.height = $(this).height();
					if(!dimensions.width) dimensions.width = $(this).width();
				};
				var a = $(this).parent();
				images+='"image":"'+this.src+'"';
				images+=',"url":"'+a.attr('href')+'"';
				if(a.attr('target') != "")
					images+=',"target":"'+a.attr('target')+'"';

				images+='}';
			}).length;
			$p.attr("items", l);
			images+=']}';
			$this.height(dimensions.height);
			$this.width(dimensions.width);
			$this.css("overflow", "hidden");
			if(!$this.attr('id')) {
				getId('slideshow', function(id){
					$this.attr('id', id);
				});
			};
			t.set($this.attr('id'), images);
			var attributes = {
				id: $this.attr('id'),
				name: $this.attr('id')
			};
			var flashvars = {
				isLoaded:"slideshowFlashloaded",
				id:$this.attr('id'),
				delayTime:"0",
				intervalTime: "3000",
				autoStart: ($p.attr("autostart") != "true") ? "true" : "false"
			};
			var params = {
				wmode:"transparent",
				scalemode:"noscale"
			};
			swfobject.embedSWF("fileadmin/swf/slideshow.swf", $this.attr('id'), dimensions.width, dimensions.height, "9.0.0", "expressInstall.swf", flashvars, params, attributes);
		});
	};
})(jQuery);
/*!
jquery.event.drag.js ~ v1.5 ~ Copyright (c) 2008, Three Dub Media (http://threedubmedia.com)
Liscensed under the MIT License ~ http://threedubmedia.googlecode.com/files/MIT-LICENSE.txt
*/
(function($){ // secure $ jQuery alias
/*******************************************************************************************/
// Created: 2008-06-04 | Updated: 2009-03-24
/*******************************************************************************************/
// Events: drag, dragstart, dragend
/*******************************************************************************************/

// jquery method
$.fn.drag = function( fn1, fn2, fn3 ){
	if ( fn2 ) this.bind('dragstart', fn1 ); // 2+ args
	if ( fn3 ) this.bind('dragend', fn3 ); // 3 args
	return !fn1 ? this.trigger('drag') // 0 args
		: this.bind('drag', fn2 ? fn2 : fn1 ); // 1+ args
	};

// local refs
var $event = $.event, $special = $event.special,

// special event configuration
drag = $special.drag = {
	not: ':input', // don't begin to drag on event.targets that match this selector
	distance: 0, // distance dragged before dragstart
	which: 1, // mouse button pressed to start drag sequence
	dragging: false, // hold the active target element
	setup: function( data ){
		data = $.extend({
			distance: drag.distance,
			which: drag.which,
			not: drag.not
			}, data || {});
		data.distance = squared( data.distance ); //  x² + y² = distance²
		$event.add( this, "mousedown", handler, data );
		if ( this.attachEvent ) this.attachEvent("ondragstart", dontStart ); // prevent image dragging in IE...
		},
	teardown: function(){
		$event.remove( this, "mousedown", handler );
		if ( this === drag.dragging ) drag.dragging = drag.proxy = false; // deactivate element
		selectable( this, true ); // enable text selection
		if ( this.detachEvent ) this.detachEvent("ondragstart", dontStart ); // prevent image dragging in IE...
		}
	};

// prevent normal event binding...
$special.dragstart = $special.dragend = { setup:function(){}, teardown:function(){} };

// handle drag-releatd DOM events
function handler ( event ){
	var elem = this, returned, data = event.data || {};
	// mousemove or mouseup
	if ( data.elem ){
		// update event properties...
		elem = event.dragTarget = data.elem; // drag source element
		event.dragProxy = drag.proxy || elem; // proxy element or source
		event.cursorOffsetX = data.pageX - data.left; // mousedown offset
		event.cursorOffsetY = data.pageY - data.top; // mousedown offset
		event.offsetX = event.pageX - event.cursorOffsetX; // element offset
		event.offsetY = event.pageY - event.cursorOffsetY; // element offset
		}
	// mousedown, check some initial props to avoid the switch statement
	else if ( drag.dragging || ( data.which>0 && event.which!=data.which ) ||
		$( event.target ).is( data.not ) ) return;
	// handle various events
	switch ( event.type ){
		// mousedown, left click, event.target is not restricted, init dragging
		case 'mousedown':
			$.extend( data, $( elem ).offset(), {
				elem: elem, target: event.target,
				pageX: event.pageX, pageY: event.pageY
				}); // store some initial attributes
			$event.add( document, "mousemove mouseup", handler, data );
			selectable( elem, false ); // disable text selection
			drag.dragging = null; // pending state
			return false; // prevents text selection in safari
		// mousemove, check distance, start dragging
		case !drag.dragging && 'mousemove':
			if ( squared( event.pageX-data.pageX )
				+ squared( event.pageY-data.pageY ) //  x² + y² = distance²
				< data.distance ) break; // distance tolerance not reached
			event.target = data.target; // force target from "mousedown" event (fix distance issue)
			returned = hijack( event, "dragstart", elem ); // trigger "dragstart", return proxy element
			if ( returned !== false ){ // "dragstart" not rejected
				drag.dragging = elem; // activate element
				drag.proxy = event.dragProxy = $( returned || elem )[0]; // set proxy
				}
		// mousemove, dragging
		case 'mousemove':
			if ( drag.dragging ){
				returned = hijack( event, "drag", elem ); // trigger "drag"
				if ( $special.drop ){ // manage drop events
					$special.drop.allowed = ( returned !== false ); // prevent drop
					$special.drop.handler( event ); // "dropstart", "dropend"
					}
				if ( returned !== false ) break; // "drag" not rejected, stop
				event.type = "mouseup"; // helps "drop" handler behave
				}
		// mouseup, stop dragging
		case 'mouseup':
			$event.remove( document, "mousemove mouseup", handler ); // remove page events
			if ( drag.dragging ){
				if ( $special.drop ) $special.drop.handler( event ); // "drop"
				hijack( event, "dragend", elem ); // trigger "dragend"
				}
			selectable( elem, true ); // enable text selection
			drag.dragging = drag.proxy = data.elem = false; // deactivate element
			break;
		}
	return true;
	};

// set event type to custom value, and handle it
function hijack ( event, type, elem ){
	event.type = type; // force the event type
	var result = $.event.handle.call( elem, event );
	return result===false ? false : result || event.result;
	};

// return the value squared
function squared ( value ){ return Math.pow( value, 2 ); };

// suppress default dragstart IE events...
function dontStart(){ return ( drag.dragging === false ); };

// toggles text selection attributes
function selectable ( elem, bool ){
	if ( !elem ) return; // maybe element was removed ?
	elem.unselectable = bool ? "off" : "on"; // IE
	elem.onselectstart = function(){ return bool; }; // IE
	//if ( document.selection && document.selection.empty ) document.selection.empty(); // IE
	if ( elem.style ) elem.style.MozUserSelect = bool ? "" : "none"; // FF
	};

/*******************************************************************************************/
})( jQuery ); // confine scope

/* ------------------------------------------------------------------------
	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;
			};
	    });

		var localizeDefault = {
			close: "Close",
			next: "next",
			previous: "previous",
			expand: "Expand",
			expandTitle: "Expand the image"
		};
 
	
		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 */
			localize: localizeDefault,
			callback: function(){}
		}, settings);
		
		// Fallback to a supported theme for IE6
		if(jQuery.browser.msie && jQuery.browser.version == '6.0'){
			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{
				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>';
				}
				// 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>';
			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="'+settings.localize.expandTitle+'">'+settings.localize.expand+'</a><div class="pp_loaderIcon"></div><div class="pp_hoverContainer"><a class="pp_next" href="#">'+settings.localize.next+'</a><a class="pp_previous" href="#">'+settings.localize.previous+'</a></div><div id="pp_full_res">'+ pp_typeMarkup +'</div><div class="pp_details clearfix"><p class="pp_description"></p><div class="pp_nav"><a href="#" class="pp_arrow_previous">'+settings.localize.previous+'</a><p class="currentTextHolder">0'+settings.counter_separator_label+'0</p><a href="#" class="pp_arrow_next">'+settings.localize.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><a class="pp_close" href="#"><span>'+settings.localize.close+'</span></a></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);

/**
 * Equal Heights Plugin
 * Equalize the heights of elements. Great for columns or any elements
 * that need to be the same size (floats, etc).
 * 
 * Version 1.0
 * Updated 12/10/2008
 *
 * Copyright (c) 2008 Rob Glazebrook (cssnewbie.com) 
 *
 * Usage: $(object).equalHeights([minHeight], [maxHeight]);
 * 
 * Example 1: $(".cols").equalHeights(); Sets all columns to the same height.
 * Example 2: $(".cols").equalHeights(400); Sets all cols to at least 400px tall.
 * Example 3: $(".cols").equalHeights(100,300); Cols are at least 100 but no more
 * than 300 pixels tall. Elements with too much content will gain a scrollbar.
 * 
 */

(function($) {
	$.fn.equalHeights = function(minHeight, maxHeight) {
		tallest = (minHeight) ? minHeight : 0;
		this.each(function() {
			if($(this).height() > tallest) {
				tallest = $(this).height();
			}
		});
		if((maxHeight) && tallest > maxHeight) tallest = maxHeight;
		return this.each(function() {
			$(this).height(tallest).css("overflow","auto");
		});
	}
	$.fn.equalOffsetTop = function() {
		tallest = 0;
		heightCorr = 0;
		difference = 0;
		this.each(function() {
			if($(this).offset().top > tallest) {
				tallest = $(this).offset().top;
			}
		});
		return this.each(function() {
			var thisOffset = $(this).offset();			
			$(this).offset({top: tallest, left: thisOffset.left });
			$(this).parent().css({height: $(this).parent().height() + tallest - thisOffset.top });
		});
	}
})(jQuery);