//  MySpace Useful Javascript Functions - Written by Richard Francis (UK)
// Email rfrancis@myspace.com for any assistance

// Create MySpace video player
function vid(divid, vidid, bg, width, height, autop) {
	global_bg = bg;
	global_width = width;
	global_height = height;
	global_vidid = vidid;
	newdivid = "myspacevidcontainer_"+divid;
	if(autop==true){
		aplay='1';
	}else{
		aplay='0';
	}
	
	vidcode='<div id="'+newdivid+'" style="width:'+width+'px;height:'+height+'px;"><embed type="application/x-shockwave-flash" src="http://mediaservices.myspace.com/services/media/embed.aspx/m='+vidid+',t=1,mt=video,ap='+aplay+'" style="" id="'+divid+'" name="'+divid+'" bgcolor="#000000" quality="high" wmode="transparent" allowscriptaccess="always" allowfullscreen="true" flashvars="e=http%3A//vids.myspace.com/&primaryColor=0x'+bg+'&secondaryColor=0x'+bg+'&sr=0" height="'+height+'" width="'+width+'"></div>';
	document.write(vidcode);
}

// Change video in existing player
function changeVid(divid, newvidid, autop){
	global_vidid = newvidid;
	if(autop==true){
		aplay='1';
	}else{
		aplay='0';
	}
	newdivid = "myspacevidcontainer_"+divid;
	document.getElementById(newdivid).innerHTML = '<embed type="application/x-shockwave-flash" src="http://mediaservices.myspace.com/services/media/embed.aspx/m='+newvidid+',t=1,mt=video,ap='+aplay+'" style="" id="'+divid+'" name="'+divid+'" bgcolor="#000000" quality="high" wmode="transparent" allowscriptaccess="always" allowfullscreen="true" flashvars="e=http%3A//vids.myspace.com/&primaryColor=0x'+global_bg+'&secondaryColor=0x'+global_bg+'&sr=0" height="'+global_height+'" width="'+global_width+'">';
}



// Add the current video to profile
function addVid() {
	window.location.href = "http://vids.myspace.com/index.cfm?fuseaction=vids.addToProfileConfirm&videoid="+global_vidid;
}



// Function for PNG fix in browsers < IE7

function doPngFix(){
	var arVersion = navigator.appVersion.split("MSIE")
	var version = parseFloat(arVersion[1])

	if ((version >= 5.5) && (document.body.filters)){
		for(var i=0; i<document.images.length; i++){
			var img = document.images[i]
			var imgName = img.src.toUpperCase()
			if (imgName.substring(imgName.length-3, imgName.length) == "PNG"){
				var imgID = (img.id) ? "id='" + img.id + "' " : ""
				var imgClass = (img.className) ? "class='" + img.className + "' " : ""
				var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
				var imgStyle = "display:inline-block;" + img.style.cssText 
				if (img.align == "left") imgStyle = "float:left;" + imgStyle
				if (img.align == "right") imgStyle = "float:right;" + imgStyle
				if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
				var strNewHTML = "<span " + imgID + imgClass + imgTitle
				+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
				+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
				+ "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
				img.outerHTML = strNewHTML
				i = i-1
			}
		}
	}
}




// ==== Contact functions ==== //

// Add to friends
function addToFriends(lid){
	window.location.href="http://friends.myspace.com/index.cfm?fuseaction=invite.addfriend_verify&friendID="+MySpaceClientContext.DisplayFriendId+"&lid="+lid;
}

// Add to favourites
function addToFavourites(lid){
	window.location.href="http://collect.myspace.com/index.cfm?fuseaction=user.addToFavorite&friendID="+MySpaceClientContext.DisplayFriendId+"&public=0&lid="+lid;
}

// Forward to friend
function forwardToFriend(lid){
	window.location.href="http://messaging.myspace.com/index.cfm?fuseaction=mail.forward&friendID="+MySpaceClientContext.DisplayFriendId+"&f=forwardprofile&lid="+lid;
}

// Send a message
function sendAMessage(lid){
	window.location.href="http://messaging.myspace.com/index.cfm?fuseaction=mail.message&friendID="+MySpaceClientContext.DisplayFriendId+"&lid="+lid;
}

// Add to group
function addToGroup(lid){
	window.location.href="http://groups.myspace.com/index.cfm?fuseaction=groups.addtogroup&friendID="+MySpaceClientContext.DisplayFriendId+"&lid="+lid;
}

// Block user
function blockUser(lid){
	window.location.href="http://friends.myspace.com/index.cfm?fuseaction=block.blockUser&userID="+MySpaceClientContext.DisplayFriendId+"&lid="+lid;
}

// Rank user
function rankUser(lid){
	window.location.href="http://collect.myspace.com/index.cfm?fuseaction=RateImage.UserRating&UserID="+MySpaceClientContext.DisplayFriendId+"&lid="+lid;
}




// ==== Other generic links ====//

// Subscribe to blog
function subscribeToBlog(lid){
	window.location.href="http://blog.myspace.com/index.cfm?fuseaction=blog.ConfirmSubscribe&friendID="+MySpaceClientContext.DisplayFriendId+"&lid="+lid;
}

// View all blog entries
function viewAllBlogEntries(lid){
	window.location.href="http://blog.myspace.com/index.cfm?fuseaction=blog.ListAll&friendID="+MySpaceClientContext.DisplayFriendId+"&lid="+lid;
}

// View all videos
function viewAllVideos(lid){
	window.location.href="http://vids.myspace.com/index.cfm?fuseaction=vids.showvids&friendID="+MySpaceClientContext.DisplayFriendId+"&lid="+lid;
}

// View all pictures
function viewAllPics(lid){
	window.location.href="http://viewmorepics.myspace.com/index.cfm?fuseaction=user.viewAlbums&friendID="+MySpaceClientContext.DisplayFriendId+"&lid="+lid;
}