if (!window.SilverlightJSApplication1)
    window.SilverlightJSApplication1 = {};

ProductPageXamlManager = function() 
{
    this.hasXamlRefs = false;
    this.uriBase = "Images/Aug07/";
    this.images = 
    [
        {
            fname: "produktVignett1.jpg",
            grayFname: "produktVignett1b.jpg",
            image: new Image(),
            grayImage: new Image(),
            xamlImage: null
        }, 
        {
            fname: "newVignett2.jpg",
            grayFname: "newVignett2.png",
            image: new Image(),
            grayImage: new Image(),
            xamlImage: null
        }, 
        {
            fname: "newVignett3.jpg",
            grayFname: "newVignett3b.jpg",
            image: new Image(),
            grayImage: new Image(),
            xamlImage: null
        }, 
        {
            fname: "produktVignett3.jpg",
            grayFname: "produktVignett3b.jpg",
            image: new Image(),
            grayImage: new Image(),
            xamlImage: null
        }
    ];
}

ProductPageXamlManager.prototype =
{
    // xaml load event handler
    handleLoad : function(plugIn, userContext, rootElement) 
    {
        var mouseEnterDelegate = Silverlight.createDelegate(this, this.handleMouseEnter);
        var mouseLeftDownDelegate = Silverlight.createDelegate(this, this.handleLeftDown); 
    
        for (var i = 0; i < this.images.length; i++)
        {
            var name = "image" + (i + 1);
            var xamlImage = plugIn.content.FindName(name);
            xamlImage.addEventListener("MouseEnter", mouseEnterDelegate);
            xamlImage.addEventListener("MouseLeftButtonDown", mouseLeftDownDelegate); 
            
            this.images[i].xamlImage = xamlImage;
            
            //Preload the mouseover images to the browser cache. 
            this.images[i].image.src = this.uriBase + this.images[i].fname;
            this.images[i].grayImage.src = this.uriBase + this.images[i].grayFname;
        }
        
        this.images[0].captionLbl = $get(image1Line1);
        this.images[1].captionLbl = $get(image2Line1);
        this.images[2].captionLbl = $get(image3Line1);
        this.images[3].captionLbl = $get(image4Line1);
    }, 
    
    handleLeftDown : function(sender, eventArgs) 
    {
        var link = null; 
        switch(sender.Name) 
        {
            case "image1": 
                link = link1; 
                break; 
            case "image2": 
                link = link2; 
                break; 
            case "image3": 
                link = link3; 
                break;
            case "image4": 
                link = link4; 
                break; 
            default:
                return;
        }
        window.location = link; 
    }, 
    
    handleMouseEnter : function(sender, eventArgs) 
    {
        for (var i = 0; i < this.images.length; i++)
        {
            this.images[i].xamlImage.Source = this.uriBase + this.images[i].grayFname;
        }
        var textSrc = null;
        var index = -1;        
        switch (sender.Name) 
        {
            case "image1":
                index = 0; 
                textSrc = image1Line1;
                break; 
            case "image2": 
                index = 1; 
                textSrc = image2Line1;
                break; 
            case "image3": 
                index = 2; 
                textSrc = image3Line1;
                break; 
            case "image4": 
                index = 3; 
                textSrc = image4Line1;
                break;
            default:
                return;
        }
        this.images[index].xamlImage.Source = this.uriBase + this.images[index].fname;
        
        if (!this.hasXamlRefs)
        {
            this.mainTB1 = sender.findName("tb1Main"); 
            this.fadeOutTB1 = sender.findName("tb1FadeOut"); 
            this.sbFadeIn = sender.findName("sbFadeIn"); 
            this.sbFadeOut = sender.findName("sbFadeOut");
            this.hasXamlRefs = true;
        }
        
        this.fadeOutTB1.Text = this.mainTB1.Text; 
        this.mainTB1.Text = textSrc;
        this.mainTB1.Opacity = 0;
        this.sbFadeIn.begin(); 
        this.sbFadeOut.begin();
    }
}

var productXamlMgr = new ProductPageXamlManager(); 