var LeftImage;
var MiddleImage;
var RightImage;
var FourthImage;
var FifthImage;
var LeftImage_SM;
var MiddleImage_SM;
var RightImage_SM;
var FourthImage_SM;
var FifthImage_SM;
var tokenLeft, tokenRight, tokenMiddle, tokenFourth, tokenFifth;

var Right_Title, Left_Title, Middle_Title, Fourth_Title, Fifth_Title;
var Right_SubTitle, Left_SubTitle, Middle_SubTitle, Fourth_SubTitle, Fifth_SubTitle;

var NextPanel = "MiddleSMPanel";
var MovePanelNext;

function LoadBg(sender)
{
   sender.findName("BackgroundImage").source = "sl/homeimages/StageBackground_full.jpg";
}

function OnLoaded(sender, args)
{
   //Assign vars
   LeftImage = 	sender.FindName("LeftImage");
   MiddleImage = sender.FindName("MiddleImage");
   RightImage = sender.FindName("RightImage");
   FourthImage = sender.FindName("FourthImage");
   FifthImage = sender.FindName("FifthImage");
   LeftImage_SM = sender.FindName("LeftImage_SM");
   MiddleImage_SM = sender.FindName("MiddleImage_SM");
   RightImage_SM = sender.FindName("RightImage_SM");
   FourthImage_SM = sender.FindName("FourthImage_SM");
   FifthImage_SM = sender.FindName("FifthImage_SM");
   //Copy
   Fourth_Title = sender.FindName("Fourth_Title");   
   Fourth_SubTitle = sender.FindName("Fourth_SubTitle");
   Fifth_Title = sender.FindName("Fifth_Title");  
   Fifth_SubTitle = sender.FindName("Fifth_SubTitle");
   Right_Title = sender.FindName("Right_Title");  
   Right_SubTitle = sender.FindName("Right_SubTitle");
   Left_Title = sender.FindName("Left_Title");
   Left_SubTitle = sender.FindName("Left_SubTitle");
   Middle_Title = sender.FindName("Middle_Title");
   Middle_SubTitle = sender.FindName("Middle_SubTitle");
   
   //LeftImage Image References
   LeftImage.source = "sl/homeimages/itforbusiness.jpg";
   LeftImage_SM.source = "sl/homeimages/tn.png";
   //Left Copy
   Left_Title.Text = "IT for Business";
   Left_SubTitle.Text = "High quality IT services";
   //Add EventListeners
   //tokenLeft = LeftImage.addEventListener("MouseLeftButtonDown", PanelImageDown);
   
   //MiddleImage Image References
   MiddleImage.source = "sl/homeimages/networksupport.jpg";
   MiddleImage_SM.source = "sl/homeimages/network_tn.png";
   //Left Copy
   Middle_Title.Text = "Computers & Networks";
   Middle_SubTitle.Text = "Reliable IT systems";
   
   //RightImage Image References
   RightImage.source = "sl/homeimages/hardware.jpg";
   RightImage_SM.source = "sl/homeimages/hardware_tn.png";
   //Left Copy
   Right_Title.Text = "Hardware & Software";  
   Right_SubTitle.Text = "Competitive prices";
      
   //FourthImage Image References
   FourthImage.source = "sl/homeimages/businesssoftware.jpg";
   FourthImage_SM.source = "sl/homeimages/businesssoftware_tn.png";
   //Left Copy
   Fourth_Title.Text = "Business Applications";  
   Fourth_SubTitle.Text = "Practical technology solutions";
   
   //FifthImage Image References
   FifthImage.source = "sl/homeimages/software.jpg";
   FifthImage_SM.source = "sl/homeimages/software_tn.png";
   //Left Copy
   Fifth_Title.Text = "Bespoke Software";
   Fifth_SubTitle.Text = "Smart business solutions";

   sender.findName("background").Visibility = "Visible";
   sender.findName("FadeIn").begin();
   sender.findName("Timer").begin();
}

//LINKS FOR LARGE PANELS
function PanelImageDown(sender, args) 
{
    switch (sender.Name)
    {
        case "LeftImage":            
            break;
        case "MiddleImage":
            window.location = "networks.htm";
            break;
	    case "RightImage":
	        window.location = "hardware.htm";
            break;
	    case "FourthImage":
	        window.location = "bizapps.htm";
            break;    
	    case "FifthImage":
	        window.location = "software.htm";	        
            break;                      
    }        
}

function PanelOver(sender)
{    
    //Stop the automove
    sender.findName("Timer").stop();
    var pausePanel = sender.FindName("PausePanel");
    
    switch (sender.Name)
    {    
        case "LeftSMPanel":	                  
            sender.FindName("RightSMPanel").visibility = "Visible";
            sender.FindName("MiddleSMPanel").visibility = "Visible";
            sender.FindName("FourthSMPanel").visibility = "Visible";
            sender.FindName("FifthSMPanel").visibility = "Visible";
            sender.FindName("LeftImage").visibility = "Visible";        
	        sender.FindName("LeftSmFadeIn").begin();
	        pausePanel.begin();
	        MovePanelNext = "MoveLeft";
	        NextPanel = "MiddleSMPanel";	        
            break;
        case "MiddleSMPanel":        
            sender.FindName("LeftSMPanel").visibility = "Visible";
            sender.FindName("RightSMPanel").visibility = "Visible";
            sender.FindName("FourthSMPanel").visibility = "Visible";
            sender.FindName("FifthSMPanel").visibility = "Visible";
            sender.FindName("MiddleImage").visibility = "Visible";                      
            sender.FindName("MiddleSmFadeIn").begin();
            pausePanel.begin();
            MovePanelNext = "MoveMiddle";
            NextPanel = "RightSMPanel";           
            break;
        case "RightSMPanel":               
            sender.FindName("LeftSMPanel").visibility = "Visible";
            sender.FindName("MiddleSMPanel").visibility = "Visible";
            sender.FindName("FourthSMPanel").visibility = "Visible";  
            sender.FindName("FifthSMPanel").visibility = "Visible";          
            sender.FindName("RightImage").visibility = "Visible";                 
            sender.FindName("RightSmFadeIn").begin();
            pausePanel.begin();
            MovePanelNext = "MoveRight";
            NextPanel = "FourthSMPanel";     
            break;      
        case "FourthSMPanel":          
            sender.FindName("LeftSMPanel").visibility = "Visible";
            sender.FindName("MiddleSMPanel").visibility = "Visible";
            sender.FindName("RightSMPanel").visibility = "Visible";
            sender.FindName("FifthSMPanel").visibility = "Visible";
            sender.FindName("FourthImage").visibility = "Visible";                                  
            sender.FindName("FourthSmFadeIn").begin();
            pausePanel.begin();
            MovePanelNext = "MoveFourth";
            NextPanel = "FifthSMPanel";          
            break;
        case "FifthSMPanel":          
            sender.FindName("LeftSMPanel").visibility = "Visible";
            sender.FindName("MiddleSMPanel").visibility = "Visible";
            sender.FindName("RightSMPanel").visibility = "Visible";
            sender.FindName("FourthSMPanel").visibility = "Visible";
            sender.FindName("FifthImage").visibility = "Visible";          
            sender.FindName("FifthSmFadeIn").begin();
            pausePanel.begin();
            MovePanelNext = "MoveFifth";
            NextPanel = "LeftSMPanel";          
            break;            
    }

}

function PanelDown(sender)
{    
    //Stop the automove
    sender.findName("Timer").stop();
    sender.FindName("PausePanel").stop();
    
    switch (sender.Name)
    {
        case "LeftSMPanel":
            sender.FindName("RightSMPanel").visibility = "Visible";
            sender.FindName("MiddleSMPanel").visibility = "Visible";
            sender.FindName("FourthSMPanel").visibility = "Visible";
            sender.FindName("FifthSMPanel").visibility = "Visible";
            sender.FindName("LeftImage").visibility = "Visible";            
            sender.FindName("MoveLeft").begin();
            MovePanelNext = "MoveLeft";
            NextPanel = "MiddleSMPanel";           
            break;
        case "MiddleSMPanel":
            sender.FindName("LeftSMPanel").visibility = "Visible";
            sender.FindName("RightSMPanel").visibility = "Visible";
            sender.FindName("FourthSMPanel").visibility = "Visible";             
            sender.FindName("FifthSMPanel").visibility = "Visible";
            sender.FindName("MiddleImage").visibility = "Visible";          
            sender.FindName("MoveMiddle").begin();
            MovePanelNext = "MoveMiddle";
            NextPanel = "RightSMPanel";           
            break;
        case "RightSMPanel":
            sender.FindName("LeftSMPanel").visibility = "Visible";
            sender.FindName("MiddleSMPanel").visibility = "Visible";
            sender.FindName("FourthSMPanel").visibility = "Visible";
            sender.FindName("FifthSMPanel").visibility = "Visible";
            sender.FindName("RightImage").visibility = "Visible";           
            sender.FindName("MoveRight").begin();
            MovePanelNext = "MoveRight";
            NextPanel = "FourthSMPanel";            
            break;
        case "FourthSMPanel":
            sender.FindName("LeftSMPanel").visibility = "Visible";
            sender.FindName("MiddleSMPanel").visibility = "Visible";
            sender.FindName("RightSMPanel").visibility = "Visible";
            sender.FindName("FifthSMPanel").visibility = "Visible";
            sender.FindName("FourthImage").visibility = "Visible";           
            sender.FindName("MoveFourth").begin();
            MovePanelNext = "MoveFourth";
            NextPanel = "FourthSMPanel";            
            break;   
        case "FifthSMPanel":
            sender.FindName("LeftSMPanel").visibility = "Visible";
            sender.FindName("MiddleSMPanel").visibility = "Visible";
            sender.FindName("RightSMPanel").visibility = "Visible";
            sender.FindName("FourthSMPanel").visibility = "Visible";
            sender.FindName("FifthImage").visibility = "Visible";           
            sender.FindName("MoveFifth").begin();
            MovePanelNext = "MoveFifth";
            NextPanel = "LeftSMPanel";            
            break;                      
    }
}

function MovePanel(sender)
{
    sender.FindName("PausePanel").stop();
    sender.FindName(MovePanelNext).begin();	
}

function PanelMoveEnd(sender, args)
{
    switch (sender.Name)
    {
        case "MoveLeft":
            sender.FindName("LeftSMPanel").visibility = "Collapsed";
            sender.FindName("MiddleImage").visibility = "Collapsed";sender.FindName("LeftImage").visibility = "Visible";
            sender.FindName("RightImage").visibility = "Collapsed";           
            sender.FindName("RightSMPanel").visibility = "Visible";
            sender.FindName("MiddleSMPanel").visibility = "Visible";
            sender.FindName("FourthImage").visibility = "Collapsed";
            sender.FindName("FourthSMPanel").visibility = "Visible";
            sender.FindName("FifthImage").visibility = "Collapsed";
            sender.FindName("FifthSMPanel").visibility = "Visible";
            //Add EventListeners
            //tokenLeft = sender.FindName("LeftImage").addEventListener("MouseLeftButtonDown", PanelImageDown);
            //Remove EventListeners
            sender.findName("MiddleImage").removeEventListener("MouseLeftButtonDown", tokenMiddle);
            sender.findName("RightImage").removeEventListener("MouseLeftButtonDown", tokenRight);
            sender.findName("FourthImage").removeEventListener("MouseLeftButtonDown", tokenFourth);
            sender.findName("FifthImage").removeEventListener("MouseLeftButtonDown", tokenFifth);
            break;
        case "MoveMiddle":
            sender.FindName("MiddleSMPanel").visibility = "Collapsed";
            sender.FindName("RightImage").visibility = "Collapsed";
            sender.FindName("LeftImage").visibility = "Collapsed";sender.FindName("MiddleImage").visibility = "Visible";            
            sender.FindName("LeftSMPanel").visibility = "Visible";
            sender.FindName("RightSMPanel").visibility = "Visible";
            sender.FindName("FourthImage").visibility = "Collapsed";
            sender.FindName("FourthSMPanel").visibility = "Visible";
            sender.FindName("FifthImage").visibility = "Collapsed";
            sender.FindName("FifthSMPanel").visibility = "Visible";
            //Add EventListeners
            tokenMiddle = sender.FindName("MiddleImage").addEventListener("MouseLeftButtonDown", PanelImageDown);
            //Remove EventListeners
            //sender.findName("LeftImage").removeEventListener("MouseLeftButtonDown", tokenLeft);
            sender.findName("RightImage").removeEventListener("MouseLeftButtonDown", tokenRight);
            sender.findName("FourthImage").removeEventListener("MouseLeftButtonDown", tokenFourth);
            sender.findName("FifthImage").removeEventListener("MouseLeftButtonDown", tokenFifth);
            break;
        case "MoveRight":
            sender.FindName("MiddleImage").visibility = "Collapsed";
            sender.FindName("LeftImage").visibility = "Collapsed";
            sender.FindName("RightSMPanel").visibility = "Collapsed";
            sender.FindName("LeftSMPanel").visibility = "Visible";sender.FindName("RightImage").visibility = "Visible";
            sender.FindName("MiddleSMPanel").visibility = "Visible";
            sender.FindName("FourthImage").visibility = "Collapsed";
            sender.FindName("FourthSMPanel").visibility = "Visible";
            sender.FindName("FifthImage").visibility = "Collapsed";
            sender.FindName("FifthSMPanel").visibility = "Visible";            
            //Add EventListeners
            tokenRight = sender.FindName("RightImage").addEventListener("MouseLeftButtonDown", PanelImageDown);
            //Remove EventListeners
            //sender.findName("LeftImage").removeEventListener("MouseLeftButtonDown", tokenLeft);
            sender.findName("MiddleImage").removeEventListener("MouseLeftButtonDown", tokenMiddle);
            sender.findName("FourthImage").removeEventListener("MouseLeftButtonDown", tokenFourth);
             sender.findName("FifthImage").removeEventListener("MouseLeftButtonDown", tokenFifth);
            break;
        case "MoveFourth":
            sender.FindName("MiddleImage").visibility = "Collapsed";
            sender.FindName("LeftImage").visibility = "Collapsed";
            sender.FindName("RightSMPanel").visibility = "Visible";
            sender.FindName("LeftSMPanel").visibility = "Visible";
            sender.FindName("RightImage").visibility = "Collapsed";
            sender.FindName("MiddleSMPanel").visibility = "Visible";sender.FindName("FourthImage").visibility = "Visible";
            sender.FindName("FourthSMPanel").visibility = "Collapsed";
            sender.FindName("FifthImage").visibility = "Collapsed";
            sender.FindName("FifthSMPanel").visibility = "Visible";
            //Add EventListeners
            tokenFourth = sender.FindName("FourthImage").addEventListener("MouseLeftButtonDown", PanelImageDown);
            //Remove EventListeners
            //sender.findName("LeftImage").removeEventListener("MouseLeftButtonDown", tokenLeft);
            sender.findName("MiddleImage").removeEventListener("MouseLeftButtonDown", tokenMiddle);
            sender.findName("RightImage").removeEventListener("MouseLeftButtonDown", tokenRight);
            sender.findName("FifthImage").removeEventListener("MouseLeftButtonDown", tokenFifth);
            break;     
        case "MoveFifth":
            sender.FindName("MiddleImage").visibility = "Collapsed";
            sender.FindName("LeftImage").visibility = "Collapsed";
            sender.FindName("RightSMPanel").visibility = "Visible";
            sender.FindName("LeftSMPanel").visibility = "Visible";
            sender.FindName("RightImage").visibility = "Collapsed";
            sender.FindName("MiddleSMPanel").visibility = "Visible";
            sender.FindName("FourthSMPanel").visibility = "Visible";
            sender.FindName("FourthImage").visibility = "Collapsed"; sender.FindName("FifthImage").visibility = "Visible";
            sender.FindName("FifthSMPanel").visibility = "Collapsed";
            //Add EventListeners
            tokenFifth = sender.FindName("FifthImage").addEventListener("MouseLeftButtonDown", PanelImageDown);
            //Remove EventListeners
            //sender.findName("LeftImage").removeEventListener("MouseLeftButtonDown", tokenLeft);
            sender.findName("MiddleImage").removeEventListener("MouseLeftButtonDown", tokenMiddle);
            sender.findName("RightImage").removeEventListener("MouseLeftButtonDown", tokenRight);
            sender.findName("FourthImage").removeEventListener("MouseLeftButtonDown", tokenFourth);
            break;                      
    }
}

function Next(sender, args)
{
    PanelOver(sender.findName(NextPanel));
    sender.findName("Timer").begin();
}

function SmallPanelOver(sender, args)
{
	var panel = sender.name.replace("SMPanel","");
	sender.findName(panel+"SmFadeIn").begin();
}
function SmallPanelLeave(sender, args)
{
	var panel = sender.name.replace("SMPanel","");
	sender.findName(panel+"SmFadeOut").begin();
}





 


