// JavaScript Document
	var ddLookUp = 
	{
		id:"",
		target:"",
		state:"default",
		expandId:0,
		rowH:12,
		rowMod:30,
		currH:20,
		maxH:500,
		minH:20,
		openArr:[],
		closedArr:[],
		doneArr:[],
		start:function(Id,Name){
			
			//check the array to determine if you can or need to do this 
			//checks the state to see if currently running
			if(ddLookUp.state!="default"){
				return
			}
			
			//alert('length of arr '+ddLookUp.doneArr.length);
						
			//alert(ddLookUp.target);
			//checks the array to see if that maker is already open
			for(var i = 0;i<ddLookUp.doneArr.length;i++){
			//	alert("inside arr = "+ddLookUp.doneArr[i] +" var Name = "+Name);
					if(ddLookUp.doneArr[i]==Name){
						//alert("I am returning");
						//check the openArr
						 for(var i=0;i<ddLookUp.openArr.length;i++){
						 	if(ddLookUp.openArr[i]==Name){
						 		//alert("I am closing")
								//move from openarr
								ddLookUp.openArr.splice(i,1);
								//add to the closearr
								ddLookUp.closedArr.push(Name);
								ddLookUp.reclose(Name);
								return;
							}
						 }
						//check the closedArr
						 for(var i=0;i<ddLookUp.closedArr.length;i++){
						 	if(ddLookUp.closedArr[i]==Name){
								//move from openarr
								ddLookUp.closedArr.splice(i,1);
								//add to the closearr
								ddLookUp.openArr.push(Name);
								ddLookUp.reopen(Name);
								return;
							}
						 }												
						return;
					}
			}

			//alert("look uo state = "+ddLookUp.state);			
			//changes the state to running 
			ddLookUp.state = 'inprogress';

			
			//pushes the name to the done and open arrays
			ddLookUp.doneArr.push(Name);
			ddLookUp.openArr.push(Name);
			document.getElementById(Name+"_button").style.backgroundPosition = 0+" "+ -1*(48)+"px";
			//creates the target
			ddLookUp.target = Name;
			ddLookUp.id = Id;			
			
			var target = Name+"_info";
			
			// append the loading image in the target
			var img = document.createElement('img');
				img.setAttribute('src',"/img/loadingphones.gif");
				// document.getElementById(ddLookUp.target).appendChild(img);
				
				ddLookUp.open();
			
		},
		preloader:function(img){
		  if (document.images)
   			{
				pic1= new Image(300,80); 
				pic1.src="/img/loadingphones.gif"; 
			}

		}(),
		open:function(){
			if(ddLookUp.expandId){
			 //alert("growing");
			 var target = document.getElementById(ddLookUp.target)
				if(ddLookUp.currH<ddLookUp.maxH){
					ddLookUp.currH += 2 + 50*(ddLookUp.currH/ddLookUp.maxH);
					target.style.height = ddLookUp.currH + "px";
				}else{
				// alert("clearing interval")
					//clear interval 
					clearInterval(ddLookUp.expandId);	
					
					target.style.height = "";
					
					target.className = "openParent";
					
				//	var target = Name+"_info";
				//		target.style.display = "block";
					
					
				
					ddLookUp.expandId = 0;		
				    //reset state
					ddLookUp.state = 'default';
					//reset start hieght
					ddLookUp.currH = 20;			

				}
			
			}else{
			//get new height
			//alert("getting height");
			ddLookUp.getHeight()			

			}
		},
		
		getHeight:function(){
			//ajax call 
			
				  _ajax = function()
				   {
					  this.OnSuccess = function()
					  {
						  //set the grow height
						  ddLookUp.maxH = ddLookUp.rowH*this.GetResponseText();
						  //add extra based on bowser type
						  ddLookUp.maxH += ddLookUp.rowMod;
						  //get hard data
						  ddLookUp.getInfo()
						  
 					  }
				
					  this.GetData = function()
					  {
					  //pID stans for productId
						 this.InitializeRequest('GET', '/functions/countrows.asp?Id='+ddLookUp.id+'&Name='+ddLookUp.target );
						 this.Commit(null);
					  }
				   }
				   _ajax.prototype = new ajax();
				
				   _obj = new _ajax();
				   _obj.GetData();
		},
		
		getInfo:function(){
			//ajax second call		
			
				  _ajax = function()
				   {
					  this.OnSuccess = function()
					  {
						  var target = ddLookUp.target+"_info";
						  
						  document.getElementById(target).innerHTML = this.GetResponseText();	  
						  						  
						  //alert("setting interval");
						  //set interval to grow
				          ddLookUp.expandId  = setInterval("ddLookUp.open()",20);
						   
					  }
				
					  this.GetData = function()
					  {
						 this.InitializeRequest('GET', '/functions/query_product_details.asp?Id='+ddLookUp.id+'&Name='+ddLookUp.target );
						 this.Commit(null);
					  }
				   }
				   _ajax.prototype = new ajax();
				
				   _obj = new _ajax();
				   _obj.GetData();
		},
		over:function(t){
		//cursor:pointer;
		t.style.cursor = "pointer";
		document.getElementById(t.id+"_button").style.backgroundPosition = 0+" "+ -1*(24)+"px";
		},
		out:function(t){
		//cursor:default
		t.style.cursor = "default"; 
		var bool = false;	
			for(var i=0;i<ddLookUp.openArr.length;i++){
				if(ddLookUp.openArr[i]==t.id){bool=true}
			}
			if(bool==true){
				document.getElementById(t.id+"_button").style.backgroundPosition = 0+" "+ -1*(48)+"px";
			}else{
				document.getElementById(t.id+"_button").style.backgroundPosition = 0+" "+0+"px";
			}	

		
		},
		reopen:function(n){
		document.getElementById(n).className = "openParent";
		},
		reclose:function(n){
		document.getElementById(n).className = "topParent";
		}
	} 
	
	