function MagicShow () {
};

var userAgent = navigator.userAgent.toLowerCase();

// Figure out what browser is being used
MagicShow.browser = {
	version: (userAgent.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [])[1],
	safari: /webkit/.test( userAgent ),
	opera: /opera/.test( userAgent ),
	msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),
	mozilla: /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent )
};

MagicShow.width = function(obj) {

    return obj == window ? MagicShow.browser.opera && document.body.clientWidth ||
        MagicShow.browser.safari && window.innerWidth ||
        document.compatMode == "CSS1Compat" && document.documentElement.clientWidth ||
        document.body.clientWidth :

        obj == document ? Math.max(Math.max(document.body.scrollWidth, document.documentElement.scrollWidth),
            Math.max(document.body.offsetWidth, document.documentElement.offsetWidth)) :
            (obj.width ? obj.width : obj.offsetWidth);
}

MagicShow.height = function(obj) {

    return obj == window ? MagicShow.browser.opera && document.body.clientHeight ||
        MagicShow.browser.safari && window.innerHeight ||
        document.compatMode == "CSS1Compat" && document.documentElement.clientHeight ||
        document.body.clientHeight :

        obj == document ? Math.max(Math.max(document.body.scrollHeight, document.documentElement.scrollHeight),
            Math.max(document.body.offsetHeight, document.documentElement.offsetHeight)) :
            (obj.height ? obj.height : obj.offsetHeight);
}

MagicShow.doane = function(event) {

	if(MagicShow.browser.msie) {
		event.returnValue = false;
		event.cancelBubble = true;
	} else if(event) {
		event.stopPropagation();
		event.preventDefault();
	}
};

MagicShow.msShowType = null;
MagicShow.ShowType = [];
MagicShow.bExpaired = false;

MagicShow.info = {
    version: '0.01.0900',
    date: '2009-02-19',
    author: 'ggkl'
};

MagicShow.getOffset = function(obj) {
    var offset = {offsetLeft: 0, offsetTop: 0};
    while (obj) {
        offset.offsetLeft += obj.offsetLeft;
        offset.offsetTop += obj.offsetTop;
        obj = obj.offsetParent;
    }
    return offset;
};

MagicShow.addEvent = function(obj, type, handle, useCapture) {
    if (obj.addEventListener)
        obj.addEventListener(type, handle, useCapture);
    else if (obj.attachEvent)
        obj.attachEvent("on" + type, handle);
};

MagicShow.getPageScroll = function(){
   var XScroll,YScroll;
   var wObj = window;
   if(wObj.pageYOffset)
   {
       XScroll = wObj.pageXOffset;
       YScroll = wObj.pageYOffset;
   }
   else if(wObj.document.documentElement && wObj.document.documentElement.scrollTop)
   {
      XScroll = wObj.document.documentElement.scrollLeft;
      YScroll = wObj.document.documentElement.scrollTop;
   }else if(wObj.document.body)
   {
      XScroll = wObj.document.body.scrollLeft;
      YScroll = wObj.document.body.scrollTop;
   }
   return {offsetLeft: XScroll, offsetTop: YScroll};
};

MagicShow.prototype = {
    msObj : null,
    msShowType : null,
    msBigImg : [],
    msMidImg : [],
    msSmallImg : [],
    msImg : [],



    init : function(obj, mstype, bExpaired) {
        if (typeof(obj) == "string")
            this.msObj = document.getElementById(obj);
        else
            this.msObj = obj;

        this.uninit(false);
        this.init0(mstype, bExpaired);
    },

    init0 : function(mstype, bExpaired) {
        this.empty();
		
		MagicShow.bExpaired = (bExpaired == undefined ? false : bExpaired);
        MagicShow.msShowType = null;
        for (var i=0; i < MagicShow.ShowType.length; i++) {
            if (MagicShow.ShowType[i].name == mstype) {
                MagicShow.msShowType = MagicShow.ShowType[i].type;
                break;
            }
        }

        if (!MagicShow.msShowType) {
            MagicShow.msShowType = MagicShow.ShowType[0].type;
        }

        MagicShow.msShowType.init(this);
        //this.uninit();
    },

    uninit: function(showinfo) {
		MagicShow.bExpaired = false;
        this.empty();

        str = "";
        if (MagicShow.msShowType) {
            str = MagicShow.msShowType.uninit(this);
            MagicShow.msShowType = null;
        }

        if (showinfo === true) {
            this.msObj.innerHTML = "<div class=\"ms_thanks\">" + str + "</div>";
        }
    },

    removeChild: function(obj) {
		if(obj !=""){
		while ( obj.firstChild ) {
            this.removeChild( obj.firstChild );
			obj.removeChild( obj.firstChild );
        }
    }},

    empty: function() {
		this.removeChild ( this.msObj );
    }
};

MagicShow.allowdebug = false;
MagicShow.debugwin = null;
MagicShow.debug = function(output) {
    if (!MagicShow.allowdebug)
        return;
    if (!MagicShow.debugwin) {
        MagicShow.debugwin = window.open('','openWindow','');
        MagicShow.debugwin.opener = null;
    }

    try {
        MagicShow.debugoutput(output);
    }
    catch (e) {
        MagicShow.debugwin = window.open('','openWindow','');
        MagicShow.debugwin.opener = null;
        MagicShow.debugoutput(output);
    }
}

MagicShow.debugoutput = function(output) {
    MagicShow.debugwin.document.write('<div style="border-left: 1px solid red; padding-left: 10px;">');
    switch (output.constructor) {
    case Number:
        MagicShow.debugwin.document.write(output + '<br />');
        break;
    case String:
        MagicShow.debugwin.document.write(output + '<br />');
        break;
    case Array:
        MagicShow.debugwin.document.write('Array [<br />');
        for (var i = 0; i < output.length; i++) {
            MagicShow.debugoutput(output[i]);
        }
        MagicShow.debugwin.document.write(']<br />');
        break;
    case Object:
        MagicShow.debugwin.document.write('Object {<br />');
        for (var name in output) {
            MagicShow.debugwin.document.write(name + ":");
            MagicShow.debugoutput(output[name]);
        }
        MagicShow.debugwin.document.write('}<br />');
        break;
    }
    MagicShow.debugwin.document.write('</div>');
}

MagicShow.winOnLoad = window.onload;

