// JavaScript Document
var divCount;
var flag = new Array();
var _steps  = [0,25,50,70,85,95,97,99,100];
var _slot = new Array();
var _top = new Array();
var _inc = new Array();
var _H = new Array(160, 0, 25);

function initFlyWinndow(){
	if(!document.getElementById("FeatureLay")){
		return;
	}
	for(var i =0; i <10; i++){
		var div = document.getElementById("Feature" + i);
		if(! div){
			divCount = i;
			break;
		}
		var divAnchor = document.getElementById("AnchorFeature" + i);
		divAnchor.innerHTML += '<img src="/mysite/images/solutions/close.png" alt="Close" />';
		var imgs = div.getElementsByTagName("img");
		var imgAnchor = imgs[0];
		flag[i] = false;
		_top["Feature" + i] = i * 45;
		_inc[i] = 0;
		div.style.top = i * 45 + "px";
		divAnchor.onclick = new Function ("flyWinndow(" + i + ")");
		imgAnchor.onclick = new Function ("flyAwayWindow(" + i + ")");
		document.getElementById("FeatureLay").style.height = 45 * i + 45 + "px";
		div.className += " show";
	}
	//alert(document.getElementById("FeatureLay").style.height+"   "+(divCount*45));
	if((divCount*45)<135){
		document.getElementById("FeatureLay").style.height = 135+"px";
	}
	for(var i =0; i <9; i++){
		_slot["Height" + i] = Math.round(25 + 135 * _steps[i] / 100);
		for(var j =divCount-3; j <divCount; j++){
			_slot["top" + i + j] = Math.round(_top["Feature" + j] - 135 * _steps[i] / 100);
		}
	}
}
function flyWinndow(i){
	document.getElementById("AnchorFeature" + i).onclick = new Function ();
	if(flag[i]){
		flyAwayWindow(i);
		return;
	}
	for(var j =0; j <divCount; j++){
		if(flag[j]){
			flyAwayWindow(j);
			break;
		}
	}
	flag[i] = true;
	document.getElementById("Feature" + i).className += " Spread";
	var _Interval = setInterval(function(){Spread(i, 8, 1, _Interval);}, 40);
}
function flyAwayWindow(i){
	var _Interval = setInterval(function(){Spread(i, 0, -1, _Interval);}, 40);
}
function Spread(i, critical, increa, _Interval){
	if(_inc[i] == critical){
		doSpread(i, increa);
		clearInterval(_Interval);
		if(increa < 0){
			var div = document.getElementById("Feature" + i);
			div.className = div.className.replace(new RegExp(" Spread\\b"), "");
			document.getElementById("AnchorFeature" + i).onclick = new Function ("flyWinndow(" + i + ")");
			flag[i] = false;
		}
		else{
			document.getElementById("AnchorFeature" + i).onclick = new Function ("flyAwayWindow(" + i + ")");
		}
		return;
	}
	doSpread(i, increa);
	_inc[i] += increa;
}

function doSpread(i, increa){
	document.getElementById("AnchorFeature" + i).style.height = _slot["Height" + _inc[i]] + "px";
	if(divCount>5){
		if(i > divCount-4){
			document.getElementById("Feature" + i).style.top = _slot["top" + _inc[i] + i] + "px";
		}
	}else{
				
        for(var j=i+1; j < divCount; j++){
		   document.getElementById("Feature" + j).style.top = _top["Feature" + j] + _slot["Height" + _inc[i]] - 25 + "px";
		}
		//var featureLayHeight = (divCount*45)<135 ? 135 : divCount*45;
		//var featureLayHeight = document.getElementById("FeatureLay").scrollHeight;
		//document.getElementById("FeatureLay").style.height = featureLayHeight + increa * _slot["Height" + _inc[i]] - 25 + "px";
		var featureLayHeight = 0;

		//alert(parseInt(document.getElementById("AnchorFeature0").style.height));
		for(var k=0; k<divCount; k++) {
			//if(k == 0)
			//alert(document.getElementById("AnchorFeature"+k).style.height);
			
			if(document.getElementById("AnchorFeature"+k).style.height){
			    featureLayHeight += (parseInt(document.getElementById("AnchorFeature"+k).style.height) + 20);
			}else{
				//alert(featureLayHeight);
				featureLayHeight += 45;
			}
		}
		if(featureLayHeight > 135 ){
		    document.getElementById("FeatureLay").style.height = featureLayHeight+"px";
		}else{
			document.getElementById("FeatureLay").style.height = 135 +"px";
		}
		
	}
}
/*if(typeof window.onload != 'function'){
	window.onload = function(){
		initFlyWinndow();
	}
}
else{
	var oldonload = window.onload;
	window.onload = function(){
		oldonload();
		initFlyWinndow();
	}
}*/


//AddToOnload(initFlyWinndow);

