﻿BannerKontrol = function(obj, PN) {
    var prm = obj.Tag.split("|");
    this.link = prm[3];
    this.pn=PN;
    var da = obj.findname("da" + obj.name);
    if (prm[1] == "1")
        da.RepeatBehavior = "Forever";
    
    var tb = obj.findname("tb" + obj.name);
    tb.width = tb.ActualWidth+5;
    da.Duration = "00:00:04";
    if (prm[2] == "0") {
        da.From = obj.width;
        da.To = -tb.width;
    }else{
        da.From = -tb.width;
        da.To = obj.width;
    }
    this.setevents(obj);
}
BannerKontrol.prototype =
{
    setevents: function(obj) {
        this.banner = obj;
        this.anim = obj.findname("an" + obj.name);
        if (this.link != "") {
            this.token1 = obj.addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.OnBannerClick));
            this.token2 = obj.addEventListener("mouseEnter", onHC);
            this.token3 = obj.addEventListener("mouseLeave", offHC);
        }
        this.autoplay();
    },
    autoplay: function() {
        if (this.anim)
            this.anim.Begin();
    },
    OnBannerClick: function() {
        window.open(this.link);
        SendLog(21, this.banner.name);
    },
    release: function() {
        if (this.link != "") {
            this.banner.RemoveEventListener("MouseLeftButtonDown", this.token1);
            this.banner.RemoveEventListener("MouseEnter", this.token2);
            this.banner.RemoveEventListener("mouseLeave", this.token3);
        }
        if (this.anim) {
            this.anim.stop();
            this.anim = null;
        }
    }
}