var xArray      = [-40,40,120,200,280,360,440,520];
var sliceArray  = [];
var imageArray  = [];
var textArray   = [];
var LIT         = "";
var FULL        = "";
var TEXT        = "";
var TITL		= "";
var COPY        = "";
var PROJ        = "";
var BTTN        = "";
var whichIsLit  = "";
var whichIdNum  = "";
var startTime   = ""
var timer       = "";
var timer2      = "";
var timerlen    = 5;
var slideAniLen = 250;
var endRight    = 640;
var opacityValue= 0;
var FULLopen    = false;
var imagePath   = "wp-content/themes/aevenia/carousel/carouselResources/images/";

window.onload = function() {
	var spans     = document.getElementById('carousel').getElementsByTagName("span");
	var temp      = "";
	var sliceSize = ["160","473"];
	var fullSize  = ["640","416"];
	
	var main            = "Aevenia, Inc. is the premier energy and electrical construction company. With eight areas of expertise, we cover every critical aspect of your project. From design to installation, management to maintenance &#8212; we offer it all.<br><br>That simplifies the entire process &#8212; saving you time and money, and controlling safety. Now there's no need to find multiple electrical contractors and subcontractors. Choose the one company with all the connections - Aevenia.";
	var renewables      = "Our services include collection systems (aerial and underground), tower wiring, substations, interconnect facilities and fiber optic systems.";
	var trans_distrb    = "Our team of experts is skilled in delivering copper, fiber optic, telecommunication and data transmission &#8212; safely and efficiently.";
	var data_comm       = "Connect with us for superior-quality products and services in all forms of connectivity, communications and surveillance solutions.";
	var urban_telecom   = "As a leader in the construction and maintenance of communication infrastructures, we’ve constructed telephone, traditional copper and fiber optic systems throughout the country.";
	var substations     = "Quality substation construction is crucial to your power supply. Our experience spans expansion, transmission, distribution and wind energy substation projects.";
	var fiber_optics    = "Our comprehensive fiber optics services include fusing, splicing and testing &#8212; and the build out of underground splice case and aboveground pedestals.";
	var indust_electric = "Turnkey design/build electrical services combine with thermal imaging capabilities to provide virtually every aspect of electrical design and construction.";
	var underground     = "From everything to rebuilding infrastructure to installing cable, we have the proven track record to tackle even the toughest of underground construction projects.";

	textArray = [main,renewables,trans_distrb,data_comm,urban_telecom,substations,fiber_optics,indust_electric,underground];
	
	LIT  = document.getElementById("LITDiv");
	FULL = document.getElementById("FULLDiv");
	TEXT = document.getElementById("textarea");
	TITL = document.getElementById("title");
	COPY = document.getElementById("copy");
	PROJ = document.getElementById("project");
	BTTN = document.getElementById("button");
	
	LIT.onmouseout = dimMe;
	LIT.onmouseup  = openMe;
	FULL.onclick   = fadeFull;
	PROJ.onclick   = goClick;
	BTTN.onclick   = goClick;
	
	COPY.innerHTML  = textArray[0];
	
	for (var i=0;i<spans.length;i++) {
		spans[i].onmouseover = turnOn;
		spans[i].onmouseout  = turnOff;
		spans[i].onclick     = openMe;
		
		if (document.images) {
			temp = spans[i].id.split('_');
			sliceArray.push(new Image(sliceSize[0],sliceSize[1]));
			sliceArray[(sliceArray.length - 1)].src = imagePath + "slices/" + temp[0] + ".png";
			imageArray.push(new Image(fullSize[0],fullSize[1]));
			imageArray[(imageArray.length - 1)].src = imagePath + "full/" + temp[0] + ".jpg";
		}
	}
	cycleCarousel();
}

function cycleCarousel() {
	var sliceArray = ["renewable-energy_1","transmission-and-distribution_2","substations_3","fiber-optics_4","underground-construction_5","data-communications_6","urban-telecom_7","electrical-contracting_8"];
	
	for (var i=0; i <= 7; i++) {
		LIT.style.backgroundImage = "url(" + imagePath + "slices/" + sliceArray[i] + ".png)";
		LIT.style.left            = xArray[i] + "px";
		LIT.style.display         = "block";
	}
}

function dimMe()        { LIT.style.display = "none"; }
function turnOff() 		{ var temp = this.id.split('_'); var ID = temp[0]; (ID != whichIsLit) ? LIT.className="hidden":true; }
function fadeFull() {
	opacityValue               = 11;
	timer2                     = setInterval("setOpacity(opacityValue,'OUT');",timerlen);
	TEXT.style.backgroundImage = "url(" + imagePath + "textareaBACKGROUND1.png)";
	TITL.style.backgroundImage = "url(" + imagePath + "titles/main.png)";
	COPY.style.marginTop	   = "0px";
	COPY.style.height          = "265px";
	COPY.innerHTML             = textArray[0];
	BTTN.style.backgroundImage = "url(" + imagePath + "buttons_services.png)";
	PROJ.style.height          = "0px";
	PROJ.style.background      = "transparent";
}
function goClick() {
	var section = "";
	var which   = "";
	var where   = "";
	
	(this.id == "project") ? section="projects" : section="services";
	
	(FULLopen) ? where = section + "/" + whichIsLit : where = section + "/";
	top.location.href  = "index.php/" + where;
}
function turnOn()  {
	if (!FULLopen) {
		var temp = this.id.split('_');
		whichIsLit                = temp[0];
		whichIdNum				  = temp[1];
		LIT.style.backgroundImage = "url(" + imagePath + "slices/" + whichIsLit + ".png)";
		LIT.style.left            = xArray[(whichIdNum-1)] + "px";
		LIT.style.display         = "block";
	}
}
function openMe() {
	startTime    = (new Date()).getTime();
	opacityValue = 0;
	FULLopen     = true;
	
	FULL.style.backgroundImage = "url(" + imagePath + "full/" + whichIsLit + ".jpg)";
	TEXT.style.backgroundImage = "url(" + imagePath + "textareaBACKGROUND2.jpg)";
	TITL.style.backgroundImage = "url(" + imagePath + "titles/" + whichIsLit + ".png)";
	BTTN.style.backgroundImage = "url(" + imagePath + "buttons_more.png)";
	PROJ.style.backgroundImage = "url(" + imagePath + "projects/" + whichIsLit + ".jpg)";
	
	FULL.style.display = "block";
	LIT.style.display  = "none";
	PROJ.style.marginTop = "0px";
	PROJ.style.height  = "217px";
	COPY.style.marginTop = "0px";
	COPY.style.height  = "85px";
	COPY.innerHTML     = textArray[whichIdNum];
	
	setOpacity(opacityValue);
	timer = setInterval("slidetick('FULLDiv');",timerlen);
}
function slidetick(objname){
	var elapsed = (new Date()).getTime() - startTime;

	if (elapsed >= slideAniLen) {
		clearInterval(timer);
		if (parseInt(FULL.style.width) < endRight) { FULL.style.width = (endRight-1)+"px"; }
		if (opacityValue < 10) { setOpacity(10); }
	} else {
		var r = Math.round(elapsed / slideAniLen * endRight);
		FULL.style.width = r + "px";
		opacityValue = opacityValue+.5;
		setOpacity(opacityValue);
	}
	return;
}
function setOpacity(value,which) {
	if (which) {
		value = value-1;
		opacityValue = opacityValue-1;
		if (value <= 0) {
			clearInterval(timer2);
			FULL.style.display = "none";
			FULLopen = false;
		}
	}
	FULL.style.opacity = value/10;
	FULL.style.filter = 'alpha(opacity=' + value*10 + ')';
}
