  $(function() {

	$('.package').packagePreview();

	$('body:not(.blog)').each(function() {
	    $('.share-link').initializeSharing();
	    //$('.vcalendar').eventPreview();
	});

	if ( location.href.indexOf('debugger') != -1 ) {
	    $('<div id="debugger"></div>').appendTo('body')
	    $('<iframe/>').attr('src', 'javascript:false').attr('id', 'debugger-shim').appendTo('body')
	    $('<form id="console-form"><textarea name="text" id="console-input"></textarea><input type="submit" value="Run"/></form>').appendTo('#debugger');
	    $('<ol/>').appendTo('#debugger');
	    $('#console-form').submit(function(e) {
		e.preventDefault()
		eval( $('#console-input').val() );
	    });
	}

	window.log = function( msg ) {
	    if ( window.console && console.log ) {
		console.log( msg )
	    }

	    if ( $('#debugger').length ) {
		$('#debugger ol').append( $('<li/>').text( msg ) );
	    }
	}

      	var ie6 = /*@cc_on!@*/false && !window.XMLHttpRequest;
	
	if ( ie6 ) {

	    $(document).pngFix({
		blankgif:'/images/blank.gif'
	    });
	    
	    $('#logo, #nav-primary > li > a, #nav-utility a, #push-gift, #push-photo, #home-btn-next').each(function() {
		$(this).css('background-image', 'url(/images/blank.gif)');
	    });
	}

	/*
	// Old homepage push - keeping just in case
	$('#la-home-push').each(function() {
	    var pushEls = $('.home-push-item', this),
		first = current = window.current = $(pushEls).eq(0),
		rest = $(first).nextAll().hide(),
		duration = 450, // ms
		button = $('#home-btn-next')
		    .click(function(e) {
			window.a = current;
			e.preventDefault()
			$(current).next().length 
			    ? ( current = $(current).stop().fadeOut(duration).next().stop().fadeIn(duration) )
			    : ( current = $(current).stop().fadeOut(duration).prevAll('div.home-push-item:last').stop().fadeIn(duration) )
			window.b = current;
		    });
	});*/
	
	$('a.pop-up').click( function () {
		var pLink = this.href;
		window.open( pLink,'PopUp','width=680,height=610, scrollbars=yes')
		return false;
		});
	
	$("div#vtour").each(function() {
		var file = $(this).attr("class");
		$(this).flash(
			{src:"/vt/PurePlayer.swf",
			 width:640,
			 height:480,
			 wmode:"transparent",
			 quality:"high"},
			 {version:"9"},
				function(htmlOptions) { //Use this to specify a query string, take out if not needed.
					htmlOptions.flashvars.panorama = "vt/"+file+".ivp";
					$(this).html($.fn.flash.transform(htmlOptions));
				}
		);
	 });
	
	// Spa Appointment Request
		$('#spa-service1').change(function() {
			$('#options').css('visibility','hidden').before('<span>loading services...</span>');
			$.get('treatment-list.php', {cat_id:$(this).val()},function(data) { $('#options').html(data);$('#options').css('visibility','visible').prev().remove(); });
		});

	// Sifr
	
		$('div#headers h2').sifr(
			{ strSWF: '/flash/sabon-lt-std.swf', strColor: '#ffffff', strWmode: 'transparent' },
			{ expressInstall: true }
		);
		
		$('div#newsletter-headers h2').sifr(
			{ strSWF: '/flash/mrs-eaves-smallcaps.swf', strColor: '#B07D54', strLinkColor: '#B07D54', strHoverColor: '#B07D54', strWmode: 'transparent', intPadding: [0, 10, 0, 0] },
			{ expressInstall: true }
		);

		$('div#headers h3').sifr(
			{ strSWF: '/flash/gill-sans.swf', strColor: '#ffffff', strWmode: 'transparent', strCase: 'upper' },
			{ expressInstall: true }
		);

		$('body.brochure div#content h4').sifr(
			{ strSWF: '/flash/gill-sans.swf', strColor: '#5191a3', strWmode: 'transparent', strCase: 'upper' },
			{ expressInstall: true }
		);
		
		$('div#quicklinks h3').sifr(
			{ strSWF: '/flash/sabon-lt-std.swf', strColor: '#154e5e', strWmode: 'transparent', intPadding: [13, 13, 0, 0] },
			{ expressInstall: true }
		);

/* Interior pages share button */
	$("#share-interior-wrapper").each( function() {
		var x = $(this);
		$(".share-panel").css({left:"73px", top:"305px"});
		$("#share-btn-interior a", x).click( function() {
			$("#share-panel-interior", x).slideDown();
			return false;
		});
		$("a.share-close-interior", x).click( function () {
			$("#share-panel-interior", x).slideUp();
			return false;
		});
	});


	//Dropdowm menu
		$("ul#nav-primary li").hover(
			function(){ $("ul", this).show(); }, 
			function(){ } 
		);
		
		if ( ie6 ) {
		     $('ul#nav-primary > li').hoverClass('sfHover');
		     $('ul#nav-utility > li').hoverClass('sfHover');
		}
		
//Start of expand/collapse of team bios
	$("div.team-member").not('.no-js').each(function() {
								   
	// Div for the Toggler to be Held
	$(this).append("<div class=\"bio-toggle\" style=\"clear:right;\">");

		// If this is a package that is going to be expanded
		// add a control for it
		if( $(this).is(".team-member") ) {
			// Since this is expandable hide the details
			$(this).find("div.bio-long").hide();
			// Add the Control
			$(this).find(".bio-toggle").append("<a href=\"#\">View Details</a>");
		}
	});


// Once the Package Toggler Control is clicked
// Toggle the details and chance the text
	$("div.bio-toggle a").toggle(function() {
		$(this).parents("div.team-member").find("div.bio-long").show();
		// Changes the Text of the Control
		$(this).html("Hide Details");
	}, function() {
		$(this).parents("div.team-member").find("div.bio-long").hide();
		// Changes the Text of the Control
		$(this).html("View Details");
	});
//End of expand/collapse for team bios


// Once the Package Toggler Control is clicked
// Toggle the details and chance the text
	$("a.view-details").not('.specials').toggle(function() {
		$(this).parents("li.event").find(".description").animate({
			height: 'show',
			opacity: 'show'
		}, 'slow');
		// Changes the Text of the Control
		$(this).html("Close");
	}, function() {
		$(this).parents("li.event").find(".description").animate({
			height: 'hide',
			opacity: 'hide'
		}, 'slow');
		// Changes the Text of the Control
		$(this).html("Details");
	});

//end of expand collapse for calendar
 
		   
// Sample usage of jquery.flash plugin - remove if not needed
	/*	If given the following markup:

	<div id="masthead-wrapper">
		<img src="images/mastheads/flash-alt.jpg" alt="" /><br />
	</div>
	
	you would use the following to replace the alternate content:*/
	$("div#home-flash").flash(
		{src:"/flash/hp-masthead.swf",
		 width:620,
		 height:329,
		 wmode:"transparent",
		 quality:"high"},
		 {version:"7"});
	
	$("div#epostcard").flash(
		{src:"/epostcard/postcard.swf?xmlCategory=epostcard/postcard_xml.php",
		 width:490,
		 height:430,
		 wmode:"transparent",
		 quality:"high"},
		 {version:"7"});
	$("div#map-flash").flash(
		{src:"/flash/map.swf",
		 width:576,
		 height:375,
		 wmode:"transparent",
		 quality:"high"},
		 {version:"7"});
	
	
	$(".photo-window").click(function() {window.open($(this).attr("href"), 'newWin', 'scrollbars=no,resizable=no,status=no,toolbar=no,location=no,width=490,height=430'); return false;});
	$(".popup-window").click(function() {window.open($(this).attr("href"), 'newWin', 'scrollbars=yes,resizable=yes,status=no,toolbar=no,location=no,width=680,height=430'); return false;});

	$('.styleswitch').click(function()
	{
		switchStylesheet($(this).attr("rel"));
		window.print();
		return false;
	});

//styles for send-to-friend.php form -- Add a Friend
	var i = 0;
			$('p#add-friend').click(function() {
				i++;
				$('p#add-friend').before('<br /><div class="field">\n\
				<label for="to_name[]"class="required">Name*</label>\n\
				<input type="text" name="to_name[]" id="to_name[]" maxlength="100" class="textfield required" />\n\
				</div>\n\
				<div class="field">\n\
				<label for="to_email[]" class="required">Email*</label>\n\
				<input type="text" name="to_email[]" id="to_email[]" maxlength="100" class="textfield email required" />\n\</div>');
				if (i>=4) {
				$('p#add-friend').remove();
				}
			});

	$('body.spa-team').each(function() {
	    var hash = location.hash;
	    if ( hash.length ) {
		$(window).load(function() {
		    $.scrollTo( hash );
		});
	    }
	});

});

//stylesheet switcher for driving directions
function switchStylesheet(sheet) {
	$('link[rel*=style][title]').each(function() {
			$(this).attr('disabled', true);
			if ($(this).attr('title') == sheet) {
				$(this).attr('disabled', false);
			}
	});
}

// Function to add/remove "over" class for drop down nav - remove if not needed
$.fn.hoverClass = function(c) {
	return this.each(function(i,o){
	    var primary = $(o).parent().is('#nav-primary');
		$(this).hover( 
			function() { 
			    $(this).addClass(c);
			    $(this).find('a').css('visibility', 'visible');
			},
			function() { 
			    $(this).removeClass(c);
			    $(this).find('a').css('visibility', 'hidden');
			}
		);
	});

};   

	$.fn.eventPreview = function(options) {
		var defaults = {
			hideDetails : 'Close',
			viewDetails : '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')) {
				    log('if');
					$(this).html(opts.viewDetails).parent().removeClass('active').parent().children('.event-description').slideUp('slow', function() { 
						$(this).html(''); 
					});
				}
				else {
					var el = $(this);
					var temp = $(this).attr('rel').split(':');
					log(temp)
					$.get('/direct/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.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');
			});
		});
	};

	$.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) {
			    $(this).addClass('hide-details-special')
				event.preventDefault();
				$('.share-panel').hide();
				var el = $(this);
				$.get('/direct/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) { 
			    $(this).addClass('view-details-special')
				event.preventDefault();
				$('.share-panel').hide();
				$(this).html(opts.viewDetails).parent().removeClass('active').parent().find('.package-long').slideUp('slow', function() { 
					$(this).html(''); 
				});
			});
		});
	};

