var yourLogin;
yourLogin = {};
var yourGallery = [];

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf("&",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}


function userLogin(data, site) {
	
	if (data.ResponseStatus.StatusCode == 'ProcessingException') {
		return;	
	}

	if (data.User.UserKey.Key != 'anonymous') { 
	
		$('.login .avatar').append('<img src="' + data.User.AvatarPhotoUrl + '" alt="Avatar" title="Avatar"/>');
		$('.login .welcome').append('<a href="/'+site+'/contribute/account.htm" class="color3">'+data.User.DisplayName+'</a>');
		$('.login .tier').append('<span style="color:#4D4D4D">Your Status:</span> ' + data.User.UserTier );
		$('.login .status').append(data.User.UserStatus);
		$('#nav_sub .nopipe').attr('class','').after('<li class="nopipe"><a href="/'+site+'/contribute/account.htm?ref=nav" class="color6">Account Settings</a></li>');
		
		$('#abc_pluck-success').attr('style','display: none;');
		$('.login').toggle('slow');
		//$('.login').attr('style','display: block;');
		yourLogin['userTier'] = data.User.UserTier;
		yourLogin['displayName'] = data.User.DisplayName;
	} else {
		return "";
	}	
}



// View Media 


function displayGalleria(data, site, directory) {
	




	for (var i=0; i<data.Items.length;i++) {
												
			var imgFull, imgLarge, imgMedium, imgSmall, imgTitle, imgKey, imgDescription;
			
			imgFull = "imgFull" + i;
			imgLarge = "imgLarge" + i;
			imgMedium = "imgMedium" + i;
			imgSmall = "imgSmall" + i;
			imgTitle = "imgTitle" + i;
			imgKey = "imgKey" + i;
			imgDescription = "imgDescription" + i;
			
				var title = data.Items[i].Title;
				title = title.replace(/.jpg/g,"");
				title = title.replace(/.gif/g,"");
				title = title.replace(/.png/g,"");
				title = title.replace(/.jpeg/g,"");
				title = title.replace(/.bmp/g,"");

				title = title.replace(/.JPG/g,"");
				title = title.replace(/.GIF/g,"");
				title = title.replace(/.PNG/g,"");
				title = title.replace(/.JPEG/g,"");
				title = title.replace(/.BMP/g,"");
			
			
			yourPhotos[imgFull] = data.Items[i].Image.Full;
			yourPhotos[imgLarge] = data.Items[i].Image.Large;	
			yourPhotos[imgMedium] = data.Items[i].Image.Medium;	
			yourPhotos[imgSmall] = data.Items[i].Image.Small;
			yourPhotos[imgTitle] = title;		
			yourPhotos[imgKey] = data.Items[i].PhotoKey.Key;	
			yourPhotos[imgDescription] = data.Items[i].Description;	
			yourPhotos['imgTotal'] = i;
			
			
			//$('#galleria340').append('<a href="/' + site + '/contribute/view_media.htm?id='+yourPhotos['imgKey' + i]+'&title='+yourPhotos['imgTitle' + i]+'"><img src="'+yourPhotos['imgMedium' + i]+'" alt="'+yourPhotos['imgKey' + i]+'" title="'+yourPhotos['imgTitle' + i]+'" id="'+yourPhotos['imgKey' + i]+'"></a>');
			
		
		yourGallery[i] = {
			"thumb":data.Items[i].Image.Small,
			"image":data.Items[i].Image.Small,
			"big":data.Items[i].Image.Small,
			"title":title + " ("+data.Items[i].Owner.DisplayName+")",
			"description":data.Items[i].PhotoKey.Key+"&title="+title,
			"link":data.Items[i].PhotoKey.Key+"&title="+title
		};	
		
		
			
	}		
	



	// Load the classic theme
	// Using MOD version
	Galleria.loadTheme('/' + directory + '/global_scripts/galleria/versions/latest/themes/classic/galleria.classic.modLocal.js');		

	// Initialize Galleria
	$('#galleria340').galleria({
		dataSource: yourGallery
	});	

}


function reportAbuse(id) {
	var ReportAbuseActionRequest = new PluckSDK.ReportAbuseActionRequest(); 
	var PhotoKey = new PluckSDK.PhotoKey(); 
	PhotoKey.Key = id;
	ReportAbuseActionRequest.AbuseOnKey = PhotoKey;
	ReportAbuseActionRequest.Description = $('.report_info').attr('value');
	ReportAbuseActionRequest.Reason = $('.report_options option:selected').val();							
	
	PluckSDK.SendRequests([ReportAbuseActionRequest], successReport);		

}

/* OLD replace with displayMedia_photo, .._video, .._audio etc.. */

function displayMediaPhoto(data, site, display) {

	if (data.Photo != undefined) { 
	
		yourMedia['imgLarge'] = data.Photo.Image.Large;
		yourMedia['imgFull'] = data.Photo.Image.Full;
		yourMedia['imgTitle'] = unescape(data.Photo.Title);
		yourMedia['imgTags'] = data.Photo.Tags;
		yourMedia['imgDescription'] = data.Photo.Description;
		yourMedia['imgOwnerDisplayName'] = data.Photo.Owner.DisplayName;
		yourMedia['imgOwnerAvatarPhotoUrl'] = data.Photo.Owner.AvatarPhotoUrl;
		yourMedia['imgOwner'] = data.Photo.Owner.DisplayName;
		yourMedia['userKey'] = data.Photo.Owner.UserKey.Key;		
	
		if (yourMedia.imgOwnerAvatarPhotoUrl != 'undefined') {
			$('.owner .avatar').append('<img src="' + yourMedia.imgOwnerAvatarPhotoUrl + '" title="Avatar" alt="Avatar"/>');
		}
		
		$('.owner .byline').append('<strong>By:</strong> ' + yourMedia.imgOwnerDisplayName + '');
		$('.owner .other').append('<a href="/' + site + '/contribute/view_more.htm?searchTermInput=DisplayName:'+yourMedia.imgOwnerDisplayName+'" class="color3">Other photos by this user</a>');
		
		$('#col1 .title').html(yourMedia.imgTitle);
		$(document).attr('title', yourMedia.Title);
		
		

		if (yourMedia.imgDescription != "") {
			$('.module .media_description .description').append("<h3>Description</h3>"+yourMedia.imgDescription);
		}
		
		
		$('.media .item').append('<a href="'+yourMedia.imgFull+'"><img src="'+yourMedia.imgLarge+'" alt="'+yourMedia.imgTitle+'" title="'+yourMedia.imgTitle+'"/></a>');	


			
		//Break up tags, split with commas
		var tagString = yourMedia.imgTags.split(", ");
		
		for (var i=0; i<tagString.length; i++) {
				
			tagString[i] = '<a href="/' + site + '/contribute/view_more.htm?searchTermInput=Tags:'+tagString[i]+'" class="color3">' + tagString[i] + '</a>, ';
			
		
			if (display == true) {
				$('.tags').append(tagString[i]);
			} else {
				if (tagString[i].indexOf('YYY') < 0) {
					$('.tags').append(tagString[i]);
				}	
			}

		
			
			if (tagString[i].indexOf('YYYrmplocalYYYlocationYYY') >= 0) {
				$('.location').append(tagString[i]);
				var labelLocation = $('.location a').html();
				labelLocation = labelLocation.replace('YYYrmplocalYYYlocationYYY','');		
				//labelLocation = labelLocation.replace('_',' ');	
				labelLocation = labelLocation.replace(/_/g," ");
				//labelLocation = decodeURIComponent(labelLocation);
				$('.location a').html(labelLocation);	
				
				labelLocation = $('.location').html();
				labelLocation = labelLocation.substr(0,labelLocation.length-2);
				 $('.location').html(labelLocation);
				
				
			}	
			

			
		
		}	
	
		var tagStringFinal = $('.tags').html();
		tagStringFinal = tagStringFinal.substr(0,tagStringFinal.length-2);
		 $('.tags').html(tagStringFinal);
	

		//Report Abuse		
		if ((data.Photo.AbuseCounts.CurrentUserHasReportedAbuse == true) && (data.Photo.AbuseCounts.AbuseReportCount > 0)) {
			$('.report .heading h3').html('Report Abuse: <span class="reported">Reported</span>');
			$('.report .heading a').remove();
			$('.report .container').remove();		
		}
		
		
	}
}



function displayMediaVideo(data, site, display) {
	
	if (data.Video != undefined) { 
	
		yourMedia['ThumbnailUrl'] = data.Video.ThumbnailUrl;
		yourMedia['Url'] = data.Video.Url;
		yourMedia['Title'] = unescape(data.Video.Title);
		yourMedia['Tags'] = data.Video.Tags;
		yourMedia['Description'] = data.Video.Description;
		yourMedia['OwnerDisplayName'] = data.Video.Owner.DisplayName;
		yourMedia['OwnerAvatarPhotoUrl'] = data.Video.Owner.AvatarPhotoUrl;
		yourMedia['userKey'] = data.Video.Owner.UserKey.Key;		
	
		if (yourMedia.OwnerAvatarPhotoUrl != 'undefined') {
			$('.owner .avatar').append('<img src="' + yourMedia.OwnerAvatarPhotoUrl + '" title="Avatar" alt="Avatar"/>');
		}
		
		$('.owner .byline').append('<strong>By:</strong> ' + yourMedia.OwnerDisplayName + '');
		$('.owner .other').append('<a href="/' + site + '/contribute/view_more.htm?type=video&searchTermInput=DisplayName:'+yourMedia.OwnerDisplayName+'" class="color3">Other photos by this user</a>');
	
		$('#col1 .title').html(yourMedia.Title);
		$(document).attr('title', yourMedia.Title);
		
		

		if (yourMedia.Description == undefined) {
			$('.module .media_description .description').append("<h3>Description</h3>No description entered.");	
		} else if (yourMedia.Description != "") {
			$('.module .media_description .description').append("<h3>Description</h3>"+yourMedia.Description);
		}
		
		
		if (data.Video.VideoState == 'Processing') {
			$('.media .item').append('<img src="/local/global_img/spacer.gif" alt="'+yourMedia.Title+'" title="'+yourMedia.Title+'" id="media_main_player"/>');	
		} else {		
			$('.media .item').append('<a href="'+yourMedia.ThumbnailUrl+'"><img src="'+yourMedia.ThumbnailUrl+'" alt="'+yourMedia.Title+'" title="'+yourMedia.Title+'" id="media_main_player"/></a>');	
		}



	if (yourMedia.Tags != undefined) {
			
		//Break up tags, split with commas
		var tagString = yourMedia.Tags.split(", ");
		
		for (var i=0; i<tagString.length; i++) {
				
			tagString[i] = '<a href="/' + site + '/contribute/view_more.htm?searchTermInput=Tags:'+tagString[i]+'" class="color3">' + tagString[i] + '</a>, ';
			
		
			if (display == true) {
				$('.tags').append(tagString[i]);
			} else {
				if (tagString[i].indexOf('YYY') < 0) {
					$('.tags').append(tagString[i]);
				}	
			}

		
			
			if (tagString[i].indexOf('YYYrmplocalYYYlocationYYY') >= 0) {
				$('.location').append(tagString[i]);
				var labelLocation = $('.location a').html();
				labelLocation = labelLocation.replace('YYYrmplocalYYYlocationYYY','');		
				//labelLocation = labelLocation.replace('_',' ');	
				labelLocation = labelLocation.replace(/_/g," ");
				//labelLocation = decodeURIComponent(labelLocation);
				$('.location a').html(labelLocation);	
				
				labelLocation = $('.location').html();
				labelLocation = labelLocation.substr(0,labelLocation.length-2);
				 $('.location').html(labelLocation);
				
				
			}	
			

			
		
		}	
	
		var tagStringFinal = $('.tags').html();
		tagStringFinal = tagStringFinal.substr(0,tagStringFinal.length-2);
		 $('.tags').html(tagStringFinal);
		 
	}
	

		//Report Abuse		
		if ((data.Video.AbuseCounts.CurrentUserHasReportedAbuse == true) && (data.Video.AbuseCounts.AbuseReportCount > 0)) {
			$('.report .heading h3').html('Report Abuse: <span class="reported">Reported</span>');
			$('.report .heading a').remove();
			$('.report .container').remove();		
		}
		
		
	}
}


/* END - OLD replace with displayMedia_photo, .._video, .._audio etc.. */

/* NEW replaced with displayMedia_photo, .._video, .._audio etc.. */


function displayMedia_photo(data, site, display) {

	if (data.Photo != undefined) { 
	
		yourMedia['imgLarge'] = data.Photo.Image.Large;
		yourMedia['imgFull'] = data.Photo.Image.Full;
		yourMedia['imgTitle'] = unescape(data.Photo.Title);
		yourMedia['imgTags'] = data.Photo.Tags;
		yourMedia['imgDescription'] = data.Photo.Description;
		yourMedia['imgOwnerDisplayName'] = data.Photo.Owner.DisplayName;
		yourMedia['imgOwnerAvatarPhotoUrl'] = data.Photo.Owner.AvatarPhotoUrl;
		yourMedia['imgOwner'] = data.Photo.Owner.DisplayName;
		yourMedia['userKey'] = data.Photo.Owner.UserKey.Key;		
	
		if (yourMedia.imgOwnerAvatarPhotoUrl != 'undefined') {
			$('.owner .avatar').append('<img src="' + yourMedia.imgOwnerAvatarPhotoUrl + '" title="Avatar" alt="Avatar"/>');
		}
		
		$('.owner .byline').append('<strong>By:</strong> ' + yourMedia.imgOwnerDisplayName + '');
		$('.owner .other').append('<a href="/' + site + '/contribute/view_more.htm?searchTermInput=DisplayName:'+yourMedia.imgOwnerDisplayName+'" class="color3">Other photos by this user</a>');
	
		$('#col1 .title').html(yourMedia.imgTitle);
		var pageTitle = $(document).attr('title');
		pageTitle = pageTitle.replace(/\\'/g,"'");;
		$(document).attr('title',pageTitle);
		
		

		if (yourMedia.imgDescription != "") {
			$('.module .media_description .description').append("<h3>Description</h3>"+yourMedia.imgDescription);
		}
		
		
		$('.media .item').append('<a href="'+yourMedia.imgFull+'"><img src="'+yourMedia.imgLarge+'" alt="'+yourMedia.imgTitle+'" title="'+yourMedia.imgTitle+'"/></a>');	


			
		//Break up tags, split with commas
		var tagString = yourMedia.imgTags.split(", ");
		
		for (var i=0; i<tagString.length; i++) {

		
			
				if (tagString[i].indexOf('YYYrmplocalYYYsiteYYY') >= 0) {
						
						var tagConfigCheck = tagString[i];
						
							$.ajax({
							  url:"/local/global_config/pluck/header_config.js",
							  context: document.body,
							  success: function(){							
								if (typeof headerConfig[tagConfigCheck] == "undefined") {
	
								} else {
									$.get(headerConfig[tagConfigCheck], function(data) {$('#col1 .status').before(data);},'html');
								}
							  }						
							});
				}
			
			

				
			if (tagString[i].indexOf('YYYsubjectYYY') >= 0) {
				var labelFix = tagString[i].replace(/YYYsubjectYYY/g," ");
				labelFix = labelFix.replace(/_/g," ");
			} else {
				var labelFix = tagString[i];
			}
				
			tagString[i] = '<a href="/' + site + '/contribute/view_more.htm?searchTermInput=Tags:'+tagString[i]+'" class="color3">' + labelFix + '</a>, ';
			
		
			if (display == true) {
				$('.tags').append(tagString[i]);
			} else {
				if ((tagString[i].indexOf('YYY') < 0) || (tagString[i].indexOf('YYYsubjectYYY') >= 0)) {
					$('.tags').append(tagString[i]);
				}
			}


		
			
			if (tagString[i].indexOf('YYYrmplocalYYYlocationYYY') >= 0) {
				$('.location').append(tagString[i]);
				var labelLocation = $('.location a').html();
				labelLocation = labelLocation.replace('YYYrmplocalYYYlocationYYY','');		
				//labelLocation = labelLocation.replace('_',' ');	
				labelLocation = labelLocation.replace(/_/g," ");
				//labelLocation = decodeURIComponent(labelLocation);
				$('.location a').html(labelLocation);	
				
				labelLocation = $('.location').html();
				labelLocation = labelLocation.substr(0,labelLocation.length-2);
				 $('.location').html(labelLocation);
				
				
			}	
			

			
		
		}	
	
		var tagStringFinal = $('.tags').html();
		tagStringFinal = tagStringFinal.substr(0,tagStringFinal.length-2);
		 $('.tags').html(tagStringFinal);
	

		//Report Abuse		
		if ((data.Photo.AbuseCounts.CurrentUserHasReportedAbuse == true) && (data.Photo.AbuseCounts.AbuseReportCount > 0)) {
			$('.report .heading h3').html('Report Abuse: <span class="reported">Reported</span>');
			$('.report .heading a').remove();
			$('.report .container').remove();		
		}
		
		
	}
}



function displayMedia_video(data, site, display) {
	
	if (data.Video != undefined) { 
	
		yourMedia['ThumbnailUrl'] = data.Video.ThumbnailUrl;
		yourMedia['Url'] = data.Video.Url;
		yourMedia['Title'] = unescape(data.Video.Title);
		yourMedia['Tags'] = data.Video.Tags;
		yourMedia['Description'] = data.Video.Description;
		yourMedia['OwnerDisplayName'] = data.Video.Owner.DisplayName;
		yourMedia['OwnerAvatarPhotoUrl'] = data.Video.Owner.AvatarPhotoUrl;
		yourMedia['userKey'] = data.Video.Owner.UserKey.Key;		
	
		if (yourMedia.OwnerAvatarPhotoUrl != 'undefined') {
			$('.owner .avatar').append('<img src="' + yourMedia.OwnerAvatarPhotoUrl + '" title="Avatar" alt="Avatar"/>');
		}
		
		$('.owner .byline').append('<strong>By:</strong> ' + yourMedia.OwnerDisplayName + '');
		$('.owner .other').append('<a href="/' + site + '/contribute/view_more.htm?type=video&searchTermInput=DisplayName:'+yourMedia.OwnerDisplayName+'" class="color3">Other videos by this user</a>');
	
		$('#col1 .title').html(yourMedia.Title);
		$(document).attr('title', yourMedia.Title);
		
		

		if (yourMedia.Description == undefined) {
			$('.module .media_description  .description').append("<h3>Description</h3>No description entered.");	
		} else if (yourMedia.Description != "") {
			$('.module .media_description .description').append("<h3>Description</h3>"+yourMedia.Description);
		}
		
		
		if (data.Video.VideoState == 'Processing') {
			$('.media .item').append('<img src="/local/global_img/spacer.gif" alt="'+yourMedia.Title+'" title="'+yourMedia.Title+'" id="media_main_player"/></a>');	
		} else {		
			$('.media .item').append('<a href="'+yourMedia.ThumbnailUrl+'"><img src="'+yourMedia.ThumbnailUrl+'" alt="'+yourMedia.Title+'" title="'+yourMedia.Title+'" id="media_main_player"/></a>');	
			play_video(yourMedia.Url, yourMedia.Title);		
		}



	if (yourMedia.Tags != undefined) {
			
		//Break up tags, split with commas
		var tagString = yourMedia.Tags.split(", ");
		
		for (var i=0; i<tagString.length; i++) {
			
			if (tagString[i].indexOf('YYYsubjectYYY') >= 0) {
				var labelFix = tagString[i].replace(/YYYsubjectYYY/g," ");
				labelFix = labelFix.replace(/_/g," ");
			} else {
				var labelFix = tagString[i];
			}
				
			tagString[i] = '<a href="/' + site + '/contribute/view_more.htm?searchTermInput=Tags:'+tagString[i]+'&type=video" class="color3">' + labelFix + '</a>, ';
			
		
			if (display == true) {
				$('.tags').append(tagString[i]);
			} else {
				if ((tagString[i].indexOf('YYY') < 0) || (tagString[i].indexOf('YYYsubjectYYY') >= 0)) {
					$('.tags').append(tagString[i]);
				}
			}

		
			
			if (tagString[i].indexOf('YYYrmplocalYYYlocationYYY') >= 0) {
				$('.location').append(tagString[i]);
				var labelLocation = $('.location a').html();
				labelLocation = labelLocation.replace('YYYrmplocalYYYlocationYYY','');		
				//labelLocation = labelLocation.replace('_',' ');	
				labelLocation = labelLocation.replace(/_/g," ");
				//labelLocation = decodeURIComponent(labelLocation);
				$('.location a').html(labelLocation);	
				
				labelLocation = $('.location').html();
				labelLocation = labelLocation.substr(0,labelLocation.length-2);
				 $('.location').html(labelLocation);
				
				
			}	
			

			
		
		}	
	
		var tagStringFinal = $('.tags').html();
		tagStringFinal = tagStringFinal.substr(0,tagStringFinal.length-2);
		 $('.tags').html(tagStringFinal);
		 
	}
	

		//Report Abuse		
		if ((data.Video.AbuseCounts.CurrentUserHasReportedAbuse == true) && (data.Video.AbuseCounts.AbuseReportCount > 0)) {
			$('.report .heading h3').html('Report Abuse: <span class="reported">Reported</span>');
			$('.report .heading a').remove();
			$('.report .container').remove();		
		}
		
		
	}
}



function displayMedia_audio(data, site, display, dataAudio) {
	
	if (data.Video != undefined) { 
	
		yourMedia['ThumbnailUrl'] = data.Video.ThumbnailUrl;
		yourMedia['Url'] = data.Video.Url;
		yourMedia['Title'] = unescape(data.Video.Title);
		yourMedia['Tags'] = data.Video.Tags;
		yourMedia['Description'] = data.Video.Description;
		yourMedia['OwnerDisplayName'] = data.Video.Owner.DisplayName;
		yourMedia['OwnerAvatarPhotoUrl'] = data.Video.Owner.AvatarPhotoUrl;
		yourMedia['userKey'] = data.Video.Owner.UserKey.Key;		
	
		if (yourMedia.OwnerAvatarPhotoUrl != 'undefined') {
			$('.owner .avatar').append('<img src="' + yourMedia.OwnerAvatarPhotoUrl + '" title="Avatar" alt="Avatar"/>');
		}
		
		$('.owner .byline').append('<strong>By:</strong> ' + yourMedia.OwnerDisplayName + '');
		$('.owner .other').append('<a href="/' + site + '/contribute/view_more.htm?type=audio&searchTermInput=DisplayName:'+yourMedia.OwnerDisplayName+'" class="color3">Other audio by this user</a>');
	
		$('#col1 .title').html(yourMedia.Title);
		$(document).attr('title', yourMedia.Title);
		
		

		if (yourMedia.Description == undefined) {
			$('.module .media_description .description').append("<h3>Description</h3>No description entered.");	
		} else if (yourMedia.Description != "") {
			$('.module .media_description .description').append("<h3>Description</h3>"+yourMedia.Description);
		}
		
		
		if (data.Video.VideoState == 'Processing') {
			$('.media .item').append('<img src="/local/global_img/spacer.gif" alt="'+yourMedia.Title+'" title="'+yourMedia.Title+'" id="media_main_player"/></a>');	
			
		} else {			
			$('.media .item').append('<img src="/local/global_img/spacer.gif" alt="'+yourMedia.Title+'" title="'+yourMedia.Title+'" id="media_main_player"/></a><ul class="standard_list"><li><a target="_top" class="color3" href="'+dataAudio.OriginalVideoUrl+'">Download original audio</a></li></ul>');		
			//play_audio(yourMedia.Url, yourMedia.Title);	
			
		   jwplayer("media_main_player").setup({
		    	flashplayer					: "/res/players/aacPlayer.swf",
		        width						: '700',
		        height						: '36', 
		    	autostart					:'false',
				file						: yourMedia.Url,
				streamingMessage			: yourMedia.Title,
				autoStart					: 'false',
				bgCornerRadius:'10',
				controlsBgCornerRadius:'5',	
				bgColor						: "#D5D5D5" // "none" = no bg (can be used with wmode transparent to float player over bmp bg's etc)
		    });		
		   
		}



	if (yourMedia.Tags != undefined) {
			
		//Break up tags, split with commas
		var tagString = yourMedia.Tags.split(", ");
		
		for (var i=0; i<tagString.length; i++) {
				
			if (tagString[i].indexOf('YYYsubjectYYY') >= 0) {
				var labelFix = tagString[i].replace(/YYYsubjectYYY/g," ");
				labelFix = labelFix.replace(/_/g," ");
			} else {
				var labelFix = tagString[i];
			}
				
			tagString[i] = '<a href="/' + site + '/contribute/view_more.htm?searchTermInput=Tags:'+tagString[i]+'&type=audio" class="color3">' + labelFix + '</a>, ';
			
		
			if (display == true) {
				$('.tags').append(tagString[i]);
			} else {
				if ((tagString[i].indexOf('YYY') < 0) || (tagString[i].indexOf('YYYsubjectYYY') >= 0)) {
					$('.tags').append(tagString[i]);
				}
			}


		
			
			if (tagString[i].indexOf('YYYrmplocalYYYlocationYYY') >= 0) {
				$('.location').append(tagString[i]);
				var labelLocation = $('.location a').html();
				labelLocation = labelLocation.replace('YYYrmplocalYYYlocationYYY','');		
				//labelLocation = labelLocation.replace('_',' ');	
				labelLocation = labelLocation.replace(/_/g," ");
				//labelLocation = decodeURIComponent(labelLocation);
				$('.location a').html(labelLocation);	
				
				labelLocation = $('.location').html();
				labelLocation = labelLocation.substr(0,labelLocation.length-2);
				 $('.location').html(labelLocation);
				
				
			}	
			

			
		
		}	
	
		var tagStringFinal = $('.tags').html();
		tagStringFinal = tagStringFinal.substr(0,tagStringFinal.length-2);
		 $('.tags').html(tagStringFinal);
		 
	}
	

		//Report Abuse		
		if ((data.Video.AbuseCounts.CurrentUserHasReportedAbuse == true) && (data.Video.AbuseCounts.AbuseReportCount > 0)) {
			$('.report .heading h3').html('Report Abuse: <span class="reported">Reported</span>');
			$('.report .heading a').remove();
			$('.report .container').remove();		
		}
		
		
	}
}

/* END - NEW replace with displayMedia_photo, .._video, .._audio etc.. */


function displayEdit(id,site,type) {

		if (type=='video') {
	
			if ((yourMedia.userKey == getCookie('u')) || (yourLogin.userTier == 'Editor')) {
				$('.heading .edit').html('(<a href="/'+site+'/contribute/upload_tag.htm?id='+id+'&type='+type+'" class="color3">Edit this item</a>)');	
			}	
			
		} else if (type=='audio') {

			if ((yourMedia.userKey == getCookie('u')) || (yourLogin.userTier == 'Editor')) {
				$('.heading .edit').html('(<a href="/'+site+'/contribute/upload_tag.htm?id='+id+'&type='+type+'" class="color3">Edit this item</a>)');	
			}	

		} else if (type=='photo') {
			
			if ((yourMedia.userKey == getCookie('u')) || (yourLogin.userTier == 'Editor')) {
				$('.heading .edit').html('(<a href="/'+site+'/contribute/upload_tag.htm?id='+id+'" class="color3">Edit this photo</a>)');	
			}				
			
		}
		
}


$(document).ready(function() {	

	$('.report .button').click(function() {	
		$('.report .container').toggle('slow');	
		if ( $('.report .heading').attr('class') == 'heading collapse' ) {
			$('.report .heading').removeClass('collapse').addClass('expand');		
		} else {
			$('.report .heading').removeClass('expand').addClass('collapse');
		}		
		return false;	
	});
	
	
	$('.report h3').click(function() {	
		$('.report .container').toggle('slow');	
		if ( $('.report .heading').attr('class') == 'heading collapse' ) {
			$('.report .heading').removeClass('collapse').addClass('expand');		
		} else {
			$('.report .heading').removeClass('expand').addClass('collapse');
		}		
		return false;	
	});	
	
	$('.report .cancel').click(function() {	
		$('.report .container').toggle('slow');	
		if ( $('.report .heading').attr('class') == 'heading collapse' ) {
			$('.report .heading').removeClass('collapse').addClass('expand');		
		} else {
			$('.report .heading').removeClass('expand').addClass('collapse');
		}		
		return false;	
	});		

 });


// END View Media



/* Play Video */

function play_video(url, title, id, width, height, autostart) {
	//create a colour object to define the colors for the player.
	//highlightColour is the color of the bar that follows the play head.
	//backgroundColour is the colour of the page behind the player.
	//textColour is the colour of the title and the counters.
	
	
	
	/*The replace function replaces an element on the page with the cinerama player. The  parameters are:
	
	(id, source, width, height, colour object, title, autoStart)
		
	id: (required) The id of the element to be replaced, usually an image element. The image will then be pulled into the player and displayed before the video is started.
	
	source: (required) This can be a single flv or h.264 mp4 file or a media rss file containing 1 or more items. 
		    If a media rss file does contain more that one item the multiClip section is automatically embedded next to the player.
		   
	width:  (required) The width of the video to be displayed.
	
	height:  (required) The height of the video to be displayed. Note that the player will embed slightly higher that this to allow for the controlls.
	
	colour object: A javascript object defining the colours for the player (see above).
	
	title: The beginning title displayed on the player before a movie is played. If no title is supplied the script will attempt to use the alt text of the image it is replacing.
	
	autoStart: 'true' tells the player to start the video as soon as it loads. 'false' tells the player to wait for the user to initiate the video by pressing play.
	
	embedSrc: 'true' tells the player to show the embed src for the video. 'false' hides the embed Src.
	
	*/
	
	cinerama.ratings = false;
	cinerama.secure = false;
	cinerama.geoBlock = false;
	cinerama.embedSrc = true;
	cinerama.highlightColour = "#006CD9";
	cinerama.backgroundColour = "#FFFFFF";
	cinerama.textColour = "#77BBFF";
	
	if (id == undefined) {
		id = 'media_main_player';		
	}
	
	if (width == undefined) {
		width = 700;
	}
	
	if (height == undefined) {
		height = 466;
	}
	
	if (title == undefined) {
		title = '';
	}
	
	if (autostart == undefined) {
		autostart = 'false';
	}
	
	// Default height and widths, overwritten by css.
	cinerama.embedPlayer(id,url,width,height,title,autostart);

			

}

/* END Play Video */


/* Play Audio */

function play_audio(url, title) {
	//create a colour object to define the colors for the player.
	//highlightColour is the color of the bar that follows the play head.
	//backgroundColour is the colour of the page behind the player.
	//textColour is the colour of the title and the counters.
	
	
	
	/*The replace function replaces an element on the page with the cinerama player. The  parameters are:
	
	(id, source, width, height, colour object, title, autoStart)
		
	id: (required) The id of the element to be replaced, usually an image element. The image will then be pulled into the player and displayed before the video is started.
	
	source: (required) This can be a single flv or h.264 mp4 file or a media rss file containing 1 or more items. 
		    If a media rss file does contain more that one item the multiClip section is automatically embedded next to the player.
		   
	width:  (required) The width of the video to be displayed.
	
	height:  (required) The height of the video to be displayed. Note that the player will embed slightly higher that this to allow for the controlls.
	
	colour object: A javascript object defining the colours for the player (see above).
	
	title: The beginning title displayed on the player before a movie is played. If no title is supplied the script will attempt to use the alt text of the image it is replacing.
	
	autoStart: 'true' tells the player to start the video as soon as it loads. 'false' tells the player to wait for the user to initiate the video by pressing play.
	
	embedSrc: 'true' tells the player to show the embed src for the video. 'false' hides the embed Src.
	
	
	
	cinerama.ratings = false;
	cinerama.secure = false;
	cinerama.geoBlock = false;
	cinerama.embedSrc = true;
	cinerama.highlightColour = "#006CD9";
	cinerama.backgroundColour = "#FFFFFF";
	cinerama.textColour = "#77BBFF";
	
	// Default height and widths, overwritten by css.
	cinerama.embedPlayer('media_main_player',url,700,140,title,'false');
	
	
	*/
	
		   jwplayer("media_main_player").setup({
		    	flashplayer					: "/res/players/aacPlayer.swf",
		        width						: '700',
		        height						: '36', 
				file						: url,
				title						: title,
				autostart					: 'false',
				playlist					: 'bottom',
				bgCornerRadius:'10',
				controlsBgCornerRadius:'5',	
				bgColor						: "#D5D5D5" // "none" = no bg (can be used with wmode transparent to float player over bmp bg's etc)
		    });		

			

}

/* END Play Audio */

