function expandProfile(){
  //detectBrowser();

	$('#profileImgs>img').not('.selected').mouseover(function(){
		thisSrc = $(this).attr("src");
		newSrc = thisSrc.replace('','');
		newSrc = newSrc.replace('','');
		$(this).attr({src:newSrc});
	}).click(function(){
       $('#profiles-instructions').fadeOut("slow");
			if(profileActive === true){
				profileActive = false;
				$('#profileImgs>img').addClass('pausedImg');
        thisTop = $(this).css('top');
				thisLeft = $(this).css('left');
				$(this).addClass("selected");
				a = $('#profileImgs>img').index(this);

				$('#profileImgs>img').not(this).fadeOut().css({display:"none",zIndex:"-100"});

				$(this).attr({src:newSrc}).css({zIndex:"100"}).animate({width:"300px",height:"330px",top:topLine,left:"0px"},function(){
					$('#front-right-top .field-content').eq(a).fadeIn().animate({left:leftLine});

				});
				$(this).mouseout(function(){
					$(this).attr({src:newSrc});
				}).click(function(){

				});
			}
		/* $(this).attr({src:newSrc}).css({zIndex:"100"}).animate({width:"300",height:"302",top:"273px",left:"576px"},function(){
				$('.field-content').eq(a).fadeIn().animate({left:"876px"});
		}); */
	}).mouseout(function(){
		var thisClass = $(this).attr("class");
		thisSrc = thisSrc.replace('_over','');
		if(thisClass!='selected'){
			$(this).attr({src:thisSrc});
		}
	});
}

// This controls the actions when a displayed profile is minimized
function minimizeProfile(){


	$('#front-right-top .field-content').click(function(){
	  $('#profiles-instructions').fadeIn(3000);
		$('#front-right-top .field-content').eq(a).animate({left:leftLine2}).fadeOut(function(){
			$('#profileImgs>img').eq(a).animate({width:"150",height:"150",top:thisTop,left:thisLeft},function(){
				$(this).css({zIndex:"1"});
			}).removeClass('selected');
			$('#profileImgs>img').each(function(){
				var imgSrc = $(this).attr("src").replace('_over','');
				$(this).attr({src:imgSrc});
			  }).mouseout(function(){
				var thisClass = $(this).attr("class");
				if(thisClass!='selected'){
					var thisSrc2 = $(this).attr("src").replace('_over','');
					$(this).attr({src:thisSrc2});
				}
			});
				$('#profileImgs>div.pausedImg').removeClass('pausedImg');
				$('#profileImgs>div.selected').removeClass('selected');
				$('#profileImgs>img').not(this).css({zIndex:'1',display:"block"}).fadeIn();

		});

					expandProfile();
					profileActive = true;

	});


}

//This function expands the profile pictures and shows the corresponding text
function profilePics(){
	$("#front-right-top .field-content>img").wrapAll("<div id=\"profileImgs\"></div>");	//Separate the images from the text
	$('#profileImgs').remove().prependTo('#profiles');
	$('#profileImgs').css({position:"relative"});
	$('#front-right-top .field-content').css({display:"none"});
	$('#front-right-top .field-content').appendTo('#profileText');
	expandProfile();
	minimizeProfile();
  }

function detectBrowser(){
	jQuery.each(jQuery.browser, function(i, val) {
	  //if($.browser.mozilla){
		 $('#profileImgs').css({top:"0px"});
		 topLine = "0px";		//sets the top line for the top row of profile thumbnails
		 topLine2 = "172px";	//sets the top line for the bottom row of profiles thumbnails
		 leftLine = "0px";	//sets the left edge of the green profile information popup after the animation
		 leftLine2 = "-300px";	//sets the left edge of the green profile information popup before the animation
		 return true;
	});

}


//this function positions the profile pictures
function positionProfiles(){
	detectBrowser();
  $('#profileImgs>img:first').css({top:topLine,left:"0px"}).next().css({left:"149px",top:topLine}).next().css({left:"299px",top:topLine}).next().css({left:"449px",top:topLine}).next().css({top:topLine2,left:"0px"}).next().css({left:"149px",top:topLine2}).next().css({left:"299px",top:topLine2}).next().css({left:"449px",top:topLine2});
	$('#front-right-top .field-content').css({left:leftLine2});

}

$(document).ready(function(){
	profileActive = true;
	profilePics();
	positionProfiles();
	detectBrowser();
});
