// JavaScript Document
var currSocialTab = 'youtube';
var currYoutubeInd = 0;
var currFlickrInd = 0;

jQuery(window).ready(function(){
	if (document.getElementById('socialHub')) {		
		// Prep Overlay
		$('#lightboxOverlay > .bg').css('opacity', 0.7);
		$('#lightboxOverlay').css('height', $(document).height()+'px');
		
		$('#lightboxOverlay > .container > .closeBtn > a').click(
			function() {
				$('#lightboxOverlay').css('display', 'none');
				$('#youtubeOverlayContent > .videoPlayer > iframe').attr('src', '');
				$('#flickrOverlayContent > .imageContainer > img').attr('src', '');
			}
		);
		
		$('#lightboxOverlay > .bg').click(
			function() {
				$('#lightboxOverlay').css('display', 'none');
				$('#youtubeOverlayContent > .videoPlayer > iframe').attr('src', '');
				$('#flickrOverlayContent > .imageContainer > img').attr('src', '');
			}
		);
		
		// Nav Tab
		$('#socialHub > .navTab > a').click(
			function() {				
				var previewID = $(this).attr('id');
				previewID = previewID.replace("nav", "").toLowerCase();
				currSocialTab = previewID;
				
				// SHOW TAB
				if (previewID != 'youtube') {
					$('#youtube').css('display', 'none');
					$('#navYoutube').removeClass('selected');
				}
				
				if (previewID != 'facebook') {
					$('#facebook').css('display', 'none');
					$('#navFacebook').removeClass('selected');
				}
				
				if (previewID != 'flickr') {
					$('#flickr').css('display', 'none');
					$('#navFlickr').removeClass('selected');
				}
				
				if (previewID != 'twitter') {
					$('#twitter').css('display', 'none');
					$('#navTwitter').removeClass('selected');
				}
				
				if (previewID != 'blog') {
					$('#blog').css('display', 'none');
					$('#navBlog').removeClass('selected');
				}
				// END SHOW TAB
				
				// CHANGE TAB CONTENT
				if (previewID == 'youtube' || previewID == 'flickr') {
					$('#socialHub > .content').css('display', 'block');
					$('#socialHub > .blogContent').css('display', 'none');
					
					if (previewID == 'youtube') {
						$('#socialHub > .content > .cta > a').html('SUBSCRIBE');
						
						$('#socialHub > .content').html("");
						
						try {
							var tempObj = youtubeVideos[currYoutubeInd];
								
							var contentText = "<h1>" + tempObj.Title + "</h1>";
							
							if (tempObj.Desc.length > 300) {
								contentText += "<p>" + tempObj.Desc.substring(0, 300) + "......</p>";
							}
							else {
								contentText += "<p>" + tempObj.Desc + "</p>";
							}
							
							contentText += '<p class="cta"><a href="http://www.youtube.com/subscription_center?add_user=travelontariocanada" target="_blank">SUBSCRIBE</a></p>';
							
							$('#socialHub > .content').html(contentText);
						}
						catch (err) {}
					}
					
					if (previewID == 'flickr') {
						$('#socialHub > .content > .cta > a').html('FOLLOW');
						
						$('#socialHub > .content').html("");
						
						try {
							var tempObj = flickrPictures[currFlickrInd];
								
							var contentText = "<h1>" + tempObj.title + "</h1>";
	
							if (tempObj.desc.length > 300) {
								contentText += "<p>" + tempObj.desc.substring(0, 300) + "......</p>";
							}
							else {
								contentText += "<p>" + tempObj.desc + "</p>";
							}
							
							contentText += '<p class="cta"><a href="http://www.flickr.com/groups_join.gne?id=1574784@N25" target="_blank">FOLLOW</a></p>';
							
							$('#socialHub > .content').html(contentText);
						}
						catch (err) {}
					}
				}
				else {
					$('#socialHub > .content').css('display', 'none');
					$('#socialHub > .blogContent').css('display', 'none');
					
					if (previewID == 'blog') {
						$('#socialHub > .blogContent').css('display', 'block');
					}
				}
				// END CHANGE TAB CONTENT
				
				$('#'+previewID).css('display', 'block');
				$(this).addClass('selected');
			}
		);
		
		// Feed Scroll
		$('#socialHub > .preview > .container > .navDown > a').click(
			function() {
				var maxHeight = $('#' + currSocialTab + ' > .feedMask > .feeds').height();
				var maskHeight = $('#' + currSocialTab + ' > .feedMask').height();
				
				if (maxHeight > maskHeight) {
					var currTop = $('#' + currSocialTab + ' > .feedMask > .feeds').css("top");
					currTop = currTop.replace("px", "");					
					currTop = parseInt(currTop);
					
					currTop -= 100;
					
					if (currTop + maxHeight < maskHeight) {
						currTop = maskHeight - maxHeight;
					}
					
					$('#' + currSocialTab + ' > .feedMask > .feeds').stop().animate({top:currTop}, 750, function(){});
				}
			}
		);
		
		$('#socialHub > .preview > .container > .navUp > a').click(
			function() {
				var maxHeight = $('#' + currSocialTab + ' > .feedMask > .feeds').height();
				var maskHeight = $('#' + currSocialTab + ' > .feedMask').height();
				
				if (maxHeight > maskHeight) {
					var currTop = $('#' + currSocialTab + ' > .feedMask > .feeds').css("top");
					currTop = currTop.replace("px", "");					
					currTop = parseInt(currTop);
					
					currTop += 100;
					
					if (currTop > 0) {
						currTop = 0;
					}
					
					$('#' + currSocialTab + ' > .feedMask > .feeds').stop().animate({top:currTop}, 750, function(){});
				}
			}
		);
		
		// Thumbnail Scroll
		$('#socialHub > .preview > .container > .thumbnails > .navRight > a').click(
			function() {
				var maxWidth = $('#' + currSocialTab + ' > .thumbnails > .thumbMask > .thumbContainer').width();
				var maskWidth = $('#' + currSocialTab + ' > .thumbnails > .thumbMask').width();

				if (maxWidth > maskWidth) {
					var currLeft = $('#' + currSocialTab + ' > .thumbnails > .thumbMask > .thumbContainer').css("left");
					currLeft = currLeft.replace("px", "");					
					currLeft = parseInt(currLeft);
									
					currLeft = (Math.ceil(Math.abs(currLeft)/298)+1) * 298 * -1;
					
					//currLeft -= 298;

					if (currLeft < (0 - maxWidth + maskWidth)) {
						currLeft = (0 - maxWidth + 298);
					}
					
					$('#' + currSocialTab + ' > .thumbnails > .thumbMask > .thumbContainer').stop().animate({left:currLeft}, 750, function(){});
				}
			}
		);
		
		$('#socialHub > .preview > .container > .thumbnails > .navLeft > a').click(
			function() {
				var maxWidth = $('#' + currSocialTab + ' > .thumbnails > .thumbMask > .thumbContainer').width();
				var maskWidth = $('#' + currSocialTab + ' > .thumbnails > .thumbMask').width();
				
				if (maxWidth > maskWidth) {
					var currLeft = $('#' + currSocialTab + ' > .thumbnails > .thumbMask > .thumbContainer').css("left");
					currLeft = currLeft.replace("px", "");
					currLeft = parseInt(currLeft);
					
					currLeft = (Math.round(Math.abs(currLeft)/298)-1) * 298 * -1;
					
					//currLeft += 298;
					
					if (currLeft > 0) {
						currLeft = 0;
					}
					
					$('#' + currSocialTab + ' > .thumbnails > .thumbMask > .thumbContainer').stop().animate({left:currLeft}, 750, function(){});
				}
			}
		);
		
		// Proxy Calls For Social Feeds
		youtubeCall();
		flickrCall();
		facebookCall();
		twitterCall();

		// HOME ROW SECTION BADGE ROTATION
		// List of links
		var links = new Array();
		links.push('landscapes.aspx?language=en');
		links.push('getaways.aspx?language=en');
		
		// List of image paths
		var imgs = new Array();
		imgs.push('../../images/en/social/OD_HP_Right_1.jpg');
		imgs.push('../../images/en/social/OD_HP_Right_2.jpg');
		
		// List of alt context with respect to the above image paths
		var alts = new Array();
		alts.push('Signature Landscapes');
		alts.push('Outdoor Adventures');

		// List of title context with respect to the above image paths
		var titles = new Array();
		titles.push('Signature Landscapes');
		titles.push('Outdoor Adventures');
		
		randomImage('test1', links, imgs, alts, titles);

	}
});

////////////////////////////////////////////////////////////////////////////
// YOUTUBE SOCIAL FEEDS SECTION
var youtubeVideos = new Object();	// ID, Title, thumbURL, largeThumbURL, Desc, Tags, viewCount, updated

// Getting YouTube Social Feeds
function youtubeCall(){
	var uri = "../../socialProxy.php?";
	
	$.get(uri, { type: "youtubeplaylist", playlistID: "905B6AAEAA8B15AF"}, 
		function(data) {				
			youtubeParse(data);
		}
	);
}

// Parse Data
function youtubeParse(data) {
	youtubeVideos = new Object();
	
	var rawData = jQuery.parseJSON(data);
	var feedData = rawData.feed;
	var videoData = feedData.entry;
	
	$('#youtube > .thumbnails > .thumbMask > .thumbContainer').html("");
	$('#youtube > .thumbnails > .thumbMask > .thumbContainer').width((149)*videoData.length);
	
	// Go Through Videos
	for (var i = 0; i < videoData.length; i++) {
		var videoDetails = new Object();
		
		// Get Video Title
		var videoTitleObj = videoData[i].title;
		
		for (var key in videoTitleObj) {
			videoDetails.Title = videoTitleObj[key];
		}
		// END Video Title
		
		// Get Video Updated
		var videoUpdateObj = videoData[i].updated;
		
		for (var key in videoUpdateObj) {
			videoDetails.updated = videoUpdateObj[key];
		}
		// END Video Updated
		
		// Get Video Thumbnail, Description, Tags, View Counts
		for (var key in videoData[i]) {		
			// Get Video Thumbnail, Description, Tags			
			if (key == "media$group") {
				var videoMedia = videoData[i][key];
				
				for (var key2 in videoMedia) {
					if (key2 == "media$thumbnail") {									
						videoDetails.thumbURL = videoMedia[key2][0].url;
						videoDetails.largeThumbURL = videoMedia[key2][1].url;
					}
					
					if (key2 == "media$description") {
						var videoDescObj = videoMedia[key2];
						for (var key3 in videoDescObj) {
							if (key3 == "$t") {
								videoDetails.Desc = videoDescObj[key3];
							}
						}
					}
					
					if (key2 == "media$keywords") {
						var videoDescObj = videoMedia[key2];
						for (var key3 in videoDescObj) {
							if (key3 == "$t") {
								videoDetails.Tags = videoDescObj[key3];
							}
						}
					}
					
					if (key2 == "yt$videoid") {
						var videoDescObj = videoMedia[key2];
						for (var key3 in videoDescObj) {
							if (key3 == "$t") {
								videoDetails.ID = videoDescObj[key3];
							}
						}
					}
				}
			}
			// END Video Thumbnail, Description, Tags
			
			// Get Video Stats
			if (key == "yt$statistics") {
				videoDetails.viewCount = videoData[i][key].viewCount;
			}
			// END Video Stats
		}
		// END Video Thumbnail, Description, Tags
				
		if (videoDetails.viewCount === undefined) {
			videoDetails.viewCount = 0;
			
		}
		
		youtubeVideos[i] = videoDetails;
		
		// Update Thumbs
		if (i == 0) {
			/*
			var bigThumb = '<img src="images/social/socialPreloader.gif" alt="Loading ..." title="Loading ..." border="0" class="preloader"/>';
			bigThumb += '<a href="javascript:viewYoutube('+i+');" target="_parent"><img src="'+youtubeVideos[i].largeThumbURL+'" alt="'+youtubeVideos[i].Title+'" title="'+youtubeVideos[i].Title+'" width="332" border="0" style="top:-12px;"/></a>';
			bigThumb += '<div id="socialYoutubePlay"><a href="javascript:viewYoutube('+i+');" target="_parent"><img src="images/play-icon.png" alt="'+youtubeVideos[i].Title+'" title="'+youtubeVideos[i].Title+'" border="0"/></a></div>';
			*/
			var bigThumb = '<img src="images/social/socialPreloader.gif" alt="Loading ..." title="Loading ..." border="0" class="preloader"/>';
			bigThumb += '<span onclick="javascript:viewYoutube('+i+');"><img src="'+youtubeVideos[i].largeThumbURL+'" alt="'+youtubeVideos[i].Title+'" title="'+youtubeVideos[i].Title+'" width="332" border="0" style="top:-12px;"/></span>';
			bigThumb += '<div id="socialYoutubePlay"><span onclick="javascript:viewYoutube('+i+');"><img src="images/play-icon.png" alt="'+youtubeVideos[i].Title+'" title="'+youtubeVideos[i].Title+'" border="0"/></span></div>';
			
			$('#youtube > .mainViewer').html(bigThumb);
			
			
			
			var tempObj = youtubeVideos[i];
							
			var contentText = "<h1>" + tempObj.Title + "</h1>";
			
			if (tempObj.Desc.length > 300) {
				contentText += "<p>" + tempObj.Desc.substring(0, 300) + "......</p>";
			}
			else {
				contentText += "<p>" + tempObj.Desc + "</p>";
			}
			
			contentText += '<p class="cta"><a href="http://www.youtube.com/subscription_center?add_user=travelontariocanada" target="_blank">SUBSCRIBE</a></p>';
			
			$('#socialHub > .content').html(contentText);
		}
		
		var imgThumb = '<span onclick="javascript:changeYoutube('+i+');" target="_parent"><img src="images/social/socialPreloader.gif" alt="Loading ..." title="Loading ..." border="0" class="preloader"/><img src="'+youtubeVideos[i].thumbURL+'" alt="'+youtubeVideos[i].Title+'" title="'+youtubeVideos[i].Title+'" border="0" width="140" height="83"/></span>';
		
		$('#youtube > .thumbnails > .thumbMask > .thumbContainer').append(imgThumb);
		// END Update Thumbs
	}
	// END Through
}

// Change YouTube Large Thumbnail
function changeYoutube(objInd) {
	var tempObj = youtubeVideos[objInd];
	
	currYoutubeInd = objInd;
	
	$('#youtube > .mainViewer > span > img').attr("src", "images/social/spacer.gif");
	$('#youtube > .mainViewer > span > img').attr("alt", "");
	$('#youtube > .mainViewer > span > img').attr("title", "");
	
	$('#youtube > .mainViewer > span > img').stop().animate(
		{opacity:0}, 
		250, 
		function(){
			$('#youtube > .mainViewer > span > img').attr("src", tempObj.largeThumbURL);
			$('#youtube > .mainViewer > span > img').attr("alt", tempObj.title);
			$('#youtube > .mainViewer > span > img').attr("title", tempObj.title);
			$('#youtube > .mainViewer > span > img').css("opacity", 1);
		}
	);
	
	/*
	$('#youtube > .mainViewer > span').attr("onclick", "javascript:viewYoutube("+objInd+")");
	$('#socialYoutubePlay > span').attr("onclick", "javascript:viewYoutube("+objInd+")");
	*/

	var js = "viewYoutube("+objInd+"); return false;";
	var newClick = new Function(js);
	$('#youtube > .mainViewer > span').attr("onclick", "").click(newClick);
	$('#socialYoutubePlay > span').attr("onclick", "").click(newClick);

		
	var contentText = "<h1>" + tempObj.Title + "</h1>";
	
	if (tempObj.Desc.length > 300) {
		contentText += "<p>" + tempObj.Desc.substring(0, 300) + "......</p>";
	}
	else {
		contentText += "<p>" + tempObj.Desc + "</p>";
	}
	
	contentText += '<p class="cta"><a href="http://www.youtube.com/subscription_center?add_user=travelontariocanada" target="_blank">SUBSCRIBE</a></p>';
	
	$('#socialHub > .content').html(contentText);
}

// View YouTube Overlay
function viewYoutube(objInd) {
	var tempObj = youtubeVideos[objInd];
	
	$('#flickrOverlayContent').css('display', 'none');
	$('#youtubeOverlayContent').css('display', 'block');
	
	$('#youtubeOverlayContent > .title').html(tempObj.Title);
	$('#youtubeOverlayContent > .videoPlayer > iframe').attr("src", "http://www.youtube.com/embed/"+tempObj.ID+"?autoplay=1");
	$('#youtubeOverlayContent > .viewCount').html("Views: "+tempObj.viewCount);
	$('#youtubeOverlayContent > .videoDetails > .desc').html(tempObj.Desc);
	$('#youtubeOverlayContent > .videoDetails > .tags').html("Tags: "+tempObj.Tags);
	$('#lightboxOverlay').css('height', $(document).height()+'px');
	$('#lightboxOverlay').css('display', 'block');
	scroll(0, 0);
}
// END YOUTUBE SOCIAL FEED SECTION


////////////////////////////////////////////////////////////////////////////
// FLICKR SOCIAL FEEDS SECTION
var flickrPictures = new Object(); // id, secret, server, farm, title, desc, thumbURL, largeThumbURL, imgURL, views, dateupload (in seconds), datetaken (eg. 2010-10-24 10:28:27), lastupdate (in seconds)

function flickrCall() {
	var uri = "../../socialProxy.php?";
	
	$.get(uri, { type: "flickrsets", setID: "72157626175412206" },
		function(data) {
			flickrParse(data);
		}
	);
}

// Parse Data
function flickrParse(data) {
                flickrPictures = new Object();
                var rawData = jQuery.parseJSON(data);
                var feedData;
                if (rawData.photos === undefined) {
                                feedData = rawData.photoset.photo;
                }
                else {
                                feedData = rawData.photos.photo;
                }
               
                $('#flickr > .thumbnails > .thumbMask > .thumbContainer').html("");
                $('#flickr > .thumbnails > .thumbMask > .thumbContainer').width((149)*feedData.length);
	
	// Flickr photo size
	// http://www.flickr.com/services/api/misc.urls.html
	// http://farm{farm-id}.static.flickr.com/{server-id}/{id}_{secret}_[stmzb].jpg
	// s (75x75), t (100 on longest side), m (240 on longest), z (640 on longest), b (1024 on longest)
	
	for (var i = 0; i < feedData.length; i++) {
		var pictureDetails = new Object();
		
		pictureDetails.id = feedData[i].id;
		pictureDetails.secret = feedData[i].secret;
		pictureDetails.server = feedData[i].server;
		pictureDetails.farm = feedData[i].farm;
		pictureDetails.title = feedData[i].title;
		pictureDetails.desc = feedData[i].description._content;
		pictureDetails.thumbURL = "http://farm"+feedData[i].farm+".static.flickr.com/"+feedData[i].server+"/"+feedData[i].id+"_"+feedData[i].secret+"_t.jpg";
		pictureDetails.largeThumbURL = "http://farm"+feedData[i].farm+".static.flickr.com/"+feedData[i].server+"/"+feedData[i].id+"_"+feedData[i].secret+"_z.jpg";
		pictureDetails.imgURL = "http://farm"+feedData[i].farm+".static.flickr.com/"+feedData[i].server+"/"+feedData[i].id+"_"+feedData[i].secret+"_b.jpg";
		pictureDetails.views = feedData[i].views;

		pictureDetails.dateupload = feedData[i].dateupload;
		pictureDetails.datetaken = feedData[i].datetaken;
		pictureDetails.lastupdate = feedData[i].lastupdate;
		
		flickrPictures[i] = pictureDetails;
		
		// Update Thumbs
		if (i == 0) {
			/*
			var bigThumb = '<img src="images/social/socialPreloader.gif" alt="Loading ..." title="Loading ..." border="0" class="preloader"/>';
			bigThumb += '<a href="javascript:viewFlickr('+i+');" target="_parent"><img src="'+flickrPictures[i].largeThumbURL+'" alt="'+flickrPictures[i].title+'" title="'+flickrPictures[i].title+'" width="332" border="0"/></a>';
			bigThumb += '<div id="socialFlickrView"><a href="javascript:viewFlickr('+i+');" target="_parent"><img src="images/social/magnify-icon.png" alt="'+flickrPictures[i].title+'" title="'+flickrPictures[i].title+'" border="0"/></a></div>';
			*/
			var bigThumb = '<img src="images/social/socialPreloader.gif" alt="Loading ..." title="Loading ..." border="0" class="preloader"/>';
			bigThumb += '<span onclick="javascript:viewFlickr('+i+');"><img src="'+flickrPictures[i].largeThumbURL+'" alt="'+flickrPictures[i].title+'" title="'+flickrPictures[i].title+'" width="332" border="0"/></span>';
			bigThumb += '<div id="socialFlickrView"><span onclick="javascript:viewFlickr('+i+');"><img src="images/social/magnify-icon.png" alt="'+flickrPictures[i].title+'" title="'+flickrPictures[i].title+'" border="0"/></span></div>';
			$('#flickr > .mainViewer').html(bigThumb);
		}
		
		var imgThumb = '<span onclick="javascript:changeFlickr('+i+');"><img src="images/social/socialPreloader.gif" alt="Loading ..." title="Loading ..." border="0" class="preloader"/><img src="'+flickrPictures[i].thumbURL+'" alt="'+flickrPictures[i].title+'" title="'+flickrPictures[i].title+'" border="0" width="140" height="83"/></span>';
		
		$('#flickr > .thumbnails > .thumbMask > .thumbContainer').append(imgThumb);
		// END Update Thumbs
	}
}

// Change Flickr Large Thumbnail
function changeFlickr(objInd) {
	var tempObj = flickrPictures[objInd];
	
	currFlickrInd = objInd;
	
	$('#flickr > .mainViewer > span > img').attr("src", "images/social/spacer.gif");
	$('#flickr > .mainViewer > span > img').attr("alt", "");
	$('#flickr > .mainViewer > span > img').attr("title", "");
	
	$('#flickr > .mainViewer > span > img').stop().animate(
		{opacity:0}, 
		250, 
		function(){
			$('#flickr > .mainViewer > span > img').attr("src", tempObj.largeThumbURL);
			$('#flickr > .mainViewer > span > img').attr("alt", tempObj.title);
			$('#flickr > .mainViewer > span > img').attr("title", tempObj.title);
			$('#flickr > .mainViewer > span > img').css("opacity", 1);
		}
	);

	/*
	$('#flickr > .mainViewer > a').attr("href", "javascript:viewFlickr("+objInd+")");
	$('#socialFlickrView > a').attr("href", "javascript:viewFlickr("+objInd+")");
	*/

	var js = "viewFlickr("+objInd+"); return false;";
	var newClick = new Function(js);
	$('#flickr > .mainViewer > span').attr("onclick", "").click(newClick);
	$('#socialFlickrView > span').attr("onclick", "").click(newClick);
		
	var contentText = "<h1>" + tempObj.title + "</h1>";

	if (tempObj.desc.length > 300) {
		contentText += "<p>" + tempObj.desc.substring(0, 300) + "......</p>";
	}
	else {
		contentText += "<p>" + tempObj.desc + "</p>";
	}
	
	contentText += '<p class="cta"><a href="http://www.flickr.com/groups_join.gne?id=1574784@N25" target="_blank">FOLLOW</a></p>';
	
	$('#socialHub > .content').html(contentText);
}

// View Flickr Overlay
function viewFlickr(objInd) {
	var tempObj = flickrPictures[objInd];
	
	$('#flickrOverlayContent').css('display', 'block');
	$('#youtubeOverlayContent').css('display', 'none');

	
	$('#flickrOverlayContent > .title').html(tempObj.title);
	$('#flickrOverlayContent > .imageContainer > .image').attr("src", tempObj.imgURL);
	$('#flickrOverlayContent > .imageContainer > .image').attr("alt", tempObj.desc);
	$('#flickrOverlayContent > .imageContainer > .image').attr("title", tempObj.desc);
	$('#flickrOverlayContent > .imageDetails').html(tempObj.desc);
	$('#lightboxOverlay').css('height', $(document).height()+'px');
	$('#lightboxOverlay').css('display', 'block');
	
	scroll(0, 0);
}
// END FLICKR	

////////////////////////////////////////////////////////////////////////////
// FACEBOOK SOCIAL FEEDS SECTION
function facebookCall() {
	var uri = "../../socialProxy.php?";
	
	$.get(uri, { type: "facebook" },
		function(data) {
			var rawData = jQuery.parseJSON(data);
			var feedData = rawData.data;
			
			var feeds = "";
			
			// Loop through news feed
			for (var i = 0; i < feedData.length; i++) {
				// Add if message in the feed
				// There are times when the feed only has an image and no message
				if (feedData[i].message !== undefined) {
					var msg ='<div class="feed">';
					msg += '<p class="title"><a href="http://www.facebook.com/'+feedData[i].from.id+'" target="_blank">'+feedData[i].from.name+'</a></p>';
					
					// Add the picture if there's an image attached to the feed
					if (feedData[i].picture !== undefined) {
						msg += '<p style="min-height:80px;">';
						
						// Crops the title/alt for the image
						if (feedData[i].message.length <= 20) {
							msg += '<img src="' + feedData[i].picture + '" alt="' + feedData[i].message + '" title="' + feedData[i].message + '" border="0" align="left" height="80" style="display:block;padding-right:5px;"/>';
						}
						else {
							msg += '<img src="' + feedData[i].picture + '" alt="' + feedData[i].message.substring(0, 20) + ' ......" title="' + feedData[i].message.substring(0, 20) + ' ......" border="0" align="left" height="80" style="display:block;padding-right:5px;"/>';
						}
					}
					else {
						msg += '<p>';
					}
					
					// Making all links an active link
					var tempMsg = feedData[i].message;
				
					var exp = /(\b(http:\/\/|https:\/\/|www.)[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/i;
    				tempMsg = tempMsg.replace(exp,"<a href='$1'>$1</a>");
					
					var exp2 = /(\b[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|]@[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/i;
    				tempMsg = tempMsg.replace(exp2,"<a href='mailto:$1'>$1</a>");
					
					msg += tempMsg;
					
					msg += '</p>';
					msg += '</div>';
					
					feeds += msg;
				}
			}
			
			$('#facebook > .feedMask > .feeds').html(feeds);
		}
	);
}

////////////////////////////////////////////////////////////////////////////
// TWITTER SOCIAL FEEDS SECTION
function twitterCall() {
	var uri = "../../socialProxy.php?";
	
	// Custom code added to jquery.tweet.js
	// var randInd = Math.floor(Math.random()*s.count);
	// tweets = $.grep(tweets, s.filter).sort(s.comparator).slice(randInd, randInd+1);
	// Selects one tween randomly from 'count' tweets
	
	$('#twitter > .feedMask > .feeds').tweet({
		username: ["OutdoorOntario", "OutdoorOntario"], // bug to fix IE
		join_text: null,
		avatar_size: 0,
		count: 20,
		//auto_join_text_default: "we said,",
		//auto_join_text_ed: "we",
		//auto_join_text_ing: "we were",
		//auto_join_text_reply: "we replied to",
		//auto_join_text_url: "we were checking out",
		loading_text: "<img src='images/social/socialPreloader.gif' style='position:relative;top:8px;' alt='' title=''/> Loading tweets ..."
	});
}

////////////////////////////////////////////////////////////////////////////
// HOMEROW SECTION BADGE ROTATION

function randomImage(id, links, imgs, alt, title) {	
	var randInd = Math.floor(Math.random() * imgs.length);

	if (randInd == imgs.length) {
		randInd = imgs.length - 1;
	}
	
	// Use this if the ID is on the img tag
	$('#'+id).attr('src', imgs[randInd]);
	$('#'+id).attr('alt', alt[randInd]);
	$('#'+id).attr('title', title[randInd]);
	$('#'+id).parent().attr('href', links[randInd]);
}
