﻿function InitializeRequest(sender, args) {
	document.body.style.cursor = 'wait';
}

function EndRequest(sender, args) {
	document.body.style.cursor = 'auto';
	Cufon.refresh();
	StarsRefresh();
	MultiplePerformance();
}

function StarsRefresh() {
	jQuery(".star").rating();
}

function clickclear(thisfield, defaulttext) {
	if (thisfield.value == defaulttext) {
		thisfield.value = "";
	}
}

function clickrecall(thisfield, defaulttext) {
	if (thisfield.value == "") {
		thisfield.value = defaulttext;
	}
}

// several performance on the same date
function MultiplePerformance() {
	$('a.multi').click(function () {
		return false;
	}).focus(function () {
		$(this).parent().find('.more-time').show();
		return false;
	}).blur(function () {
		$(this).parent().find('.more-time').hide();
		return false;
	}).hover(function () {
		$(this).parent().find('.more-time').show();
	}, function () {
		$(this).parent().find('.more-time').hide();
	});
	$('.more-time').hover(function () {
		$(this).show();
	}, function () {
		$(this).hide();
	});
}

//wrap $ inside to avoid conflicts with other libraries
(function ($) {

	$(function () {

		MultiplePerformance();
		
		//$(".theatre-col").click(function(){$(this).remove()})
		//load the addThis script... 
		//loadScript('http://s7.addthis.com/js/250/addthis_widget.js#username=xa-4b59be836c1bb90c');

		if ($('#venue-bar').length) {
			var bar = $("#venue-bar");
			var top = bar.offset().top;
			var detached = false;
			$(window).scroll(function (e) {
				if ($(this).scrollTop() >= top) {
					if (!detached) {
						detached = true;
						bar.addClass('fixed');
					}
				} else {
					if (detached) {
						detached = false;
						bar.removeClass('fixed');
					}
				}
			});
		}

		// cufon replacements
		/* * /
		Cufon.replace('.menu a,.foot span,.teaser h2,.searchresults h1,.showfilter h3,.bigbox h1,.calendar_popup h1',{fontFamily:'press-serif'});
		Cufon.replace('.bigbox strong',{fontFamily:'press-serif-bold'});	
		Cufon.replace('.showfilter .pad p,.showbox h2 a,.show h1 a,.bigbox h2 a,.theatrebox h2 a',{fontFamily:'press-gothic',hover: true});
		Cufon.replace('.textcontent h2,.showbox h2,.showdetail h1,.contentbox h4,.showdetail .black .rating h4',{fontFamily:'press-gothic'});
		/* */
		Cufon.replace('h1, h2, h4, div.showfilter p, .link-btn', { fontFamily: 'press-gothic', hover: true });
		Cufon.replace('ul.menu, .serif', { fontFamily: 'press-serif', hover: true });

		/* 
		h4 !3col_page.html
	
		*/

		$(".selector .toggle").click(function () { // handles the custom select
			if ($(this).parent().hasClass("open")) {
				$(".selector").removeClass("open");
				$($(this).parent()).removeClass("open");
			} else {
				$(".selector").removeClass("open");
				$(this).parent().addClass("open");
			}
			return false;
		});

		$(".selector ul a").click(function () { // sets the chosen value to the form 
			if ($(this).attr("name").substr(0, 1) == 'v') {
				$("select.venues").val($(this).attr("name").substr(2));
			} else {
				$("select.times").val($(this).attr("name").substr(2));
			}
			$(".selector").removeClass("open");
			$(this).closest(".selector").children(".toggle").html($(this).html());
			return false;
		});

		$("body").click(function (e) { // closes the custom select when clicked outside
			$(".selector").removeClass("open");
		});

//		// several performance on the same date
//		$('a.multi').click(function () {
//			return false;
//		}).focus(function () {
//			$(this).parent().find('.more-time').show();
//			return false;
//		}).blur(function () {
//			$(this).parent().find('.more-time').hide();
//			return false;
//		}).hover(function () {
//			$(this).parent().find('.more-time').show();
//		}, function () {
//			$(this).parent().find('.more-time').hide();
//		});
//		$('.more-time').hover(function () {
//			$(this).show();
//		}, function () {
//			$(this).hide();
//		});

		// google maps
		if ($("#map").length) {
			$("#map").googleMap(null, null, 4, {
				controls: ["GSmallMapControl", "GMapTypeControl"],
				markers: $(".geo")
			});
		}

		// image gallery
		if ($('#coda-slider-1').length) {
			$('#coda-slider-1').codaSlider({
				dynamicArrows: false,
				dynamicTabs: false,
				autoHeight: 0
			});
		}

		// Remove the coda-slider-no-js class from the body
		$("body").removeClass("coda-slider-no-js");
		// Preloader
		$(".coda-slider").children('.panel').hide(); //.end().prepend('<p class="loading">Loading...<br /><img src="images/ajax-loader.gif" alt="loading..." /></p>');



	});

	var Calendar = {
		close: function () {
			$(".calendar_popup").slideUp(100, function () {
			});
			return false;
		},
		open: function () {
			$(".calendar_popup").slideDown(100);
			return false;
		}
	}






	/*
	jQuery Coda-Slider v2.0 - http://www.ndoherty.biz/coda-slider
	Copyright (c) 2009 Niall Doherty
	This plugin available for use in all personal or commercial projects under both MIT and GPL licenses.
	*/
	/// CODA SLIDER
	var sliderCount = 1;
	$.fn.codaSlider = function (settings) {
		settings = $.extend({
			autoHeight: true,
			autoHeightEaseDuration: 1000,
			autoHeightEaseFunction: "easeInOutExpo",
			autoSlide: false,
			autoSlideInterval: 7000,
			autoSlideStopWhenClicked: true,
			crossLinking: true,
			dynamicArrows: true,
			dynamicArrowLeftText: "&#171; left",
			dynamicArrowRightText: "right &#187;",
			dynamicTabs: true,
			dynamicTabsAlign: "center",
			dynamicTabsPosition: "top",
			externalTriggerSelector: "a.xtrig",
			firstPanelToLoad: 1,
			panelTitleSelector: "h2.title",
			slideEaseDuration: 1000,
			slideEaseFunction: "easeInOutExpo"
		}, settings);

		return this.each(function () {

			// Uncomment the line below to test your preloader
			// alert("Testing preloader");

			var slider = $(this);

			// If we need arrows
			if (settings.dynamicArrows) {
				slider.parent().addClass("arrows");
				slider.before('<div class="coda-nav-left" id="coda-nav-left-' + sliderCount + '"><a href="#">' + settings.dynamicArrowLeftText + '</a></div>');
				slider.after('<div class="coda-nav-right" id="coda-nav-right-' + sliderCount + '"><a href="#">' + settings.dynamicArrowRightText + '</a></div>');
			};

			var panelWidth = slider.find(".panel").width();
			var panelCount = slider.find(".panel").size();
			var panelContainerWidth = panelWidth * panelCount;
			var navClicks = 0; // Used if autoSlideStopWhenClicked = true

			// Surround the collection of panel divs with a container div (wide enough for all panels to be lined up end-to-end)
			$('.panel', slider).wrapAll('<div class="panel-container"></div>');
			// Specify the width of the container div (wide enough for all panels to be lined up end-to-end)
			$(".panel-container", slider).css({ width: panelContainerWidth });

			// Specify the current panel.
			// If the loaded URL has a hash (cross-linking), we're going to use that hash to give the slider a specific starting position...
			if (settings.crossLinking && location.hash && parseInt(location.hash.slice(1)) <= panelCount) {
				var currentPanel = parseInt(location.hash.slice(1));
				var offset = -(panelWidth * (currentPanel - 1));
				$('.panel-container', slider).css({ marginLeft: offset });
				// If that's not the case, check to see if we're supposed to load a panel other than Panel 1 initially...
			} else if (settings.firstPanelToLoad != 1 && settings.firstPanelToLoad <= panelCount) {
				var currentPanel = settings.firstPanelToLoad;
				var offset = -(panelWidth * (currentPanel - 1));
				$('.panel-container', slider).css({ marginLeft: offset });
				// Otherwise, we'll just set the current panel to 1...
			} else {
				var currentPanel = 1;
			};

			// Left arrow click
			$("#coda-nav-left-" + sliderCount + " a").click(function () {
				navClicks++;
				if (currentPanel == 1) {
					offset = -(panelWidth * (panelCount - 1));
					alterPanelHeight(panelCount - 1);
					currentPanel = panelCount;
					slider.siblings('.coda-nav').find('a.current').removeClass('current').parents('ul').find('li:last a').addClass('current');
				} else {
					currentPanel -= 1;
					alterPanelHeight(currentPanel - 1);
					offset = -(panelWidth * (currentPanel - 1));
					slider.siblings('.coda-nav').find('a.current').removeClass('current').parent().prev().find('a').addClass('current');
				};
				$('.panel-container', slider).animate({ marginLeft: offset }, settings.slideEaseDuration, settings.slideEaseFunction);
				if (settings.crossLinking) { location.hash = currentPanel }; // Change the URL hash (cross-linking)
				return false;
			});

			// Right arrow click
			$('#coda-nav-right-' + sliderCount + ' a').click(function () {
				navClicks++;
				if (currentPanel == panelCount) {
					offset = 0;
					currentPanel = 1;
					alterPanelHeight(0);
					slider.siblings('.coda-nav').find('a.current').removeClass('current').parents('ul').find('a:eq(0)').addClass('current');
				} else {
					offset = -(panelWidth * currentPanel);
					alterPanelHeight(currentPanel);
					currentPanel += 1;
					slider.siblings('.coda-nav').find('a.current').removeClass('current').parent().next().find('a').addClass('current');
				};
				$('.panel-container', slider).animate({ marginLeft: offset }, settings.slideEaseDuration, settings.slideEaseFunction);
				if (settings.crossLinking) { location.hash = currentPanel }; // Change the URL hash (cross-linking)
				return false;
			});

			// If we need a dynamic menu
			if (settings.dynamicTabs) {
				var dynamicTabs = '<div class="coda-nav" id="coda-nav-' + sliderCount + '"><ul></ul></div>';
				switch (settings.dynamicTabsPosition) {
					case "bottom":
						slider.parent().append(dynamicTabs);
						break;
					default:
						slider.parent().prepend(dynamicTabs);
						break;
				};
				ul = $('#coda-nav-' + sliderCount + ' ul');
				// Create the nav items
				$('.panel', slider).each(function (n) {
					ul.append('<li class="tab' + (n + 1) + '"><a href="#' + (n + 1) + '">' + $(this).find(settings.panelTitleSelector).text() + '</a></li>');
				});
				navContainerWidth = slider.width() + slider.siblings('.coda-nav-left').width() + slider.siblings('.coda-nav-right').width();
				ul.parent().css({ width: navContainerWidth });
				switch (settings.dynamicTabsAlign) {
					case "center":
						ul.css({ width: ($("li", ul).width() + 2) * panelCount });
						break;
					case "right":
						ul.css({ float: 'right' });
						break;
				};
			};

			// If we need a tabbed nav
			$('#coda-nav-' + sliderCount + ' a').each(function (z) {
				// What happens when a nav link is clicked
				$(this).bind("click", function () {
					navClicks++;
					$(this).addClass('current').parents('ul').find('a').not($(this)).removeClass('current');
					offset = -(panelWidth * z);
					alterPanelHeight(z);
					currentPanel = z + 1;
					$('.panel-container', slider).animate({ marginLeft: offset }, settings.slideEaseDuration, settings.slideEaseFunction);
					if (!settings.crossLinking) { return false }; // Don't change the URL hash unless cross-linking is specified
				});
			});

			// External triggers (anywhere on the page)
			$(settings.externalTriggerSelector).each(function () {
				// Make sure this only affects the targeted slider
				if (sliderCount == parseInt($(this).attr("rel").slice(12))) {
					$(this).bind("click", function () {
						navClicks++;
						targetPanel = parseInt($(this).attr("href").slice(1));
						offset = -(panelWidth * (targetPanel - 1));
						alterPanelHeight(targetPanel - 1);
						currentPanel = targetPanel;
						// Switch the current tab:
						slider.siblings('.coda-nav').find('a').removeClass('current').parents('ul').find('li:eq(' + (targetPanel - 1) + ') a').addClass('current');
						// Slide
						$('.panel-container', slider).animate({ marginLeft: offset }, settings.slideEaseDuration, settings.slideEaseFunction);
						if (!settings.crossLinking) { return false }; // Don't change the URL hash unless cross-linking is specified
					});
				};
			});

			// Specify which tab is initially set to "current". Depends on if the loaded URL had a hash or not (cross-linking).
			if (settings.crossLinking && location.hash && parseInt(location.hash.slice(1)) <= panelCount) {
				$("#coda-nav-" + sliderCount + " a:eq(" + (location.hash.slice(1) - 1) + ")").addClass("current");
				// If there's no cross-linking, check to see if we're supposed to load a panel other than Panel 1 initially...
			} else if (settings.firstPanelToLoad != 1 && settings.firstPanelToLoad <= panelCount) {
				$("#coda-nav-" + sliderCount + " a:eq(" + (settings.firstPanelToLoad - 1) + ")").addClass("current");
				// Otherwise we must be loading Panel 1, so make the first tab the current one.
			} else {
				$("#coda-nav-" + sliderCount + " a:eq(0)").addClass("current");
			};

			// Set the height of the first panel
			if (settings.autoHeight) {
				panelHeight = $('.panel:eq(' + (currentPanel - 1) + ')', slider).height();
				slider.css({ height: panelHeight });
			};

			// Trigger autoSlide
			if (settings.autoSlide) {
				slider.ready(function () {
					setTimeout(autoSlide, settings.autoSlideInterval);
				});
			};

			function alterPanelHeight(x) {
				if (settings.autoHeight) {
					panelHeight = $('.panel:eq(' + x + ')', slider).height()
					slider.animate({ height: panelHeight }, settings.autoHeightEaseDuration, settings.autoHeightEaseFunction);
				};
			};

			function autoSlide() {
				if (navClicks == 0 || !settings.autoSlideStopWhenClicked) {
					if (currentPanel == panelCount) {
						var offset = 0;
						currentPanel = 1;
					} else {
						var offset = -(panelWidth * currentPanel);
						currentPanel += 1;
					};
					alterPanelHeight(currentPanel - 1);
					// Switch the current tab:
					slider.siblings('.coda-nav').find('a').removeClass('current').parents('ul').find('li:eq(' + (currentPanel - 1) + ') a').addClass('current');
					// Slide:
					$('.panel-container', slider).animate({ marginLeft: offset }, settings.slideEaseDuration, settings.slideEaseFunction);
					setTimeout(autoSlide, settings.autoSlideInterval);
				};
			};

			// Kill the preloader
			$('.panel', slider).show().end().find("p.loading").remove();
			slider.removeClass("preload");

			sliderCount++;

		});
	};

	/*
	* jQuery Easing v1.3 - http://gsgd.co.uk/sandbox/jquery/easing/
	*
	* Uses the built in easing capabilities added In jQuery 1.1
	* to offer multiple easing options
	*
	* TERMS OF USE - jQuery Easing
	* 
	* Open source under the BSD License. 
	* 
	* Copyright © 2008 George McGinley Smith
	* All rights reserved.
	* 
	* Redistribution and use in source and binary forms, with or without modification, 
	* are permitted provided that the following conditions are met:
	* 
	* Redistributions of source code must retain the above copyright notice, this list of 
	* conditions and the following disclaimer.
	* Redistributions in binary form must reproduce the above copyright notice, this list 
	* of conditions and the following disclaimer in the documentation and/or other materials 
	* provided with the distribution.
	* 
	* Neither the name of the author nor the names of contributors may be used to endorse 
	* or promote products derived from this software without specific prior written permission.
	* 
	* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
	* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
	* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
	*  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
	*  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
	*  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
	* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
	*  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
	* OF THE POSSIBILITY OF SUCH DAMAGE. 
	*
	*/

	// t: current time, b: begInnIng value, c: change In value, d: duration
	jQuery.easing['jswing'] = jQuery.easing['swing'];

	jQuery.extend(jQuery.easing,
{
	def: 'easeOutQuad',
	swing: function (x, t, b, c, d) {
		//alert(jQuery.easing.default);
		return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
	},
	easeInQuad: function (x, t, b, c, d) {
		return c * (t /= d) * t + b;
	},
	easeOutQuad: function (x, t, b, c, d) {
		return -c * (t /= d) * (t - 2) + b;
	},
	easeInOutQuad: function (x, t, b, c, d) {
		if ((t /= d / 2) < 1) return c / 2 * t * t + b;
		return -c / 2 * ((--t) * (t - 2) - 1) + b;
	},
	easeInCubic: function (x, t, b, c, d) {
		return c * (t /= d) * t * t + b;
	},
	easeOutCubic: function (x, t, b, c, d) {
		return c * ((t = t / d - 1) * t * t + 1) + b;
	},
	easeInOutCubic: function (x, t, b, c, d) {
		if ((t /= d / 2) < 1) return c / 2 * t * t * t + b;
		return c / 2 * ((t -= 2) * t * t + 2) + b;
	},
	easeInQuart: function (x, t, b, c, d) {
		return c * (t /= d) * t * t * t + b;
	},
	easeOutQuart: function (x, t, b, c, d) {
		return -c * ((t = t / d - 1) * t * t * t - 1) + b;
	},
	easeInOutQuart: function (x, t, b, c, d) {
		if ((t /= d / 2) < 1) return c / 2 * t * t * t * t + b;
		return -c / 2 * ((t -= 2) * t * t * t - 2) + b;
	},
	easeInQuint: function (x, t, b, c, d) {
		return c * (t /= d) * t * t * t * t + b;
	},
	easeOutQuint: function (x, t, b, c, d) {
		return c * ((t = t / d - 1) * t * t * t * t + 1) + b;
	},
	easeInOutQuint: function (x, t, b, c, d) {
		if ((t /= d / 2) < 1) return c / 2 * t * t * t * t * t + b;
		return c / 2 * ((t -= 2) * t * t * t * t + 2) + b;
	},
	easeInSine: function (x, t, b, c, d) {
		return -c * Math.cos(t / d * (Math.PI / 2)) + c + b;
	},
	easeOutSine: function (x, t, b, c, d) {
		return c * Math.sin(t / d * (Math.PI / 2)) + b;
	},
	easeInOutSine: function (x, t, b, c, d) {
		return -c / 2 * (Math.cos(Math.PI * t / d) - 1) + b;
	},
	easeInExpo: function (x, t, b, c, d) {
		return (t == 0) ? b : c * Math.pow(2, 10 * (t / d - 1)) + b;
	},
	easeOutExpo: function (x, t, b, c, d) {
		return (t == d) ? b + c : c * (-Math.pow(2, -10 * t / d) + 1) + b;
	},
	easeInOutExpo: function (x, t, b, c, d) {
		if (t == 0) return b;
		if (t == d) return b + c;
		if ((t /= d / 2) < 1) return c / 2 * Math.pow(2, 10 * (t - 1)) + b;
		return c / 2 * (-Math.pow(2, -10 * --t) + 2) + b;
	},
	easeInCirc: function (x, t, b, c, d) {
		return -c * (Math.sqrt(1 - (t /= d) * t) - 1) + b;
	},
	easeOutCirc: function (x, t, b, c, d) {
		return c * Math.sqrt(1 - (t = t / d - 1) * t) + b;
	},
	easeInOutCirc: function (x, t, b, c, d) {
		if ((t /= d / 2) < 1) return -c / 2 * (Math.sqrt(1 - t * t) - 1) + b;
		return c / 2 * (Math.sqrt(1 - (t -= 2) * t) + 1) + b;
	},
	easeInElastic: function (x, t, b, c, d) {
		var s = 1.70158; var p = 0; var a = c;
		if (t == 0) return b; if ((t /= d) == 1) return b + c; if (!p) p = d * .3;
		if (a < Math.abs(c)) { a = c; var s = p / 4; }
		else var s = p / (2 * Math.PI) * Math.asin(c / a);
		return -(a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b;
	},
	easeOutElastic: function (x, t, b, c, d) {
		var s = 1.70158; var p = 0; var a = c;
		if (t == 0) return b; if ((t /= d) == 1) return b + c; if (!p) p = d * .3;
		if (a < Math.abs(c)) { a = c; var s = p / 4; }
		else var s = p / (2 * Math.PI) * Math.asin(c / a);
		return a * Math.pow(2, -10 * t) * Math.sin((t * d - s) * (2 * Math.PI) / p) + c + b;
	},
	easeInOutElastic: function (x, t, b, c, d) {
		var s = 1.70158; var p = 0; var a = c;
		if (t == 0) return b; if ((t /= d / 2) == 2) return b + c; if (!p) p = d * (.3 * 1.5);
		if (a < Math.abs(c)) { a = c; var s = p / 4; }
		else var s = p / (2 * Math.PI) * Math.asin(c / a);
		if (t < 1) return -.5 * (a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b;
		return a * Math.pow(2, -10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p) * .5 + c + b;
	},
	easeInBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c * (t /= d) * t * ((s + 1) * t - s) + b;
	},
	easeOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b;
	},
	easeInOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		if ((t /= d / 2) < 1) return c / 2 * (t * t * (((s *= (1.525)) + 1) * t - s)) + b;
		return c / 2 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2) + b;
	},
	easeInBounce: function (x, t, b, c, d) {
		return c - jQuery.easing.easeOutBounce(x, d - t, 0, c, d) + b;
	},
	easeOutBounce: function (x, t, b, c, d) {
		if ((t /= d) < (1 / 2.75)) {
			return c * (7.5625 * t * t) + b;
		} else if (t < (2 / 2.75)) {
			return c * (7.5625 * (t -= (1.5 / 2.75)) * t + .75) + b;
		} else if (t < (2.5 / 2.75)) {
			return c * (7.5625 * (t -= (2.25 / 2.75)) * t + .9375) + b;
		} else {
			return c * (7.5625 * (t -= (2.625 / 2.75)) * t + .984375) + b;
		}
	},
	easeInOutBounce: function (x, t, b, c, d) {
		if (t < d / 2) return jQuery.easing.easeInBounce(x, t * 2, 0, c, d) * .5 + b;
		return jQuery.easing.easeOutBounce(x, t * 2 - d, 0, c, d) * .5 + c * .5 + b;
	}
});

	/*
	*
	* TERMS OF USE - EASING EQUATIONS
	* 
	* Open source under the BSD License. 
	* 
	* Copyright © 2001 Robert Penner
	* All rights reserved.
	* 
	* Redistribution and use in source and binary forms, with or without modification, 
	* are permitted provided that the following conditions are met:
	* 
	* Redistributions of source code must retain the above copyright notice, this list of 
	* conditions and the following disclaimer.
	* Redistributions in binary form must reproduce the above copyright notice, this list 
	* of conditions and the following disclaimer in the documentation and/or other materials 
	* provided with the distribution.
	* 
	* Neither the name of the author nor the names of contributors may be used to endorse 
	* or promote products derived from this software without specific prior written permission.
	* 
	* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
	* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
	* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
	*  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
	*  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
	*  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
	* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
	*  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
	* OF THE POSSIBILITY OF SUCH DAMAGE. 
	*
	*/

	/*
	### jQuery Star Rating Plugin v3.12 - 2009-04-16 ###
	* Home: http://www.fyneworks.com/jquery/star-rating/
	* Code: http://code.google.com/p/jquery-star-rating-plugin/
	*
	* Dual licensed under the MIT and GPL licenses:
	*   http://www.opensource.org/licenses/mit-license.php
	*   http://www.gnu.org/licenses/gpl.html
	###
	*/


	// IE6 Background Image Fix
	//if ($.browser.msie) try { document.execCommand("BackgroundImageCache", false, true)} catch(e) { };
	// Thanks to http://www.visualjquery.com/rating/rating_redux.html

	// plugin initialization
	$.fn.rating = function (options) {
		if (this.length == 0) return this; // quick fail

		// Handle API methods
		if (typeof arguments[0] == 'string') {
			// Perform API methods on individual elements
			if (this.length > 1) {
				var args = arguments;
				return this.each(function () {
					$.fn.rating.apply($(this), args);
				});
			};
			// Invoke API method handler
			$.fn.rating[arguments[0]].apply(this, $.makeArray(arguments).slice(1) || []);
			// Quick exit...
			return this;
		};

		// Initialize options for this call
		var options = $.extend(
		{}/* new object */,
		$.fn.rating.options/* default options */,
		options || {} /* just-in-time options */
	);

		// Allow multiple controls with the same name by making each call unique
		$.fn.rating.calls++;

		// loop through each matched element
		this
	 .not('.star-rating-applied')
		.addClass('star-rating-applied')
	.each(function () {

		// Load control parameters / find context / etc
		var control, input = $(this);
		var eid = (this.name || 'unnamed-rating').replace(/\[|\]/g, '_').replace(/^\_+|\_+$/g, '');
		var context = $(this.form || document.body);

		// FIX: http://code.google.com/p/jquery-star-rating-plugin/issues/detail?id=23
		var raters = context.data('rating');
		if (!raters || raters.call != $.fn.rating.calls) raters = { count: 0, call: $.fn.rating.calls };
		var rater = raters[eid];

		// if rater is available, verify that the control still exists
		if (rater) control = rater.data('rating');

		if (rater && control)//{// save a byte!
		// add star to control if rater is available and the same control still exists
			control.count++;

		//}// save a byte!
		else {
			// create new control if first star or control element was removed/replaced

			// Initialize options for this raters
			control = $.extend(
					{}/* new object */,
					options || {} /* current call options */,
					($.metadata ? input.metadata() : ($.meta ? input.data() : null)) || {}, /* metadata options */
					{count: 0, stars: [], inputs: [] }
				);

			// increment number of rating controls
			control.serial = raters.count++;

			// create rating element
			rater = $('<span class="star-rating-control"/>');
			input.before(rater);

			// Mark element for initialization (once all stars are ready)
			rater.addClass('rating-to-be-drawn');

			// Accept readOnly setting from 'disabled' property
			if (input.attr('disabled')) control.readOnly = true;

			// Create 'cancel' button
			rater.append(
					control.cancel = $('<div class="rating-cancel"><a title="' + control.cancel + '">' + control.cancelValue + '</a></div>')
					.mouseover(function () {
						$(this).rating('drain');
						$(this).addClass('star-rating-hover');
						//$(this).rating('focus');
					})
					.mouseout(function () {
						$(this).rating('draw');
						$(this).removeClass('star-rating-hover');
						//$(this).rating('blur');
					})
					.click(function () {
						$(this).rating('select');
					})
					.data('rating', control)
				);

		}; // first element of group

		// insert rating star
		var star = $('<div class="star-rating rater-' + control.serial + '"><a title="' + (this.title || this.value) + '">' + this.value + '</a></div>');
		rater.append(star);

		// inherit attributes from input element
		if (this.id) star.attr('id', this.id);
		if (this.className) star.addClass(this.className);

		// Half-stars?
		if (control.half) control.split = 2;

		// Prepare division control
		if (typeof control.split == 'number' && control.split > 0) {
			var stw = ($.fn.width ? star.width() : 0) || control.starWidth;
			var spi = (control.count % control.split), spw = Math.floor(stw / control.split);
			star
			// restrict star's width and hide overflow (already in CSS)
				.width(spw)
			// move the star left by using a negative margin
			// this is work-around to IE's stupid box model (position:relative doesn't work)
				.find('a').css({ 'margin-left': '-' + (spi * spw) + 'px' })
		};

		// readOnly?
		if (control.readOnly)//{ //save a byte!
		// Mark star as readOnly so user can customize display
			star.addClass('star-rating-readonly');
		//}  //save a byte!
		else//{ //save a byte!
		// Enable hover css effects
			star.addClass('star-rating-live')
		// Attach mouse events
					.mouseover(function () {
						$(this).rating('fill');
						$(this).rating('focus');
					})
					.mouseout(function () {
						$(this).rating('draw');
						$(this).rating('blur');
					})
					.click(function () {
						$(this).rating('select');
					})
				;
		//}; //save a byte!

		// set current selection
		if (this.checked) control.current = star;

		// hide input element
		input.hide();

		// backward compatibility, form element to plugin
		input.change(function () {
			$(this).rating('select');
		});

		// attach reference to star to input element and vice-versa
		star.data('rating.input', input.data('rating.star', star));

		// store control information in form (or body when form not available)
		control.stars[control.stars.length] = star[0];
		control.inputs[control.inputs.length] = input[0];
		control.rater = raters[eid] = rater;
		control.context = context;

		input.data('rating', control);
		rater.data('rating', control);
		star.data('rating', control);
		context.data('rating', raters);
	}); // each element

		// Initialize ratings (first draw)
		$('.rating-to-be-drawn').rating('draw').removeClass('rating-to-be-drawn');

		return this; // don't break the chain...
	};

	/*--------------------------------------------------------*/

	/*
	### Core functionality and API ###
	*/
	$.extend($.fn.rating, {
		// Used to append a unique serial number to internal control ID
		// each time the plugin is invoked so same name controls can co-exist
		calls: 0,

		focus: function () {
			var control = this.data('rating'); if (!control) return this;
			if (!control.focus) return this; // quick fail if not required
			// find data for event
			var input = $(this).data('rating.input') || $(this.tagName == 'INPUT' ? this : null);
			// focus handler, as requested by focusdigital.co.uk
			if (control.focus) control.focus.apply(input[0], [input.val(), $('a', input.data('rating.star'))[0]]);
		}, // $.fn.rating.focus

		blur: function () {
			var control = this.data('rating'); if (!control) return this;
			if (!control.blur) return this; // quick fail if not required
			// find data for event
			var input = $(this).data('rating.input') || $(this.tagName == 'INPUT' ? this : null);
			// blur handler, as requested by focusdigital.co.uk
			if (control.blur) control.blur.apply(input[0], [input.val(), $('a', input.data('rating.star'))[0]]);
		}, // $.fn.rating.blur

		fill: function () { // fill to the current mouse position.
			var control = this.data('rating'); if (!control) return this;
			// do not execute when control is in read-only mode
			if (control.readOnly) return;
			// Reset all stars and highlight them up to this element
			this.rating('drain');
			this.prevAll().andSelf().filter('.rater-' + control.serial).addClass('star-rating-hover');
		}, // $.fn.rating.fill

		drain: function () { // drain all the stars.
			var control = this.data('rating'); if (!control) return this;
			// do not execute when control is in read-only mode
			if (control.readOnly) return;
			// Reset all stars
			control.rater.children().filter('.rater-' + control.serial).removeClass('star-rating-on').removeClass('star-rating-hover');
		}, // $.fn.rating.drain

		draw: function () { // set value and stars to reflect current selection
			var control = this.data('rating'); if (!control) return this;
			// Clear all stars
			this.rating('drain');
			// Set control value
			if (control.current) {
				control.current.data('rating.input').attr('checked', 'checked');
				control.current.prevAll().andSelf().filter('.rater-' + control.serial).addClass('star-rating-on');
			}
			else
				$(control.inputs).removeAttr('checked');
			// Show/hide 'cancel' button
			control.cancel[control.readOnly || control.required ? 'hide' : 'show']();
			// Add/remove read-only classes to remove hand pointer
			this.siblings()[control.readOnly ? 'addClass' : 'removeClass']('star-rating-readonly');
		}, // $.fn.rating.draw

		select: function (value) { // select a value
			var control = this.data('rating'); if (!control) return this;
			// do not execute when control is in read-only mode
			if (control.readOnly) return;
			// clear selection
			control.current = null;
			// programmatically (based on user input)
			if (typeof value != 'undefined') {
				// select by index (0 based)
				if (typeof value == 'number')
					return $(control.stars[value]).rating('select');
				// select by literal value (must be passed as a string
				if (typeof value == 'string')
				//return 
					$.each(control.stars, function () {
						if ($(this).data('rating.input').val() == value) $(this).rating('select');
					});
			}
			else
				control.current = this[0].tagName == 'INPUT' ?
				 this.data('rating.star') :
					(this.is('.rater-' + control.serial) ? this : null);

			// Update rating control state
			this.data('rating', control);
			// Update display
			this.rating('draw');
			// find data for event
			var input = $(control.current ? control.current.data('rating.input') : null);
			// click callback, as requested here: http://plugins.jquery.com/node/1655
			if (control.callback) control.callback.apply(input[0], [input.val(), $('a', control.current)[0]]); // callback event
		}, // $.fn.rating.select

		readOnly: function (toggle, disable) { // make the control read-only (still submits value)
			var control = this.data('rating'); if (!control) return this;
			// setread-only status
			control.readOnly = toggle || toggle == undefined ? true : false;
			// enable/disable control value submission
			if (disable) $(control.inputs).attr("disabled", "disabled");
			else $(control.inputs).removeAttr("disabled");
			// Update rating control state
			this.data('rating', control);
			// Update display
			this.rating('draw');
		}, // $.fn.rating.readOnly

		disable: function () { // make read-only and never submit value
			this.rating('readOnly', true, true);
		}, // $.fn.rating.disable

		enable: function () { // make read/write and submit value
			this.rating('readOnly', false, false);
		} // $.fn.rating.select

	});

	/*--------------------------------------------------------*/

	/*
	### Default Settings ###
	eg.: You can override default control like this:
	$.fn.rating.options.cancel = 'Clear';
	*/
	$.fn.rating.options = { //$.extend($.fn.rating, { options: {
		cancel: 'Cancel Rating',   // advisory title for the 'cancel' link
		cancelValue: '',           // value to submit when user click the 'cancel' link
		split: 0,                  // split the star into how many parts?

		// Width of star image in case the plugin can't work it out. This can happen if
		// the jQuery.dimensions plugin is not available OR the image is hidden at installation
		starWidth: 16//,

		//NB.: These don't need to be pre-defined (can be undefined/null) so let's save some code!
		//half:     false,         // just a shortcut to control.split = 2
		// required: true         // disables the 'cancel' button so user can only select one of the specified values
		//readOnly: false,         // disable rating plugin interaction/ values cannot be changed
		//focus:    function(){},  // executed when stars are focused
		//blur:     function(){},  // executed when stars are focused
		//callback: function(){},  // executed when a star is clicked
	}; //} });

	/*--------------------------------------------------------*/

	/*
	### Default implementation ###
	The plugin will attach itself to file inputs
	with the class 'multi' when the page loads
	*/
	$(function () {
		$('input[type=radio].star').rating();
	});

	/* jQuery googleMap Copyright Dylan Verheul <dylan@dyve.net>
	* Licensed like jQuery, see http://docs.jquery.com/License
	* Modified by Kraftvaerk 2010-04-14 for zoom functionality
	*/

	$.googleMap = {
		maps: {},
		marker: function (m) {
			if (!m) {
				return null;
			} else if (m.lat == null && m.lng == null) {
				return $.googleMap.marker($.googleMap.readFromGeo(m));
			} else {
				var marker = new GMarker(new GLatLng(m.lat, m.lng));
				if (m.txt) {
					GEvent.addListener(marker, "click", function () {
						marker.openInfoWindowHtml(m.txt);
					});
				}
				return marker;
			}
		},
		readFromGeo: function (elem) {
			var latElem = $(".latitude", elem)[0];
			var lngElem = $(".longitude", elem)[0];
			if (latElem && lngElem) {
				return { lat: parseFloat($(latElem).attr("title")), lng: parseFloat($(lngElem).attr("title")), txt: $(elem).attr("title") }
			} else {
				return null;
			}
		},
		mapNum: 1
	};

	$.fn.googleMap = function (lat, lng, zoom, options) {

		// If we aren't supported, we're done
		if (!window.GBrowserIsCompatible || !GBrowserIsCompatible()) return this;

		// Default values make for easy debugging
		//if (lat == null) lat = 37.4419;
		//if (lng == null) lng = -122.1419;
		//if (!zoom) zoom = 13;

		if (lat == null) {

			var minLat = false;
			var maxLat, minLng, maxLng;

			$(options.markers).each(function () {
				//myLat = parseFloat($(".latitude:first", this).text())
				//myLng = parseFloat($(".longitude:first", this).text())

				myLat = parseFloat($(".latitude:first").attr("title"))
				myLng = parseFloat($(".longitude:first").attr("title"))

				if (!minLat) {
					minLat = myLat;
					maxLat = myLat;
					minLng = myLng;
					maxLng = myLng;
				}
				if (myLat < minLat) minLat = myLat;
				if (myLat > maxLat) maxLat = myLat;
				if (myLng < minLng) minLng = myLng;
				if (myLng > maxLng) maxLng = myLng;
			})
		}
		lat = minLat + (maxLat - minLat) / 2;
		lng = minLng + (maxLng - minLng) / 2;


		var R = 6371; // 6371 = km, 3958.75 = miles

		/* formula
		http://www.movable-type.co.uk/scripts/latlong.html
		http://www.daftlogic.com/projects-google-maps-distance-calculator.htm
		http://www.meridianworlddata.com/Distance-Calculation.asp
		http://www.codedblog.com/2007/09/28/how-to-auto-zoom-and-auto-center-google-maps/
		
		based on the Great Circle Distance Formula using decimal degrees
		www.meridianworlddata.com/Distance-Calculation.asp... use 3963.0 for value in miles.
		*/
		dist = 6378.7 * Math.acos(Math.sin(minLat / 57.2958) * Math.sin(maxLat / 57.2958) + Math.cos(minLat / 57.2958) * Math.cos(maxLat / 57.2958) * Math.cos(maxLng / 57.2958 - minLng / 57.2958));

		//todo: adjust these settings a bit
		if (dist < 0.5) zoom = 16;
		else if (dist < 2) zoom = 15;
		else if (dist < 3) zoom = 14;
		else if (dist < 4) zoom = 13;
		else if (dist < 6) zoom = 12;
		else if (dist < 12) zoom = 11;
		else if (dist < 26) zoom = 10;
		else if (dist < 50) zoom = 9;
		else zoom = 8;

		//debugging:
		//console.log('lat:'+lat+', lng:'+lng +', zoom:'+zoom+', distance:' +dist+' km');
		//console.log('zoom:'+zoom+', distance:' +dist+' km');

		// Sanitize options
		if (!options || typeof options != 'object') options = {};
		options.mapOptions = options.mapOptions || {};
		options.markers = options.markers || [];
		options.controls = options.controls || {};

		// Map all our elements
		return this.each(function () {
			// Make sure we have a valid id
			if (!this.id) this.id = "gMap" + $.googleMap.mapNum++;
			// Create a map and a shortcut to it at the same time
			var map = $.googleMap.maps[this.id] = new GMap2(this, options.mapOptions);
			// Center and zoom the map
			map.setCenter(new GLatLng(lat, lng), zoom);
			// Add controls to our map
			for (var i = 0; i < options.controls.length; i++) {
				var c = options.controls[i];
				eval("map.addControl(new " + c + "());");
			}
			// If we have markers, put them on the map
			var marker = null;
			for (var i = 0; i < options.markers.length; i++) {
				if (marker = $.googleMap.marker(options.markers[i])) map.addOverlay(marker);
			}
		});

	};

	//end the jQuery namescope wrap
})(jQuery);

/*
 * SimpleModal 1.3.3 - jQuery Plugin
 * http://www.ericmmartin.com/projects/simplemodal/
 * Copyright (c) 2009 Eric Martin (http://twitter.com/EricMMartin)
 * Dual licensed under the MIT and GPL licenses
 * Revision: $Id: jquery.simplemodal.js 228 2009-10-30 13:34:27Z emartin24 $
 */
;(function($){var ie6=$.browser.msie&&parseInt($.browser.version)==6&&typeof window['XMLHttpRequest']!="object",ieQuirks=null,w=[];$.modal=function(data,options){return $.modal.impl.init(data,options);};$.modal.close=function(){$.modal.impl.close();};$.fn.modal=function(options){return $.modal.impl.init(this,options);};$.modal.defaults={appendTo:'body',focus:true,opacity:50,overlayId:'simplemodal-overlay',overlayCss:{},containerId:'simplemodal-container',containerCss:{},dataId:'simplemodal-data',dataCss:{},minHeight:200,minWidth:300,maxHeight:null,maxWidth:null,autoResize:false,autoPosition:true,zIndex:1000,close:true,closeHTML:'<a class="modalCloseImg" title="Close"></a>',closeClass:'simplemodal-close',escClose:true,overlayClose:false,position:null,persist:false,onOpen:null,onShow:null,onClose:null};$.modal.impl={o:null,d:{},init:function(data,options){var s=this;if(s.d.data){return false;}ieQuirks=$.browser.msie&&!$.boxModel;s.o=$.extend({},$.modal.defaults,options);s.zIndex=s.o.zIndex;s.occb=false;if(typeof data=='object'){data=data instanceof jQuery?data:$(data);if(data.parent().parent().size()>0){s.d.parentNode=data.parent();if(!s.o.persist){s.d.orig=data.clone(true);}}}else if(typeof data=='string'||typeof data=='number'){data=$('<div></div>').html(data);}else{alert('SimpleModal Error: Unsupported data type: '+typeof data);return s;}s.create(data);data=null;s.open();if($.isFunction(s.o.onShow)){s.o.onShow.apply(s,[s.d]);}return s;},create:function(data){var s=this;w=s.getDimensions();if(ie6){s.d.iframe=$('<iframe src="javascript:false;"></iframe>').css($.extend(s.o.iframeCss,{display:'none',opacity:0,position:'fixed',height:w[0],width:w[1],zIndex:s.o.zIndex,top:0,left:0})).appendTo(s.o.appendTo);}s.d.overlay=$('<div></div>').attr('id',s.o.overlayId).addClass('simplemodal-overlay').css($.extend(s.o.overlayCss,{display:'none',opacity:s.o.opacity/100,height:w[0],width:w[1],position:'fixed',left:0,top:0,zIndex:s.o.zIndex+1})).appendTo(s.o.appendTo);s.d.container=$('<div></div>').attr('id',s.o.containerId).addClass('simplemodal-container').css($.extend(s.o.containerCss,{display:'none',position:'fixed',zIndex:s.o.zIndex+2})).append(s.o.close&&s.o.closeHTML?$(s.o.closeHTML).addClass(s.o.closeClass):'').appendTo(s.o.appendTo);s.d.wrap=$('<div></div>').attr('tabIndex',-1).addClass('simplemodal-wrap').css({height:'100%',outline:0,width:'100%'}).appendTo(s.d.container);s.d.data=data.attr('id',data.attr('id')||s.o.dataId).addClass('simplemodal-data').css($.extend(s.o.dataCss,{display:'none'})).appendTo('body');data=null;s.setContainerDimensions();s.d.data.appendTo(s.d.wrap);if(ie6||ieQuirks){s.fixIE();}},bindEvents:function(){var s=this;$('.'+s.o.closeClass).bind('click.simplemodal',function(e){e.preventDefault();s.close();});if(s.o.close&&s.o.overlayClose){s.d.overlay.bind('click.simplemodal',function(e){e.preventDefault();s.close();});}$(document).bind('keydown.simplemodal',function(e){if(s.o.focus&&e.keyCode==9){s.watchTab(e);}else if((s.o.close&&s.o.escClose)&&e.keyCode==27){e.preventDefault();s.close();}});$(window).bind('resize.simplemodal',function(){w=s.getDimensions();s.setContainerDimensions(true);if(ie6||ieQuirks){s.fixIE();}else{s.d.iframe&&s.d.iframe.css({height:w[0],width:w[1]});s.d.overlay.css({height:w[0],width:w[1]});}});},unbindEvents:function(){$('.'+this.o.closeClass).unbind('click.simplemodal');$(document).unbind('keydown.simplemodal');$(window).unbind('resize.simplemodal');this.d.overlay.unbind('click.simplemodal');},fixIE:function(){var s=this,p=s.o.position;$.each([s.d.iframe||null,s.d.overlay,s.d.container],function(i,el){if(el){var bch='document.body.clientHeight',bcw='document.body.clientWidth',bsh='document.body.scrollHeight',bsl='document.body.scrollLeft',bst='document.body.scrollTop',bsw='document.body.scrollWidth',ch='document.documentElement.clientHeight',cw='document.documentElement.clientWidth',sl='document.documentElement.scrollLeft',st='document.documentElement.scrollTop',s=el[0].style;s.position='absolute';if(i<2){s.removeExpression('height');s.removeExpression('width');s.setExpression('height',''+bsh+' > '+bch+' ? '+bsh+' : '+bch+' + "px"');s.setExpression('width',''+bsw+' > '+bcw+' ? '+bsw+' : '+bcw+' + "px"');}else{var te,le;if(p&&p.constructor==Array){var top=p[0]?typeof p[0]=='number'?p[0].toString():p[0].replace(/px/,''):el.css('top').replace(/px/,'');te=top.indexOf('%')==-1?top+' + (t = '+st+' ? '+st+' : '+bst+') + "px"':parseInt(top.replace(/%/,''))+' * (('+ch+' || '+bch+') / 100) + (t = '+st+' ? '+st+' : '+bst+') + "px"';if(p[1]){var left=typeof p[1]=='number'?p[1].toString():p[1].replace(/px/,'');le=left.indexOf('%')==-1?left+' + (t = '+sl+' ? '+sl+' : '+bsl+') + "px"':parseInt(left.replace(/%/,''))+' * (('+cw+' || '+bcw+') / 100) + (t = '+sl+' ? '+sl+' : '+bsl+') + "px"';}}else{te='('+ch+' || '+bch+') / 2 - (this.offsetHeight / 2) + (t = '+st+' ? '+st+' : '+bst+') + "px"';le='('+cw+' || '+bcw+') / 2 - (this.offsetWidth / 2) + (t = '+sl+' ? '+sl+' : '+bsl+') + "px"';}s.removeExpression('top');s.removeExpression('left');s.setExpression('top',te);s.setExpression('left',le);}}});},focus:function(pos){var s=this,p=pos||'first';var input=$(':input:enabled:visible:'+p,s.d.wrap);input.length>0?input.focus():s.d.wrap.focus();},getDimensions:function(){var el=$(window);var h=$.browser.opera&&$.browser.version>'9.5'&&$.fn.jquery<='1.2.6'?document.documentElement['clientHeight']:$.browser.opera&&$.browser.version<'9.5'&&$.fn.jquery>'1.2.6'?window.innerHeight:el.height();return[h,el.width()];},getVal:function(v){return v=='auto'?0:v.indexOf('%')>0?v:parseInt(v.replace(/px/,''));},setContainerDimensions:function(resize){var s=this;if(!resize||(resize&&s.o.autoResize)){var ch=s.getVal(s.d.container.css('height')),cw=s.getVal(s.d.container.css('width')),dh=s.d.data.outerHeight(true),dw=s.d.data.outerWidth(true);var mh=s.o.maxHeight&&s.o.maxHeight<w[0]?s.o.maxHeight:w[0],mw=s.o.maxWidth&&s.o.maxWidth<w[1]?s.o.maxWidth:w[1];if(!ch){if(!dh){ch=s.o.minHeight;}else{if(dh>mh){ch=mh;}else if(dh<s.o.minHeight){ch=s.o.minHeight;}else{ch=dh;}}}else{ch=ch>mh?mh:ch;}if(!cw){if(!dw){cw=s.o.minWidth;}else{if(dw>mw){cw=mw;}else if(dw<s.o.minWidth){cw=s.o.minWidth;}else{cw=dw;}}}else{cw=cw>mw?mw:cw;}s.d.container.css({height:ch,width:cw});if(dh>ch||dw>cw){s.d.wrap.css({overflow:'auto'});}}if(s.o.autoPosition){s.setPosition();}},setPosition:function(){var s=this,top,left,hc=(w[0]/2)-(s.d.container.outerHeight(true)/2),vc=(w[1]/2)-(s.d.container.outerWidth(true)/2);if(s.o.position&&Object.prototype.toString.call(s.o.position)==="[object Array]"){top=s.o.position[0]||hc;left=s.o.position[1]||vc;}else{top=hc;left=vc;}s.d.container.css({left:left,top:top});},watchTab:function(e){var s=this;if($(e.target).parents('.simplemodal-container').length>0){s.inputs=$(':input:enabled:visible:first, :input:enabled:visible:last',s.d.data[0]);if((!e.shiftKey&&e.target==s.inputs[s.inputs.length-1])||(e.shiftKey&&e.target==s.inputs[0])||s.inputs.length==0){e.preventDefault();var pos=e.shiftKey?'last':'first';setTimeout(function(){s.focus(pos);},10);}}else{e.preventDefault();setTimeout(function(){s.focus();},10);}},open:function(){var s=this;s.d.iframe&&s.d.iframe.show();if($.isFunction(s.o.onOpen)){s.o.onOpen.apply(s,[s.d]);}else{s.d.overlay.show();s.d.container.show();s.d.data.show();}s.focus();s.bindEvents();},close:function(){var s=this;if(!s.d.data){return false;}s.unbindEvents();if($.isFunction(s.o.onClose)&&!s.occb){s.occb=true;s.o.onClose.apply(s,[s.d]);}else{if(s.d.parentNode){if(s.o.persist){s.d.data.hide().appendTo(s.d.parentNode);}else{s.d.data.hide().remove();s.d.orig.appendTo(s.d.parentNode);}}else{s.d.data.hide().remove();}s.d.container.hide().remove();s.d.overlay.hide().remove();s.d.iframe&&s.d.iframe.hide().remove();s.d={};}}};})(jQuery);
