
/*
 *  profileResize 
 *  resize video, audio and image files based on the parent <p id="mv"> size
 */
 
var currImgW;
var currImgH;
var initial = 0;

function profileResize(objId,srcString) {

    var objElement = document.getElementById(objId);    
    var currentW = objElement.offsetWidth;
    var pObj = document.getElementById('mv');
    
    pObj.style.visibility="visible";
		
		pObj.style.width = (pObj.parentNode.offsetWidth-10)+'px';
    
 // Video
    if (document.getElementById('profileFLVPlayer')) {        
    	flvObj = document.getElementById('profileFLVPlayer');
    	flvObj.style.display="none";

               if (currentW > 387) {
                        pObj.style.width = "357px";
                        pObj.style.height = "255px";

                        flvObj.style.width = "357px";
                        flvObj.style.height = "255px";
                } else {
                        pObj.style.width = (currentW - 12 )+ "px";
                        pObj.style.height = ((currentW - 12 ) / 1.4) + "px";

                        flvObj.style.width = (currentW - 12 )+ "px";
                        flvObj.style.height = ((currentW - 12 ) / 1.4) + "px";
                }

			objectResizeFixes( pObj, flvObj);
    
    // Audio
    	} else if (document.getElementById('mp3player')) {
			mp3Obj = document.getElementById('mp3player');
			mp3Obj.style.display = "none";
    
		if (currentW > 387) {
			pObj.style.width = "357px";
			pObj.style.height = "94px";
		} else {
			pObj.style.width = (currentW - 12 )+ "px";  
			pObj.style.height = ((currentW - 12 ) / 3.8) + "px";
		}

		objectResizeFixes( pObj, mp3Obj);
    
	// Profile Image
		} else {
		
			pObj.style.display="block";

			var imgObj;
			var imgW;
			var imgH;

            imgObj = pObj.getElementsByTagName('img')[0];
            
            if (imgObj) {
            	if (document.all) {
           		 	imgObj.style.display="none";
            	}
            
				//explicitly state paragraph dim. to overide 
				//those set above when user changes to an image
				//from audio or video
			/*
				// in #c2
				if (currentW >= 357) {
					pObj.style.width = "355px";
					pObj.style.height = "257px";
			
				// in #c3
				} else {
					pObj.style.width = "240px";
					pObj.style.height = "171px";
				}
*/
				var parentWidth = pObj.offsetWidth;
				var parentHeight = pObj.offsetHeight;
				
            	// on change of pic
				if (initial==0 && srcString) {
					imgW = currImgW;
					imgH = currImgH;
					initial = 1;
				}

				// on load of page
				if (initial==0 && !srcString) {
					currImgW = imgObj.width;
					currImgH = imgObj.height;
					initial = 1;
				}

				// on drag
				if (currImgW != undefined && initial==1) {
					imgW = currImgW;
					imgH = currImgH;
				}

				imgW = currImgW;
				imgH = currImgH;

				imgObj.setAttribute('height', imgH);
				imgObj.setAttribute('width', imgW);

				aspect_ratio = imgW/imgH;
				
				if ((imgW<parentWidth && imgH<parentHeight)) {
					imgObj.style.display="block";

				} else {

				//portrait 
				if (aspect_ratio < 1.381) {
					imgObj.setAttribute('height', parentHeight);
					imgObj.setAttribute('width', parentHeight * aspect_ratio);

				//landscape
				}
				if (aspect_ratio > 1.381) {
					imgObj.setAttribute('height', parentWidth / aspect_ratio);
					imgObj.setAttribute('width', parentWidth);
				
				//square
				}
				if (aspect_ratio==1) {
					imgObj.setAttribute('height', parentHeight);
					imgObj.setAttribute('width', parentHeight);
				}
				
				
				imgObj.style.display="block";
			}
		}
	}
	pObj.style.display="block";
} 
