/**
 * 修正IE6对PNG图片显示的BUG
 */
var PngCorrector = new Class({
	
	initialize: function(){
		if (Browser.Engine.trident4) {
	        for (var i = 0; i < document.images.length; i++) {
	            var img = document.images[i];
	            var imgName = img.src.toUpperCase();
	            
	            if (imgName.substring(imgName.length - 3, imgName.length) == "PNG") {
	                var imgID = (img.id) ? "id='" + img.id + "' " : "";
	                var imgClass = (img.className) ? "class='" + img.className + "' " : "";
	                var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' ";
	                var imgStyle = "display:inline-block;" + img.style.cssText;
	                
					if (img.align == "left") {
	                    imgStyle = "float:left;" + imgStyle;
	                }
	                if (img.align == "right") {
	                    imgStyle = "float:right;" + imgStyle;
	                }
	                if (img.parentElement.href) {
	                    imgStyle = "cursor:hand;" + imgStyle;
	                }
	                
	                img.outerHTML =["<span ",imgID,imgClass,imgTitle," style=\"width:",img.width,"px; height:",img.height,"px;",imgStyle,";","filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(","src=\'",img.src,"\', sizingMethod='scale'",");\"></span>"] .join("");
	                i--;
	            }
	        }
	    }
	}
	
});

/**
 * 实现Marquee(消息滚屏效果)的功能类
 */
var MooMarquee = new Class({
	
    Implements: Options,
    
    options: {
        stepSpeed: 35
    },
    
    initialize: function(containerId, options){
        this.setOptions(options);
        this.container = $(containerId);
        
		this.container.addEvents({
            'mouseover': function(){
		        $clear(this.timer4step);
		    }.bind(this),
            'mouseout': function(){
		        this.timer4step = this.doMarquee.periodical(this.options.stepSpeed, this);
		    }.bind(this)
        });
		
		this.timer4step = this.doMarquee.periodical(this.options.stepSpeed, this);
    },
    
    doMarquee: function(){
        var coord = this.container.getCoordinates();
        var scroll = this.container.getScroll();
		
		var tbHeight = this.container.getElements('table')[0].getCoordinates().height;
		if (scroll.y >= tbHeight) {
          	this.container.scrollTop = 0;
        } else {
        	this.container.scrollTop++;
        }
    }
});

var Validator = {
	date: function(str){
		 var r = str.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/);
	     if(r==null) return false;
	     var d= new Date(r[1], r[3]-1, r[4]);
	     return (d.getFullYear()==r[1]&&(d.getMonth()+1)==r[3]&&d.getDate()==r[4]); 
	}
};

window.addEvent("domready", function(){
	new PngCorrector();
	//$(document.body).fade('hide').fade('in');
});
