// GenericAccordion
/* 
 * @title GenericAccordion
 * @version 1.1
 * @author Ben Kimpel
 * @description Generic accordion
 */
(function ($) {
    $.fn.accordion = function (options) {
        // Merge defaults and options
        var o = $.extend({}, $.fn.accordion.defaults, options);
        
        // Attach event to container (Event delegation)
        return $(this).each(function () {
            $(this).bind(o.event, function (e, t) {
               var accordion = $(this);         // Store a reference to the accordion
               var target = $(t || e.target);   // Get the event target as jQuery object
               var toHide = false;              // Show, hide, and default content objects/flags
               var toShow = false;     
            
               // Inspect the target. Get header -OR- set flag
               var header = target.is(o.header) ? target : (target.parent().is(o.header) ? target.parent() : false);
               var defaultContent = o.defaultContent ? $(o.defaultContent).find(o.header).next() : false;

               // Handle conditions
               if (header) {
                   // Target is not selected
                   if (!header.parent().hasClass(o.selectedClass)) {
                       toHide = !o.allowMultiple ? accordion.find('.' + o.selectedClass + '>' + o.header).next() : false;
                       toShow = header.next();
                   // Target is already selected
                   } else if (header.parent().hasClass(o.selectedClass)) {
                       toHide = o.allowClose ? header.next() : false;
                   }
                
                   // Note: jQuery slideUp/Down does not animate padding/margin. This results in some visible jumping in the animation.
                   // Wrap the content in a div, set overflow hidden, animate the div, hide the content, replace the div with the content.         

                   if (toShow) {
                       toShow.parent().addClass(o.selectedClass);
                       toShow.wrap('<div style="overflow:hidden;height:0;margin:0;padding:0;width:100%;"></div>')
                           .show()
                           .parent()
                           .animate({ 'height':toShow.outerHeight() }, o.speed, 'swing', function () {
                               $(this).replaceWith(toShow);
                           });  
                       if (defaultContent) {
                           defaultContent.wrap('<div style="overflow:hidden;margin:0;padding:0;width:100%;"></div>')
                               .parent()
                               .animate({ 'height':0 }, o.speed, 'swing', function () {
                                   defaultContent.hide();
                                   $(this).replaceWith(defaultContent);
                               });
                       } 
                   } else if (defaultContent) {
                       defaultContent.wrap('<div style="overflow:hidden;height:0;margin:0;padding:0;width:100%;"></div>')
                           .show()
                           .parent()
                           .animate({ 'height':defaultContent.outerHeight() }, o.speed, 'swing', function () {
                               $(this).replaceWith(defaultContent);
                           });
                   }
                   if (toHide) {
                       toHide.parent().removeClass(o.selectedClass);
                       toHide.wrap('<div style="overflow:hidden;margin:0;padding:0;width:100%;"></div>')
                           .parent()
                           .animate({ 'height':0 }, o.speed, 'swing', function () {
                               toHide.hide();
                               $(this).replaceWith(toHide);
                           });
                   }       
                   return false;   // This could become an option, I guess...in case header is a link.
               }
            });
        });
    };
    
    // Defaults (public)
    $.fn.accordion.defaults = {
        header: 'h1',
        event: 'mousedown',
        selectedClass: 'sectionOn',
        defaultContent: '',
        speed: 250,
        allowMultiple: false,
        allowClose: true,
        fixedHeight: true,   // Todo
        comparator: false
    };
})(jQuery);

// Thinbox
/* @title         ThinBox
 * @version       1.0
 * @author        Ben Kimpel
 * @description   Attaches thickbox-like overlay/dialog functionality to click event of target element. Loads element's href or rel URL 
 *                via ajax and fires callback when complete. Only applies overlay styles, otherwise style is left up to the HTML 
 *                fragment and styles that are being pulled in. Doesn't attempt to give titles, image galleries, etc. just loads 
 *                content into a dialog.
 */
(function ($) {
   $.fn.thinbox = function (options) {
      return $(this).each(function () {
         var $this = $(this);
         
         // Merge defaults and options
         var o = $.extend(true, $.fn.thinbox.defaults, options);

         // Browser/OS Flags (Necessary evil)
         var ie6 = ($.browser.msie && parseInt($.browser.version) == 6) ? true : false;
         var macff2 = (($.browser.mozilla && parseFloat($.browser.version) < 1.9) && (navigator.userAgent.indexOf('Mac') !== -1)) ? true : false;

         // IE6 CSS compensation
         if (ie6) {
            $.extend(o.overlay.CSS, { position:'absolute', height:'100%', top:0, left:0 });
            $.extend(o.loadingImage.CSS, { position:'absolute' });
         }

         // Mac FF2 / Flash bug
         if (macff2) {
            $.extend(o.overlay.CSS, { opacity:1, background:'transparent url(' + o.macFF2Image + ') 0 0 repeat' });
         }

         $this.click(function () {
            // Make sure there is a valid URL to load and return if not
            var targetURL = $this.attr('href') || $this.attr('rel') || null;
            targetURL = o.escapeURL ? escape(unescape(targetURL)) : targetURL;		
         
            if (!targetURL || targetURL === '#' || targetURL === 'null') {
               return false;
            }
            
            
            // Start creating the elements
            // OVERLAY
            if (ie6) {
               $('select').css({ visibility:'hidden' });
            }
            var overlay = $('<div></div>');
            var overlayOpacity = o.overlay.CSS.opacity;
            o.overlay.CSS.opacity = 0;
            overlay
               .css(o.overlay.CSS)
               .attr('id', o.overlay.ID || '')
               .attr('class', o.overlay.CLASS || '')
               .prependTo('body')
               .animate({ opacity:overlayOpacity }, 600);
            o.overlay.CSS.opacity = overlayOpacity;
            
            overlay.before('<div id="overlay_loading"><img src="' + o.loadingImage.url + '" /><p>Loading...</p></div>');
            loadingImage = $('#overlay_loading');
            loadingImage
               .css(o.loadingImage.CSS)
               .css({ display:'block', marginLeft:-(loadingImage.width()/2), marginTop:-(loadingImage.height()/2) });
            
            // IE6 CSS compensation
            if (ie6) {
               loadingImage.css({ marginTop:-parseInt(this.offsetHeight / 2) + (document.documentElement && document.documentElement.scrollTop || document.body.scrollTop) + 'px' });
            }
            
            // CONTENT BOX
            var contentBox = $('<div></div>');
            contentBox
               .css(o.contentBox.CSS)
               .attr('id', o.contentBox.ID || '')
               .attr('class', o.contentBox.CLASS || '')
               .appendTo('body');
            
            // IE6 CSS compensation
            if (ie6) {
               $('html')
                  .css({ overflow:'scroll' })
                  .find('body')
                  .andSelf()
                  .css({ height:'100%', width:'100%' });
            }
            
            // Get content
            contentBox.load(targetURL, {}, function () {
               scroll(0, 0);
               var t = $(window).height() > contentBox.height() ? ($(window).height() - contentBox.height()) * 0.5 : 13;
               var l = $(window).width() > contentBox.width() ? ($(window).width() - contentBox.width()) * 0.5 : 0;
               contentBox.css({ display:'block', position:'absolute', top:t, left:l });

               // Remove loading image
               loadingImage.fadeOut('fast', function () { $(this).remove(); });

               if (ie6) {
                  contentBox.find('select').css({ visibility:'visible' });
               }

               // Close
               overlay.click(function () {
                  contentBox.remove();
                  overlay.fadeOut('fast', function () { 
                     $(this).remove();
                     $('html').css({ overflow:'auto' });
                     if (ie6) {
                        $('select').css('visibility', 'visible');
                     }
                  });					
                  return false;
               });
               contentBox.find(o.closeSelector).click(function () {
                  overlay.triggerHandler('click');
                  return false;
               });

               // User callback
               typeof(o.callback) == 'function' ? o.callback() : false;
            });

            return false;
         });
      });
   };
   
   // Defaults (public)
   $.fn.thinbox.defaults = {
      macFF2Image: '/vailresorts/sites/global/assets/img/thinbox/macFF2Image.png',
      modal: true,  // TODO (if necessary)
      closeSelector: 'a.close',
      escapeURL: false,
      overlay: {
          ID: null,
          CLASS: null,
          CSS: { backgroundColor:'#000', position:'fixed', opacity:0.75, zIndex:1000, top:0, left:0, height:'100%', width:'100%' }
      },
      loadingImage: {
         url: '/vailresorts/sites/global/assets/img/thinbox/loadingImage.gif',
         ID: null,
         CLASS: null,
         CSS: { display:'none', zIndex:1001, position:'fixed', top:'50%', left:'50%' }
      },
      contentBox: {
          ID: null,
          CLASS: null,
          CSS: { display:'none', zIndex:1002 }
      },
      callback: null
   };
})(jQuery);

// Generic Carousel
/* @title         GenericCarousel
 * @version       1.0
 * @author        Ben Kimpel
 * @description   Generic carousel with flexible HTML configuration
 */
(function($){$.fn.carousel=function(options){var o=$.extend({},$.fn.carousel.defaults,options);return this.each(function(){var $this=$(this);var current=0;$this.find(o.counterSelector).text(current+1);var sections=$this.find(o.sectionSelector).not($this.find(o.sectionSelector+' '+o.sectionSelector));sections.each(function(i){(i!=0)?$(this).hide():false;});$this.find(o.totalSelector).text(sections.length);(!o.loop&&current+1==1)?$(o.previousSelector).css('visibility','hidden'):$(o.previousSelector).css('visibility','visible');$this.find(o.nextSelector).click(function(){if(!o.slideTransition){$(sections[current]).hide();current=(current===sections.length-1)?0:current+1;$(sections[current]).show();$this.find(o.counterSelector).text(current+1);(!o.loop&&current+1==1)?$this.find(o.previousSelector).css('visibility','hidden'):$this.find(o.previousSelector).css('visibility','visible');(!o.loop&&current===sections.length-1)?$this.find(o.nextSelector).css('visibility','hidden'):$this.find(o.nextSelector).css('visibility','visible');}else{$(sections[current]).css('width',$(sections[current]).width()).animate({'left':-$(sections[current]).width()},o.slideSpeed,'swing');current=(current===sections.length-1)?0:current+1;$(sections[current]).css({'width':$(sections[current]).width(),'left':$(sections[current]).width()}).show().animate({'left':0},o.slideSpeed,'swing',function(){$this.find(o.counterSelector).text(current+1);(!o.loop&&current+1==1)?$this.find(o.previousSelector).css('visibility','hidden'):$this.find(o.previousSelector).css('visibility','visible');(!o.loop&&current===sections.length-1)?$this.find(o.nextSelector).css('visibility','hidden'):$this.find(o.nextSelector).css('visibility','visible');});}
return false;});$this.find(o.previousSelector).click(function(){if(!o.slideTransition){$(sections[current]).hide();current=(current===0)?sections.length-1:current-1;$(sections[current]).show();$this.find(o.counterSelector).text(current+1);(!o.loop&&current+1==1)?$this.find(o.previousSelector).css('visibility','hidden'):$this.find(o.previousSelector).css('visibility','visible');(!o.loop&&current===sections.length-1)?$this.find(o.nextSelector).css('visibility','hidden'):$this.find(o.nextSelector).css('visibility','visible');}else{$(sections[current]).css('width',$(sections[current]).width()).animate({'left':$(sections[current]).width()},o.slideSpeed,'swing');current=(current===0)?sections.length-1:current-1;$(sections[current]).css({'width':$(sections[current]).width(),'left':-$(sections[current]).width()}).show().animate({'left':0},o.slideSpeed,'swing',function(){$this.find(o.counterSelector).text(current+1);(!o.loop&&current+1==1)?$this.find(o.previousSelector).css('visibility','hidden'):$this.find(o.previousSelector).css('visibility','visible');(!o.loop&&current===sections.length-1)?$this.find(o.nextSelector).css('visibility','hidden'):$this.find(o.nextSelector).css('visibility','visible');});}
return false;});});};$.fn.carousel.defaults={loop:true,slideTransition:false,slideSpeed:300,sectionSelector:'._contents li',nextSelector:'._next',previousSelector:'._previous',counterSelector:'._counter',totalSelector:'._total'};})(jQuery);

// Unordered List Columns
/* @title         UnorderedListColumns
 * @version       1.0
 * @author        Chad Romanski
 * @description   Unordered list column display that allows user to span one unordered list accross multiple columns
 */
(function($){$.fn.listColumns=function(options){var o=$.extend({},$.fn.listColumns.defaults,options);return this.each(function(){$(this).css('position','relative');var unorderdList=$(this);var totalLineHeight=highestColumn=listCount=0;var columnNumber=0;var columnWidth=100/o.numberOfColumns;var tempBreakPoint=Math.round($(unorderdList).find('li').length/o.numberOfColumns);var tempRemainder=$(unorderdList).find('li').length%o.numberOfColumns;if(tempRemainder===1){tempBreakPoint=tempBreakPoint+1;}
for(var listloop=0;listloop<($(unorderdList).find('li').length);listloop++){$(unorderdList).find('li').eq(listloop).css('position','absolute');$(unorderdList).find('li').eq(listloop).css('width',columnWidth+'%');if(listCount!=tempBreakPoint){$(unorderdList).find('li').eq(listloop).css('marginLeft',columnNumber*columnWidth+'%');$(unorderdList).find('li').eq(listloop).css('marginTop',totalLineHeight);totalLineHeight=totalLineHeight+$(unorderdList).find('li').eq(listloop).height();listCount++;}else{columnNumber++;$(unorderdList).find('li').eq(listloop).css('marginLeft',columnNumber*columnWidth+'%');$(unorderdList).find('li').eq(listloop).css("marginTop",0);if(highestColumn<totalLineHeight){highestColumn=totalLineHeight;}
totalLineHeight=0;totalLineHeight=totalLineHeight+$(unorderdList).find('li').eq(listloop).height();listCount=1;}}
if(highestColumn<totalLineHeight){highestColumn=totalLineHeight;}
$(unorderdList).css('height',highestColumn);});};$.fn.listColumns.defaults={numberOfColumns:2};})(jQuery);

// Page Header Photo Pager
/* @title         PageHeaderPhotoPager
 * @version       1.0
 * @author        Chad Romanski
 * @description   Creates a photo pager in the header of the page
 */
(function($){$.fn.headPhotoPager=function(){return this.each(function(){$(this).wrapInner('<div class="images"></div>');var imageCount=$(this).find('div.images img').length;$(this).find('div.images img').eq(0).addClass('on').show();if(imageCount>1){$(this).find('div.images').append('<ul class="control"></ul>');for(var i=0;i<imageCount;i++){var className=(i==0)?'photoOn':'';$(this).find('ul.control').append('<li class="'+className+'"><a href="#">'+(i+1)+'</a></li>');}
$(this).find('ul.control').append('<li class="last-child">&nbsp;</li>');$(this).find('ul.control').click(function(ev){var target=$(ev.target);if(target[0].tagName.toLowerCase()=='a'){var index=$('ul.control li').index(target.parent());$('ul.control li').removeClass('photoOn');$('div.images img.on').removeClass('on').fadeOut("fast",function(){$($('div.images img')[index]).addClass('on').fadeIn("fast");$($('ul.control li')[index]).addClass('photoOn');});return false;}});}});};})(jQuery);


/*
 * Superfish v1.4.1 - jQuery menu widget
 * Copyright (c) 2008 Joel Birch
 *
 * Dual licensed under the MIT and GPL licenses:
 * 	http://www.opensource.org/licenses/mit-license.php
 * 	http://www.gnu.org/licenses/gpl.html
 *
 * CHANGELOG: http://users.tpg.com.au/j_birch/plugins/superfish/changelog.txt
 */
var superfish_iframe;
;(function($){
	$.superfish = {};
	$.superfish.o = [];
	$.superfish.op = {};
	$.superfish.defaults = {
		hoverClass	: 'sfHover',
		pathClass	: 'overideThisToUse',
		delay		: 800,
		animation	: {opacity:'show'},
		speed		: 'normal',
		oldJquery	: false, /* set to true if using jQuery version below 1.2 */
		disableHI	: false, /* set to true to disable hoverIntent usage */
        animate : true,
		// callback functions:
		onInit		: function(){},
		onBeforeShow: function(){},
		onShow		: function(){}, /* note this name changed ('onshow' to 'onShow') from version 1.4 onward */
		onHide		: function(){}
	};
	$.fn.superfish = function(op){
		var bcClass = 'sfbreadcrumb',
			over = function(){
				var $$ = $(this), menu = getMenu($$);
				getOpts(menu,true);
				clearTimeout(menu.sfTimer);
				$$.showSuperfishUl().siblings().hideSuperfishUl();
			},
			out = function(){
				var $$ = $(this), menu = getMenu($$);
				var o = getOpts(menu,true);
				clearTimeout(menu.sfTimer);
				if ( !$$.is('.'+bcClass) ) {
					menu.sfTimer=setTimeout(function(){
						$$.hideSuperfishUl();
						if (o.$path.length){over.call(o.$path);}
					},o.delay);
				}		
			},
			getMenu = function($el){ return $el.parents('ul.superfish:first')[0]; },
			getOpts = function(el,menuFound){ el = menuFound ? el : getMenu(el); return $.superfish.op = $.superfish.o[el.serial]; },
			hasUl = function(){ return $.superfish.op.oldJquery ? 'li[ul]' : 'li:has(ul)'; };

		return this.each(function() {
			var s = this.serial = $.superfish.o.length;
			var o = $.extend({},$.superfish.defaults,op);			
			o.$path = $('li.'+o.pathClass,this).each(function(){
				$(this).addClass(o.hoverClass+' '+bcClass)
					.filter(hasUl()).removeClass(o.pathClass);
			});
			$.superfish.o[s] = $.superfish.op = o;
			
			$(hasUl(),this)[($.fn.hoverIntent && !o.disableHI) ? 'hoverIntent' : 'hover'](over,out)
			.not('.'+bcClass)
				.hideSuperfishUl();
			
			var $a = $('a',this);
			$a.each(function(i){
				var $li = $a.eq(i).parents('li');
				$a.eq(i).focus(function(){over.call($li);}).blur(function(){out.call($li);});
			});
			
			o.onInit.call(this);
			
		}).addClass('superfish');
	};
	
	$.fn.extend({
		hideSuperfishUl : function(){
			var o = $.superfish.op;
			if(o.animate){				
				$ul = $('li.'+o.hoverClass,this).add(this).removeClass(o.hoverClass).find('>ul').hide();
			}else{				
				$ul = $('li.'+o.hoverClass,this).add(this).removeClass(o.hoverClass).find('>ul').hide().css('visibility','hidden');
				o.onHide.call($ul);
			}			
			return this;
		},
		showSuperfishUl : function(){
			var o = $.superfish.op;
			$ul = this.addClass(o.hoverClass).find('>ul:hidden').css('visibility','visible');
			o.onBeforeShow.call($ul);			
			if(o.animate){				
				$ul.show();
			}else{					
				$ul.animate(o.animation,o.speed,function(){ o.onShow.call(this); });
			}			
			return this;
		}
	});
	
	$(window).unload(function(){
		$('ul.superfish').each(function(){
			$('li',this).unbind('mouseover','mouseout','mouseenter','mouseleave');
		});
	});
})(jQuery);