  var win;


var productsImg=new Array(11);
productsImg[0]="img/mysql.jpg";
productsImg[1]="img/nagios.jpg";
productsImg[2]="img/neogia.jpg";
productsImg[3]="img/nuxeo.jpg";
productsImg[4]="img/openbravo.jpg";
productsImg[5]="img/asterisk.jpg";
productsImg[6]="img/sugarcrm.jpg";
productsImg[7]="img/opentaps.jpg";
productsImg[8]="img/suse.jpg";
productsImg[9]="img/sun.jpg";
productsImg[10]="img/vmware.jpg";


var productsURL=new Array(11);
productsURL[0]="products.html#mysql";
productsURL[1]="products.html#nagios";
productsURL[2]="products.html#neogia";
productsURL[3]="products.html#nuxeo";
productsURL[4]="products.html#openbravo";
productsURL[5]="products.html#asterisk";
productsURL[6]="products.html#sugarcrm";
productsURL[7]="products.html#opentaps";
productsURL[8]="products.html#suse";
productsURL[9]="products.html#sun";
productsURL[10]="products.html#vmware";


var randomArray;
var randomPos;


Ext.onReady(function(){

    Ext.QuickTips.init();
    
  var spot = new Ext.Spotlight({
        easing: 'easeOut',
        duration: .3
    });
 
    var linkContact = Ext.get('contact_us');  
    if (linkContact) {
    linkContact.on('click',popupContactWin);
    }
    
    var tabContact = Ext.get('contact_us_tab'); 
    if (tabContact) {
    tabContact.on('click',popupContactWin);
    }
    
    var searchButton = Ext.get('search-submit'); 
    if (searchButton) {
    searchButton.on('click',function(){
      var searchWin;
      if (!searchWin){
      searchWin =  new Ext.Window({
                id:'searchWin',
                layout:'fit',
                width:500,
                height:300,                              
                plain: true,
                autoScroll: true, 
                title: 'Search Result'         
            
            });
      }
      searchWin.on('beforeclose', function() {
          spot.hide();
      },this);     
      
      searchWin.show(this);     
      spot.show('searchWin');
      
     
      searchWin.load("searchpage.php?q=" + document.getElementById('search-input').value);
     
     
    });
    }
    
    var loginSubmit = Ext.get('login-submit');
    if (loginSubmit) {
     loginSubmit.on('click', function(){
        Ext.MessageBox.show({
           msg: '<font color="black">Contacting Server, please wait...</font>',
           progressText: 'Logging In...',
           width:300,
           wait:true,
           waitConfig: {interval:200},
           //icon:'ext-mb-download', //custom class in msg-box.html
           animEl: 'login-submit'
       });
        setTimeout(function(){
            
           
            Ext.MessageBox.hide();
            Ext.MessageBox.alert('Login Unsuccessful', '<font color="black">The system cannot log you on.<br/> Please make sure your user name and password is correct.</font>');
        }, 3000);
    });
    }
    
    
  if (Ext.get('photos'))
	{ 
    setTimeout(rotateRandom, 5000);
    
      randomArray=shuffle([0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10]);
      randomPos=shuffle([0, 1, 2, 3, 4]);
      
      
     document.getElementById('photoPlace1').src= productsImg[randomArray[0]];
     document.getElementById('photoURL1').href = productsURL[randomArray[0]];  
     document.getElementById('photoPlace2').src= productsImg[randomArray[1]];
     document.getElementById('photoURL2').href = productsURL[randomArray[1]];  
     document.getElementById('photoPlace3').src= productsImg[randomArray[2]];
     document.getElementById('photoURL3').href = productsURL[randomArray[2]];  
     document.getElementById('photoPlace4').src= productsImg[randomArray[3]];
     document.getElementById('photoURL4').href = productsURL[randomArray[3]];  
     document.getElementById('photoPlace5').src= productsImg[randomArray[4]];
     document.getElementById('photoURL5').href = productsURL[randomArray[4]];   
     
  }
   
    
    
	setTimeout(function(){
        Ext.get('loading').remove();        
        Ext.get('loading-mask').fadeOut({remove:true});               
    }, 250);
	
	
	
	
   
});



function displayBack1()
{
  document.getElementById('photoPlace1').src= productsImg[randomArray[5]];
  document.getElementById('photoURL1').href = productsURL[randomArray[5]];  
  Ext.get('photoPlace1').fadeIn({duration:1,callback:setTimeout(rotateRandom, 5000)});
}

function displayBack2()
{
  document.getElementById('photoPlace2').src= productsImg[randomArray[5]];
  document.getElementById('photoURL2').href = productsURL[randomArray[5]];  
  Ext.get('photoPlace2').fadeIn({duration:1,callback:setTimeout(rotateRandom, 5000)});
}
 
function displayBack3()
{
  document.getElementById('photoPlace3').src= productsImg[randomArray[5]];
  document.getElementById('photoURL3').href = productsURL[randomArray[5]];  
  Ext.get('photoPlace3').fadeIn({duration:1,callback:setTimeout(rotateRandom, 5000)});
}
  

function displayBack4()
{
  document.getElementById('photoPlace4').src= productsImg[randomArray[5]];
  document.getElementById('photoURL4').href = productsURL[randomArray[5]];  
  Ext.get('photoPlace4').fadeIn({duration:1,callback:setTimeout(rotateRandom, 5000)});
}

function displayBack5()
{
  document.getElementById('photoPlace5').src= productsImg[randomArray[5]];
  document.getElementById('photoURL5').href = productsURL[randomArray[5]];  
  Ext.get('photoPlace5').fadeIn({duration:1,callback:setTimeout(rotateRandom, 5000)});
}





function rotateRandom()
{


var first_ele = randomArray.shift();
randomArray.push(first_ele);

first_ele = randomPos.shift();
randomPos.push(first_ele);


if (randomPos[0]<1) {
  Ext.get('photoPlace1').fadeOut({duration:1,callback:setTimeout(displayBack1, 1300)});
  
}else if (randomPos[0]<2){
  Ext.get('photoPlace2').fadeOut({duration:1,callback:setTimeout(displayBack2, 1300)});

}else if (randomPos[0]<3){
  Ext.get('photoPlace3').fadeOut({duration:1,callback:setTimeout(displayBack3, 1300)});

}else if (randomPos[0]<4){
  Ext.get('photoPlace4').fadeOut({duration:1,callback:setTimeout(displayBack4, 1300)});

}else if (randomPos[0]<5){
  Ext.get('photoPlace5').fadeOut({duration:1,callback:setTimeout(displayBack5, 1300)});

}




}



function popupContactWin()
{
        // create the window on the first click and reuse on subsequent clicks
        if(!win){
            win = new Ext.Window({
                el:'contact-us-win',
                layout:'fit',
                width:500,
                height:300,
                closeAction:'hide',
                plain: true,
                
                items: new Ext.TabPanel({
                    el: 'contact-us-tabs',
                    autoTabs:true,
                    activeTab:0,
                    deferredRender:false,
                    border:false
                }),

                buttons: [{
                    text:'Submit',
                   handler: function(){
                      document.mailform.submit();
                    }
                },{
                    text: 'Close',
                    handler: function(){
                        win.hide();
                    }
                }]
            });
        }
        win.show(this);
    }


function shuffle(o){ 
	for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
	return o;
}
