

/* trigger when page is ready */
$(document).ready (function (){
	
	$.ajax({
		type: "GET",
		mimeType: 'text/xml"',
		cache: false,
		url: "jhmrsnowtsatsproxy.ashx",
		dataType: "xml",
		success: function(xml) {
			$( ".daysnow" ).append($(xml).find('snowfall_twenty-four_hour_summit').text() +'"');
			$( ".twodaysnow" ).append($(xml).find('snowfall_forty-eight_hour_mid').text() +'"');
			$( ".snowdepth" ).append($(xml).find('snow_depth_summit').text() +'"');
			$( ".snowfall" ).append($(xml).find('season_total_summit').text() +'"');
		}
	});

	$('#tiles').tiles ({
		tileWidth: 239,
		tileHeight: 213
	});
		
	// Tabs
	$('#tabs').tabs();
		
	// Date Picker
	$( "#datepicker" ).datepicker({
		showOn: "both",
		buttonImage: "/themes/tvs/_/images/icons/calendar.png",
		buttonImageOnly: true,
		currentText: 'Now'
	});
		
	$('.chk_avail_btn').click(function() {
		var mydate = $('#datepicker').val();
		if (mydate != ""){
			
	window.location.href = 'http://www.tetonvillagesports.com/estore/Content/Commerce/Products/DisplayProducts.aspx?ProductGroupCode=227&date='+ encodeURIComponent(mydate);
		} else {
		window.location.href = 'http://www.tetonvillagesports.com/estore/Content/Commerce/Products/DisplayProducts.aspx?ProductGroupCode=227';
		}	
	});
		

	var urlFlickrFeed = 'http://api.flickr.com/services/rest/?format=json&method=flickr.photosets.getPhotos&photoset_id=72157627825427854&api_key=a652087e0a343657d35bb7fb179ff496&jsoncallback=?';
	
	$.getJSON (urlFlickrFeed, function (data) {
		if (data && data.photoset && data.photoset.photo) {
			var countIX = data.photoset.total;
			var myTitle, urlImgLg, urlImg, flickrItem;
			flickrItem = null;

			$.each (data.photoset.photo, function (ix, item) {
				myTitle = item.title;
				urlImg = 'http://farm' + item.farm + '.static.flickr.com/' + item.server + '/' + item.id + '_' + item.secret + '_m.jpg';
				urlImgLg = 'http://farm' + item.farm + '.static.flickr.com/' + item.server + '/' + item.id + '_' + item.secret + '_z.jpg';
				if (ix == (data.photoset.total - 1))
					flickrItem = $('<a class="pop_img" rel="groupP" title ="' + myTitle.replace ('\'', '') + '" href="' + urlImgLg + '" ><img src="' + urlImg + '" alt="" /></a><p>' + myTitle + '</p>');
				else if (ix > (countIX - 5))
					flickrItem = $('<a class="pop_img" rel="groupP" title ="' + myTitle.replace ('\'', '') + '" href="' + urlImgLg + '" ></a>');
				if (flickrItem)
					$(flickrItem).appendTo('#flickr_feed');
			});
		}
		$("#flickr_feed a.pop_img").fancybox();
	});
	
	// You tube feed parser
	var urlYTFeed = 'http://gdata.youtube.com/feeds/base/users/jacksonholemtnresort/uploads?alt=rss&v=2&orderby=published&client=ytapi-youtube-profile';
	$.jGFeed (urlYTFeed, function (feeds) {
		// Check for errors
		if (!feeds) {
			// there was an error
			return false;
		}
		var html = '';
		for (var i=0; i<feeds.entries.length; i++) {
			var entry = feeds.entries[i];
			embedurl = entry.link.replace("watch?v=","embed/");
			embedurl = embedurl.replace("&feature=youtube_gdata","?autoplay=1");
			html += '<a class="pop_vid iframe" href="' + embedurl + '" title="' + entry.title + '"><img src="' + $.jYoutube(entry.link, 'med') + '" class="thumb left"></a>';
		}

		
		$('#you_tube_feed').html(html);
		
		$("a.pop_vid").fancybox({
			'width'				: '75%',
			'height'			: '75%',
			'autoScale'			: false,
			'transitionIn'		: 'elastic',
			'transitionOut'		: 'fade',
			'type'				: 'iframe'
		});
		
	}, 1);
 
});

