var EDS= {
	scroller:false,
	win_width:'',
	img_width:'',
	timer:'',
	stop:true,
	dir:'right',
	type:'',
	scheduler:false,
	speed:0.3,
	load:function() {
		$$('.loader')[0].hide();
		$('homepage-all-bg').setStyle('visibility:visible;').insert('<div class="homepage-image-4"><img src="'+SITE_URL+'images/homepage-main-04.jpg" alt="EDS" usemap="#Map4" /></div>\
																   <div class="homepage-image-5"><img src="'+SITE_URL+'images/homepage-main-05.jpg" alt="EDS" usemap="#Map5" /></div>\
																   <div class="homepage-image-6"><img src="'+SITE_URL+'images/homepage-main-06.jpg" alt="EDS" usemap="#Map6" /></div>')
		.observe('mouseover',function() {EDS.hover();}).observe('mouseout',function() { EDS.out(); });
		$('homepage-image').setStyle('visibility:visible;');
		$$('.scroll-left')[0].hide();
		$$('.scroll-right')[0].hide();
		$$('.scroll-left div').each(
			function(obj) {
				$(obj).observe('mouseover',function() {EDS.scrollRight(obj.className.split('-')[2]);}).observe('mouseout',function() {EDS.scrollOut();});
			}
		);
		$$('.scroll-right div').each(
			function(obj) {
				$(obj).observe('mouseover',function() {EDS.scrollLeft(obj.className.split('-')[2]);}).observe('mouseout',function() {EDS.scrollOut();});
			}
		);
		$('homepage-image').morph('left:-200px;',{duration:2}).morph('left:0px;',{duration:2,delay:2});
		setTimeout(function() {EDS.setAnim(2);},4000);
		//EDS.setAnim(2);
	},
	hover:function() {
		if(this.type==1) {
			if(this.scheduler) clearTimeout(this.scheduler);
			EDS.stop = true;
			if(this.scroller) EDS.scroller.cancel();
		}
	},
	out:function() {
		if(this.type==1) {
			if(this.dir=='right') {
				this.scrollLeft(this.speed);
			} else {
				this.scrollRight(this.speed);
			}
		}
	},
	scrollLeft:function(init_speed) {
		if(this.type==2) $$('.scroll-left')[0].show();
		this.win_width = parseInt(document.viewport.getWidth());
		this.img_width = parseInt($('homepage-image').getStyle('width'));
		//alert(document.viewport.getWidth());
		var scrollable = (this.img_width - this.win_width)+(parseInt($('homepage-image').getStyle('left')));
		//alert(scrollable);
		var speed = (Math.ceil(scrollable/50)/init_speed);
		//alert(speed);
		this.scroller = new Effect.Move('homepage-image',{ duration:speed,x: -1*(scrollable), y: 0, transition: Effect.Transitions.linear,afterFinish:EDS.scrollOut });
		if(scrollable!=0){ 
			this.stop = false;
			this.dir = 'right';
			//this.scrollHide('scroll-right');
		}
		if(this.type==1) {
			this.scheduler = setTimeout('EDS.scrollRight('+init_speed+');',(speed*1000)+500);	
		}
		
	},
	scrollRight:function(init_speed) {
		if(this.type==2) $$('.scroll-right')[0].show();
		this.win_width = parseInt(document.viewport.getWidth());
		this.img_width = parseInt($('homepage-image').getStyle('width'));
		var scrollable = -1*(parseInt($('homepage-image').getStyle('left')));
		var speed = (Math.ceil(scrollable/50)/init_speed);
		this.scroller = new Effect.Move('homepage-image',{ duration:speed,x: 1*(scrollable), y: 0, transition: Effect.Transitions.linear,afterFinish:EDS.scrollOut });
		if(scrollable!=0){ 
			this.stop = false;
			this.dir = 'left';
			//this.scrollHide('scroll-left');
		}
		if(this.type==1) {
			this.scheduler = setTimeout('EDS.scrollLeft('+init_speed+');',(speed*1000)+500);	
		}
	},
	scrollOut:function() {
		EDS.scroller.cancel();
		EDS.stop = true;
		if(parseInt($('homepage-image').getStyle('left'))==0) $$('.scroll-left')[0].hide();
		EDS.win_width = parseInt(document.viewport.getWidth());
		EDS.img_width = parseInt($('homepage-image').getStyle('width'));
		if(parseInt($('homepage-image').getStyle('left'))==-1*(EDS.img_width - EDS.win_width)) $$('.scroll-right')[0].hide();
	},
	scrollShow:function() {
		//if(!EDS.stop)
		//	$$('.scroll-'+EDS.dir)[0].appear({duration:0.3,to:0.8,afterFinish:EDS.scrollHide});
		//else $$('.scroll-'+EDS.dir)[0].setOpacity(0.7);
	},
	scrollHide:function(id) {
		//if(!EDS.stop)
		//	$$('.scroll-'+EDS.dir)[0].fade({duration:0.3,to:0.2,afterFinish:EDS.scrollShow});
		//else $$('.scroll-'+EDS.dir)[0].setOpacity(0.7);
	},
	setAnim:function(type,speed) {
		if(typeof(speed)=="undefined") speed = 0.3;
		this.speed = speed;
		this.type=type;
		if(type==1) {
			//$('anim_speed').show();
			EDS.stop = true;
			$$('.scroll-left')[0].hide();
			$$('.scroll-right')[0].hide();
			if(EDS.scroller) EDS.scroller.cancel();
			if(this.scheduler) clearTimeout(this.scheduler);
			if(this.dir=='right') {
				this.scrollLeft(this.speed);
			} else {
				this.scrollRight(this.speed);
			}
			
		} else if(type==2) {
			//$('anim_speed').hide();
			if(this.scheduler) clearTimeout(this.scheduler);
			if(EDS.scroller) EDS.scroller.cancel();
			if(parseInt($('homepage-image').getStyle('left'))==0) $$('.scroll-left')[0].hide();
			else $$('.scroll-left')[0].show();
			EDS.win_width = parseInt(document.viewport.getWidth());
			EDS.img_width = parseInt($('homepage-image').getStyle('width'));
			if(parseInt($('homepage-image').getStyle('left'))==-1*(EDS.img_width - EDS.win_width)) $$('.scroll-right')[0].hide();
			else $$('.scroll-right')[0].show();
		} else if(type==3) {
			
		}
	},
	showPopup:function(block,color,text) {
		this.popupActive=true;
		setTimeout("EDS.showPopupFinal('"+block+"','"+color+"','"+text+"');",400);
 	},
	setPopup:function(event) {
		//var top = (Event.pointerY(event)-parseInt($('ovly-popup').getStyle('height')));
		//if(top<0) top = 0;
		//$('ovly-popup').show().setStyle('top:'+(5+top)+'px;left:'+(Event.pointerX(event)+5)+'px;');
	},
	hidePopup:function() {
		$('ovly-popup').fade({duration:0.1,delay:0.3});
		this.popupActive=false;
	},
	showPopupFinal:function(block,color,text) {
		if(this.popupActive) {
			
			$$('#ovly-popup .content')[0].update(text);
			if(this.Homepage.Cordinates[block]) {
				var coor = this.Homepage.Cordinates[block].split(',');
				//alert(parseInt(coor[1])+parseInt($('homepage-image').getStyle('left')));
				
				/// Need to swap (pt:1 & pt:2) when scroll amount will be addded
				///---- pt:1--------------//
				///$('ovly-popup').setStyle('top:'+(parseInt(coor[2])+20)+'px;left:'+(parseInt(coor[1])+parseInt($('homepage-image').getStyle('left')))+'px;').setOpacity(0).show().appear({duration:0.3});
				///---- pt:1 End----------//
				///---- pt:2--------------//
				$('ovly-popup').setStyle('top:'+(parseInt(coor[2])+20)+'px;left:'+(parseInt(coor[1])+0)+'px;').setOpacity(0).show().appear({duration:0.3});
				///---- pt:2 End----------//
				$$('#ovly-popup .content')[0].setStyle('font-size:'+coor[0]+'px;color:#'+coor[4]+';');
				$$('#ovly-popup .bg')[0].setStyle('background-color:#'+coor[3]+';');
			} else {
				//$('ovly-popup').show().setStyle('top:'+(5)+'px;left:'+(5)+'px;');
			}
			$$('#ovly-popup .bg')[0].setStyle("height:"+($$('#ovly-popup .content')[0].getHeight()-3)+"px;").setOpacity(0.85);
		}
	}
	
};
EDS.Homepage={};
EDS.Homepage.Cordinates = new Array();
EDS.Homepage.Cordinates['CDM']="15,9,25,D2A2A3,000000"; //?
EDS.Homepage.Cordinates['AdaptedPlantsVsInvasiveSpecies']="13,3235,10,C6CF84,000000";//
EDS.Homepage.Cordinates['AlternativeTransportationBicyclesFuelEfficientVehiclesElectricCars']="14,3588,115,A0784B,FFFFFF";//
EDS.Homepage.Cordinates['CarbonFootprint']="14,3666,141,141516,FFFFFF";//
EDS.Homepage.Cordinates['Commissioning']="15,2183,39,FFFFFF,000000";//
EDS.Homepage.Cordinates['ConstructionWasteManagement']="15,2017,124,CDD0D2,000000";//
EDS.Homepage.Cordinates['CoolRoofsForCoolDelhi']="15,891,14,AAC8D1,000000";//
EDS.Homepage.Cordinates['DaylightingAnalysis']="15,2768,49,F9E870,000000";//
EDS.Homepage.Cordinates['DaylitSpaces']="15,130,0,FAE226,000000"; //
EDS.Homepage.Cordinates['EnergyEfficientHousingFeasibilityResearch']="15,3022,-18,FFFFFF,000000";//
EDS.Homepage.Cordinates['EnhancingCoolingSystemEfficiency']="15,2823,138,0098C5,000000";//
EDS.Homepage.Cordinates['EnvironmentalDesignSolutions']="13,67,65,221E1F,F4EACB";//
EDS.Homepage.Cordinates['FactoriesCanBeGreenToo']="13,2344,66,CDDE51,000000";//
EDS.Homepage.Cordinates['GraywaterRecycling']="15,2548,117,FFFFFF,000000";//
EDS.Homepage.Cordinates['GreenBuildingRating']="13,281,-10,EFE7A2,000000";
EDS.Homepage.Cordinates['GreenRatingForHomes']="15,1570,28,EF7E58,000000";//
EDS.Homepage.Cordinates['LightTrespass']="13,2639,43,EDE35E,000000";//
EDS.Homepage.Cordinates['LowVocPaints']="13,2785,85,F07A69,000000";//
EDS.Homepage.Cordinates['MassTransit']="13,415,50,F17937,000000";//
EDS.Homepage.Cordinates['OpenGridPavingForParking']="15,749,34,FAE226,000000";
EDS.Homepage.Cordinates['RainwaterHarvesting']="15,1393,87,6BAAC2,000000";//
EDS.Homepage.Cordinates['RapidlyRenewableMaterials']="15,1923,50,D5E07A,000000";//
EDS.Homepage.Cordinates['RecycledContent']="15,275,34,6BAAC2,000000";//
EDS.Homepage.Cordinates['ReduceReuseRecycle']="13,152,14,F5A477,000000";//
EDS.Homepage.Cordinates['ReducingGHGEmissionsInBuildingSectorIndia']="15,748,-14,2A363A,FFFFFF";//
EDS.Homepage.Cordinates['ReflectiveRoofs']="15,1182,127,ECEDED,000000";//
EDS.Homepage.Cordinates['RenewableEnergy']="15,1323,-18,E7EA5C,000000";//
EDS.Homepage.Cordinates['ShadowAnalysis']="15,724,16,4C6870,FFFFFF";//
EDS.Homepage.Cordinates['SolarRoofs']="15,1034,127,EFE464,000000";//
EDS.Homepage.Cordinates['SunControlThroughOverhangsShadingAnalysis']="15,2973,32,EEB343,000000";//
EDS.Homepage.Cordinates['ThermalComfortDesignAndControls']="15,1999,53,6BAAC2,000000";//
EDS.Homepage.Cordinates['UrbanHeatIslandEffect']="15,1324,157,F4C559,000000";//
EDS.Homepage.Cordinates['VegetativeRoofs']="15,963,126,D8E283,000000";//
EDS.Homepage.Cordinates['WhatIsABrownfield']="15,1086,68,995754,FFFFFF";//
EDS.Homepage.Cordinates['WhatIsExteriorLightingSimulation']="15,248,-3,F6EAAA,000000";//


window.homeTextSwap = function(id1,id2,action,domore){
	if(action == "IN"){
		EDS.hover();
		$(id1).setStyle('visibility:hidden;');
		$(id2).setStyle('visibility:visible;');
		if(domore){
			if(domore == "EDS"){
				$("EDS_tree").setStyle('visibility:visible;');
			} else if(domore == "RainwaterHarvesting"){
				$("RainwaterHarvesting_water").setStyle('visibility:visible;');
			}
		}
	} else if(action == "OUT"){
		EDS.hidePopup();
		$(id1).setStyle('visibility:visible;')
		$(id2).setStyle('visibility:hidden;');
		if(domore){
			if(domore == "EDS"){
				$("EDS_tree").setStyle('visibility:hidden;');
			} else if(domore == "RainwaterHarvesting"){
				$("RainwaterHarvesting_water").setStyle('visibility:hidden;');
			}
		}
	}
}
