if(typeof __ === 'undefined') var __ = new environment;

hs.registerOverlay({
	html: '<a class="closebutton" onclick="return hs.close(this)" href="javascript://closePopup();" title="Close"></a>',
	position: 'top right',
	fade: 2, // fading the semi-transparent overlay looks bad in IE
	useOnHtml: true
});
hs.graphicsDir = '/edit/js/highslide/graphics/';
hs.outlineType = 'rounded-white';
hs.showCredits = false;
hs.align = 'center';
hs.preserveContent = false;
hs.width = 420;
hs.useControls = false;
hs.anchor = 'left';
hs.dimmingOpacity = 0.50;

$(document).ready(function(){
	// grayscale for appropriate images
	var elmsPhotoNavigation = $(".mainphotos.multi .navigation li");
	__.navGrayscaler = new __.classes.navigationGrayscaler({elmsItems: elmsPhotoNavigation});
	
	// topnavigation dropdowns
	__.topnavigationDropdownhandler = new __.classes.suckerfish({"menuID":"topnavigation", "wrapperClass":"menu", menuPadding: 0});
	__.topnavigationDropdownhandler.sizeAndCenter2();

	// image switcher
	__.imageSwitcher = new __.classes.imageSwitcher({
		elmsListItems: $(".mainphotos.multi .navigation li, .photos.navigation .photoitem")
		,elmImage: $(".mainphotos .mainimage img")
		,elmKeepDimensions: $(".mainphotos .mainimage")
		,attrKeepWidth: "data-fullwidth"
		,attrKeepHeight: "data-fullheight"
		,dimKeepDimensionsAddedHeight: 2,
		onpreselect: function(elmThis){ if(!$.browser.msie) __.navGrayscaler.colorify(elmThis); elmThis.addClass("current"); },
		ondeselect: function(elmThis){ if(!$.browser.msie) __.navGrayscaler.grayify(elmThis); },
		listItemUnselectedState:{fontSize:"12px"}
		,listItemSelectedState:{fontSize:"16px"}
//		,attrImageURL:"data-image-url"
		,classSelected: "current"
	});
	
	// pager
	__.pager = new __.classes.hashPagerStatic({
		elmsPages: $(".pagecontentpieces .pagecontentpiece")
		,elmsNavigation: $(".pageswitcher li")
		,duration: 0
		,onpreswitch: function(args){
			if(args.idNext != this.boot.selectorTabBeforePhotos && __.imageSwitcher.elmLICurrent.closest(this.boot.selectorTabBeforePhotos).length > 0){
				__.imageSwitcher.switchToItem(__.imageSwitcher.elmsListItems.first());
			}
		},
		boot: {
			selectorTabBeforePhotos: "#content_before_photos" 
		}
	});

	//--banner
	var elmsBanners = $("#bannerbox .banners .banner");
	if(elmsBanners.length > 0){
		__.bannerPager = new __.classes.pagerSlidingHash({elmsPages:elmsBanners, itemSelector:".banner", elmNavigation: $("#bannerbox .navigation"), elmPreviousButton:$("#bannerbox .navigation .previous"), elmNextButton:$("#bannerbox .navigation .next"), elmsItemNavigation: $("#bannerbox .navigation li")
		});
		__.bannerPagerInterval = setInterval(function(){__.bannerPager.switchPagesToNext();}, 5000);
	}
});


/* ********* 
©suckerfish
********* */
__.classes.suckerfish = function (arguments){
		this.menuID = (arguments.menuID)? arguments.menuID : "topnavigation";
		this.wrapperClass = (arguments.wrapperClass)? arguments.wrapperClass : "menu_li";
		this.toplevelClass = (arguments.toplevelClass)? arguments.toplevelClass : "toplevel";
		this.submenuClass = (arguments.submenuClass)? arguments.submenuClass : "submenu";
		this.doSizeAndCenter = (arguments.doSizeAndCenter)? arguments.doSizeAndCenter : 0;
		this.menuPadding = (arguments.menuPadding)? arguments.menuPadding : 0;
		this.submenuOffset = (arguments.submenuOffset)? arguments.submenuOffset : 0;
		this.addedWidth = (arguments.addedWidth)? arguments.addedWidth : 0;
		this.classSelected = arguments.classSelected || "selected";
		
		this.elmMenu = document.getElementById(this.menuID);
		this.elmsWrapper = __.getElementsByClassName({"className": this.wrapperClass, "element": this.elmMenu});
		this.elmsMenuAssociations = this.getAllMenuPieces();
		this.elmCurrentlySelected = 0;
		
		this.timeout;
		
		this.attachListeners();
	}
	__.classes.suckerfish.prototype.getAllMenuPieces = function(){
		var fncReturnArray = new Array();
		for(var i=0; i < this.elmsWrapper.length; ++i){
			var forArray = new Array;
			var forElmToplevel = __.getElementsByClassName({"className": this.toplevelClass, "element": this.elmsWrapper[i]});
			var forElmSubmenu = __.getElementsByClassName({"className": this.submenuClass, "element": this.elmsWrapper[i]});
			fncReturnArray.push({"elmItemWrapper":this.elmsWrapper[i], "elmToplevel":forElmToplevel[0], "elmSubmenu": (forElmSubmenu[0])?forElmSubmenu[0]:null})
		}
		return fncReturnArray;
	}
	__.classes.suckerfish.prototype.attachListeners = function(){
		var fncThis = this;
		for(var i=0;i < this.elmsMenuAssociations.length; ++i){
			var forElmMenuItemArray = this.elmsMenuAssociations[i];
			if(this.elmsMenuAssociations[i]["elmSubmenu"]){
				var callbackFull = function(forElmMenuItemArray, fncThis) {
					return function(){
						clearTimeout(fncThis.timeout);
						if(!(this.elmCurrentlySelected === forElmMenuItemArray["elmItemWrapper"]))
							fncThis.dropdownOpen(forElmMenuItemArray["elmItemWrapper"]);
					}
				}(forElmMenuItemArray, fncThis);
				var callbackMouseout = function(fncThis){
					return function(){
						fncThis.timeout = setTimeout(function(fncThis){ return function(){fncThis.dropdownCloseCurrent(); };}(fncThis) ,750);
					};
	
				}(fncThis);
				__.addListener(forElmMenuItemArray["elmItemWrapper"], "mouseover", callbackFull, false);
				__.addListener(forElmMenuItemArray["elmToplevel"], "mouseover", callbackFull, false);
				__.addListener(forElmMenuItemArray["elmSubmenu"], "mouseover", callbackFull, false);
				__.addListener(forElmMenuItemArray["elmItemWrapper"], "click", callbackFull, false);
				__.addListener(forElmMenuItemArray["elmItemWrapper"], "touchstart", callbackFull, false);
				__.addListener(forElmMenuItemArray["elmItemWrapper"], "mouseout", callbackMouseout, false);
			}
			// empty menu items
			else{
				var callbackEmpty = function(fncThis){
					return function(){
						fncThis.dropdownCloseCurrent();
					}
				}(fncThis)
				__.addListener(forElmMenuItemArray["elmItemWrapper"], "mouseover", callbackEmpty, false);
				__.addListener(forElmMenuItemArray["elmItemWrapper"], "click", callbackEmpty, false);
				__.addListener(forElmMenuItemArray["elmItemWrapper"], "touchstart", callbackEmpty, false);
			}
		}
	}
	__.classes.suckerfish.prototype.dropdownOpen = function(argElement){
		if(this.elmCurrentlySelected && this.elmCurrentlySelected !== argElement)
			this.dropdownCloseCurrent();
		if(argElement){
			__.addClass(argElement, this.classSelected);
			this.elmCurrentlySelected = argElement;
		}
	}
	__.classes.suckerfish.prototype.dropdownCloseCurrent = function(){
		if(this.elmCurrentlySelected){
			__.removeClass(this.elmCurrentlySelected, this.classSelected);
			this.elmCurrentlySelected = 0;
			return 1;
		}
		return 0;
	}
	__.classes.suckerfish.prototype.dropdownCloseAll = function(){
		for(j=0;j < argElmsMenuArray.length; ++j){
			__.removeClass(argElmsMenuArray[j]["elmItemWrapper"], this.classSelected);
		}
	}
	__.classes.suckerfish.prototype.sizeAndCenter1 = function(){	
		for(var i=0; i < this.elmsMenuAssociations.length; ++i){
			var forElmMenuItemArray = this.elmsMenuAssociations[i];
			if(forElmMenuItemArray["elmSubmenu"]){
				if(forElmMenuItemArray["elmSubmenu"].offsetWidth < forElmMenuItemArray["elmToplevel"].offsetWidth + this.addedWidth && !__.isIE6()){
					forElmMenuItemArray["elmSubmenu"].style.width = (forElmMenuItemArray["elmToplevel"].offsetWidth + this.addedWidth/*  - this.submenuPadding */) + "px";
				}
				if(forElmMenuItemArray["elmSubmenu"].offsetWidth > forElmMenuItemArray["elmToplevel"].offsetWidth){
					ifOffset = ((forElmMenuItemArray["elmToplevel"].offsetWidth - (forElmMenuItemArray["elmSubmenu"].offsetWidth/*  + this.ubmenuPadding */)) / 2);
					if(__.isIE6()) ifOffset += this.submenuOffset;
					forElmMenuItemArray["elmSubmenu"].style.left = ifOffset+ "px";
				}
			}
		}
	}
	__.classes.suckerfish.prototype.sizeAndCenter2 = function(){	
		for(var i=0; i < this.elmsMenuAssociations.length; ++i){
			var forElmMenuItemArray = this.elmsMenuAssociations[i];
			if(forElmMenuItemArray["elmSubmenu"]){	
				forElmMenuItemArray["elmSubmenu"].style.visibility = "hidden";
				forElmMenuItemArray["elmSubmenu"].style.display = "block";
				if(forElmMenuItemArray["elmSubmenu"].offsetWidth < forElmMenuItemArray["elmToplevel"].offsetWidth + this.addedWidth && !__.isIE6()){
					forElmMenuItemArray["elmSubmenu"].style.width = (forElmMenuItemArray["elmToplevel"].offsetWidth + this.addedWidth + this.menuPadding*2) + "px";
				}
				if(forElmMenuItemArray["elmSubmenu"].offsetWidth > forElmMenuItemArray["elmToplevel"].offsetWidth){
					ifOffset = ((forElmMenuItemArray["elmToplevel"].offsetWidth - forElmMenuItemArray["elmSubmenu"].offsetWidth ) / 2) + this.menuPadding;
					if(__.isIE6()) ifOffset += this.submenuOffset;
					forElmMenuItemArray["elmSubmenu"].style.left = ifOffset+ "px";
				}
				forElmMenuItemArray["elmSubmenu"].style.display = "";
				forElmMenuItemArray["elmSubmenu"].style.visibility = "";
			}
		}
	}


/* ********* 
©navigationGrayscaler
depends on: jquery, grayscale.js
********* */
__.classes.navigationGrayscaler = function(arguments){
		// not needed in ie
		if($.browser.msie) return false;
		this.elmsItems = arguments.elmsItems || false; if(this.elmsItems.length < 1) return false;
		this.classCurrent = arguments.classCurrent || "current";
		this.eventCurrentChange = arguments.eventCurrentChange || "changeCurrent";
		this.classGrayed = arguments.classGrayed || "grayed";
		this.duration = arguments.duration || 500;
		
		this.init(this.elmsItems)
	}
	__.classes.navigationGrayscaler.prototype.init = function(argElms){
		var fncThis = this;
		if(argElms.length > 0){
			argElms.each(function(){
				var elmThis = $(this);
				if(elmThis.css("position") == "static" || elmThis.css("position") == "")
					elmThis.css("position", "relative");
				var elmClone = elmThis.find("img").clone().addClass(fncThis.classGrayed).attr("alt","").css({"position":"absolute", "top":"0", "left":"0", "z-index":"10"});
				
				elmThis.append(elmClone);
				fncLoaded = function(){
					grayscale.prepare(elmClone);
					grayscale(elmClone);
					if(elmThis.hasClass(fncThis.classCurrent)){
						fncThis.colorify(elmThis, 0);
						elmClone.hide(); // for Safari only, colorify doesn't seem to take
					}
				}
				
				if(elmClone.height() > 0)
					fncLoaded();
				else
					elmClone.load(fncLoaded);
			});
			
			argElms.bind("mouseenter focus", function(){
				var elmThis = $(this);
				if(!elmThis.hasClass(fncThis.classCurrent))
					fncThis.colorify(elmThis, 0);
			});
			argElms.bind("mouseleave blur", function(){
				var elmThis = $(this);
				if(!elmThis.hasClass(fncThis.classCurrent))
					fncThis.grayify(elmThis, 0);
			});
		}
	}
	__.classes.navigationGrayscaler.prototype.grayify = function(argElms, argDuration){
		var fncElms = argElms.not("."+this.classCurrent);
		if(fncElms.length > 0){
			var fncDuration = (argDuration === undefined) ? this.duration : argDuration;
			var fncElmsImages = fncElms.find("img."+this.classGrayed);
			if(fncDuration == 0)
				fncElmsImages.show(fncDuration);
			else
				fncElmsImages.fadeIn(fncDuration);
		}
	}
	__.classes.navigationGrayscaler.prototype.colorify = function(argElms, argDuration){
			var fncDuration = (argDuration === undefined) ? this.duration : argDuration;
			var fncElmsImages = argElms.find("img."+this.classGrayed);
			if(fncDuration == 0)
				fncElmsImages.hide(fncDuration);
			else
				fncElmsImages.fadeOut(fncDuration);
	}
	

/*-------------
©imageswitcher
------------*/
__.classes.imageSwitcher = function(arguments){
		//--optional arguments
		this.attrImageURL = (arguments.attrImageURL)?arguments.attrImageURL:"href";
		this.attrKeepWidth = arguments.attrKeepWidth || null;
		this.attrKeepHeight = arguments.attrKeepHeight || null;
		this.boot = arguments.boot || null;
		this.classCurrent = (typeof arguments.classCurrent != "undefined")? arguments.classCurrent: "current";
		this.dimKeepDimensionsAddedWidth = arguments.dimKeepDimensionsAddedWidth || 0;
		this.dimKeepDimensionsAddedHeight = arguments.dimKeepDimensionsAddedHeight || 0;
		this.doAttachEvents = (typeof arguments.doAttachEvents != "undefined")? arguments.doAttachEvents: true;
		this.duration = (arguments.duration)? arguments.duration: 500;
//		this.elmImage = (arguments.elmImage && arguments.elmImage.length > 0) ? arguments.elmImage : null;
		this.elmKeepDimensions = arguments.elmKeepDimensions || false;
		this.elmListImages = arguments.elmListImages || null;
		this.htmlNewImage = arguments.htmlNewImage || "<img alt=\"\" />";
		this.listItemSelectedState = arguments.listItemSelectedState || null;
		this.listItemUnselectedState = arguments.listItemUnselectedState || null;
		this.ondeselect = arguments.ondeselect || null;
		this.oninit = arguments.oninit || null;
		this.onpredeselect = arguments.onpredeselect || null;
		this.onpreimageanimation = arguments.onpreimageanimation || null;
		this.onpreselect = arguments.onpreselect || null;
		this.onpostimageanimation = arguments.onpostimageanimation || null;
		this.onpreimageanimationfadeout = arguments.onpreimageanimationfadeout || null;
		this.onpreimageanimationkeepheight = arguments.onpreimageanimationkeepheight || null;
		this.onpreimageanimationfadein = arguments.onpreimageanimationfadein || null;
		this.onpreimageanimationpostkeepheight = arguments.onpreimageanimationpostkeepheight || null;
		this.onselect = arguments.onselect || null;
		this.onsetimage = arguments.onsetimage || null;
		this.onsetlistitems = arguments.onsetlistitems || null;
		this.selectorListItemContainer = (typeof arguments.selectorListItemContainer != "undefined")?arguments.selectorListItemContainer:"li";
		this.selectorElmImageUrl = arguments.selectorElmImageUrl || "a";
		this.typeAnimation = arguments.typeAnimation || "fadeoutfadein";
		
		//--derived members
		this.inprogress=false;
		this.queue = new __.classes.animationQueue({name: "image", autoDequeue: false});
		if(arguments.elmImage)
			this.setImage(arguments.elmImage);
		else
			this.elmImage = null;
		if(arguments.elmsListItems)
			this.setListItems(arguments.elmsListItems);
		else
			this.elmsListItems = null;
		
		if(this.oninit)
			this.oninit.call(this);
	}
	__.classes.imageSwitcher.prototype.findElmLIForURL = function(argURL){
		var selectorAttribute = "["+this.attrImageURL+"='"+$.trim(argURL)+"']";
		if(this.selectorElmImageUrl == "this"){
			return this.elmsListItems.filter(selectorAttribute);
		}else{
			return this.elmsListItems.has(this.selectorElmImageUrl+selectorAttribute);
		}
	}
	__.classes.imageSwitcher.prototype.setImage = function(argElement){
		this.elmImage = argElement;
		this.urlCurrent = this.elmImage.attr("src");
		if(this.onsetimage)
			this.onsetimage.call(this);
	}
	__.classes.imageSwitcher.prototype.setListItems = function(argElements){
		this.elmsListItems = argElements;
		if(this.elmsListItems.length > 0){
			this.elmLICurrent = this.elmsListItems.filter(this.classCurrent);
			if(this.elmLICurrent.length < 1){
				this.elmLICurrent = this.findElmLIForURL(this.urlCurrent);
				this.elmLICurrent.addClass(this.classCurrent);
			}
			if(this.doAttachEvents)
				this.attachEvents();
			if(this.onsetlistitems)
				this.onsetlistitems.call(this);
		}
	}
	__.classes.imageSwitcher.prototype.attachEvents = function(){
		if(this.elmsListItems.length == 0) return false;
		var fncThis = this;
		fncThis.elmsListItems.children("a").bind("click", function(event){
			if(event.preventDefault) event.preventDefault();

			var thisItem = $(this).closest(fncThis.selectorListItemContainer);
			fncThis.switchToItem(thisItem);
			
			return false;
		});
	}
	__.classes.imageSwitcher.prototype.switchToNext = function(){
		var currentItem = this.elmsListItems.filter("."+this.classCurrent);
		this.switchToItem(currentItem.next());
	}
	__.classes.imageSwitcher.prototype.switchToPrevious = function(){
		var currentItem = this.elmsListItems.filter("."+this.classCurrent);
		this.switchToItem(currentItem.prev());
	}
	__.classes.imageSwitcher.prototype.switchToItem = function(elmNewItem){
		var currentItem = this.elmsListItems.filter("."+this.classCurrent);
//->return
		if(elmNewItem[0] == currentItem[0] || elmNewItem.length < 1) return false;		
		if(this.selectorElmImageUrl == "this"){
			var newImageURL = elmNewItem.attr(this.attrImageURL);
		}else{
			var elmA = elmNewItem.find(this.selectorElmImageUrl);
			var newImageURL = elmA.attr(this.attrImageURL);
		}
		if(!newImageURL) newImageURL = elmNewItem.attr(this.attrImageURL);
//->return
		if(!newImageURL) return false;
		this.switche(newImageURL);
	}
	__.classes.imageSwitcher.prototype.switche = function(newImageURL, arguments){
		var fncThis = this;

//-> return
		if(fncThis.inprogress==true) return false;		
		
		var oldLI = fncThis.elmsListItems.filter("."+fncThis.classCurrent);
		var newLI = this.findElmLIForURL($.trim(newImageURL));
		var newA = newLI.find("a");

		fncThis.inprogress = true;

		//--run pre-animate callback
		if(fncThis.onpredeselect)
			fncThis.onpredeselect.call(fncthis, oldLI);
		if(fncThis.onpreselect)
			fncThis.onpreselect.call(fncThis, newLI);
		
		var elmTempImage = $("<img class=\"tempimage\" src='"+newImageURL+"' />").css({"position":"absolute", "left":"-9000px", "top":"-9000px"}).appendTo("body");
		
		if(fncThis.elmKeepDimensions){
			fncThis.elmKeepDimensions.css({"width": fncThis.elmImage.width() + fncThis.dimKeepDimensionsAddedWidth, "height": fncThis.elmImage.height() + fncThis.dimKeepDimensionsAddedHeight});
			var widthNew = false, heightNew = false;
			if(fncThis.attrKeepWidth)
				widthNew = newLI.attr(fncThis.attrKeepWidth) || false;
			if(fncThis.attrKeepHeight)
				heightNew = newLI.attr(fncThis.attrKeepHeight) || false;
			
			var callbackGetNewWidthHeight = function(){
				if(!(widthNew || heightNew)){
					widthNew = widthNew || elmTempImage.width();
					heightNew = heightNew || elmTempImage.height();
				}
				if(widthNew && heightNew){
					widthNew += fncThis.dimKeepDimensionsAddedWidth;
					heightNew += fncThis.dimKeepDimensionsAddedHeight;
					fncThis.queue.dequeue("image");
				}else{
					elmTempImage.load(callbackGetNewWidthHeight);
				}
			}
			
			if(!(widthNew || heightNew)){
				fncThis.queue.queue({name: "image", callback: callbackGetNewWidthHeight});
			}
		}
		
		var fncLocalVariables = {newLI: newLI, oldLI: oldLI};

		//--animate navigation
		fncThis.queue.queue({name: "navigation", callback: function(){
			oldLI.children("a").animate(fncThis.listItemUnselectedState, fncThis.duration, function(){fncThis.queue.dequeue("navigation")});
		}});
		fncThis.queue.queue({name: "navigation", callback: function(){
			oldLI.children("a").closest(fncThis.selectorListItemContainer).removeClass(fncThis.classCurrent);
			if(fncThis.ondeselect)
				fncThis.ondeselect.call(fncThis, oldLI);
			fncThis.queue.dequeue("navigation")
		}});

		fncThis.queue.dequeue({name: "navigation"});
		
		//--animate image
		newLI.addClass(fncThis.classCurrent);
		if(fncThis.onpreimageanimation)
			fncThis.queue.queue({name: "image", callback: function(){
				fncThis.onpreimageanimation.call(fncThis, fncLocalVariables);
			}});
		fncThis.queue.queue({name: "image", callback: function(){
			if(newA.length > 0)
				newA.animate(fncThis.listItemSelectedState, fncThis.duration, function(){fncThis.queue.dequeue("image");});
			else
				fncThis.queue.dequeue("image");
		}});
		if(fncThis.typeAnimation == "dissolve"){
			fncThis.queue.queue({name: "image", callback: function(){
				fncThis.elmOldImage = fncThis.elmImage;
				fncThis.elmImage = $(fncThis.htmlNewImage);
				fncThis.elmImage.attr("src", newImageURL);
				fncThis.elmListImages.prepend(fncThis.elmImage);
				if(fncThis.elmImage.width() > 0){
					fncThis.queue.dequeue("image");
				}else{
					fncThis.elmImage.bind("load", function(){
						fncThis.queue.dequeue("image");
					});
				}
			}});
		}
		if(fncThis.onpreimageanimationfadeout)
			fncThis.queue.queue({name: "image", callback: function(){
				fncThis.onpreimageanimationfadeout.call(fncThis, fncLocalVariables);
			}});
		fncThis.queue.queue({name: "image", callback: function(){
			if(fncThis.typeAnimation == "dissolve"){
				fncThis.elmOldImage.fadeOut(fncThis.duration, function(){fncThis.queue.dequeue("image");});
			}else{
				fncThis.elmImage.fadeOut(fncThis.duration, function(){fncThis.queue.dequeue("image");});
			}
		}});
		if(fncThis.onpreimageanimationkeepheight)
			fncThis.queue.queue({name: "image", callback: function(){
				fncThis.onpreimageanimationkeepheight.call(fncThis, fncLocalVariables);
			}});
		fncThis.queue.queue({name: "image", callback: function(){
			if(fncThis.elmKeepDimensions){
				fncThis.elmKeepDimensions.animate({"height":heightNew, "width":widthNew}, function(){fncThis.queue.dequeue("image");});
			}else
				fncThis.queue.dequeue();
		}});
		if(fncThis.onpreimageanimationfadein)
			fncThis.queue.queue({name: "image", callback: function(){
				fncThis.onpreimageanimationfadein.call(fncThis, fncLocalVariables);
			}});
		fncThis.queue.queue({name: "image", callback: function(){
			if(fncThis.typeAnimation == "dissolve"){
				fncThis.elmOldImage.fadeOut(fncThis.duration).remove();
			}else{
				fncThis.elmImage.attr("src", newImageURL).fadeIn(fncThis.duration);
			}
			elmTempImage.remove();

			if(fncThis.onselect)
				fncThis.onselect.call(fncThis, newLI);
			if(fncThis.elmKeepDimensions){
				fncThis.elmKeepDimensions.animate({"height":heightNew, "width":widthNew}, function(){fncThis.queue.dequeue("image");});
			}else
				fncThis.queue.dequeue("image");
		}});
		if(fncThis.onpreimageanimationpostkeepheight)
			fncThis.queue.queue({name: "image", callback: function(){
				fncThis.onpreimageanimationpostkeepheight.call(fncThis, fncLocalVariables);
			}});
		fncThis.queue.queue({name: "image", callback: function(){
			if(fncThis.elmKeepDimensions)
				fncThis.elmKeepDimensions.css({"height":"auto", "width":"auto"});
			fncThis.queue.dequeue("image");
		}});
		fncThis.queue.queue({name: "image", callback: function(){
			fncThis.urlCurrent = fncThis.elmImage.attr("src");
			if(newLI && newLI.length > 0)
				fncThis.elmLICurrent = newLI;
			else
				fncThis.elmLICurrent = fncThis.findElmLIForURL(fncThis.urlCurrent);
			if(fncThis.onpostimageanimation)
				fncThis.onpostimageanimation.call(fncThis, fncLocalVariables);
			fncThis.inprogress = false;
		}});
		
		fncThis.queue.dequeue({name: "image"});
	}
	__.classes.imageSwitcher.prototype.updateElements = function(arguments){
		this.elmImage = (arguments.elmImage)?arguments.elmImage:this.elmImage;
		if(arguments.elmsListItems){
			this.elmsListItems = arguments.elmsListItems;
			if(this.doAttachEvents)
				this.attachEvents();
		}
	}

/*-------------
©animationQueue
------------*/
__.classes.animationQueue = function(arguments){
		if(typeof arguments == "undefined") arguments = {};
		//--optional variables
		this.name = arguments.name || "tmlib";
		this.autoDequeue = arguments.autoDequeue || false;
		
		//--derived variables
		this.objQueue = $({});
	}
	__.classes.animationQueue.prototype.queue = function(arguments){
		var fncThis = this;
		var fncName = arguments.name || this.name;
		var fncCallback = arguments.callback || arguments; //-arguments is (assumed) the callback if not set explicitely
		var fncAutoDequeue = (typeof arguments.autoDequeue != "undefined")? arguments.autoDequeue: fncThis.autoDequeue;
		var fncQueueCallback = (fncAutoDequeue)
			?function(){
					var fncArguments = arguments;
					var internalThis = this;
					fncCallback.apply(internalThis, fncArguments);
					fncThis.dequeue();
				}
			:fncCallback
		;
		this.objQueue.queue(fncName, fncQueueCallback);
	}
	__.classes.animationQueue.prototype.dequeue = function(arguments){
		if(typeof arguments != "undefined")
			var fncName = arguments.name || arguments;
		else
			var fncName = this.name;
		this.objQueue.dequeue(fncName);
	}
	__.classes.animationQueue.prototype.unshift = function(arguments){
		if(typeof arguments != "undefined"){
			var fncCallback = arguments.callback || arguments;
			var fncName = arguments.name || this.name;
		}
		if(typeof fncCallback == "undefined" || !fncCallback) return false;
//->return
		var fncQueue = this.objQueue.queue(fncName);
		fncQueue.unshift(fncCallback);
	}
	__.classes.animationQueue.prototype.clearQueue = function(arguments){
		if(typeof arguments != "undefined")
			var fncName = arguments.name || arguments;
		else
			var fncName = this.name;
		this.objQueue.clearQueue(fncName);
	}


/*-------------
©pager
------------*/
__.classes.hashPagerStatic = function(arguments){
		this.boot = arguments.boot || {};
		this.elmsPages = arguments.elmsPages || false; if(!this.elmsPages || this.elmsPages.length < 1) return false;
		this.elmsNavigation = arguments.elmsNavigation || false;
			if(!this.elmsNavigation) return false;
			this.elmsNavigation = this.elmsNavigation.has("a[href^='#']");
		this.classCurrentNavigation = arguments.classCurrentNavigation || "current";
		this.classCurrentPage = arguments.classCurrentPage || "current";
		this.duration = (arguments.duration !== undefined) ? arguments.duration : 500;
		this.onpreswitch = arguments.onpreswitch || false;
		this.onpostswitch = arguments.onpostswitch || false;
		
		this.inProgress = true;
		
		// hide all, display first
		this.elmsPages.hide();
		if(window.location.hash){
			this.idCurrent = window.location.hash;
			this.elmsNavigation.has("a[href="+window.location.hash+"]").addClass(this.classCurrentNavigation);
		}else{
			var elmCurrentNavigation = this.elmsNavigation.filter("."+this.classCurrentNavigation);
			if(elmCurrentNavigation.length > 0){
				this.idCurrent = elmCurrentNavigation.find("a").attr("href");
			}else{
				this.idCurrent = this.elmsNavigation.first().addClass(this.classCurrentNavigation).find("a").attr("href");
			}
		}
		this.elmsPages.filter(__.lib.escapeHash(this.idCurrent)).show().addClass(this.classCurrentPage);
		
		// attach listeners
		this.attachListeners(this.elmsNavigation);
		
		this.inProgress = false;
	}
	__.classes.hashPagerStatic.prototype.attachListeners = function(argElements){
		var fncThis = this;
		argElements.bind("click", function(event){
			if(event.preventDefault)
				event.preventDefault();
			fncThis.switche($(this).find("a").attr("href"));
			
			return false;
		});
	}
	__.classes.hashPagerStatic.prototype.switche = function(argID){
		if(this.inProgress == true || argID == this.idCurrent){
			return false;
		}else{
			var fncThis = this;
			var localvars = {};
			localvars.idNext = argID;
			localvars.elmNextNavigation = this.elmsNavigation.has("a[href='"+argID+"']");
			localvars.elmNextPage = this.elmsPages.filter(__.lib.escapeHash(argID));
			localvars.elmCurrentNavigation = this.elmsNavigation.filter("."+this.classCurrentNavigation);
			localvars.elmCurrentPage = this.elmsPages.filter("."+this.classCurrentPage);

			fncThis.inProgress = true;

			if(this.onpreswitch)
				this.onpreswitch.call(this, localvars);

			localvars.elmNextNavigation.addClass(fncThis.classCurrentNavigation);
			localvars.elmCurrentPage.removeClass(fncThis.classCurrentPage).hide(this.duration, function(){
				localvars.elmCurrentNavigation.removeClass(fncThis.classCurrentNavigation);
				localvars.elmNextPage.show(fncThis.duration, function(){
					localvars.elmNextPage.addClass(fncThis.classCurrentPage);
					fncThis.idCurrent = localvars.idNext;
					fncThis.inProgress = false;
					if(fncThis.onpostswitch)
						fncThis.onpostswitch.call(fncThis, localvars);
				});
			});
		}
	}

/* --------
slides new "pages" into view while sliding old out
------- */
__.classes.pagerSlidingHash = function(arguments){
		var fncThis = this;
		this.elmsPages = arguments.elmsPages || null;
		this.elmNavigation = arguments.elmNavigation || null;
		this.elmPreviousButton = arguments.elmPreviousButton || null;
		this.elmNextButton = arguments.elmNextButton || null;
		this.elmsItemNavigation = arguments.elmsItemNavigation || null;
		this.itemSelector = (arguments.itemSelector !== undefined)? arguments.itemSelector: "item";
		this.classCurrentItem = (arguments.classCurrentItem !== undefined)? arguments.classCurrentItem: "selected";
		this.classPreviousItem = (arguments.classPreviousItem !== undefined)? arguments.classPreviousItem: "previous";
		this.classNextItem = (arguments.classNextItem !== undefined)? arguments.classNextItem: "next";
		this.classCurrentNavItem = arguments.classCurrentNavItem || "current";
		this.classDisabled = arguments.classDisabled || "disabled";
		this.classEnabled = arguments.classEnabled || "enabled";
		this.duration = (arguments.duration !== undefined)? arguments.duration: 500;
		this.contentWidth = (arguments.contentWidth !== undefined)? arguments.contentWidth: 960;
		this.contentLeft = arguments.contentLeft || 0;
		this.elmNavigationPointer = arguments.elmNavigationPointer || null;
		this.elmNavigationOrientation = arguments.elmNavigationOrientation || "horizontal";
		this.callbackPreSlide = arguments.callbackPreSlide || null;
		this.callbackPostSlide = arguments.callbackPostSlide || null;
		this.boot = arguments.boot || null;
		
		// set up current pages
		this.elmCurrent = this.elmsPages.filter("."+this.classCurrentItem);
		if(this.elmCurrent.length < 1){
			this.elmCurrent = this.elmsPages.first();
			this.elmCurrent.addClass(this.classCurrentItem).css({"display":"block"});
		}
		
		// show navigation
		this.elmNavigation.show();
		this.pageOffsetLeft = arguments.pageOffsetLeft || 0;
		this.pageOffsetRight = arguments.pageOffsetRight || 0;
		
		// set up non-current pages
		var elmsPrevious = this.elmsPages.filter("."+this.classCurrentItem).prevAll()
		elmsPrevious.addClass(this.classPreviousItem);
		var elmsNext = this.elmsPages.filter("."+this.classCurrentItem).nextAll()
		elmsNext.addClass(this.classNextItem);
		elmsPrevious.css({"left":0 - this.pageOffsetLeft - this.contentWidth, "display":"none"});
		elmsNext.css({"left":this.pageOffsetRight + this.contentWidth, "display":"none"});
		
		// set up relative navigation
		this.updateRelativeNavigation(0);
		
		this.inprogress = 0;
		
		this.attachEvents();
	}
	__.classes.pagerSlidingHash.prototype.attachEvents = function(){
		var fncThis = this;
		if(fncThis.elmPreviousButton){
			fncThis.elmPreviousButton.children("a").bind("click", function(){
				if(fncThis.inprogress == 0 && $(this).attr("href")){
					fncThis.inprogress = 1;
					if(!fncThis.switchPagesByID(fncThis.parsePath(fncThis.elmPreviousButton.children("a").attr("href"))))
						fncThis.inprogress = 0;
				}
				return false;
			});
		}
		if(fncThis.elmNextButton){
			fncThis.elmNextButton.children("a").bind("click", function(){
				if(fncThis.inprogress == 0 && $(this).attr("href")){
					fncThis.inprogress = 1;
					if(!fncThis.switchPagesByID(fncThis.parsePath(fncThis.elmNextButton.children("a").attr("href"))))
						fncThis.inprogress = 0;
				}
				return false;
			});
		}
		if(fncThis.elmsItemNavigation){
			fncThis.elmsItemNavigation.bind("click", function(){
				if(fncThis.inprogress == 0){
					fncThis.inprogress = 1;
					if(!fncThis.switchPagesByID(fncThis.parsePath($(this).children("a").attr("href"))))
						fncThis.inprogress = 0;
				}
				return false;
			});
		}
	}
	__.classes.pagerSlidingHash.prototype.switchPagesByID = function(id){
		var elmNewPage = this.elmsPages.filter("#"+id);
		return this.switchPages(elmNewPage);
	}
	__.classes.pagerSlidingHash.prototype.switchPagesToPrevious = function(){
		var elmPrevious = this.elmCurrent.previous();
		if(elmPrevious.length > 0)
			this.switchPages(elmPrevious);
		else
			this.switchPages(this.elmsPages.last());
	}
	__.classes.pagerSlidingHash.prototype.switchPagesToNext = function(){
		var elmNext = this.elmCurrent.next();
		if(elmNext.length > 0)
			this.switchPages(elmNext);
		else
			this.switchPages(this.elmsPages.first());
	}
	__.classes.pagerSlidingHash.prototype.switchPages = function(elmNewPage){
		if(elmNewPage[0] == this.elmCurrent[0]) return false;
		var fncThis = this;
		var callback = function(){
			fncThis.elmCurrent.removeClass(fncThis.classCurrentItem);
			elmNewPage.removeClass(fncThis.classNextItem).removeClass(fncThis.classPreviousItem).addClass(fncThis.classCurrentItem);
			fncThis.elmCurrent = elmNewPage;
			
			var elmsPagesLength = fncThis.elmsPages.length;
			var elmIndexCurrent = fncThis.getPageIndex(elmNewPage);
			// set all previous elements to previous
			for(var i = 0; i < elmIndexCurrent; ++i){
				$(fncThis.elmsPages[i]).removeClass(fncThis.classNextItem).addClass(fncThis.classPreviousItem).css({"display":"none"});
			}
			// set all next elements to next
			for(var i = elmIndexCurrent + 1; i < elmsPagesLength; ++i){
				$(fncThis.elmsPages[i]).addClass(fncThis.classNextItem).removeClass(fncThis.classPreviousItem).css({"display":"none"});
			}

			if(fncThis.callbackPostSlide)
				fncThis.callbackPostSlide.call(this);

			fncThis.updateRelativeNavigation();
			
			fncThis.inprogress = 0;
		}
		fncThis.inprogress = 1;
		// call preslide callback
		if(fncThis.callbackPreSlide)
			fncThis.callbackPreSlide.call(this, elmNewPage);
		
		// swap pieces
		if(elmNewPage.hasClass(fncThis.classNextItem)){
			// animate left
			fncThis.elmCurrent.css({"display":"block"}).animate({left: 0 - fncThis.pageOffsetLeft - fncThis.contentWidth}, fncThis.duration)
			elmNewPage.css({"display":"block", "left":this.pageOffsetRight + this.contentWidth}).animate({left: fncThis.contentLeft}, fncThis.duration+1, callback);
		}
		else{
			// animate right
			fncThis.elmCurrent.css("display","block").animate({left: this.pageOffsetRight + this.contentWidth}, fncThis.duration)
			elmNewPage.css({"display":"block", "left":0 - this.pageOffsetLeft - this.contentWidth}).animate({left: fncThis.contentLeft}, fncThis.duration, callback);
		}
		
		
		return true;
	}
	__.classes.pagerSlidingHash.prototype.parsePath = function(path){
		return path;
	}
	__.classes.pagerSlidingHash.prototype.updateRelativeNavigation = function(argDuration){
		fncDuration = (typeof argDuration !== 'undefined')? argDuration: this.duration;

		var previousURL = "#"+this.elmCurrent.prev(this.itemSelector).attr("id");
		var nextURL = "#"+this.elmCurrent.next(this.itemSelector).attr("id");
		if(previousURL != "#undefined")
			this.elmPreviousButton.removeClass(this.classDisabled).addClass(this.classEnabled).children("a").attr("href", previousURL);
		else
			this.elmPreviousButton.removeClass(this.classEnabled).addClass(this.classDisabled).children("a").attr("href", "");
		if(nextURL != "#undefined")
			this.elmNextButton.removeClass(this.classDisabled).addClass(this.classEnabled).children("a").attr("href", nextURL);
		else
			this.elmNextButton.removeClass(this.classEnabled).addClass(this.classDisabled).children("a").attr("href", "");
		
		// set up current navigation item
		this.elmsItemNavigation.removeClass(this.classCurrentNavItem).has("[href=#"+this.elmCurrent.attr("id")+"]").addClass(this.classCurrentNavItem);
		if(this.elmsItemNavigation && this.elmNavigationPointer){
			fncThis.pointToCurrentNavigation(this.elmsItemNavigation.filter("."+this.classCurrentNavItem));
			fncThis.elmNavigationPointer.css("display","block");
		}
	}
	__.classes.pagerSlidingHash.prototype.getPageIndex = function(argElement){
		var arrayLength = this.elmsPages.length;
		for(i=0;i<arrayLength;++i){
			if(this.elmsPages[i] == argElement[0]){
				return i;
			}
		}
	}
	__.classes.pagerSlidingHash.prototype.pointToCurrentNavigation = function(argID){
		if(this.elmsItemNavigation){
			var currentItem = this.elmsItemNavigation.filter("["+this.attrID+"="+argID+"]");
			this.elmsItemNavigation.filter(".selected").removeClass("selected");
			currentItem.addClass("selected");
			if(this.elmNavigationPointer){
				switch(this.elmNavigationOrientation){
					case "horizontal":
						this.elmNavigationPointer.animate({left: currentItem.position().left + currentItem.width()/2}, this.duration);
						break;
					case "vertical":
						this.elmNavigationPointer.animate({top: currentItem.position().top + currentItem.height()/2}, this.duration);
						break;
				}
			}
		}
	}

/* ********* 
©tmlib
********* */
function environment(){
		this.classes = {};
		this.lib = {};
		this.cfg = {};
	}
	__.lib.init = function(){
		__.addClass(document.body, "hasjavascript");
	}
	environment.prototype.message = function(argument){
		if(window.console) 
			console.log(argument);
//		else alert(argument);
	}
	environment.prototype.addListener = function(argElement, argEvent, argFunction, argBubble){
		var fncBubble = (argBubble)?argBubble : false;
		if(argElement.attachEvent)
			argElement.attachEvent("on"+argEvent, argFunction);
		else
			argElement.addEventListener(argEvent, argFunction, fncBubble);
	}
	environment.prototype.getElementsByClassName = function(args){
		var fncClassName = (args.className)?args.className:null; if(!fncClassName) return;
		var fncElement = (args.element)?args.element:document;
		var fncTagName = (args.tagName)?args.tagName:null;
		
		var fncReturn = [], fncElementsToSearch = [];
		var fncRegex = new RegExp('\\b'+fncClassName+'\\b');
		
		if(fncTagName){
			fncElementsToSearch = fncElement.getElementsByTagName(fncTagName);
		}
		else if(fncElement.all)
			fncElementsToSearch = fncElement.all;
		else
			fncElementsToSearch = fncElement.getElementsByTagName('*');
	
		for(var i=0; i < fncElementsToSearch.length; ++i){
			if(fncRegex.test(fncElementsToSearch[i].className))
				fncReturn.push(fncElementsToSearch[i]);
		}
		
		return fncReturn;
	}
	environment.prototype.addClass = function(argElement, argClass){
		if(new RegExp('\\b'+argClass+'\\b').test(argElement.className))
			return 0;
		else{
			argElement.className+=argElement.className?' '+argClass:argClass;
			return 1;
		}
	}
	environment.prototype.removeClass = function(argElement, argClass){
		var fncReplace = argElement.className.match(' '+argClass)?' '+argClass:argClass;
		argElement.className=argElement.className.replace(fncReplace,'');
	}
	environment.prototype.hasClass = function(argElement, argClass){
		if(new RegExp('\\b'+argClass+'\\b').test(argElement.className))
			return 1;
		else
			return 0;
	}
	
	environment.prototype.isIE = function(){
		if(this.isievar)
			return this.isie;
		else{
			this.initUA();
			if(this.browser.indexOf("Internet Explorer", 0) == -1) return 1
			else return 0;
		}
	}
	environment.prototype.isIE6 = function(){
		if(this.isIE){
			if(!this.ieversion) // http://www.javascriptkit.com/javatutors/navigator.shtml
				if(/MSIE (\d+\.\d+);/.test(navigator.userAgent))
					this.ieversion = new Number(RegExp.$1) // capture x.x portion and store as a number
			if(this.ieversion == 6)
				return 1;
			else return 0;
		}
		else
			return 0;
	}
	environment.prototype.initUA = function(){
		if(!this.browser) this.browser = navigator.appName;
		if(!this.verion){
			this.version = parseFloat(navigator.appVersion);
		}
	}
	__.lib.escapeHash = function(hash){
		return hash.replace(/\//g, "\\/");
	}
	__.lib.unescapeHash = function(hash){
		return hash.replace(/\\\//g, "\/");
	}
	
__.addListener(window, "load", __.lib.init, false);



