/* ----- tabs ----- */

$(function () {
			var tabContainers = $('div.tabs > div');
			tabContainers.hide().filter(':first').show();
			
			$('div.tabs ul.tabNavigation a').click(function () {
				tabContainers.hide();
				tabContainers.filter(this.hash).show();
				$('div.tabs ul.tabNavigation a').removeClass('selected');
				$(this).addClass('selected');
				return false;
			}).filter(':first').click();
		});

///* ----- golf galleries ----- */

//$(document).ready(function () {
//	
//	var opts = {
//		controls: {
//			playPause: {auto: true},
//			previousSlide: {auto: true},
//			nextSlide: {auto: true},
//			index: {auto: true}
//		}
//	};
//	$('.rs-slideshow').rsfSlideshow(opts);
//	
//});

(function($){var methods={init:function(options){return this.each(function(){var slideshow=this,$slideshow=$(this),data=$slideshow.data('rsf_slideshow');if(!data){var settings=$.extend(true,{},$.rsfSlideshow.defaults);if(typeof options==='object'){$.extend(true,settings,options);};$slideshow.data('rsf_slideshow',{slides:Array(),this_slide:0,effect_iterator:{this_effect:-1,direction:1},settings:settings,interval_id:false,loaded_imgs:Array(),queued:0});}
$slideshow.rsfSlideshow('getSlidesFromMarkup');if(settings.slides.length){$slideshow.rsfSlideshow('addSlides',settings.slides);settings.slides=Array();}
if(typeof settings.eventHandlers==='object'){$.each(settings.eventHandlers,function(evnt,fn){$slideshow.bind(evnt,function(e){fn($slideshow,e);});});}
if(settings.controls.playPause.auto){$slideshow.rsfSlideshow('addControl','playPause');}
if(settings.controls.previousSlide.auto){$slideshow.rsfSlideshow('addControl','previousSlide');}
if(settings.controls.index.auto){$slideshow.rsfSlideshow('addControl','index');}
if(settings.controls.nextSlide.auto){$slideshow.rsfSlideshow('addControl','nextSlide');}
if(settings.autostart){$slideshow.rsfSlideshow('startShow');}});},addSlides:function(slides){if(slides instanceof Array){for(var i=0,len=slides.length;i<len;i++){private._addSlide(this,slides[i]);}}
else{private._addSlide(this,slides);}
return this;},startShow:function(interval,instant){var $slideshow=this;var data=$slideshow.data('rsf_slideshow');if(!data.interval_id){if(instant){$slideshow.rsfSlideshow('nextSlide');}
if(!interval){interval=data.settings.interval;}
data.interval_id=setInterval(function(){$slideshow.rsfSlideshow('nextSlide');},interval*1000);private._trigger($slideshow,'rsStartShow');}
return this;},stopShow:function(){var data=this.data('rsf_slideshow');if(data.interval_id){clearInterval(data.interval_id);data.interval_id=false;private._trigger(this,'rsStopShow');}
return this;},toggleShow:function(){if(this.rsfSlideshow('isRunning')){this.rsfSlideshow('stopShow');}
else{this.rsfSlideshow('startShow');}},isRunning:function(){if(this.data('rsf_slideshow').interval_id){return true;}
return false;},currentSlideKey:function(){var data=this.data('rsf_slideshow');return data.this_slide;},totalSlides:function(){var data=this.data('rsf_slideshow');return data.slides.length;},getSlidesFromMarkup:function(options){var data=this.data('rsf_slideshow');if(!options){options={};}
if(!options.data_container){options.data_container=data.settings.data_container;}
if(options.data_container.charAt(0)==='#'){var $cntnr=$(options.data_container);}
else{var $cntnr=$(this).children(options.data_container);}
if(!$cntnr.length){return false;}
if(!options.slide_data_container){options.slide_data_container=data.settings.slide_data_container;}
var slide_data_selectors=$.extend(true,{},data.settings.slide_data_selectors);if(options.slide_data_selectors){$.extend(true,slide_data_selectors,options.slide_data_selectors);}
options.slide_data_selectors=slide_data_selectors;var self=this;$cntnr.children(options.slide_data_container).each(function(){var slide=private._findData($(this),options.slide_data_selectors);$(self).rsfSlideshow('addSlides',slide);});return this;},nextSlide:function(){var data=this.data('rsf_slideshow');data.this_slide++;if(data.this_slide>=data.slides.length){if(data.settings.loop){data.this_slide=0;}
else{data.this_slide=data.slides.length-1;this.rsfSlideshow('stopShow');return this;}}
this.rsfSlideshow('showSlide',data.slides[data.this_slide]);return this;},previousSlide:function(){var data=this.data('rsf_slideshow');data.this_slide--;if(data.this_slide<0){if(data.settings.loop){data.this_slide=data.slides.length-1;}
else{data.this_slide=0;this.rsfSlideshow('stopShow');return this;}}
this.rsfSlideshow('showSlide',data.slides[data.this_slide]);return this;},goToSlide:function(key){var data=this.data('rsf_slideshow');if(typeof data.slides[key]==='object'){data.this_slide=key;this.rsfSlideshow('showSlide',data.slides[data.this_slide]);}
return this;},showSlide:function(slide,_queue_id){var $slideshow=this,data=$slideshow.data('rsf_slideshow');if(!_queue_id){data.queued+=1;_queue_id=data.queued;private._trigger($slideshow,'rsPreTransition');}
else if(_queue_id!=data.queued){return;}
var containerWidth=$slideshow.width();var containerHeight=$slideshow.height();$slideshow.children('img:first').css('z-index',0);var newImg=new Image();newImg.src=slide.url;var whenLoaded=function(img){var width=img.width;var height=img.height;if(!width||!height){setTimeout(function(){$slideshow.rsfSlideshow('showSlide',slide,_queue_id);},200);return;}
if($.inArray(slide.url,data.loaded_imgs)<0){data.loaded_imgs.push(slide.url);}
private._trigger($slideshow,'rsImageReady');$(img).addClass('rsf-slideshow-image');$slideshow.prepend($(img));width=$(img).outerWidth();height=$(img).outerHeight();$(img).detach();var leftOffset=Math.ceil((containerWidth/2)-(width/2));var topOffset=Math.ceil((containerHeight/2)-(height/2));$(img).css({left:leftOffset});$(img).css({top:topOffset});if(slide.link_to){var $img=$('<a href="'+slide.link_to+'"></a>').append($(img));}
else{$img=$(img);}
var $slideEl=$('<div></div>');$slideEl.addClass(data.settings.slide_container_class);$slideEl.append($img).css('display','none');if(slide.caption){var $capt=$('<span>'+slide.caption+'</span>');$capt.addClass(data.settings.slide_caption_class);$capt.appendTo($slideEl);}
var effect=data.settings.effect;if(slide.effect){effect=slide.effect;}
$slideEl.appendTo($slideshow);private._transitionWith($slideshow,$slideEl,effect);return true;};if($.inArray(slide.url,data.loaded_imgs)<0){if(newImg.width){whenLoaded(newImg);}
else{$(newImg).bind('load',function(){whenLoaded(newImg);});}}
else{whenLoaded(newImg);}
return this;},addControl:function(type){return this.each(function(){var $slideshow=$(this),settings=$slideshow.data('rsf_slideshow').settings;$control=settings.controls[type].generate($slideshow);private._controlsContainer($slideshow);settings.controls[type].place($slideshow,$control);bind_method='bind'+type.substr(0,1).toUpperCase()+type.substr(1,type.length);$slideshow.rsfSlideshow(bind_method,$control);});},bindPlayPause:function($playPause){return this.each(function(){var $slideshow=$(this);var data=$slideshow.data('rsf_slideshow');$playPause.bind('click.rsfSlideshow',function(e){e.preventDefault();$slideshow.rsfSlideshow('toggleShow');});});},bindPreviousSlide:function($prev,autostop){return this.each(function(){var $slideshow=$(this);var data=$slideshow.data('rsf_slideshow');if(!autostop){autostop=data.settings.controls.previousSlide.autostop;}
$prev.bind('click.rsfSlideshow',function(e){e.preventDefault();$slideshow.rsfSlideshow('previousSlide');if(autostop){$slideshow.rsfSlideshow('stopShow');}});});},bindNextSlide:function($next,autostop){return this.each(function(){var $slideshow=$(this);var data=$slideshow.data('rsf_slideshow');if(!autostop){autostop=data.settings.controls.nextSlide.autostop;}
$next.bind('click.rsfSlideshow',function(e){e.preventDefault();$slideshow.rsfSlideshow('nextSlide');if(autostop){$slideshow.rsfSlideshow('stopShow');}});});},bindIndex:function($index,autostop){return this.each(function(){var $slideshow=$(this),settings=$slideshow.data('rsf_slideshow').settings;if(!autostop){autostop=settings.controls.index.autostop;}
$indexLinks=settings.controls.index.getEach($slideshow);$indexLinks.bind('click.rsfSlideshow',function(e){e.preventDefault();var slide_key=settings.controls.index.getSlideKey($(this));if(slide_key){$slideshow.rsfSlideshow('goToSlide',slide_key);if(autostop){$slideshow.rsfSlideshow('stopShow');}}});private._bindActiveIndex($slideshow);});}};$.fn.rsfSlideshow=function(method){if(!this.length){return this;}
if(methods[method]){return methods[method].apply(this,Array.prototype.slice.call(arguments,1));}
else if(typeof method==='object'||!method){return methods.init.apply(this,arguments);}
else{$.error('Method '+method+' does not exist on jQuery.rsfSlidehow');}};var private={_findData:function($slideData,slide_data_selectors){var slide={};var slide_attr;for(var key in slide_data_selectors){var $slideDataClone=$.extend(true,{},$slideData);if(slide_data_selectors[key].selector){$slideDataClone=$slideDataClone.children(slide_data_selectors[key].selector);}
if(slide_data_selectors[key].attr){slide_attr=$slideDataClone.attr(slide_data_selectors[key].attr);}
else{slide_attr=$slideDataClone.text();}
slide[key]=slide_attr;}
return slide;},_addSlide:function($slideshow,slide){var data=$slideshow.data('rsf_slideshow');if((typeof slide)=='string'){url=$.trim(slide);data.slides.push({url:url});}
else if(slide.url){for(var key in slide){slide[key]=$.trim(slide[key]);}
data.slides.push(slide);}},_transitionWith:function($slideshow,$slide,effect){var data=$slideshow.data('rsf_slideshow');var $previousSlide=$slideshow.children('div.'+data.settings.slide_container_class+':first');var effect_iteration='random';if(typeof effect==='object'&&effect.iteration&&effect.effects){effect_iteration=effect.iteration;effect=effect.effects;}
if(effect instanceof Array){switch(effect_iteration){case'loop':data.effect_iterator.this_effect++;if(data.effect_iterator.this_effect>effect.length-1){data.effect_iterator.this_effect=0;}
break;case'backAndForth':data.effect_iterator.this_effect+=data.effect_iterator.direction;if(data.effect_iterator.this_effect<0){data.effect_iterator.this_effect=1;data.effect_iterator.direction=data.effect_iterator.direction*-1;}
if(data.effect_iterator.this_effect>effect.length-1){data.effect_iterator.this_effect=effect.length-2;data.effect_iterator.direction=data.effect_iterator.direction*-1;}
break;default:data.effect_iterator.this_effect=Math.floor(Math.random()*effect.length);break;}
effect=effect[data.effect_iterator.this_effect];}
switch(effect){case'none':$slide.css('display','block');private._endTransition($slideshow);break;case'fade':$slide.fadeIn(data.settings.transition,function(){private._endTransition($slideshow);});break;case'slideLeft':var left_offset=$slide.outerWidth();private._doSlide($slideshow,$slide,$previousSlide,left_offset,0);break;case'slideRight':var left_offset=(0-$slide.outerWidth());private._doSlide($slideshow,$slide,$previousSlide,left_offset,0);break;case'slideUp':var top_offset=$slide.outerHeight();private._doSlide($slideshow,$slide,$previousSlide,0,top_offset);break;case'slideDown':var top_offset=(0-$slide.outerHeight());private._doSlide($slideshow,$slide,$previousSlide,0,top_offset);break;}},_doSlide:function($slideshow,$slide,$previousSlide,left_offset,top_offset){var data=$slideshow.data('rsf_slideshow');$slide.css({top:top_offset,left:left_offset});$slide.css('display','block');$slide.stop().animate({top:0,left:0},data.settings.transition,data.settings.easing,function(){private._endTransition($slideshow);});$previousSlide.stop().animate({top:(0-top_offset),left:(0-left_offset)},data.settings.transition,data.settings.easing);},_endTransition:function($slideshow){var data=$slideshow.data('rsf_slideshow');$slideshow.children('div.'+data.settings.slide_container_class+':not(:last-child)').remove();private._trigger($slideshow,'rsPostTransition');if($slideshow.rsfSlideshow('currentSlideKey')==$slideshow.rsfSlideshow('totalSlides')-1){private._trigger($slideshow,'rsLastSlide');}
else if($slideshow.rsfSlideshow('currentSlideKey')==0){private._trigger($slideshow,'rsFirstSlide');}},_bindActiveIndex:function($slideshow){var indexSettings=$slideshow.data('rsf_slideshow').settings.controls.index;$slideshow.bind('rsPreTransition',function(){var current_slide_key=$(this).rsfSlideshow('currentSlideKey');indexSettings.getEach($slideshow).removeClass(indexSettings.active_class);indexSettings.getSingleByKey($slideshow,current_slide_key).addClass(indexSettings.active_class);});},_controlsContainer:function($slideshow){var settings=$slideshow.data('rsf_slideshow').settings;if(!settings.controls.container.get($slideshow).length){$container=settings.controls.container.generate($slideshow);settings.controls.container.place($slideshow,$container);}},_trigger:function($slideshow,e,event_data){var data=$slideshow.data('rsf_slideshow');if(typeof event_data!=='object'){event_data={};}
$.extend(event_data,{slide_key:data.this_slide,slide:data.slides[data.this_slide]});$slideshow.trigger(e,event_data);}};$.rsfSlideshow={defaults:{interval:5,transition:1000,effect:'fade',easing:'swing',loop:true,autostart:true,slides:Array(),slide_container_class:'slide-container',slide_caption_class:'slide-caption',data_container:'ol.slides',slide_data_container:'li',slide_data_selectors:{url:{selector:'a',attr:'href'},caption:{selector:'a',attr:'title'},link_to:{selector:'a',attr:'data-link-to'},effect:{selector:'a',attr:'data-effect'}},eventHandlers:{rsStartShow:function(rssObj,e){var controlSettings=$(rssObj).data('rsf_slideshow').settings.controls.playPause;var $playPause=controlSettings.get($(rssObj));$playPause.html('Pause').addClass(controlSettings.playing_class);},rsStopShow:function(rssObj,e){var controlSettings=$(rssObj).data('rsf_slideshow').settings.controls.playPause;var $playPause=controlSettings.get($(rssObj));$playPause.html('Play').addClass(controlSettings.paused_class);}},controls:{playPause:{generate:function($slideshow){return $('<a href="#" class="rs-play-pause" data-control-for="'
+$slideshow.attr('id')+'">Pause</a>');},place:function($slideshow,$control){$container=$slideshow.data('rsf_slideshow').settings.controls.container.get($slideshow);$container.append($control);},get:function($slideshow){return $('.rs-play-pause[data-control-for="'+$slideshow.attr('id')+'"]');},playing_class:'rs-playing',paused_class:'rs-paused',auto:false},previousSlide:{generate:function($slideshow){return $('<a href="#" class="rs-prev" data-control-for="'
+$slideshow.attr('id')+'">&lt;</a>');},place:function($slideshow,$control){$container=$slideshow.data('rsf_slideshow').settings.controls.container.get($slideshow);$container.append($control);},get:function($slideshow){return $('.rs-prev[data-control-for="'+$slideshow.attr('id')+'"]');},autostop:true,auto:false},nextSlide:{generate:function($slideshow){return $('<a href="#" class="rs-next" data-control-for="'
+$slideshow.attr('id')+'">&gt;</a>');},place:function($slideshow,$control){$container=$slideshow.data('rsf_slideshow').settings.controls.container.get($slideshow);$container.append($control);},get:function($slideshow){return $('.rs-next[data-control-for="'+$slideshow.attr('id')+'"]');},autostop:true,auto:false},index:{generate:function($slideshow){var slide_count=$slideshow.rsfSlideshow('totalSlides'),$indexControl=$('<ul class="rs-index-list clearfix"></ul>');$indexControl.attr('data-control-for',$slideshow.attr('id'));for(var i=0;i<slide_count;i++){var $link=$('<a href="#"></a>');$link.addClass('rs-index');$link.attr('data-control-for',$slideshow.attr('id'));$link.attr('data-slide-key',i);$link.append(i+1);if(i===$slideshow.rsfSlideshow('currentSlideKey')){$link.addClass('rs-active');}
$li=$('<li></li>');$li.append($link);$indexControl.append($li);}
return $indexControl;},place:function($slideshow,$control){$container=$slideshow.data('rsf_slideshow').settings.controls.container.get($slideshow);$container.append($control);},get:function($slideshow){return $('.rs-index-list[data-control-for="'+$slideshow.attr('id')+'"]');},getEach:function($slideshow){return $('.rs-index[data-control-for="'+$slideshow.attr('id')+'"]');},getSingleByKey:function($slideshow,slide_key){return $('.rs-index[data-control-for="'+$slideshow.attr('id')
+'"][data-slide-key="'+slide_key+'"]');},getSlideKey:function($controlItem){return $controlItem.attr('data-slide-key');},active_class:'rs-active',autostop:true,auto:false},container:{generate:function($slideshow){return $('<div class="rs-controls clearfix" id="rs-controls-'+$slideshow.attr('id')+'"></div>');},place:function($slideshow,$control){$slideshow.after($control);},get:function($slideshow){return $('#rs-controls-'+$slideshow.attr('id'));}}}}};})(jQuery);

/* ----- weather ----- */

(function($) {
	$.extend({
		simpleWeather: function(options){
			var options = $.extend({
				zipcode: '76309',
				location: '',
				unit: 'f',
				success: function(weather){},
				error: function(message){}
			}, options);
			
			now = new Date(); //cachebust
			
			var weatherUrl = 'http://query.yahooapis.com/v1/public/yql?format=json&rnd='+now.getFullYear()+now.getMonth()+now.getDay()+now.getHours()+'&diagnostics=true&callback=?&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&q=';
			if(options.location != '')
				weatherUrl += 'select * from weather.forecast where location in (select id from weather.search where query="'+options.location+'") and u="'+options.unit+'"';
			else if(options.zipcode != '')
				weatherUrl += 'select * from weather.forecast where location in ("'+options.zipcode+'") and u="'+options.unit+'"';
			else {
				options.error("No location given.");
				return false;
			}
						
			$.getJSON(
				weatherUrl,
				function(data) {
					if(data != null && data.query.results != null) {
						$.each(data.query.results, function(i, result) {
							if (result.constructor.toString().indexOf("Array") != -1)
								result = result[0];
														
							currentDate = new Date();
							sunRise = new Date(currentDate.toDateString() +' '+ result.astronomy.sunrise);
							sunSet = new Date(currentDate.toDateString() +' '+ result.astronomy.sunset);
							if(currentDate>sunRise && currentDate<sunSet)
								timeOfDay = 'd'; 
							else
								timeOfDay = 'n';
							
							compass = ['N', 'NNE', 'NE', 'ENE', 'E', 'ESE', 'SE', 'SSE', 'S', 'SSW', 'SW', 'WSW', 'W', 'WNW', 'NW', 'NNW', 'N'];
						    windDirection = compass[Math.round(result.wind.direction / 22.5)];
							
							if(result.item.condition.temp < 80 && result.atmosphere.humidity < 40)
								heatIndex = -42.379+2.04901523*result.item.condition.temp+10.14333127*result.atmosphere.humidity-0.22475541*result.item.condition.temp*result.atmosphere.humidity-6.83783*(Math.pow(10, -3))*(Math.pow(result.item.condition.temp, 2))-5.481717*(Math.pow(10, -2))*(Math.pow(result.atmosphere.humidity, 2))+1.22874*(Math.pow(10, -3))*(Math.pow(result.item.condition.temp, 2))*result.atmosphere.humidity+8.5282*(Math.pow(10, -4))*result.item.condition.temp*(Math.pow(result.atmosphere.humidity, 2))-1.99*(Math.pow(10, -6))*(Math.pow(result.item.condition.temp, 2))*(Math.pow(result.atmosphere.humidity,2));
							else
								heatIndex = result.item.condition.temp;
							
							var weather = {					
								title: result.item.title,
								temp: result.item.condition.temp,
								code: result.item.condition.code,
								units:{
									temp: result.units.temperature,
									distance: result.units.distance,
									pressure: result.units.pressure,
									speed: result.units.speed
								},
								currently: result.item.condition.text,
								high: result.item.forecast[0].high,
								low: result.item.forecast[0].low,
								forecast: result.item.forecast[0].text,
								wind:{
									chill: result.wind.chill,
									direction: windDirection,
									speed: result.wind.speed
								},
								humidity: result.atmosphere.humidity,
								heatindex: heatIndex,
								pressure: result.atmosphere.pressure,
								rising: result.atmosphere.rising,
								visibility: result.atmosphere.visibility,
								sunrise: result.astronomy.sunrise,
								sunset: result.astronomy.sunset,
								description: result.item.description,
								thumbnail: "http://l.yimg.com/a/i/us/nws/weather/gr/"+result.item.condition.code+timeOfDay+"s.png",
								image: "http://l.yimg.com/a/i/us/nws/weather/gr/"+result.item.condition.code+timeOfDay+".png",
								tomorrow:{
									high: result.item.forecast[1].high,
									low: result.item.forecast[1].low,
									forecast: result.item.forecast[1].text,
									code: result.item.forecast[1].code,
									date: result.item.forecast[1].date,
									day: result.item.forecast[1].day,
									image: "http://l.yimg.com/a/i/us/nws/weather/gr/"+result.item.forecast[1].code+"d.png"
								},
								city: result.location.city,
								country: result.location.country,
								region: result.location.region,
								updated: result.item.pubDate,
								link: result.item.link
							};
							
							options.success(weather);
						});
					} else {
						if (data.query.results == null)
							options.error("Invalid location given.");
						else
							options.error("Weather could not be displayed. Try again.");
					}
				}
			);
			return this;
		}		
	});
})(jQuery);

/* ----- pop up window -----*/

<!--
function popitup(url) {
	newwindow=window.open(url,'name','height=800,width=800,scrollbars=yes');
	if (window.focus) {newwindow.focus()}
	return false;
}

// -->

/* ----- 360 Photos ----- */

/* =========================================================
// jquery.panorama.js
// Author: OpenStudio (Arnault PACHOT)
// Mail: apachot@openstudio.fr
// Web: http://www.openstudio.fr
// Copyright (c) 2008 Arnault Pachot
// licence : GPL
========================================================= */

(function($) {
	$.fn.panorama = function(options) {
		this.each(function(){ 
			var settings = {
				viewport_width: 460,
				speed: 25000,
				direction: 'left',
				control_display: 'auto',
				start_position: 0,
				auto_start: false,
				mode_360: true
			};
			if(options) $.extend(settings, options);
		
			var elemWidth = parseInt($(this).attr('width'));
			var elemHeight = parseInt($(this).attr('height'));
			var currentElement = this;
			var panoramaViewport, panoramaContainer;
			var bMouseMove = false;
			var mouseMoveStart = 0;
			var mouseMoveMarginStart = 0;

			$(this).attr('unselectable','on')
				.css('position', 'relative')
				.css('-moz-user-select','none')
				.css('-webkit-user-select','none')
				.css('margin', '0')
				.css('padding', '0')
				.css('border', 'none')
				.wrap("<div class='panorama-container'></div>");
			if (settings.mode_360) 
				$(this).clone().insertAfter(this);
			
			panoramaContainer = $(this).parent();
			panoramaContainer.css('height', elemHeight+'px').css('overflow', 'hidden').wrap("<div class='panorama-viewport'></div>").parent().css('width',settings.viewport_width+'px')
				.append("<div class='panorama-control'><a href='#' class='panorama-control-left'><<</a> <a href='#' class='panorama-control-pause'>Stop</a> <a href='#' class='panorama-control-right'>>></a> </div>");
			
			panoramaViewport = panoramaContainer.parent();

			panoramaViewport.mousedown(function(e){
			      if (!bMouseMove) {
				bMouseMove = true;
				mouseMoveStart = e.clientX;
			      }
			      return false;
			}).mouseup(function(){
			      bMouseMove = false;
			      mouseMoveStart = 0;
			      return false;
			}).mousemove(function(e){
			      if (bMouseMove){
				  var delta = parseInt((mouseMoveStart - e.clientX)/30);
				  if ((delta>10) || (delta<10)) {
				      var newMarginLeft = parseInt(panoramaContainer.css('marginLeft')) + (delta);
				      if (settings.mode_360) {
					    if (newMarginLeft > 0) {newMarginLeft = -elemWidth;}
					    if (newMarginLeft < -elemWidth) {newMarginLeft = 0;}
				      } else {
					    if (newMarginLeft > 0) {newMarginLeft = 0;}
					    if (newMarginLeft < -elemWidth) {newMarginLeft = -elemWidth;}
				      }
				      panoramaContainer.css('marginLeft', newMarginLeft+'px');
				  }
				
			      }
			}).bind('contextmenu',function(){return false;});
			
			panoramaViewport.css('height', elemHeight+'px').css('overflow', 'hidden').find('a.panorama-control-left').bind('click', function() {
				$(panoramaContainer).stop();
				settings.direction = 'right';
				panorama_animate(panoramaContainer, elemWidth, settings);
				return false;
			});
			panoramaViewport.bind('click', function() {
				$(panoramaContainer).stop();
			});
			panoramaViewport.find('a.panorama-control-right').bind('click', function() {
				$(panoramaContainer).stop();
				settings.direction = 'left';
				panorama_animate(panoramaContainer, elemWidth, settings);
				return false;
			});
			panoramaViewport.find('a.panorama-control-pause').bind('click', function() {
				$(panoramaContainer).stop();
				return false;
			});
			
			if (settings.control_display == 'yes') {
				panoramaViewport.find('.panorama-control').show();
			} else if (settings.control_display == 'auto') {
				panoramaViewport.bind('mouseover', function(){
					$(this).find('.panorama-control').show();
					return false;
				}).bind('mouseout', function(){
					$(this).find('.panorama-control').hide();
					return false;
				});
				
			}
		
			$(this).parent().css('margin-left', '-'+settings.start_position+'px');

			if (settings.auto_start) 
				panorama_animate(panoramaContainer, elemWidth, settings);
			
		});
		function panorama_animate(element, elemWidth, settings) {
			currentPosition = 0-parseInt($(element).css('margin-left'));
			
			if (settings.direction == 'right') {
				
				$(element).animate({marginLeft: 0}, ((settings.speed / elemWidth) * (currentPosition)) , 'linear', function (){ 
					if (settings.mode_360) {
						$(element).css('marginLeft', '-'+(parseInt(parseInt(elemWidth))+'px'));
						panorama_animate(element, elemWidth, settings);
					}
				});
			} else {
 				
				var rightlimit;
				if (settings.mode_360) 
					rightlimit = elemWidth;
				else
					rightlimit = elemWidth-settings.viewport_width;
					
				$(element).animate({marginLeft: -rightlimit}, ((settings.speed / rightlimit) * (rightlimit - currentPosition)), 'linear', function (){ 
					if (settings.mode_360) {
						$(element).css('margin-left', 0); 
						panorama_animate(element, elemWidth, settings);
					}
				});
			}

			
		}
		
	};

$(document).ready(function(){
	$("img.panorama").panorama();
});
})(jQuery);
