﻿/*
Author:char
Date:2011.5.20
QQ:21458
*/
function playerPara() {
    this.pics = new Array();
    this.last = 0;
    this.next = 1;
    this.btncolor1 = "#666666";
    this.btncolor2 = "#C30101";
    this.fontcolor1 = "white";
    this.fontcolor2 = "white";
    this.width = "0";
    this.height = "0";
    //this.containerID = "";
    this.btnIdx = "";
    this.ImgID = "";
    this.LinkID = "";
    this.noEffect = false;
    this.time = 3500;
    this.len = 50;
}
function picplayer(playerpara,funName) {
    this.para = playerpara;
    this.img = $(playerpara.ImgID);
    this.link = playerpara.LinkID.length>0?$(playerpara.LinkID):null;
    this.f_timer = null;
    this.init = function() {
        this.img.style.width = this.para.width;
        this.img.style.height = this.para.height;
        for (var ii = 0; ii < this.para.pics.length; ii++) {
            var btn = $(this.para.btnIdx + (ii + 1));
            btn.className = "flash_btn";
            btn.style.backgroundColor = this.para.btncolor1;
            btn.style.color = this.para.fontcolor1;
            btn.onmouseover = new Function(funName+".btnOver(this)");
            btn.onmouseout = new Function(funName+".btnOut(this)");
            btn.onclick = new Function(funName+".btnClick(this)");
        }
        //this.change(this.para.pics[0][0], this.para.pics[0][1], this.para.pics[0][2], this.para.pics[0][3]);
        this.play();
    }
    this.btnOver=function(obj){
        obj.style.color = this.para.fontcolor2;
    }
    this.btnOut=function(obj){
        obj.style.color = this.para.fontcolor1;
    }
    this.btnClick=function(obj){
        var count = obj.id.substring(obj.id.length - 1, obj.id.length);
        if (this.para.last == count) return;
        this.para.next = count;
        this.play();
    }
    this.play = function() {
        clearTimeout(this.f_timer);
        if (this.para.last > 0) $(this.para.btnIdx + this.para.last).style.backgroundColor = this.para.btncolor1;
        $(this.para.btnIdx + this.para.next).style.backgroundColor = this.para.btncolor2;
        if (getOs() == "Firefox" || this.para.last == 0 || this.para.noEffect) {
            this.change(this.para.pics[this.para.next - 1][0], this.para.pics[this.para.next - 1][1], this.para.pics[this.para.next - 1][2], this.para.pics[this.para.next - 1][3]);
        } else {
            this.img.filters.revealTrans.Transition = Math.floor(Math.random() * 23);
            this.img.filters.revealTrans.apply();
            this.change(this.para.pics[this.para.next - 1][0], this.para.pics[this.para.next - 1][1], this.para.pics[this.para.next - 1][2], this.para.pics[this.para.next - 1][3]);
            this.img.filters.revealTrans.play();
        }
        this.para.last = this.para.next;
        this.para.next++;
        if (this.para.next > this.para.pics.length) this.para.next = 1;
        this.f_timer = setTimeout(funName + ".play()", this.para.time);
    }
    this.change = function(_src,_title,_href,_targ) {
        this.img.src = _src;
        this.img.alt = _title;
        this.img.parentNode.title = _title;
        this.img.parentNode.href = _href;
        this.img.parentNode.target=_targ==0?"_blank":"_self";
        if(this.link!=null){
            this.link.title = _title;
            this.link.innerHTML = _title.CutStr(this.para.len);
            this.link.href = _href;
            this.link.target=_targ==0?"_blank":"_self";
        }
    }
}
function getOs() {
    if (navigator.userAgent.indexOf("MSIE") > 0) {
        return "MSIE";
    }
    if (isFirefox = navigator.userAgent.indexOf("Firefox") > 0) {
        return "Firefox";
    }
    if (isSafari = navigator.userAgent.indexOf("Safari") > 0) {
        return "Safari";
    }
    if (isCamino = navigator.userAgent.indexOf("Camino") > 0) {
        return "Camino";
    }
    if (isMozilla = navigator.userAgent.indexOf("Gecko/") > 0) {
        return "Gecko";
    }
}
String.prototype.CutStr=function(_l){
    var l = 0;
    var newstr="";
    var schar = this.split("");
    for (var i=0;i<schar.length;i++) {
        if (schar[i].charCodeAt(0)<299) l++; 
        else l+=2;
        newstr+=schar[i];
        if(l>=_l) return newstr;
    }
    return this;
}
