﻿/*
slidebar ver 1.0 beta
author: 淡然
homepage: www.freeatom.com
date: 2009-10-23
*/
if(window.HTMLElement) 
{
    HTMLElement.prototype.__defineSetter__
    (
        "outerHTML",function(sHTML)
        {
            var r=this.ownerDocument.createRange();
            r.setStartBefore(this);
            var df=r.createContextualFragment(sHTML);
            this.parentNode.replaceChild(df,this);
            return sHTML;
        }
    );

    HTMLElement.prototype.__defineGetter__
    (
        "outerHTML",function()
        {
            var attr;
            var attrs=this.attributes;
            var str="<"+this.tagName.toLowerCase();
            for(var i=0;i<attrs.length;i++){
                attr=attrs[i];
                if(attr.specified)
                    str+=" "+attr.name+'="'+attr.value+'"';
                }
            if(!this.canHaveChildren)
                return str+">";
            return str+">"+this.innerHTML+"</"+this.tagName.toLowerCase()+">";
        }
    );
    HTMLElement.prototype.__defineGetter__
    (
        "canHaveChildren",function()
        {
            switch(this.tagName.toLowerCase())
            {
                case "area":
                case "base":
                case "basefont":
                case "col":
                case "frame":
                case "hr":
                case "img":
                case "br":
                case "input":
                case "isindex":
                case "link":
                case "meta":
                case "param":
                return false;
            }
            return true;
        }
    );
}
function $(o){return document.getElementById(o);}
function $t(a,b){a.appendChild(document.createTextNode(b))}
var ps = pics.split('|');
var ls = links.split('|');
var ts = titles.split('|');
function _ss()
{
    var a=document.createElement("style"),c=b=null;
    document.getElementsByTagName("head")[0].appendChild(a);
    if(navigator.userAgent.indexOf("MSIE")>0)
    {
        b=a.styleSheet;
        c=function(k,q){b.addRule(k,q);};
    }
    else
    {
        b=a.sheet;
        c=function(k,q){var e=k+"{"+q+"}";b.insertRule(e,b.cssRules.length);}
    }
    c(".s","overflow:hidden;border:1px solid #9fd7e9;z-index:99;background:#fff;margin-bottom:15px;position:relative;width:"+pic_width+"px;height:"+pic_height+"px;");
    c(".i","z-index:9999;position:absolute;height:"+title_height+"px;top:0;left:0;padding:5px 10px 0 0;margin:"+(pic_height-30)+"px 0 0 "+(pic_width-20*ps.length)+"px");
    c(".i a","padding:0 3px;border:solid 1px #ccc;text-decoration:none;margin-right:4px;background:#000;color:#fff;font-family:arial,helvetica,sans-serif;font-size:12px");
    c(".i a.activeslide","color:#ff5300")
    c(".m","position:relative;")
    c(".m a","position:absolute;top:0;left:-"+pic_width+"px;display:block;z-index:999;width:"+pic_width+"px;height:"+pic_height+"px;");//ff下不一样
    c(".m img","border:0;width:"+pic_width+"px;height:"+pic_height+"px;");
}
_ss();
var isrun=true,_rn=0,d=document.createElement("div"),_tt=_t2=null;
d.className="s";
if(ps.length==ls.length)
{
    //a
    var ct = document.createElement("div");
    d.appendChild(ct);
    ct.className="i";
    ct.id="_st";
    for(var i=0;i<ps.length;i++)
    {
        var a=document.createElement("a");
        ct.appendChild(a);
        a.innerHTML=(i+1).toString();
        a.href="javascript:void(0)";
        a.onclick="_osd("+(i+1)+")";
        a.setAttribute("onclick","_osd("+(i+1)+")");
        if(i==0)
            a.className="activeslide";
    }
    //img
    var md = document.createElement("div");
    d.appendChild(md);
    md.className="m";
    md.id="_sc";
    for(var i=0;i<ps.length;i++)
    {
        var b=document.createElement("a");
        md.appendChild(b);
        b.href=ls[i];
        b.target="_blank";
        if(i==0)
            b.style.left="0";
        var m=document.createElement("img");
        b.appendChild(m);
        m.src=ps[i];
        m.title=ts[i];
        m.alt=ts[i];
    }
}
else
{
    $t(d,"数据源错误！");
    isrun=false;
}
document.writeln(d.outerHTML);
if(isrun) _tt = setTimeout(_sd,5*1000);
function _sd()
{
    var a=$("_st").getElementsByTagName("a"),m=$("_sc").getElementsByTagName("a");
    var rnb=_rn;
    if(arguments.length>0&&arguments[0]>0)
    {
        if(arguments[0]-1>m.length-1)
           _rn+=1
        else
           _rn = arguments[0]-1;
    }
    else
        _rn+=1;
    
    if(_rn>a.length-1)
        _rn=0;
    for(var i=0;i<a.length;i++)
    {
        if(i!=_rn)
            a[i].className="";
        else
            a[i].className="activeslide";
    }
    if(_rn>0&&_rn<m.length&&rnb>=0&&rnb<m.length&&_rn!=rnb)
        _sr(m[_rn],m[rnb],false);
    else
        _sr(m[0],m[m.length-1],false);
    _tt = setTimeout(_sd,5*1000);
}
function _sr(a,b,e)
{
    var n=pic_width/5;
    if(!e)
    {
        a.style.left=pic_width+"px";
        b.style.left=0+"px";
        e=true;
    }
    if(parseInt(a.style.left)-n>0)
    {
        a.style.left = (parseInt(a.style.left)-n)+"px";
        b.style.left = (parseInt(b.style.left)-n)+"px";
        _t2 = setTimeout(function(){_sr(a,b,e)},20);
    }
    else
    {
        a.style.left="0px";
        b.style.left=(-pic_width)+"px";
    }
}
function _osd(r)
{
    clearTimeout(_tt);
    clearTimeout(_t2);
    _sd(r);
}