/****************************************
|
| A-Line / Muru
| http://www.a-linetool.com
|
| Created by: Kevin Biskaborn
| Copyright 2010 ScriptReaction
| http://www.scriptreaction.com
|
*****************************************
| Load Dependencies	: None
| Run Dependencies	: Global{}
****************************************/

var ServList = {
	info: {
		activeIndex: -1,
		elementTotal: -1,
		elementLabelPrefix: "servIndexList_elementLabel_"
	},
	get: {
		elementById: function ( id ){
			return document.getElementById( id );
		},
		labelElementByIndex: function ( index ){
			return this.elementById( ServList.info.elementLabelPrefix + index );
		},
		elementIndexFromLabelIdString: function ( idString ){
			return JS_Format.string.remove.prefix( idString, ServList.info.elementLabelPrefix );
		},
		groupElementByIndex: function ( index ){
			return this.elementById( "servIndexList_group_" + index );
		}
	},
	launch: function ( inputObject ){
		
		// extract incoming
		var total 		= inputObject.total;
		var activeIndex	= inputObject.active;
		
		// save the total service count
		this.info.elementTotal = total;
		
		// setup the list
		this.setup();
		
		// save the active index
		this.info.activeIndex = activeIndex;
		
		// active the initial group
		// only the label needs to be activated initially
		this.elements.activateLabelByIndex( activeIndex );
		
	},
	setup: function (){
		
		var labelElement, labelAnchor;
		
		// get the total number of elements
		var elementTotal = this.info.elementTotal;
		
		// cycle through all elements
		for( var i = 0; i < elementTotal; i++ ){
			
			// get the element label
			labelElement = this.get.labelElementByIndex( i );
			
			// add the click action
			labelElement.onclick = function (){
				ServList.actions.do_press( this.id );
			}
			
			// get the anchor tag within the element
			labelAnchor = labelElement.getElementsByTagName( "a" )[ 0 ];
			
			// add the anchor click action
			labelAnchor.onclick = function (){
				this.blur();
				return false;
			}
		}
		
	},
	actions: {
		do_press: function ( idString ){
			
			// get the element index
			var index = ServList.get.elementIndexFromLabelIdString( idString );
			
			// activate the requested element
			ServList.elements.activateByIndex( index );
		}
	},
	elements: {
		activateByIndex: function ( index ){
			
			// check if the requested index is already active
			if( !( index == ServList.info.activeIndex ) ){
				
				// reset all elements
				ServList.elements.deactivateAll();
			
				// activate the label
				this.activateLabelByIndex( index );
				
				// get the element group
				var groupElement = ServList.get.groupElementByIndex( index );
				
				// get the group image
				var groupImage = groupElement.getElementsByTagName( "img" )[ 0 ];
				
				// create an opacity fade object
				var imageFader = ReactorFX.alpha.createOnElement( groupImage );
				
				// set the image alpha to zero
				ReactorFX.alpha.clear( imageFader );
				
				// display the group
				JS_Format.divElement.setDisplay_block( groupElement );
				
				// fade the image in
				ReactorFX.alpha.fadeIn( imageFader );
				
				// save the active index
				ServList.info.activeIndex = index;
			}
			
		},
		activateLabelByIndex: function ( index ){
			
			// get the element label
			var labelElement = ServList.get.labelElementByIndex( index );
			
			// add the active class
			JS_Format.elementClass.addToElement( labelElement, "servIndexList_active" );
		},
		deactivateByIndex: function ( index ){
			
			// get the element label
			var labelElement = ServList.get.labelElementByIndex( index );
			
			// remove the active class
			JS_Format.elementClass.removeFromElement( labelElement, "servIndexList_active" );
			
			// get the element group
			var groupElement = ServList.get.groupElementByIndex( index );
			
			// hide the group
			JS_Format.divElement.setDisplay_none( groupElement );
			
		},
		deactivateAll: function (){
			
			// get the total number of elements
			var elementTotal = ServList.info.elementTotal;
			
			// cycle through all elements
			for( var i = 0; i < elementTotal; i++ )
				
				// deactivate each element
				this.deactivateByIndex( i );
		}
	}
}



