$(function() {
	$('.package').packagePreview();
	$('.vcalendar').eventPreview();
	$('.share-link').initializeSharing();

	$('#sidebar-tabs-new').accordion({
		header: "a.acc-link",
		fillSpace: true
	}).accordion("activate",2);
	
	
	$("div#flashWrapper").flash({src:"flash/loader.swf?path=flash/home-splash-winter.swf", width:567, height:372, wmode:"transparent", bgcolor:"#FFFFFF", quality:"high"}, {version:"7"});	
	$("div#dhr-logo").flash({src:"http://www.destinationhotels.com/flash/branding/flash_logoDhr-white.swf?link=mountainlodgetelluride", width:250, height:25, wmode:"transparent", allowScriptAccess:"always", quality:"high"}, {version:"7"});
	$("div#tour").flash({src:"flash/gallery.swf", width:500, height:300, wmode:"transparent", quality:"high"}, {version:"7"});	
	$("div#resort-map").flash({src:"flash/map.swf", width:500, height:375, wmode:"transparent", quality:"high"}, {version:"7"});

	$('.link-popup').click(function() {
		var opts = this.rel.split(","),
		strOptions = "width="+opts[1]+",height="+opts[2];
		if (opts.length > 3) {
			for (k = 3; k < opts.length; k++) {
				strOptions += "," + opts[k];
			}
		}
		window.open(this.href,opts[0],strOptions);
		return false;
	});
	
	$('.jqModal').click(function() {
		var li = $(this).parents('li'),
			img = this.href,
			subject = $('.photo-subject', li).text(),
			photog = $('.photo-photog', li).text(),
			attr = this.rel.split(',');
		
		$('#dialog').load('photo-popup.php', { image: img, title: subject, name: photog, id: attr[0], height: attr[1] }, function(data) {
			$('.voter').voter();
			$('#dialog').jqm().jqmShow().jqmAddClose($('.jqmClose'));
			$('.jqmClose').click(function() {
				$('#photo-contest-large').attr('src', '');					  
			});
		});
		return false;
	});
		

	$("ul#nav-primary li").hover(
        function(){ $("ul", this).show(); }, 
        function(){ $("ul", this).hide(); } 
    );
    if (document.all) {
        $("ul#nav-primary li").hoverClass("sfhover");
		/*$("ul#nav-primary li ul li").hoverClass("sfhover");*/
    }
	
	//Shows and hides disclaimer info for photo submission
		$('div.terms').hide();
		$('a.toggle').toggle(function(){
		$(this).parents('li').children('.terms').show();
		 return false;
		},function(){
		$(this).parents('li').children('.terms').hide();
		return false;
		});
		
		
});

(function($) {	
	$.fn.expand = function(options) {
		var defaults = {
			openText: 'View Details',
			closeText: 'Hide Details',
			longClass: '.package-long'
		},
		opts = $.extend(defaults, options);
		return this.each(function() {
			var obj = $(this);
			var tog = $('<span />').addClass('toggle');
			var control = $('<a />').attr('href', '#')
							.addClass('toggler')
							.html(opts.openText)
							.appendTo(tog)
							.toggle(function() { $(opts.longClass, obj).slideDown('slow'); $(this).html(opts.closeText).addClass('open'); },
									function() { $(opts.longClass, obj).slideUp('slow'); $(this).html(opts.openText).removeClass('open'); });
			
			$(opts.longClass, obj).after(tog).hide();
		});
	};

	$.fn.eventPreview = function(options) {
		var defaults = {
			hideDetails : 'Hide Details',
			viewDetails : 'View Details'
		},
		opts = $.extend(defaults, options);
		return this.each(function() {
			$('.view-details').live('click',function(event) {
				event.preventDefault();
				$('.share-panel').hide();
				if ($(this).parent().hasClass('active')) {
					$(this).html(opts.viewDetails).parent().removeClass('active').parent().children('.event-description').slideUp('slow', function() { 
						$(this).html(''); 
					});
				}
				else {
					var el = $(this);
					var temp = this.rel.split(':');
					$.get('/events-calendar-ajax.php', { permalink: temp[0], rssfeed: temp[1], lang: 'en', op: 'details' },function(data) { 
						el.html(opts.hideDetails).parent().addClass('active').parent().children('.event-description').hide().html(data).slideDown('slow');});
				}
			});
		});
	};
	
	$.fn.packagePreview = function(options) {
		var defaults = {
			hideDetails : 'Hide Details',
			viewDetails : 'View Details'
		},
		opts = $.extend(defaults, options);
		return this.each(function() {
			$('.package-details a', this).toggle(function(event) {
				event.preventDefault();
				$('.share-panel').hide();
				var el = $(this);
				$.get('/package-details.php', { package_id: this.id.substr(3), channel: this.rel, lang: 'en' },function(data) { 
					el.html(opts.hideDetails).parent().addClass('active').parent().find('.package-long').hide().html(data).slideDown('slow');
				});
			},function(event) { 
				event.preventDefault();
				$('.share-panel').hide();
				$(this).html(opts.viewDetails).parent().removeClass('active').parent().find('.package-long').slideUp('slow', function() { 
					$(this).html(''); 
				});
			});
		});
	};
	
	$.fn.initializeSharing = function() {
		return this.each(function() {
			$('.share-link').live('click',function(event) {
				event.preventDefault();
				$('.share-panel').hide();
				$(this).parents('.rss-item').find('.share-panel').css('display','inline');
			});
			$('.share-close').live('click',function(event){
				event.preventDefault();
				$(this).parents('.rss-item').find('.share-panel').slideUp('fast');
			});
		});
	};

})(jQuery);

// Function to add/remove "over" class for drop down nav - remove if not needed
$.fn.hoverClass = function(c) {
	return this.each(function(){
		$(this).hover( 
			function() { $(this).addClass(c);  },
			function() { $(this).removeClass(c); }
		);
	});

};  

function mycarousel_initCallback(carousel) {
    jQuery('.jcarousel-control a').bind('click', function() {
        carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
        return false;
    });

    jQuery('.jcarousel-scroll select').bind('change', function() {
        carousel.options.scroll = jQuery.jcarousel.intval(this.options[this.selectedIndex].value);
        return false;
    });

    jQuery('#mycarousel-next').bind('click', function() {
        carousel.next();
        return false;
    });
};

// Ride the carousel...
jQuery(document).ready(function() {
    jQuery("#mycarousel").jcarousel({
        scroll: 1,
		  size: 6,
		  wrap: 'last',
        initCallback: mycarousel_initCallback,		  
        // This tells jCarousel NOT to autobuild prev/next buttons
        buttonNextHTML: null,
        buttonPrevHTML: null
    });
});





