window.console.log("hello world");
var JQ = jQuery.noConflict();



JQ(document).ready( function () {

	var cd = new Date();

	var feedURL = "/sportswear/global/jsp/clearspaceServiceProxy.jsp?url=" +

		// The url for the feed you want to pull in

		nsw_data.blog_base_url + "/blogs/sportswear-" + nsw_data.blog_locale + "/feeds/tags/features_sidebar" +

		"&eventDateRangeMinMillis=" + Date.parse((cd.getMonth() + 1) + '/' + (cd.getDate() + 1) + '/' + cd.getFullYear()) +

		"&eventDateRangeMaxMillis=" + Date.parse((cd.getMonth() + 1) + '/' + cd.getDate() + '/' + (cd.getFullYear() + 1));

	var events = new Array();

	

	JQ.ajax({

		type:		"GET",

		url:		feedURL,

		dataType:	"xml",

		success:	function (xml) {

			var counter = 0;

			JQ(xml).find("item").each( function () {

				events[counter] = {

					title:		JQ(this).find("title").text(),

					date:		JQ(this).find("clearspace\\:eventDate").text(),

					thumbnail:	JQ(this).find("media\\:content").find("media\\:thumbnail").attr("url"),

					image:		"none",

					tag:		"",

					guid:		blogURL(nsw_data.view_post_link(JQ(this).find("guid").text()))

				};

				if (events[counter].date == ""		|| events[counter].date == null)		events[counter].date		= JQ(this).find("eventDate").text();

				if (events[counter].thumbnail == ""	|| events[counter].thumbnail == null)	events[counter].thumbnail	= JQ(this).find("content").find("thumbnail").attr("url");

				if (events[counter].image == ""		|| events[counter].image == null)		events[counter].image		= JQ(this).find("content").attr("url");

				

				// FIREFOX VERSION

				JQ(this).find("content").each( function () {

					if (JQ(this).find("thumbnail").length == 0) {

						events[counter].image = JQ(this).attr("url");

					}

				});

				JQ(this).find("category").each( function () {

					switch (JQ(this).text()) {

						case "news":

							events[counter].tag = getLocal("News");

							break;

						case "events":

							events[counter].tag = getLocal("Events");

							break;

						case "productdrops":

							events[counter].tag = getLocal("Product Drops");

							break;

						case "stories":

							events[counter].tag = getLocal("Stories");

							break;

					}

				});

				// IE VERSION

				JQ(this).find("media\\:content").each( function () {

					if (JQ(this).find("media\\:thumbnail").length == 0) {

						events[counter].image = JQ(this).attr("url");

					}

				});

				counter++;

			});

		},

		complete:	function () {

			if (events.length >= 1) {

				for (var i = 0; i < events.length && i < 2; i++) {

					JQ("#side-articles").append(

						'<div class="side-post">' +

							'<div class="date">' +

								'<span>' + getLocal(events[i].tag) + '</span>' +

								dateToNumbers(events[i].date.substring(5, 16)) +

							'</div>' +

							'<h1><a href="' + events[i].guid + '">' + events[i].title + '<img src="' + nsw_data.resize_img(events[i].image, 155, 276) + '" alt="'+events[i].title+'" title="'+events[i].title+'" /></a></h1>' +

						'</div>'

					);

				}

			}

		},

		error:		function () {

		}

	});

	var feedURL = "/sportswear/global/jsp/clearspaceServiceProxy.jsp?url=" +

		// The url for the feed you want to pull in

		nsw_data.blog_base_url + "/blogs/sportswear-" + nsw_data.blog_locale + "/feeds/tags/features_hero";

	JQ.ajax({

		type:		"GET",

		url:		feedURL,

		dataType:	"xml",

		success:	function (xml) {



			// FIREFOX VERSION

			JQ(xml).find("item:first").find("content").each( function () {

				if (JQ(this).find("thumbnail").length == 0) {
					if(JQ(this).attr("url").match(/swf$/)) {
						var swfSource = JQ(this).attr("url");
						JQ("#top-image .hidden-container a").replaceWith(
							'<embed width="908" height="510" flashvars="locale='+ nsw_data.video_region +'" wmode="transparent" allowfullscreen="true" allowscriptaccess="always" scale="noscale" quality="high" bgcolor="#ffffff" name="feature" id="feature" style="" src="'+ swfSource +'" type="application/x-shockwave-flash"/>'
						);
					} else {
						JQ("#top-image img").attr("src", JQ(this).attr("url"));
					}

				}

			});

			JQ("#top-image img").attr("alt", JQ(xml).find("item:first").find("title").text());

			JQ("#top-image img").attr("title", JQ(xml).find("item:first").find("title").text());

			// IE VERSION

			JQ(xml).find("item:first").find("media\\:content").each( function () {

				if (JQ(this).find("media\\:thumbnail").length == 0) {
					if(JQ(this).attr("url").match(/swf$/)) {
						var swfSource = JQ(this).attr("url");
						JQ("#top-image .hidden-container a").replaceWith(
							'<embed width="908" height="510" flashvars="locale='+ nsw_data.video_region +'" wmode="transparent" allowfullscreen="true" allowscriptaccess="always" scale="noscale" quality="high" bgcolor="#ffffff" name="feature" id="feature" style="" src="'+ swfSource +'" type="application/x-shockwave-flash"/>'
						);
					} else {
						JQ("#top-image img").attr("src", JQ(this).attr("url"));
					}

				}

			});

			JQ("#top-image h1").text("");

			JQ("#top-image h1").text(JQ(xml).find("item:first").find("title").text());

			JQ("#top-image a").attr("href", blogURL(nsw_data.view_post_link(JQ(xml).find("item:first").find("guid").text())));

			if (!JQ("#top-image img").attr("src")) JQ("#top-image img").attr("src", "/sportswear/global/images/080808.jpg");
			
		},

		complete:	function () {

			JQ("#top-image img, #top-image .hidden-container").show();

		}

	});

});
