	var hideThesePlaylists = [
		/* MothersDay 1*/ 	'1C8716E156718790',
		/* MothersDay 2*/ 	'9260D2B0E426C827',
		/* MothersDay 3*/ 	'D1B250B2B7E5477D',
		/* MothersDay 4*/ 	'A2172FEEFF830EC6'

	];
	var hideTheseVideos = [
		/* Welcome Back Spring with Lowes */ 	'rzrbfMenV2w',
		/* Rapid Fire - Commercial */ 			'dukTS6KAlX4',
		/* Nursery - Commericial */				'8thg6jf94xo',
		/* Lunch Break - Commercial */			'utxFLL-b2dc',
		/* Help You - Commerical */				'8B98rXwBxKU',
		/* Outdoors - Commerical */				'ZQ6V0NqTVMk'
	];
//================================
	//share (addthis) options
	var addthis_pub='lowes';
	var addthis_brand = 'Lowe\'s Videos';
	var addthis_options = 'delicious, digg, email, facebook, favorites, google, linkedin, live, myspace, reddit, stumbleupon, twitter';
	var shareLink;
	// end addthis options
	
	google.load("feeds", "1");
	var videoSearchArray = [];
	var videoIDArray = [];
	var ytID = j$(document).getUrlParam("ytID");
	var ytPL = j$(document).getUrlParam("ytPL");
	var themeVideos = '';
	var themeVideos = [];
	var videoProducts = [];
	var playListEntries = [];
	var getSingleVideo = 0;
	var mastHeadHeight = 210;
	var isContentShowing = 1;
	var showProducts = 0;
	var showVideos = 0;
	var showHowTo = 0;
	var showBuyGuide = 0;
	var autoplayVid = 0;
	var autoplayPl = 0;
	var showInstructions = 0;
	var defaultPl = '';
	var defaultVid = '';
	var bypassPl = 0;
	var vidSlider;
	var vidResultArray = [];
	var tempVidResultArray = [];
//================================	
j$(function() {
	//ensure this is not an instore user
	if(store_check() == 'false' && j$('#videoPlayer').length > 0){
		getAllPlaylists();
		playlist_change();
		getDefaults();
		vidSlider = new Accordion('.vidToggle','.relVideoContainer',{
			//opacity: 0,
			onActive: function(toggler, element){
				$(toggler).setStyle('cursor','default');
				$(toggler).getChildren().setStyle('background','url(/lowes2/includes/project_center/pc_minus.gif) no-repeat center left');
				var setProperties = function(){
					$(element).getChildren().setStyle('overflow-y','auto');
					}
				setProperties.delay(500);
			},
			onBackground: function(toggler, element){
				$(toggler).setStyle('cursor','pointer');
				$(toggler).getChildren().setStyle('background','url(/lowes2/includes/project_center/pc_plus.gif) no-repeat center left');
				$(element).getChildren().setStyle('overflow-y','hidden');
			}
		}, $('vidAccordion'));
		
	}
});
//get the default playlist or video
function getDefaults(){	
	rel_string = j$('#videoPlayer').attr('rel');
	rel_array = rel_string.split(",");
	
	for(j=0; j<rel_array.length; ++j){
		switch(rel_array[j]){
			case 'products': 
			showProducts = 1; 
			break;
			
			case 'videos': 
			showVideos = 1;
			break;
			
			case 'howTo' :
			showHowTo = 1;
			break;
			
			case 'buyGuide' :
			showBuyGuide = 1;
			break;
			
			case 'apVid' :
			autoplayVid = 1;
			break;
			
			case 'apPl' :
			autoplayPl = 1;
			break;
			
			case 'inst' :
			showInstructions = 1;
			break;
		}
	
		if(rel_array[j].indexOf("plID:") > -1){
			myString = rel_array[j];
			defaultPl = myString.substr(5);
			//setVideoCookie('pcLowesVidPlaylistID',defaultPl,1);	
		}
		else if(rel_array[j].indexOf("vidID:") > -1){
			myString = rel_array[j];
			defaultVid = myString.substr(6);				
		}
	}
	//check to see if there is a previously viewed cookie
	var prevVideo = getVideoCookie('pcLowesLastViewed');
	var prevVidParam = getVideoCookie('pcLowesVidParamID');
	//var prevPlaylist = getVideoCookie('pcLowesVidPlaylistID');
	
	if(prevVideo != null && prevVidParam == null){
		defaultVid = prevVideo;
		bypassPl = 1;
	}
	else if(prevVideo != null && prevVidParam != null){
		if(prevVidParam == ytID){
			defaultVid = prevVideo;
		}
		else if(ytID == null){
			defaultVid = prevVideo;
		}
		else{
			defaultVid = prevVidParam;
		}
		bypassPl = 1;
	}
	//check to see if there's a video ID param
	if(ytID != null && (prevVidParam != ytID)){
		setVideoCookie('pcLowesVidParamID',ytID,1);
		defaultVid = ytID;
		bypassPl = 1;
	}
	//check to see if there's a playlist param	
	if(ytPL != null){
		//setVideoCookie('pcLowesVidPlaylistID',ytPL,1);
		defaultPl = ytPL;
		bypassPl = 0;
	}
	if((defaultPl).length > 0 && !bypassPl){
		getVideos(defaultPl);
	}
	else{ 
		getOneVideo(defaultVid);
	}
}
//===============================
//GET VIDEO CATEGORIES AND ASSOCIATE VIDEOS
function getAllPlaylists() {
playListEntries = [];
  j$.ajax({
    type: 'GET',
    dataType: 'jsonp',
    url: 'http://gdata.youtube.com/feeds/api/users/lowes/playlists?alt=json-in-script&max-results=50',
    cache: false,
	error: function(){
		showErrorMsg('We\'re having trouble retrieving all Lowe\'s playlists right now.',1);
	},
    success: function(data) {
      var feed = data.feed;
      plfeed = feed.entry || [];
	  if(plfeed.length > 0){
		  j$(plfeed).each(function(i) {
			playListEntries[i] = [];
			playListEntries[i].id = plfeed[i].yt$playlistId.$t;
			playListEntries[i].title = plfeed[i].title.$t;
			playListEntries[i].author = plfeed[i].author[0].name.$t;
			playListEntries[i].countHint = plfeed[i].gd$feedLink[0].countHint;  
		  }).ready(function(){
			  
		  		playListEntries.sort(arraySort);
		  	j$(playListEntries).each(function(i){
				if(playListEntries[i].countHint > 0 && (playListEntries[i].author == 'lowes' || playListEntries[i].author == 'Lowes') && j$.inArray(playListEntries[i].id,hideThesePlaylists) == -1){
					numVideos = (playListEntries[i].countHint > 1) ? 'videos' : 'video';
					j$('#ytPlaylists').append('<option value = "' + playListEntries[i].id + '">' + playListEntries[i].title + ' ('+ playListEntries[i].countHint +' ' + numVideos + ')</option>');
				}
			});
			// if bypass playlist is false, set the drop down label to the default playlist value
		  	if(!bypassPl){
				setDefaultPlaylist(defaultPl);
			}
			buildVideoArray('http://gdata.youtube.com/feeds/api/users/lowes/uploads?',1,50);
		  });
	  }
    }
  });
}
//=============
function arraySort(a,b){
	if (a.title < b.title){ 
		return -1; 
	}
	else if (a.title > b.title){
		return 1; 
	}
	else{
		return 0;
	}
}
function arrayRelSort(a,b){
	if (a.rel > b.rel){ 
		return -1; 
	}
	else if (a.rel < b.rel){
		return 1; 
	}
	else{
		return 0;
	}
}
//===================
function buildVideoArray(feed,start,maxReturns){
	var entry = [];
	if(maxReturns > 50){
		maxReturns = 50;
	}
	var url = feed + '&start-index=' + start + '&max-results=' + maxReturns
	getFeed = new google.feeds.Feed(url);
	getFeed.setNumEntries(maxReturns);
	getFeed.setResultFormat(google.feeds.Feed.JSON_FORMAT);
	getFeed.load(function(result){
		entry = result.feed.entries;
		j$(entry).each(function(i){
			var thisVideoID = stripFeature(entry[i].link.substring(entry[i].link.indexOf('=')+1,entry[i].link.length));
			if(j$.inArray(thisVideoID,videoIDArray) == -1 && j$.inArray(thisVideoID,hideTheseVideos) == -1){
				videoIDArray.push(thisVideoID);
				newI = videoIDArray.length - 1;
				videoSearchArray[newI] = [];
				videoSearchArray[newI]['id'] = thisVideoID;
				videoSearchArray[newI]['title'] = entry[i].title;
				videoSearchArray[newI]['desc'] = entry[i].content;
			}
		}).ready(function(){
			if(entry.length == 50){
				var newStart = start+50;
				buildVideoArray(feed,newStart,maxReturns);
			}
			else if(entry.length < 50){
				enableSearchBox();
			}
		});
	});
}
//===================================
function enableSearchBox(){
	j$('#vidSearch').removeAttr('disabled');
	var stSearch;
	var stResults;
	j$('#vidSearch').bind('keyup',function(){
		clearTimeout(stSearch);
		stSearch = setTimeout(function(){
			if(j$('#vidSearch').val().length == 0){
				j$('#returnedVidResults').empty();
				j$('#returnedVidResults').css('display','none');
			}
			if(j$('#vidSearch').val().length >= 3){
				parseSearchRequest(j$('#vidSearch').val());
			}
		},200);
	});
	j$('#vidSearch').bind('click',function(){
		if(j$('#vidSearch').val().length >= 3){
			parseSearchRequest(j$('#vidSearch').val());
		}
	});
	j$('#returnedVidResults').bind('mouseleave',function(){
		clearTimeout(stResults);
		stResults = setTimeout(function(){
			j$('#returnedVidResults').empty();
			j$('#returnedVidResults').css('display','none');
		},750);
	});
	j$('#returnedVidResults').bind('mouseenter',function(){
		clearTimeout(stResults);
	});
}
//=========================	
function parseSearchRequest(searchFor){
	videoIDArray = [];
	tempVidResultArray = [];
	var txtArray = searchFor.toLowerCase().split(' ');
	j$(videoSearchArray).each(function(i){
		var x = 0;
		var thisVidTitle = videoSearchArray[i].title.toLowerCase();
		var thisVidDesc = videoSearchArray[i].desc.toLowerCase();
		var thisVidTitleCased = videoSearchArray[i].title;
		var thisVidID = videoSearchArray[i].id;
		j$(txtArray).each(function(i){
			if(thisVidTitle.indexOf(txtArray[i]) >= 0 || thisVidDesc.indexOf(txtArray[i]) >= 0){
				x = x + 1
				if(j$.inArray(thisVidID,videoIDArray) == -1 && videoIDArray.length <= 7){
					videoIDArray.push(thisVidID);
					newI = videoIDArray.length - 1;
					tempVidResultArray[newI] = [];
					tempVidResultArray[newI]['id'] = thisVidID;
					tempVidResultArray[newI]['title'] = thisVidTitleCased;
					tempVidResultArray[newI]['rel'] = x;
				}
				else if(j$.inArray(thisVidID,videoIDArray) == -1 && videoIDArray.length == 8){
					videoIDArray.shift(videoIDArray);
					tempVidResultArray[7] = [];
					tempVidResultArray[7]['id'] = thisVidID;
					tempVidResultArray[7]['title'] = thisVidTitleCased;
					tempVidResultArray[7]['rel'] = x;
				}
				else if(j$.inArray(thisVidID,videoIDArray) >= 0){
					j$(tempVidResultArray).each(function(i){
						if(this.id == thisVidID){
							this.rel = x;
						}
					});
				}
			}
		}).ready(function(){
			tempVidResultArray.sort(arrayRelSort);
		});
	}).ready(function(){	
		j$('#returnedVidResults').empty();
		j$('#returnedVidResults').css('display','block');
		if(tempVidResultArray.length > 0){
			j$(tempVidResultArray).each(function(i){
				j$('#returnedVidResults').append('<div class="vidResult '+ this.id +'"><img src = "http://i.ytimg.com/vi/'+this.id+'/2.jpg" border="0" align="absmiddle" width="48" height ="36"/> ' + this.title + '</div>');
			});
		}
		else{
			j$('#returnedVidResults').append('<span style="padding:5px; line-height:15px; font-weight:bold;">No Search Results Found.</span>');
		}
	});
	j$('.vidResult').each(function(i){
	var vidClassID = j$(this).attr('class').toString();
	var n = vidClassID.indexOf(' ') + 2;
	var vidID = vidClassID.substring(vidClassID.length, vidClassID.length - n);
		j$(this).bind('click',function(){
			j$('#returnedVidResults').css('display','none');
			j$('#vidSearch').val('Search Videos');
			j$('div#videoPlayer div.video').addClass('loading');
			getOneVideo(vidID);
		});
		j$(this).mouseover(function(){
			j$(this).css('background','#eff3fa');
		});
		j$(this).mouseout(function(){
			j$(this).css('background','#fff');
		});
	});
}
//============================
//====================
//GET VIDEOS BY PLAYLIST
function getVideos(playlistID) {
	getSingleVideo = 0;
	themeVideos = [];
  var url = "http://gdata.youtube.com/feeds/api/playlists/"+playlistID+"?alt=json-in-script&max-results=50";
  j$.ajax({
    type: 'GET',
    dataType: 'jsonp',
    url: url,
    cache: false,
	error: function(){
		showErrorMsg('Sorry, at the moment we can\'t collect that playlist from YouTube.');
	},
    success: function(data) {	
	  var feed = data.feed;
	  var vfeed = feed.entry || [];
		  if(vfeed.length > 0){
			  j$(vfeed).each(function(i) {
				themeVideos[i] = [];
				themeVideos[i].id = stripFeature(vfeed[i].link[0].href.substring(vfeed[i].link[0].href.indexOf('=')+1,vfeed[i].link[0].href.length));
				themeVideos[i].url = vfeed[i].link[0].href;
				themeVideos[i].title = vfeed[i].title.$t;
				themeVideos[i].description = vfeed[i].media$group.media$description.$t;
				themeVideos[i].author = vfeed[i].author[0].name.$t;
				if(vfeed[i].yt$statistics){
					themeVideos[i].views = vfeed[i].yt$statistics.viewCount;
				}
				else if(!vfeed[i].yt$statistics){
					themeVideos[i].views = '0';
				}
				if(vfeed[i].gd$rating){
					themeVideos[i].rating = vfeed[i].gd$rating.average;
					themeVideos[i].numRaters = vfeed[i].gd$rating.numRaters;
				}
				else if(!vfeed[i].gd$rating){
					themeVideos[i].rating = '0.00';
					themeVideos[i].numRaters = '0';
				}
			  }).ready(function() {
				if(themeVideos[0].author == 'Lowes' || themeVideos[0].author == 'lowes'){
					j$('#errMsg').css('display','none');
					appendVideo(themeVideos[0].id, themeVideos[0].title,themeVideos[0].description,themeVideos[0].rating,themeVideos[0].numRaters,autoplayPl);
				}
				else{
					showErrorMsg('Your request is not a Lowe\'s playlist. Get inspired with videos from Lowe\'s.',1);
				}
			  });
		}
	}
  });
}
//Get single video
function getOneVideo(videoID){
	getSingleVideo = 1;
	var vidRating;
	var vidRaters;
  j$.ajax({
    type: 'GET',
    dataType: 'jsonp',
    url: 'http://gdata.youtube.com/feeds/api/videos/'+ videoID +'?alt=json-in-script',
    cache: false,
	error: function(){
		showErrorMsg('Sorry, we couldn\'t pull up that video from YouTube.',1);
	},
    success: function(data) {
      var thisVid = data.entry;
	  	if(thisVid.author[0].name.$t == 'lowes' || thisVid.author[0].name.$t == 'Lowes'){
			if(thisVid.gd$rating){
				vidRating = thisVid.gd$rating.average;
				vidRaters = thisVid.gd$rating.numRaters;
			}
			else if(!thisVid.gd$rating){
				vidRating = '0.00';
				vidRaters = '0';
			}
			j$('#errMsg').css('display','none');
			appendVideo(videoID,thisVid.title.$t,thisVid.media$group.media$description.$t,vidRating,vidRaters,autoplayVid);
		}
		else{
			showErrorMsg('That video is not from Lowe\'s. Please peruse our inspiring collection.',1);
		} 
    }
  });
}
//Add video HTML (if video is from playlist)
function appendVideo(videoID,videoTitle,videoDescription,videoRating,videoNumRatings,autoPlay) {
	if(!isContentShowing){
		showVideoContent();
	}
	j$('#errMsg').css('display','none');
	j$('#videoWrapper').css('display','none');
	shareLink = "<a href=\"http://www.addthis.com/bookmark.php?v=20\" onmouseover=\"return addthis_open(this, '', 'http://www.lowes.com/lowes/lkn?action=categorySelect&category=Project%20Planning&ytID="+videoID+"', '"+videoTitle+"')\" onmouseout=\"addthis_close()\" onclick=\"return addthis_sendto()\"><img src=\"/lowes2/includes/project_center/pc_share_icon.gif\" align=\"absmiddle\" alt=\"Share This Video\" title=\"Share This Video\" style=\"border:0\"/></a>";
  	rssLink = '<a href="http://gdata.youtube.com/feeds/api/users/lowes/uploads?max-results=50"><img src="/lowes2/includes/project_center/pc_rss_icon.gif" align="absmiddle" alt="Subscribe to the Lowe\'s Video Center RSS feed" title="Subscribe to the Lowe\'s Video Center RSS feed" border="0" /></a>';
	urlInput = "URL: <input type=\"text\" size=\"35\" value=\"http://www.lowes.com/lowes/lkn?action=categorySelect&category=Project Planning&ytID="+videoID+"\" />";
	embedHTML = "<div class=\"video\">"+
                "<object width=\"525\" height=\"315\">"+
                	"<param name=\"movie\" value=\"http://www.youtube.com/v/"+videoID+"&autoplay="+((autoPlay)?1:0)+"&rel=0&fs=1&color1=0xcccccc&color2=0xffffff&border=0&loop=0\">"+
                	"<param name=\"allowFullScreen\" value=\"true\">"+
					"<param name=\"wmode\" value=\"transparent\">"+
                	"<embed wmode=\"transparent\" src=\"http://www.youtube.com/v/"+videoID+"&autoplay="+((autoPlay)?1:0)+"&rel=0&fs=1&color1=0xcccccc&color2=0xffffff&border=0&loop=0\" type=\"application/x-shockwave-flash\" allowfullscreen=\"true\" width=\"525\" height=\"315\"></embed>"+
                "</object>"+
              "</div>";
	j$("div#videoPlayer div.video").removeClass('loading').replaceWith(embedHTML);
	numRatings = (videoNumRatings != 1) ? 'ratings' : 'rating';
	numStars = getStarRating(videoRating);
	j$("div#videoPlayer div.left").replaceWith("<div class=\"left\"><span class='vidTitle'>"+videoTitle+"</span><p><img class='stars"+numStars+"' src='/lowes2/includes/project_center/trans.gif' width='75px' height='15px' /> " + videoNumRatings + "  " + numRatings + " &nbsp;&nbsp;&nbsp; "+rssLink+" "+shareLink+"</p><p>"+videoDescription+"</p></div>");
	updateRelatedInfo(videoID);	
  	//set the last video viewed
	setVideoCookie('pcLowesLastViewed',videoID,1);
	// update recently viewed videos cookie
	if(getVideoCookie('pcLowesRecentViewed') == null){
		setVideoCookie('pcLowesRecentViewed',videoID,30);
		updateRecentlyViewed(videoID);
	}
	else if(getVideoCookie('pcLowesRecentViewed') != null){
		updateRecentlyViewed(videoID);
	}
	
	if(themeVideos.length >= 1 && !getSingleVideo){
	 	appendRelatedVideos(videoID);
	 }
	else if(getSingleVideo){
		getRelatedVids(videoID);
	 }
}
//Add related videos HTML
function appendRelatedVideos(currentID) {
	j$('#relatedVids').empty();
	themeVideos.sort(arraySort);
	j$(themeVideos).each(function(i) {
	if(themeVideos[i].id != currentID && j$.inArray(themeVideos[i].id,hideTheseVideos) == -1){
			numRatings = (themeVideos[i].numRaters != 1) ? 'ratings' : 'rating';
			numStars = getStarRating(themeVideos[i].rating);
		  j$("#relatedVids").append("<div class='relVideo'><a class=\""+themeVideos[i].id+"\" href=\"http://www.youtube.com/watch?v="+themeVideos[i].id+"\"><img class='relVidThumb' src=\"http://i.ytimg.com/vi/"+themeVideos[i].id+"/2.jpg\" alt=\""+themeVideos[i].title+"\" /></a><span class='relVidInfo'><a class=\""+themeVideos[i].id+"\" href=\"http://www.youtube.com/watch?v="+themeVideos[i].id+"\">"+themeVideos[i].title+"</a><br /><img class='smstars"+numStars+"' src='/lowes2/includes/project_center/trans.gif' width='60px' height='15px' /><br />"+themeVideos[i].views+" views</span></div><div class='clear'></div>");
		  j$('#relatedVids .relVideo a.'+themeVideos[i].id).bind('click', function() {
				j$("div#videoPlayer div.video").addClass('loading');
				appendVideo(themeVideos[i].id, themeVideos[i].title,themeVideos[i].description,themeVideos[i].rating,themeVideos[i].numRaters,autoplayVid);
				return false;
		  });
	}
	});
}
// add related videos from a single video request
function getRelatedVids(videoID){
	relVideos = [];
	j$('#relatedVids').addClass('relLoading');
	j$('#relatedVids').empty();
  var url = 'http://gdata.youtube.com/feeds/api/videos/'+ videoID +'/related?author=lowes&alt=json-in-script&max-results=50';
  j$.ajax({
    type: 'GET',
    dataType: 'jsonp',
    url: url,
    cache: false,
	error: function(){
		showErrorMsg('Hang on - we\'re having difficulty retrieving related videos from YouTube.',1);
	},
    success: function(data) {
      var feed = data.feed;
      var rfeed = feed.entry || [];
	  if(rfeed.length > 0){
		  j$(rfeed).each(function(i) {
			relVideos[i] = [];
			relVideos[i].id = stripFeature(rfeed[i].link[0].href.substring(rfeed[i].link[0].href.indexOf('=')+1,rfeed[i].link[0].href.length));
			relVideos[i].url = rfeed[i].link[0].href;
			relVideos[i].title = rfeed[i].title.$t;
			relVideos[i].thumbnail = rfeed[i].media$group.media$thumbnail[0].url;
			relVideos[i].description = rfeed[i].media$group.media$description.$t;
			relVideos[i].author = rfeed[i].author[0].name.$t;
			if(rfeed[i].yt$statistics){
				relVideos[i].views = rfeed[i].yt$statistics.viewCount;
				}
				else if(!rfeed[i].yt$statistics){
					relVideos[i].views = '0';
				}
				if(rfeed[i].gd$rating){
					relVideos[i].rating = rfeed[i].gd$rating.average;
					relVideos[i].numRaters = rfeed[i].gd$rating.numRaters;
				}
				else if(!rfeed[i].gd$rating){
					relVideos[i].rating = '0.00';
					relVideos[i].numRaters = '0';
				}
		  }).ready(function() {
		 	j$('#relatedVids').removeClass('relLoading');
			relVideos.sort(arraySort);
			j$(relVideos).each(function(i) {
				if(relVideos[i].id != videoID && j$.inArray(relVideos[i].id,hideTheseVideos) == -1){
					numRatings = (relVideos[i].numRaters != 1) ? 'ratings' : 'rating';
					numStars = getStarRating(relVideos[i].rating);
				  j$("#relatedVids").append("<div class='relVideo'><a class=\""+relVideos[i].id+"\" href=\"http://www.youtube.com/watch?v="+relVideos[i].id+"\"><img class='relVidThumb' src=\""+relVideos[i].thumbnail+"\" alt=\""+relVideos[i].title+"\" /></a><span class='relVidInfo'><a class=\""+relVideos[i].id+"\" href=\"http://www.youtube.com/watch?v="+relVideos[i].id+"\">"+relVideos[i].title+"</a><br /><img class='smstars"+numStars+"' src='/lowes2/includes/project_center/trans.gif' width='60px' height='15px' /><br />"+relVideos[i].views+" views</span></div><div class='clear'></div>");
				  j$('#relatedVids .relVideo a.'+relVideos[i].id).bind('click', function() {
				  		j$("div#videoPlayer div.video").addClass('loading');
						appendVideo(relVideos[i].id, relVideos[i].title,relVideos[i].description,relVideos[i].rating,relVideos[i].numRaters,autoplayVid);
						return false;
				  });
				}
			  });
		  });
		}
		else if(rfeed.length == 0){
			j$("#relatedVids").append('<p>We\'re sorry. We didn\'t find any related videos.</p>');
		}
	}
  });
}
//==============
function getRecentVideo(videoID){
	var thisRating;
	var thisRaters;
	var thisViews;
  var url = 'http://gdata.youtube.com/feeds/api/users/lowes/uploads/'+ videoID +'?&alt=json-in-script';
  j$.ajax({
    type: 'GET',
    dataType: 'jsonp',
    url: url,
    cache: false,
	error: function(){
		showErrorMsg('Hang on - we\'re having difficulty retrieving videos from YouTube.',1);
	},
    success: function(data) {
      var recentVid = data.entry;
	  	if(recentVid.author[0].name.$t == 'lowes' || recentVid.author[0].name.$t == 'Lowes'){
			if(recentVid.yt$statistics){
				thisViews = recentVid.yt$statistics.viewCount;
			}
			else{
				thisViews = '0';
			}
			if(recentVid.gd$rating){
				thisRating = recentVid.gd$rating.average;
				thisRaters = recentVid.gd$rating.numRaters;
			}
			else if(!recentVid.gd$rating){
				thisRating = '0.00';
				thisRaters = '0';
			}			
			j$('#errMsg').css('display','none');
			if(j$.inArray(videoID,hideTheseVideos) == -1){
					numRatings = (thisRaters != 1) ? 'ratings' : 'rating';
					numStars = getStarRating(thisRating);
				  j$("#recentVids").prepend("<div class='relVideo'><a class=\""+videoID+"\" href=\"http://www.youtube.com/watch?v="+videoID+"\"><img class='relVidThumb' src=\"http://i.ytimg.com/vi/"+videoID+"/2.jpg\" alt=\""+recentVid.title.$t+"\" /></a><span class='relVidInfo'><a class=\""+videoID+"\" href=\"http://www.youtube.com/watch?v="+videoID+"\">"+recentVid.title.$t+"</a><br /><img class='smstars"+numStars+"' src='/lowes2/includes/project_center/trans.gif' width='60px' height='15px' /><br />"+thisViews+" views</span></div><div class='clear'></div>");
				  j$('#recentVids .relVideo a.'+videoID).bind('click', function() {
				  		j$("div#videoPlayer div.video").addClass('loading');
						appendVideo(videoID,recentVid.title.$t,recentVid.media$group.media$description.$t,thisRating,thisRaters,autoplayVid);
						return false;
				  });
				// getRelatedVids(videoID); 
				}
		}
		else{
			showErrorMsg('That video is not from Lowe\'s. Please peruse our inspiring collection.',1);
		} 
    }
  });
}
function getSuggestedVideos(){
	suggestedVideos = [];
	var url = 'http://gdata.youtube.com/feeds/api/users/lowes/uploads?alt=json-in-script&max-results=30';
	j$.ajax({
		type: 'GET',
		dataType: 'jsonp',
		url: url,
		cache: false,
		error: function(){
			showErrorMsg('Please be patient - we\'re having trouble retrieving suggested videos from YouTube.',0);
		},
		success: function(data) {
			var feed = data.feed;
			var sfeed = feed.entry || [];
			if(sfeed.length > 0){
				j$(sfeed).each(function(i) {
				suggestedVideos[i] = [];
				suggestedVideos[i].id = stripFeature(sfeed[i].link[0].href.substring(sfeed[i].link[0].href.indexOf('=')+1,sfeed[i].link[0].href.length));
				suggestedVideos[i].url = sfeed[i].link[0].href;
				suggestedVideos[i].title = sfeed[i].title.$t;
				suggestedVideos[i].description = sfeed[i].media$group.media$description.$t;
				if(sfeed[i].yt$statistics){
				thisViews = sfeed[i].yt$statistics.viewCount;
				}
				else{
					thisViews = '0';
				}
				if(sfeed[i].gd$rating){
					thisRating = sfeed[i].gd$rating.average;
					thisRaters = sfeed[i].gd$rating.numRaters;
				}
				else if(!sfeed[i].gd$rating){
					thisRating = '0.00';
					thisRaters = '0';
				}
			  }).ready(function() {
					j$('#videoWrapper').css('display','block');
					suggestedVideos.sort(arraySort);
					j$(suggestedVideos).each(function(i) {
						if(j$.inArray(suggestedVideos[i].id,hideTheseVideos) == -1){
							j$('#videoWrapper ul').append("<li><a id=\""+suggestedVideos[i].id+"\" href=\"http://www.youtube.com/watch?v="+suggestedVideos[i].id+"\"><img src=\"http://i.ytimg.com/vi/"+suggestedVideos[i].id+"/2.jpg\" alt=\""+suggestedVideos[i].title+"\" /><span>"+suggestedVideos[i].title+"</span></a></li>");
	
							j$('#videoWrapper ul a#'+suggestedVideos[i].id).bind('click', function() {
								getSingleVideo = 1;
								appendVideo(suggestedVideos[i].id, suggestedVideos[i].title,suggestedVideos[i].description,thisRating,thisRaters,autoplayVid);
								return false;
							});
						}
					});
					adjustMainContent();
		  		});
			}
		}
	});
}
//====================================
function updateRelatedInfo(videoID) {
	fullWidth = 0;
	videoProducts = [];
	videoBuyGuides = [];
	videoHowTos = [];
	j$("div#videoPlayer div.right").empty();
	j$.ajax({
		type: 'GET',
		dataType: 'xml',
		cache: false,
		url: '/lowes2/includes/project_center/pc_videos.xml',
		success: function(xml) {
		  j$(xml).each(function() {
			j$(this).find('video').each(function(i) {
			  if(j$(this).attr('id') == videoID)
			  {
					if($defined(j$(this).attr('pdf')) && showInstructions){
						j$("div#videoPlayer div.right").append("<a target=\"blank\" class=\"viewinstructions\" href=\""+j$(this).attr('pdf')+"\">View Instructions</a>");
					}
					// find any products (if showProducts flag is true)
					if(showProducts){
						j$(this).find('product').each(function(i) {
							videoProducts[i] = [];
							videoProducts[i].video = videoID;
							videoProducts[i].name = j$(this).find('name').text();
							videoProducts[i].image = j$(this).find('image').text();
							videoProducts[i].url = j$(this).find('url').text();
						});
					}
					// find any how tos (if showHowTo flag is true)
					if(showHowTo){
						j$(this).find('howTo').each(function(h) {
							videoHowTos[h] = [];
							videoHowTos[h].video = videoID;
							videoHowTos[h].title = j$(this).find('htTitle').text();
							videoHowTos[h].url = j$(this).find('htLink').text();
						});
					}
					// find any buying guides (if showBuyGuide flag is true)
					if(showBuyGuide){
						j$(this).find('buyGuide').each(function(b) {
							videoBuyGuides[b] = [];
							videoBuyGuides[b].video = videoID;
							videoBuyGuides[b].title = j$(this).find('bgTitle').text();
							videoBuyGuides[b].url = j$(this).find('bgLink').text();
						});
					}
			  }
			}).ready(function() {
					// buy guides
					j$('#tcontent1 ul').empty();
					if(videoBuyGuides.length == 0){
						j$('#tcontent1 ul').append('<li class="first"><a href="/lowes/lkn?action=howTo&p=HTindex/BuyingGuideIndex.html&lks=pcbg5">View all of our Buying Guides</a></li>');
					}
					else if(videoBuyGuides.length >= 1){
						j$(videoBuyGuides).each(function(b) {
							j$('#tcontent1 ul').append('<li><a href="'+  videoBuyGuides[b].url +'">'+ videoBuyGuides[b].title +'</a></li>');
						}).ready(function(){
							j$('#tcontent1 ul li:first').addClass('top');
						});
					}
					// how tos
					j$('#tcontent2 ul').empty();
					if(videoHowTos.length == 0){
						j$('#tcontent2 ul').append('<li class="first"><a href="/lowes/lkn?action=topicSelect&topic=buyGuide&lks=pcht5">Visit our How-To Library</a></li>');
					}
					else if(videoHowTos.length >= 1){
						j$(videoHowTos).each(function(h){
							j$('#tcontent2 ul').append('<li><a href="'+ videoHowTos[h].url +'">'+ videoHowTos[h].title +'</a></li>');
						}).ready(function(){
							j$('#tcontent2 ul li:first').addClass('top');
						});
					}
					//related products
					j$('div#vidContainer div.relatedproducts ul').empty();
					if(videoProducts.length == 0){
						j$('div#vidContainer div.relatedproducts').css('display','none');
						j$('div#vidContainer div.relatedproducts span.videoSearch').css('display','none');
						j$('div.relatedproducts div.slideControls').css('display','none');
						adjustMainContent();
					}
					else if(j$(videoProducts.length >= 1)){ 
						j$('div#vidContainer div.relatedproducts').css('display','block');
						j$('div.relatedproducts div.slideControls').css('display','block');
						j$('div#vidContainer div.relatedproducts span.videoSearch').css('display','block');
						if(j$('div#vidContainer div.relatedproducts span.videoSearch').text() == ''){
							j$('div#vidContainer div.relatedproducts span.videoSearch').append('<p class="sc_head">Here\'s What You\'ll Need</p>');
						}
					  j$(videoProducts).each(function(i) {
						j$("div.relatedproducts div.productSlider ul").append("<li><a href=\""+videoProducts[i].url+"\"><img width=\"100\" height=\"100\" src=\""+videoProducts[i].image+"\" alt=\""+videoProducts[i].name+"\" /><span>"+videoProducts[i].name+"</span></a></li>");
					 	if($defined(j$("div.relatedproducts div.productSlider ul.slideItems li:last").css('width'))){
							fullWidth += j$("div.relatedproducts div.productSlider ul.slideItems li:last").css('width').toInt();
							fullWidth += j$("div.relatedproducts div.productSlider ul.slideItems li:last").css('padding-left').toInt();
							fullWidth += j$("div.relatedproducts div.productSlider ul.slideItems li:last").css('padding-right').toInt();
						}
					  }).ready(function() {
							j$("div.relatedproducts div.productSlider ul.slideItems").css({
								'width' : fullWidth
							});
							adjustMainContent();
							productSlider("div.relatedproducts");
						 });
				}
				
			});
		  });
		}
	});
}
//=========================================
function productSlider(parentDiv) {
var groupInc = 4;
var slideDuration = groupInc * 200;

	if(j$(parentDiv).length > 0) {
		j$(parentDiv+" div.productSlider ul.slideItems").css('left',0);
		var slides = [];
		j$(parentDiv+" div.productSlider ul li").each(function() {
		  slides.push(j$(this));
		});
		var slides_container = j$(parentDiv+" div.productSlider");
		var move_increment = slides[0].css('width').toInt()+slides[0].css('padding-right').toInt()+slides[0].css('padding-left').toInt();
		var current_slide = 0;
		var prev_arrow = j$(parentDiv+' div.slideControls a.prevbtn');
		var next_arrow = j$(parentDiv+' div.slideControls a.nextbtn');

		if(current_slide < slides.length - (groupInc - 1)){
		 	next_arrow.css('display','block');
		 }
		
		//center products if less than six items
		if(slides.length <= (groupInc - 1)){
			j$(parentDiv + ' div.productSlider ul.slideItems').css({
				'margin-left' : (j$(parentDiv + ' div.productSlider').css('width').toInt() - j$(parentDiv + ' div.productSlider ul.slideItems').css('width').toInt()) / 2
				});
		}
		else if(slides.length >= groupInc){
			j$(parentDiv + ' div.productSlider ul.slideItems').css('margin','0')
		}
		
		next_bind = function(){
			next_arrow.unbind('click.slideNext');
			next_arrow.bind('click.slideNext',function(){
				current_slide++;
				slide_items(parentDiv,0);
				return false;
			});
		}
		prev_bind = function(){
			prev_arrow.unbind('click.slidePrev');
			prev_arrow.bind('click.slidePrev',function(){
				current_slide--;
				slide_items(parentDiv,1);
				return false;
			});
		}
		prev_bind();
		next_bind();
		
		var end = 0;

		function check_arrows() {
			num_leftx = (current_slide+1) * groupInc;
			
			if(current_slide == 0 || slides.length <= groupInc){
				prev_arrow.css('display','none');
			}
			else if(current_slide > 0){
				prev_arrow.css('display','block');
			}
			
			if(end == 1 || slides.length <= groupInc || num_leftx == slides.length){
				next_arrow.css('display','none');
			}
			else{
				next_arrow.css('display','block');
			}
		}
		
		check_arrows();
		
		function slide_items(parentDiv,which) {
			prev_arrow.unbind('click');
			next_arrow.unbind('click');
			num_left = slides.length - (current_slide * groupInc) ;
			
			if(num_left >= groupInc){
				end = 0;
				num_left = groupInc;
			}
			else{
				end = 1;
			}			
			my_obj = j$(parentDiv+" div.productSlider ul.slideItems");
			
			if(which == 0){
				move_to = (my_obj.css('left').toInt())-(move_increment*num_left);
			}
			if(which == 1){
				if(current_slide == 0){
					move_to = 0;
				}
				else{
					move_to = (my_obj.css('left').toInt())+(move_increment*num_left);
				}
			}
			
			my_obj.animate({left: move_to+"px"}, { queue:false, duration:slideDuration, complete:function() {
				prev_bind();
				next_bind();
			}});
			check_arrows();
		}
	}
}
//==============
function adjustMainContent(){
	// update the height of the main content container and the top position of the left_nav
	if(j$('.sptop10bot10').children.length > 0){
		j$('.sptop10bot10').css('margin','0');
	}
	if(j$('#left_navigation').length > 0){
		var vidConHeight = j$('#vidContainer').height();
		var leftNavHeight = j$('#left_navigation').height();
		var adjustTop;
		var adjustHeight;
		adjustTop = vidConHeight + mastHeadHeight + 40;
		adjustHeight = vidConHeight + leftNavHeight;
		j$('#left_navigation').css('top',adjustTop);
		j$('#midContainer').css('top',adjustTop);
		j$('#main_content_area').css('height',adjustHeight);
	}
}
//=========================================
function playlist_change() {

	if(j$('#ytPlaylists').length > 0){
		var ytPlayList = $('ytPlaylists');
		psuedoPl = $('activePlaylist').getFirst();
		
		ytPlayList.addEvent('change', function() {
			if(!isContentShowing){
				showVideoContent();
			}
			j$('div#videoPlayer div.video').addClass('loading');
			change_pl(ytPlayList);
			psuedoPl.set('text', resultPl);
			getVideos(j$(this).attr('value'));
				
		});
	}
}
//=========================================
function change_pl(ytPlayList) {
	var changeTo = ytPlayList.get('value');
	var changeOps = $$('#ytPlaylists option');
	changeOps.each(function(element) {
		if(element.value == changeTo) {
			resultPl = element.get('text');
			psuedoPl.set('text', resultPl);
		}
	});
}
//=========================================
function setDefaultPlaylist(playlist){
	var plOptions = $$('#ytPlaylists option');
	var plDesc = $('activePlaylist').getFirst();
	plOptions.each(function(element){
		if(element.value == playlist){
			setPlaylist = element.get('text');
			plDesc.set('text', setPlaylist);
		}
	});
}
//========================================
//show the error message
function showErrorMsg(msg,suggestVideos){
	hideVideoContent();
	j$('#errMsg').css('display','block').append('<p>'+ msg +'</p>');
	if(suggestVideos){
		getSuggestedVideos();
	}
	else{
		return false;
	}
}
//========================
function showVideoContent(){
	j$('#videoPlayer').css('display','block');
	j$('#pcRR').css('display','block');
	j$('#bght').css('display','block');
	j$('.relatedproducts').css('display','block');
	isContentShowing = 1;
}
//========================
function hideVideoContent(){
	j$('#videoPlayer').css('display','none');
	j$('#pcRR').css('display','none');
	j$('#bght').css('display','none');
	j$('.relatedproducts').css('display','none');
	isContentShowing = 0;
}
//===========================
function setVideoCookie(name,videoID,days) {
	var date = new Date();
	date.setTime(date.getTime()+(days*24*60*60*1000));
	var expires = '; expires='+date.toGMTString();
	document.cookie = name+'='+videoID+expires+'; path=/';
}
//============================
function getVideoCookie(name) {
	var labelName = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(labelName) == 0){
			return c.substring(labelName.length,c.length);
		}
	}
	return null;
}
//============================
function updateRecentlyViewed(videoID){
	var poppedVid;
	var viewedVids = getVideoCookie('pcLowesRecentViewed');
	if(viewedVids != null){
		var vidArray = viewedVids.split(',');
		if(j$.inArray(videoID,vidArray) == -1 && vidArray.length <= 9){
			vidArray.push(videoID);
		} 
		else if(j$.inArray(videoID,vidArray) == -1 && vidArray.length == 10){
			poppedVid = vidArray.shift(vidArray);
			vidArray.push(videoID);
		}
		vidArray.reverse();
		setVideoCookie('pcLowesRecentViewed',vidArray,30);
	}
	j$(vidArray).each(function(i){
		if(poppedVid == vidArray[i]){
			j$(j$('#recentVids .relVideo a').hasClass(poppedVid)).remove();
		}
		if(!(j$('#recentVids .relVideo a').hasClass(vidArray[i]))){
			getRecentVideo(vidArray[i]);
		}
	});
}
//=============================
function stripFeature(vidID){
	var featureLoc = vidID.indexOf('&feature=youtube_gdata');
	if(featureLoc >= 0){
		return vidID.substring(0,featureLoc);
	} else {
		return vidID;	
	}
}
//=============================
function getStarRating(rating){
	if (rating >= 5.00){
		return '50';
	}
	else if(rating >=4.50 && rating <= 4.99){
		return '45';
	}
	else if(rating >=4.00 && rating <=4.49){
		return '40';
	}
	else if(rating >=3.50 && rating <= 3.99){
		return '35';
	}
	else if(rating >=3.00 && rating <= 3.49){
		return '30';
	}
	else if(rating >=2.50 && rating <= 2.99){
		return '25';
	}
	else if(rating >=2.00 && rating <= 2.49){
		return '20';
	}
	else if(rating >=1.50 && rating <= 1.99){
		return '15';
	}
	else if(rating >= 1.00 && rating <= 1.49){
		return '10';
	}
	else if(rating >=0.50 && rating <= 0.99){
		return '05';
	}
	else if(rating == 0.00){
		return '00';
	}
}