
// !!!!!!!!!!!!!!!!!!!!		ATTENTION		!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//
//	the functions in this script depend on the following scripts
//
//		MBF_BasicEventHandling.js
//
//		MBF_ObjectSrcParsing.js
//
//		MBF_StandardImageButtons.js
//
//	they should be loaded into the page before this script
//
//  !!!!!!!!!!!!!!!!!!!		END ATTENTION	!!!!!!!!!!!!!!!!!!!!!!!!!!!!



function initiateImageButtons(){
	
	//this function is called on page load. it attaches mouse event listeners to each image that has 'button' in its class name
	
	//alert("initializing page");
	
	//first check to see which browser the user is using, as there is a different method for attaching
	//event listeners in IE than the others (thanks microsoft)
	
	if (navigator.appVersion.indexOf("MSIE") == -1){
		
		//alert("iIBs: not IE");
		
		for (var i = 0; i < document.images.length; i++){
			
			//as we go through all the image one the page, we read the className to determine which event responders are appropriate
			//the classNames must follow a specific format described below
			//note:  (x) denotes an optional value, while <y||z> denotes either y or z 
			//'button-(language-)<overNorm || overAnim[numOfAnimationFrames-frameRate(-oSeq{frame1,frame2,frameN})]>-(<downNorm || downAnim[numOfAnimationFrames-frameRate(-dSeq{frame1,frame2,frameN})]>-)(linked[idOfLinkedObj1,idOfLinkedObj2,...idOfLinkedObjN])'
			
			if(document.images[i].className.search('button') != -1){
				if(document.images[i].className.search('overNorm') != -1){
					
					//overNorm in the className denotes a button that should have a simple mouseover state
					//which should also be the mouseup state
					
					//alert("iIBs: found normal button");
					
					document.images[i].addEventListener('mouseover', imgMouseover, false);
					document.images[i].addEventListener('mouseup', imgMouseover, false);
				}
				else if(document.images[i].className.search('overAnim') != -1){
					
					//overAnim means that the mouseover and mouseup states should be multi-frame animations
					
					//alert("iIBs: found animated button");
					
					document.images[i].addEventListener('mouseover', imgMouseoverAnimate, false);
					document.images[i].addEventListener('mouseup', imgMouseoverAnimate, false);
				}
				
				//all buttons needs to listen to mouseout events
				
				document.images[i].addEventListener('mouseout',imgOut, false);
				
				if(document.images[i].className.search('downNorm') != -1){
					
					//downNorm denotes simple mousedown state
					
					document.images[i].addEventListener('mousedown', imgMousedown, false);
				}
				else if (document.images[i].className.search('downAnim') != -1){
					
					//while downAnim is a multi-frame mousedown animation
					
					document.images[i].addEventListener('mousedown', imgMousedownAnimate, false);
				}
			}
		} 
	}
	else if (navigator.appVersion.indexOf("MSIE") != -1){
		
		//this works the same as above with only the different IE syntax
			
		//alert("iIBs: IE");
			
		for (var i = 0; i < document.images.length; i++){
			
			if	(document.images[i].className.search('button') != -1){
				
				//alert("iIBs: found button");
				
				if(document.images[i].className.search('over') != -1){
					document.images[i].attachEvent('onmouseover', imgMouseover);
					document.images[i].attachEvent('onmouseup', imgMouseover);
				}
				else if(document.images[i].className.search('overAnim') != -1){
					
					//alert("iIBs: found animated button");
					
					document.images[i].attachEvent('onmouseover', imgMouseoverAnimate);
					document.images[i].attachEvent('onmouseup', imgMouseoverAnimate);
				}
				
				document.images[i].attachEvent('onmouseout', imgOut);
				
				if(document.images[i].className.search('downNorm') != -1){
					document.images[i].attachEvent('onmousedown', imgMousedown);
				}
				else if (document.images[i].className.search('downAnim') != -1){
					document.images[i].attachEvent('onmousedown', imgMousedownAnimate);
				}
			}
		}
	}
}
