var inProgress=false;
var opened=false;
var TempZIndex = -1;
var lastOpenedBox;

function getStyle(oElm, strCssRule){
	var strValue = "";
	if(document.defaultView && document.defaultView.getComputedStyle){
		strValue = document.defaultView.getComputedStyle(oElm, "").getPropertyValue(strCssRule);
	}
	else if(oElm.currentStyle){
		strCssRule = strCssRule.replace(/\-(\w)/g, function (strMatch, p1){
			return p1.toUpperCase();
		});
		strValue = oElm.currentStyle[strCssRule];
	}
	return strValue;
}

function MaximizeBox(ThisBox, MaxDiv, FadeBox1, FadeBox2, FadeBox3, SubImage, smallMenuCall, smallMenuIndex) {
	if(opened==false && inProgress==false) {
		inProgress=true;
		$(ThisBox).className = 'LargeBoxBG';
		//document.getElementById('ManagePortfolioPic').src = SubImage;
		
		new Effect.Opacity('ProfLandingPic', { from: 1.0, to: 0.0, delay:0.0, duration: 1.1 });
		new Effect.Appear('ManagePortfolioPic', { delay:0.2, duration: 1.1 } );
		
		for(var i = 0; i<QuadBoxes.length; i++){
			var Limit = QuadBoxes.length - 1;
			if(QuadBoxes[i] != ThisBox){
				Effect.Fade(QuadBoxes[i], { delay: 0.0, duration: 0.3 });
			}
		}
		
		Effect.Fade(ThisBox+'Content', {duration: 0.4, delay:0.0, afterFinish:function(obj){ MakeBig(ThisBox, 0.5, 0.0); } });
		Effect.Appear(MaxDiv, {delay: 0.9, duration:0.4, afterFinish:function(obj){ inProgress=false; opened=true; lastOpenedBox = ThisBox; }});
	}
	else{
		alert("var opened = " + opened);
	}
	/*traceToDebug('76', "Click Source = " + smallMenuIndex);*/
	if(smallMenuIndex){
		//traceToDebug('76', "Click Source = " + smallMenuIndex);
		for(var i = 0; i<quickMenu.length; i++){
			if(quickMenu[i] == smallMenuIndex){
				$(quickMenu[i]).addClassName('Selected');
			}
			else{
				$(quickMenu[i]).removeClassName('Selected');
			}
		}
	}
}

function MinimizeBox(ThisBox, MaxDiv, FadeBox1, FadeBox2, FadeBox3, SubImage, smallMenuCall, smallMenuIndex) { 
	if(opened==true && inProgress==false){
		inProgress=true;
		$(ThisBox).className = 'SmallBoxBG';
		
		Effect.Fade(MaxDiv, {duration:0.5});
		
		MakeSmall(ThisBox); //has built-in delay of 0.3 and duration 0.5- see function

		new Effect.Fade('ManagePortfolioPic', { delay:0.0, duration: 1.0 } );
		new Effect.Opacity('ProfLandingPic', { from: 0.0, to: 1.0, delay:0.2, duration: 1.0 });
		new Effect.Fade('solutionsQuickMenu', { delay:0.0, duration: 0.5 });
		
		Effect.Appear(ThisBox+'Content', { delay:0.8, duration: 0.4 });
		
		for(var i = 0; i<QuadBoxes.length; i++){
			var Limit = QuadBoxes.length - 1;
			if(QuadBoxes[i] != lastOpenedBox){
				Effect.Appear(QuadBoxes[i], { delay: 0.6, duration: 0.3 });
			}
			if(i == Limit){
				inProgress=false;
				opened=false;
				if(smallMenuCall == true){
					/*callMaximize.delay(1.5, smallMenuIndex);*/
					/*
					changeContent.delay(1.5, smallMenuIndex);
					Effect.Fade(lastOpenedBox+'Content', {duration: 0.4, delay:0.0, afterFinish:function(obj){ 
						Effect.Fade(ThisBox+'Content', {duration: 0.4, delay:0.0 });
					} });
					*/
				}
			}
		}
	}
	else{
		//alert("Not minimizing");
	}
}

function solutionsQuickMenu(indexVal, correspondingQuad, menuID){
	if(correspondingQuad != lastOpenedBox){
		//traceToDebug('76', "Click Source = " + menuID);
		var FadeBox_arr = MinimizeArr[indexVal].split(",",5);
		var Box = FadeBox_arr[0];
		var MaxDiv_Temp = FadeBox_arr[1];
		var FadeBox1_Temp = FadeBox_arr[2];
		var FadeBox2_Temp = FadeBox_arr[3];
		var FadeBox3_Temp = FadeBox_arr[4];
		var SubImage_Temp = "/graphics/shim.gif";
		
		for(var i = 0; i<quickMenu.length; i++){
			if(quickMenu[i] == menuID){
				$(quickMenu[i]).addClassName('Selected');
			}
			else{
				$(quickMenu[i]).removeClassName('Selected');
			}
		}
		
		Effect.Fade(lastOpenedBox, {duration: 0.2, delay:0.0, afterFinish:function(obj){ 
			MakeBig(Box, 0.1, 0.0);
			$(lastOpenedBox).className = 'SmallBoxBG';
			Effect.Appear(lastOpenedBox+'Content', {duration: 0.0, delay:0.0});
			Effect.Fade(lastOpenedBox+'Maximized', {duration: 0.0, delay:0.0});
			MakeSmall(lastOpenedBox);
			
			$(Box).className = 'LargeBoxBG';
			Effect.Fade(Box+'Content', {duration: 0.0, delay:0.0});
			Effect.Appear(Box+'Maximized', {duration: 0.0, delay:0.0});
			Effect.Appear(Box, {duration: 0.2, delay:0.0 });
			inProgress=false; opened=true; lastOpenedBox = Box;
		} });
	}
}
function callMaximize(currIndex){
	var AppearBox_arr = MaximizeArr[currIndex].split(",",5);
	var Box = AppearBox_arr[0];
	var MaxDiv_Temp = AppearBox_arr[1];
	var AppearBox1_Temp = AppearBox_arr[2];
	var AppearBox2_Temp = AppearBox_arr[3];
	var AppearBox3_Temp = AppearBox_arr[4];
	var SubImage_Temp = "/graphics/shim.gif";
	MaximizeBox(Box, MaxDiv_Temp, AppearBox1_Temp, AppearBox2_Temp, AppearBox3_Temp, SubImage_Temp, true, currIndex);
}

function MakeBig(TargetDiv, durationT, delayT){
	TempZIndex = getStyle(document.getElementById(TargetDiv), "z-index");
	document.getElementById(TargetDiv).style.zIndex = "2000";//sets z-index so that it covers the other boxes
	new Effect.Morph(TargetDiv, {
		  style: {
			width:'443px',
			height:'383px'
		  }, // CSS Properties
		  duration: durationT,
		  delay:delayT// Core Effect properties
		  , afterFinish:function(obj){new Effect.Appear('solutionsQuickMenu', { delay:0.0, duration: 0.5 } );}
	});	
}			

function MakeSmall(TargetDiv){
	document.getElementById(TargetDiv).style.zIndex = TempZIndex;//returns z-index to normal
	new Effect.Morph(TargetDiv, {
		  style: {
			width:'217px',
			height:'187px'
		  }, // CSS Properties
		  duration: 0.5,
		  delay:0.3// Core Effect properties
	});	
}