function ajaxLoader(ArrInput) {
	this.div       = (ArrInput['div'])?ArrInput['div']:"" ;
	this.string    = (ArrInput['string'])?ArrInput['string']:"" ;
	this.type      = (ArrInput['type'])?ArrInput['type']:"image" ; // or "image" or "both"
	this.style     = (ArrInput['style'])?ArrInput['style']:"arrow" ; // or "wheel", "circle", "dot", "fan", "snake", "ball", "square"
	this.image     = (ArrInput['image'])?ArrInput['image']:"" ;
	this.htmlStyle = (ArrInput['htmlStyle'])?ArrInput['htmlStyle']:"" ;
	this.className = (ArrInput['className'])?ArrInput['className']:"" ;
	
	var defaultImagePath = "../js/ajax_loader/images" ;
	var imageSource = new Image ;
	var Animation = false ;
	var AnimPos = 0 ;
	var AnimString = "" ;
	var AnimBuffer = 0 ;
	var AnimTextNodId = "" ;
	var textMaxWidth = 0 ;
	
	this.init = initLoader ;
	this.initLoader = initLoader ;
	function initLoader() {
		this.checkDivStatus() ;
		this.loadImage() ;
	}

	this.checkDivStatus = checkDivStatus ;
	function checkDivStatus() {
		if (!this.div) {
			alert('Please specify tag id (area to plot) for the loader');
			return false ;
		}
	}
	
	this.loadImage = loadImage ;
	function loadImage() {
		if ((this.type == "image" || this.type == "both") && (this.style || this.image)) {
			if (this.image) {
				imageSource.src = this.image ;
			} else if (this.style) {
				imageSource.src = defaultImagePath + "/loading-" + this.style + ".gif?" ; 
			}
		}
	}
	
	this.showLoader = showLoader ;
	this.show = showLoader ;
	this.display = showLoader ;
	this.add = showLoader ;
	function showLoader() {
		this.checkDivStatus() ;
		this.hideLoader() ;
		
		if (document.getElementById(this.div)) {
			var div = document.getElementById(this.div) ;
			div.innerHTML = "" ;
			
			if (this.type == "image" || this.type == "both") {
				var Img = document.createElement('img') ;
				Img.src = imageSource.src ;
				Img.align = "absmiddle" ;
				Img.id  = this.div + '_ajax_loader_img' ;				
				if (this.string) {
					Img.title = this.string ;
					Img.alt = this.string ;
				}
				if (this.className) {
					Img.className = this.className ;
				}
				if (this.htmlStyle) {
					var Arr = (this.htmlStyle).split(";") ;
					for (var i in Arr) {
						var Str = this.trim(Arr[i]) ;
						if (Str) {
							var Style = Str.split(":");
							Style[0] = Style[0].replace(/\-(.)/ig,function (s) { return (s.substring(1,2)).toUpperCase(); } ) ;
							Img.style[this.trim(Style[0])] = this.trim(Style[1]) ;
						}
					}
				}
				
				div.appendChild(Img);
				
			} 
			if (this.type == "both") {
				var Font = document.createElement('font');
				Font.align = 'absmiddle' ;
				var TxtNode = document.createTextNode(" ") ;
				Font.appendChild(TxtNode) ;
				div.appendChild(TxtNode) ;
			}
			if (this.type == "text" || this.type == "both") {
				var string = (this.string)?this.string:"LOADING..." ;
				if (Animation) {
					window.clearInterval(Animation);
					Animation = false ;
				}
				var Txt = document.createElement('font') ;
				Txt.id = this.div + '_ajax_loader_txt' ;
				Txt.title = this.string ;
				Txt.alt = this.string ;
				if (this.className) {
					Txt.className = this.className ;
				}
				if (this.htmlStyle) {
					var Arr = (this.htmlStyle).split(";") ;
					for (var i in Arr) {
						var Str = this.trim(Arr[i]) ;
						if (Str) {
							var Style = Str.split(":");
							Style[0] = Style[0].replace(/\-(.)/ig,function (s) { return (s.substring(1,2)).toUpperCase(); } ) ;
							Txt.style[this.trim(Style[0])] = this.trim(Style[1]) ;
						}
					}
				}
				div.appendChild(Txt);
				AnimString = this.string ;
				AnimTextNodId = this.div + '_ajax_loader_txt' ;
				displayTextNode(this.string) ;
        
        window.div = this.div;
        window.imageSource = imageSource.src; 
				Animation = window.setInterval(displayAnimationText,100) ;
			} 
		} else {
			alert('error, can not display loader\ntag id (area to plot) for the loader not found');
		}
	}
	
	this.hideLoader = hideLoader ;
	this.hide = hideLoader ;
	this.remove = hideLoader ;
	function hideLoader() {
		this.checkDivStatus() ;
		if (Animation) {
			window.clearInterval(Animation);
			Animation = false ;
		}
		if (document.getElementById(this.div)) {
			document.getElementById(this.div).innerHTML = "" ;
		}
	}
	
	this.trim = trim ;
	this.Trim = trim ;
	function trim(Str) {
		Str = Str.replace(/^\s+/ig,"");
		Str = Str.replace(/\s+$/ig,"");
		return Str ;
	}
	
	function displayAnimationText() {
	/*
		var Img = document.getElementById(window.div + '_ajax_loader_img');
		if (Img) 
    {
  	    Img.src = window.imageSource + Math.round(Math.random(0,1)*100000000000);
     	  var dc = document.getElementById("DC");
        dc.innerHTML = "<br>" + window.div + "  |  " + Img.src;  	  
  	}
    */      
		AnimPos++ ;
		if (AnimPos > AnimString.length) {
			AnimPos = AnimString.length ;
			AnimBuffer++ ;
			if (AnimBuffer > 5) {
				AnimBuffer = 0 ;
				AnimPos = 0 ;
			}
		}
		displayTextNode();
	}
	
	function displayTextNode() {
		if (document.getElementById(AnimTextNodId)) {
			var div = document.getElementById(AnimTextNodId) ;
			var Font1 = document.createElement('font');
			Font1.align = 'absmiddle' ;
			var TxtNode1 = document.createTextNode(AnimString.substring(0,AnimPos)) ;
			Font1.appendChild(TxtNode1);
			
			var Font2 = document.createElement('font');
			Font2.align = 'absmiddle' ;
			Font2.style.visibility = 'hidden' ;
			var TxtNode2 = document.createTextNode(AnimString.substring(AnimPos,AnimString.length)) ;
			Font2.appendChild(TxtNode2);

			div.innerHTML = "" ;
			div.appendChild(Font1);
			div.appendChild(Font2);
		}
		
	}

}
