$(function(){
	//  Navigation Current Page Styling //
	var currentSectionParents = $("#section_nav a.currentPage").parents();
	var sectionNavDivIndex = currentSectionParents.index($("#section_nav"));
	var rest = currentSectionParents.slice(0, sectionNavDivIndex);
	rest.addClass("currentPath");

	$("#our-place-on-the-prairie a:eq(0)").attr('id', 'our-place-on-the-prairieButton');
	$("#create-space a:eq(0)").attr('id', 'create-spaceButton');
	$("#helping-houses a:eq(0)").attr('id', 'helping-housesButton');
	$("#kidstreet a:eq(0)").attr('id', 'kidstreetButton');
	$("#cmsd-outdoors a:eq(0)").attr('id', 'cmsd-outdoorsButton');
	$("#water-farm a:eq(0)").attr('id', 'water-farmButton');
	$("#mini-explorers a:eq(0)").attr('id', 'mini-explorersButton');
	
	Cufon.replace('#menu_bar li', { fontFamily: 'Gotham Rounded Medium' } );
	Cufon.replace('#homeblocks li', { fontFamily: 'Gotham Rounded Book' } );
	Cufon.replace('#homeblocks li strong', { fontFamily: 'Gotham Rounded Medium' } );
	Cufon.replace('#homepagecontent h3', { fontFamily: 'Gotham Rounded Book' } );
	Cufon.replace('#homepagecontent h4 ', { fontFamily: 'Gotham Rounded Book' } );
	Cufon.replace('.button a', { fontFamily: 'Gotham Rounded Medium' } );
	Cufon.replace('#newsbox h3 ', { fontFamily: 'Gotham Rounded Book' } );
	Cufon.replace('.graybox h3, .sectiongraybox h3 ', { fontFamily: 'Gotham Rounded Book' } );
	Cufon.replace('h3 ', { fontFamily: 'Gotham Rounded Medium' } );
	Cufon.replace('.slide h1, .slide p', { fontFamily: 'Gotham Rounded Book' } );
	Cufon.replace('#interiorHeader h1', { fontFamily: 'Gotham Rounded Book' } );
	Cufon.replace('p.callout', { fontFamily: 'Gotham Rounded Book' } );
	Cufon.replace('#section_nav li', {hover: true} );
	
	// these both fail in ie8
	if(!$.browser.msie && !jQuery.browser.version == 8){
		Cufon.replace('#yahoo_menu_bar li.yuimenuitem a', {hover: true} );
		Cufon.replace('#yahoo_menu_bar a', { fontFamily: 'Gotham Rounded Medium' } );
	}
	
	Cufon.replace('#yahoo_menu_bar li.what-you-ll-experience_yuimenubaritem li a', {hover: true} );	
	Cufon.replace('#section_nav li.navButton', { fontFamily: 'Gotham Rounded Book' } );
	Cufon.replace('#section_nav ul ul li a', { fontFamily: 'Verdana' } );
	
	Cufon.replace('#leftColumn h1, #leftColumn h2, .section #content #wrapper h2', { fontFamily: 'Gotham Rounded Book' } );
	
	Cufon.replace('.graybox h3', { fontFamily: 'Gotham Rounded Book' } );
	Cufon.replace('.calendar h2, #search_news h2', { fontFamily: 'Gotham Rounded Book' } );
	
	
	// // sifr replacements for the above. one by one.
	// var gothamRoundedBook = {
	//       src: '/media/swf/gothamRoundedBook.swf'
	//     };
	//     sIFR.activate(gothamRoundedBook);
	// sIFR.replace(gothamRoundedBook, {
	// 	selector: '#leftColumn h2',
	// 	css: '.sIFR-root { font-size: 21px;line-height: 32px !important;font-weight: normal;color: #666;margin-bottom: 10px !important;}'
	// });
	// 
	// sIFR.replace(gothamRoundedBook, {
	// 	selector: '#leftColumn h1',
	// 	css: '.sIFR-root { font-size: 44px;font-weight: normal;color: #317344;margin: 0px 0px 0px 0px;}'
	// });
	
	
	if ($.browser.msie && $.browser.version == 6) {
		DD_belatedPNG.fix(
			[
				'#navigation',
				'.green',
				'.green span',
				'.blue',
				'.blue span',
				'.orange',
				'.orange span',
				'#bgwrapper',
				'.calendar #bgwrapper',
				'#footer',
				'#secondarynav li.weather',
				'#section_nav a span',
				'li#stuff-for_yuimenubaritem .yuimenubaritemlabel',
				'li#stuff-for_yuimenubaritem div.yuimenu'
			].join(', ')
		);
	}

	$(".image_with_caption").each(function(){
		var margin_right = ($(this).width() - $(this).find('img').width());
		$(this).find('.caption').css('margin-right', margin_right);
	});
	
	// preload nav images
	$.each([
		'/media/img/hover-about.gif',
		'/media/img/selected-about.gif',
		'/media/img/hover-visit.gif',
		'/media/img/selected-visit.gif',
		'/media/img/hover-experience.gif',
		'/media/img/selected-experience.gif',
		'/media/img/hover-happen.gif',
		'/media/img/selected-happening.gif',
		'/media/img/hover-happen.gif',
		'/media/img/selected-happening.gif',
		'/media/img/hover-support.gif',
		'/media/img/selected-support.gif',
		'/media/img/hover-community.gif',
		'/media/img/selected-community.gif'
	], function(i,image){
		var img = new Image();
		img.src = image;
	});
	
	/* YUI Menu 

	-----------------------------------------------------------------------------*/

	//	Instantiate a MenuBar, passing in the id of the HTML element 
	//	representing the MenuBar.

	var mozilla_menu_bar = new YAHOO.widget.MenuBar('yahoo_menu_bar', {
		autosubmenudisplay: true,
		showdelay: 0,
		hidedelay: 250,
		iframe: false,
		lazyload: false,
		monitorresize: false,
		position: 'absolute',
		appendtodocumentbody: true,
		keepopen: true
	});
	
	function onShow(p_sType, p_aArgs) {
		// check to see if this is a submenu, or toplevel menu
		if(this.parent){
			YAHOO.util.Dom.setStyle('yui-gen0', 'left', '-286px');
			YAHOO.util.Dom.setStyle('yui-gen0', 'top', '69px');
			YAHOO.util.Dom.setStyle('yui-gen1', 'left', '-286px');
			YAHOO.util.Dom.setStyle('yui-gen1', 'top', '69px');
			YAHOO.util.Dom.setStyle('yui-gen2', 'left', '-286px');
			YAHOO.util.Dom.setStyle('yui-gen2', 'top', '69px');
			YAHOO.util.Dom.setStyle('yui-gen3', 'left', '-286px');
			YAHOO.util.Dom.setStyle('yui-gen3', 'top', '69px');
			YAHOO.util.Dom.setStyle('yui-gen4', 'left', '-286px');
			YAHOO.util.Dom.setStyle('yui-gen4', 'top', '69px');
			YAHOO.util.Dom.setStyle('yui-gen5', 'left', '-286px');
			YAHOO.util.Dom.setStyle('yui-gen5', 'top', '69px');
		}else{
			//don't hide when clicking the toplevel menus
		}
		Cufon.refresh();
	}
	function onHide(p_sType, p_aArgs) {  
        Cufon.refresh();
    }
 
    // Subscribe to the "show" and "hide" events
 
    mozilla_menu_bar.subscribe("hide", onHide);
    
	mozilla_menu_bar.subscribe("show", onShow);

	YAHOO.util.Event.on(window, "focus", function() {
		mozilla_menu_bar.hide();
		mozilla_menu_bar.show();
	});
	
	mozilla_menu_bar.subscribe('beforeShow', function(m,p){
		// don't show the submenu of if we are on a section page
		if ('_oAnchor' in this.parent && $(this.parent._oAnchor).hasClass('currentSection') && $(this.parent._oAnchor).hasClass('currentPage') && $(this.parent._oAnchor).parent()[0].id == 'what-you-ll-experience_yuimenubaritem') {
			this.destroy(); // removes the submenu from the experience section
			return false;
		}
	});

	// add "clicked" class to the menubaritem we click, to enable a clicked state we can style with css
	mozilla_menu_bar.subscribe('click', function(type,el){
		var el = el[1];
		if ('_oAnchor' in el && $(el._oAnchor).hasClass('section')) {
			$(el._oAnchor).addClass('clicked');
		}
	});
	mozilla_menu_bar.render();
  // scroller.sinescroll(".bounce");
  // sinePlayer();
	//$('#conditions').css('padding-left', $('.bounce').width());
});
var sinePlayer = function(){
  scroller.step();
  setTimeout(sinePlayer, 20);
}
function weather_styles(o){
	var myCond;
	var cond = o.query.results.channel.item.condition.code;

	if(cond == 32){  myCond = "sunny" }; 
	if(cond == 34){  myCond = "sunny" }; 
	if(cond == 36){  myCond = "sunny" };
	if(cond == 3200){  myCond = "sunny" }; 
	if(cond == 1){  myCond = "stormy" }; 
	if(cond == 2){  myCond = "stormy" }; 
	if(cond == 3){  myCond = "stormy" }; 
	if(cond == 4){  myCond = "stormy" }; 
	if(cond == 17){  myCond = "stormy" }; 
	if(cond == 35){  myCond = "stormy" }; 
	if(cond == 37){  myCond = "stormy" }; 
	if(cond == 38){  myCond = "stormy" }; 
	if(cond == 39){  myCond = "stormy" }; 
	if(cond == 45){  myCond = "stormy" }; 
	if(cond == 47){  myCond = "stormy" }; 
	if(cond == 7){  myCond = "snowy" }; 
	if(cond == 13){  myCond = "snowy" }; 
	if(cond == 14){  myCond = "snowy" }; 
	if(cond == 15){  myCond = "snowy" }; 
	if(cond == 16){  myCond = "snowy" }; 
	if(cond == 18){  myCond = "snowy" }; 
	if(cond == 41){  myCond = "snowy" }; 
	if(cond == 42){  myCond = "snowy" }; 
	if(cond == 43){  myCond = "snowy" }; 
	if(cond == 46){  myCond = "snowy" }; 
	if(cond == 5){  myCond = "rainy" }; 
	if(cond == 6){  myCond = "rainy" }; 
	if(cond == 8){  myCond = "rainy" }; 
	if(cond == 9){  myCond = "rainy" }; 
	if(cond == 10){  myCond = "rainy" }; 
	if(cond == 11){  myCond = "rainy" }; 
	if(cond == 12){  myCond = "rainy" }; 
	if(cond == 40){  myCond = "rainy" }; 
	if(cond == 0){  myCond = "windy" }; 
	if(cond == 23){  myCond = "windy" }; 
	if(cond == 24){  myCond = "windy" }; 
	if(cond == 19){  myCond = "cloudy" }; 
	if(cond == 20){  myCond = "cloudy" }; 
	if(cond == 21){  myCond = "cloudy" }; 
	if(cond == 22){  myCond = "cloudy" }; 
	if(cond == 25){  myCond = "cloudy" }; 
	if(cond == 26){  myCond = "cloudy" }; 
	if(cond == 28){  myCond = "cloudy" }; 
	if(cond == 30){  myCond = "cloudy" }; 
	if(cond == 44){  myCond = "cloudy" }; 
	if(cond == 27){  myCond = "night" }; 
	if(cond == 29){  myCond = "night" }; 
	if(cond == 31){  myCond = "night" }; 
	if(cond == 33){  myCond = "night" };
	
	var temp = o.query.results.channel.item.condition.temp;
	
	$('body').addClass(myCond);
	$("#secondarynav .weather").text(myCond);
	$('#tempjs').html(temp+'&deg;');
	$('#condition').append(" "+myCond);
	
	$('#yahoo_menu_bar ul li a.yuimenubaritemlabel').click(function(){
		$(this).addClass('yuimenubaritemlabel-selected');
		$(this).next().css({visibility: 'visible', top: '69px', left: '-286px'});
	});
}
