window.onload = ConstrainRankingImages;


//THIS FUNCTION MAKES SURE THE DEFAULT PIC THAT IS BEING USED IS THE LARGER VERSION RATHER THAN THE MEDIUM OR SMALL VERSION - TO AVOID PIXELATION

function GetSize(size) 
{
    if (imageUrl == "http://x.myspace.com/images/no_pic.gif")
        return imageUrl="http://creative.myspace.com/CodeLibrary/Global/Samples/CustomIdBadge/images/noPhoto.png";
        
	if (imageUrl.indexOf("_s") > -1)
		return imageUrl.replace(/_s/,"_" + size);
	
	if (imageUrl.indexOf("s_") > -1)
		return imageUrl.replace(/s_"/, size + "_" );

	if (imageUrl.indexOf("_m") > -1)
		return imageUrl.replace(/_m/,"_" + size);
	
	if (imageUrl.indexOf("m_") > -1)
		return imageUrl.replace(/m_/, size + "_" );

	else
		//alert('The file name is missing either s_, _s, m_ , _m');	
		
	return null;
}
	var imageUrl = GetSize('l');
	document.write('<div id="profileImage"><img name="profileImg" src="'+imageUrl+'"></div>');



//IMAGE CONSTRAINT FUNCTION 

var RANKING_MAX_WIDTH = 125; //change this to match your specific movie clip
var RANKING_MAX_HEIGHT = 118; //change this to match the dimensions of your movie clip
var RANKING_CONTAINER_ID = 'profileImage'


function ConstrainImageSize(img, maxHeight, maxWidth)
{
    var changeFactor;
    
    // if both width and height are too big, constrain off the biggest one
    if (img.height > maxHeight && img.width > maxWidth)
    {
        // find what factor to constrain by
        if (img.height > img.width)
            changeFactor = maxHeight / img.height;
        if (img.height <= img.width)
         {
		    //changeFactor = maxWidth / img.width;
			changeFactor = 1;
			return {height:maxHeight, width: maxWidth};
		}
    }
    // if width is too big constrain off it
    else if (img.width > maxWidth)
        changeFactor = maxWidth / img.width;
    // if height is too big constrain off it	
    else if (img.height > maxHeight)
        changeFactor = maxHeight / img.height;
    
    // otherwise everything is fine
    else
        changeFactor = 1;


    // now set the new size is
    return {height:img.height * changeFactor, width: img.width * changeFactor};

}

function ConstrainRankingImages()
{
	var akamaiPath="http://creative-origin.myspace.com/Client/Bennigans/FergusDargle/Swf/";//insert path to swf here such as http://creative.myspace.com/Client/Bennigans/Swf/
 
    if (isLoggedIn < 0)
    {
        document.getElementById('flashDiv').innerHTML = "<br /><br /><br /><br /><br /><br />You must be logged-in to view this content <br /><a href =\"http://www.myspace.com\" name=\"&lid=ribbonLogin\">Login</a>";
        return false;
    }
    
	var images = document.getElementById(RANKING_CONTAINER_ID).getElementsByTagName('img');
    for (i=0;i<images.length;i++)
    {
        var imageDimensions = ConstrainImageSize(images[i], RANKING_MAX_HEIGHT, RANKING_MAX_WIDTH);
        images[i].style.width = imageDimensions.width + 'px';
        images[i].style.height = imageDimensions.height + 'px';
    }
		document.getElementById('flashDiv').innerHTML = '<embed src="'+akamaiPath+'badge_hbx.swf?image='+imageUrl+'&imageWidth='+imageDimensions.width+'&imageHeight='+imageDimensions.height+'&maxHeight='+RANKING_MAX_HEIGHT+'&maxWidth='+RANKING_MAX_WIDTH+'&imageWidth='+imageDimensions.width+'&imageHeight='+imageDimensions.height+'&age='+age+'" width="245" height="415" wmode="transparent" allowScriptAccess="always" />';
}

//VIDEO SWAP

var defaultWidth = 430;
var defaultHeight = 346;

// loads the video player and then changes the text.
// width and height are optional
function OnVideoClick(videoId, headerText, width, height)
{
    LoadVideo(videoId, width, height);

}

// loads the video player
// width and height are optional
function LoadVideo(videoId, width, height)
{
    // if the width and height have been specified, we set it.
    // otherwise we use the default width and height that are defined above
    width = (width) ? width : defaultWidth;
    height = (height) ? height : defaultHeight;
    
    // change the video source   
    var videoPlayerContainer = document.getElementById('videoFlash');
    videoPlayerContainer.innerHTML = '<embed src="http://lads.myspace.com/videos/vplayer.swf" flashvars="a=1&sr=0&m=' + videoId + '&type=video" type="application/x-shockwave-flash" width="' + width + '" height="' + height + '"></embed>';
    
}