$(function() {
	
	//Old Home push push
	/*
	$('#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) {
			e.preventDefault()
			$(current).next().length 
			    ? ( current = $(current).stop().fadeOut(duration).next().stop().fadeIn(duration) )
			    : ( current = $(current).stop().fadeOut(duration).prevAll().eq(0).stop().fadeIn(duration) )
		    });
	});
	*/
		$('#la-home-push').each(function() {
			var randomnumber=Math.floor(Math.random()*2);
			if (randomnumber > 1) { randomnumber = 1 };
			var previousnumber = $.cookie('previouspush')
			function CheckNumber(num) {
				if ( num == 1 ) {
					num++;
				} else {
					num--;
				}
				return num;
			}
			var pushEls = $('.home-push-item', this);
			if ( randomnumber == previousnumber) {
				if ( previousnumber == 0 ) {
					var newnum = 1;
				}
				if ( previousnumber == 1 ) {
					var newnum = 0;
				}				
			} else {
				var newnum = randomnumber;
			}
			pushEls.hide();
			pushEls.eq(newnum).show().addClass("current-item");
			$('#home-btn-next').click(function(){
				if ( $('.home-push-item:last').hasClass("current-item") ) {
					$(".current-item").fadeOut().removeClass("current-item");
					$('.home-push-item:first').fadeIn().addClass("current-item");
				} else {
					$(".current-item").fadeOut().removeClass("current-item").next().fadeIn().addClass("current-item");
				}
				return false;
			});
			$.cookie('previouspush', newnum);
		});

	
      	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)');
	    });

	    $('ul#nav-primary > li').hoverClass('sfHover');
	    $('ul#nav-utility > li').hoverClass('sfHover');
	}

		   
	// 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 }
		);
		
		$('div#quicklinks h3').sifr(
			{ strSWF: '/flash/sabon-lt-std.swf', strColor: '#154e5e', strWmode: 'transparent', intPadding: [13, 13, 0, 0] },
			{ expressInstall: true }
		);



	//Dropdowm menu
		$("ul#nav-primary li").hover(
			function(){ $("ul", this).show(); }, 
			function(){ } 
		);
		
//Start of expand/collapse of team bios
	$("div.team-member").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").animate({
			height: 'show',
			opacity: 'show'
		}, 'slow');
		// Changes the Text of the Control
		$(this).html("Hide Details");
	}, function() {
		$(this).parents("div.team-member").find("div.bio-long").animate({
			height: 'hide',
			opacity: 'hide'
		}, 'slow');
		// Changes the Text of the Control
		$(this).html("View Details");
	});
//End of expand/collapse for team bios

	//Expand-collapse for event calendar
		$("li.event").each(function() {
	// Div for the Toggler to be Held
	$(this).find("span.description").hide().parent().next().after("<div class=\"event-toggle\" style=\"clear:both;\"><a href=\"#\">Details</a></div>");
	});


// Once the Package Toggler Control is clicked
// Toggle the details and chance the text
	$("div.event-toggle a").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">
		<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"});
	
	
	$(".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;});
});


$.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');
			}
		);
	});

};   
