var intervalId;

window.addEvent('domready', function() {



	var myVerticalSlide = new Fx.Slide('toggle_area').hide();

         

	$('expand_quotes').addEvent('click', function(e){
		
		
		/*Yui Data Table Section Start*/
		var startTheScript = 0;

        var bid = new Array();
        var ask = new Array();

        var subscript  = 0;
        var subscript2 = 0;
		
		
		
		YAHOO.example.Local_XML = new function() {
        this.connectionCallback = {
            success: function(o) {
                var xmlDoc = o.responseXML;
               
                var formatCurrencies = function(elCell, oRecord, oColumn, oData){
                	
                	var currency = oData;
                	
                	
                    // convert string to float first                	
                	var floatingCurrency = parseFloat(currency);
                	

                	
                	//since this is not the first time we're running it
                	
                	var increament  = '<img src="/fileadmin/template/main/images/streaming_quotes/tick_up.gif"/>&nbsp;<span style="color:green;font-weight: bolder;">';
                	
                	var decreament = '<img src="/fileadmin/template/main/images/streaming_quotes/tick_down.gif"/>&nbsp;<span style="color:red;font-weight: bolder;">';
                	
                	var status = '<span>';
                    
                	
                	
                	
                	
 
                          
                	      if(oColumn.getKey() == 'bid'){	
                            
                            if( floatingCurrency > bid[subscript] && startTheScript){
                            	
                            	status = increament;
                            	
                            } 
                            if (floatingCurrency < bid[subscript] && startTheScript) {
                            	
                            	status = decreament;
                            	
                            }
                             
                            bid[subscript] = floatingCurrency;
                	        subscript++;
                            
                	      } else {
                	      	
                	      	
                	    
                	      	
                	      	if( floatingCurrency > ask[subscript2] && startTheScript){
                            	
                	      		
                	      		
                            	status = increament;
                            	
                            } 
                            if (floatingCurrency < ask[subscript2]&& startTheScript) {
                            	
                            	status = decreament;
                            	
                            }
                	      	
                	      	ask[subscript2] = floatingCurrency;
                	      	subscript2++;
                	      
                	      } 
                              
                	    
 
                	

                	
                	
                	
                	// set each number to have four positions after the decimal point
                	elCell.innerHTML =  status + floatingCurrency; 
                	
                };
                
                

                
                
                subscript = 0;
                subscript2 = 0;
                

                
                
                var myColumnDefs = [
                    {key:"pair", label:"MAJORS"},
                    {key:"bid", label:"BID", formatter: formatCurrencies},
                    {key:"ask", label:"ASK", formatter: formatCurrencies} 
                ];

                this.myDataSource = new YAHOO.util.DataSource(xmlDoc);
                this.myDataSource.responseType = YAHOO.util.DataSource.TYPE_XML;
                this.myDataSource.responseSchema = {
                    resultNode: "Result",
                    fields: ["pair","bid","ask"]
                };

                
                
                this.myDataTable = new YAHOO.widget.DataTable("mini_streaming_quotes", myColumnDefs, this.myDataSource);
                
                //set this counter to one after the script was run once
                startTheScript = 1;

            },
            failure: function(o) {

            }
        };
        
		
		
        this.getXML = YAHOO.util.Connect.asyncRequest("GET",
                "/streaming_quotes/proxy.php?dealingDeskId=1001&clientTierId=5&&output=xml_mini&cache=" + Math.floor(Math.random()*1000000  ),
                this.connectionCallback);
                        
    };
		
    
    
	   if(!intervalId){	
		
                intervalId =  setInterval("YAHOO.util.Connect.asyncRequest('GET', '/streaming_quotes/proxy.php?dealingDeskId=1001&clientTierId=5&&output=xml_mini&cache=' +  Math.floor(Math.random()*1000000), YAHOO.example.Local_XML.connectionCallback)",10000);
              
	   } else {
	   	
	        intervalId =  $clear(intervalId);
	   	
	   }
        
       
		e = new Event(e);
		
		myVerticalSlide.toggle();
		 
		e.stop();
		
		

	});
   
});
