/* 没 */
;(function($) {

/* $.C */
$.C =
{
	obj : function (elementId)
	{
		if(typeof(elementId) == "object")
		{
			return elementId;
		}
		else if (document.getElementById)
		{
	        return document.getElementById(elementId);
	    }
	    else if (document.all)
	    {
	        return document.all[elementId];
	    }
	    else return null;
	},
	
	setCookie : function (name, value)
	{
		var today = new Date();
		var expires = new Date();
		expires.setTime(today.getTime() + 1000*60*60*24*365);
		document.cookie = name + "=" + escape(value) + "; expires=" + expires.toGMTString();
	},

	getCookie : function (Name)
	{
		var v = "";
		var search = Name + "=";
		if(document.cookie.length > 0)
		{
			offset = document.cookie.indexOf(search);
			if(offset != -1)
			{
				offset += search.length;
				end = document.cookie.indexOf(";", offset);
				if(end == -1) end = document.cookie.length;
				v = unescape(document.cookie.substring(offset, end));
			}
	   }
	   
	   return v;
	},
	
	IsNullOrEmpty : function(o)
	{
		return (o == null || typeof(o) == "undefined" || o == "");
	},
	
	QueryString : function(fieldName)
	{  
		var qs = document.location.search;
		
		if(qs == null) return null;
		
		var fn = fieldName + "=";
		var nEnd = qs.indexOf(fn);
		
		if(nEnd == -1) return null;
		
		var v = qs.substring(nEnd + fn.length);
		var isEnd =  v.indexOf('&');
		return (isEnd != -1) ? v.substring(0, isEnd) : v;
	},

	rndQueryTag : function (url)
	{
		var now = new Date();
		var seconds = Math.floor( now.getTime()/1000 );
		var pattern = /(\?|&)(rndQueryTag=)(\d+)/;
		
		if(pattern.test(url))
		{
			return url.replace(pattern, "$1$2" + seconds);
		}
		else
		{
			if ( url.indexOf("?") == -1 )
				return url + "?rndQueryTag=" + seconds;
			else
				return url + "&rndQueryTag=" + seconds;
		}
	},

	addQueryValue : function (url, key, value)
	{
		var pattern = eval("/(\\?|&)" + key + "=[^&]*/i");
		
		if(pattern.test(url))
		{
			return url.replace(pattern, "$1" + key + "=" + value);
		}
		else
		{
			if ( url.indexOf("?") == -1 )
				return url + "?" + key + "=" + value;
			else
				return url + "&" + key + "=" + value;
		}
	}
};

$.C.O = $.C.o = $.C.obj;

/* metadata */
$.extend({
	metadata : {
		defaults : {
			type: 'attr',
			name: 'metadata',
			cre: /({.*})/,
			single: 'metadata'
		},
		setType: function( type, name ){
			this.defaults.type = type;
			this.defaults.name = name;
		},
		get: function( elem, opts ){
			var settings = $.extend({}, this.defaults, opts);
			// check for empty string in single property
			if ( !settings.single.length ) settings.single = 'metadata';
			
			var data = $.data(elem, settings.single);
			// returned cached data if it already exists
			if ( data ) return data;
			
			if( settings.type == "attr" )
			{
				if ( elem.getAttribute != undefined )
				{
					data = elem.getAttribute( settings.name );
				}
			}
			else if ( settings.type == "class" )
			{
				data = elem.className;
			}
			else if ( settings.type == "elem" )
			{
				if( elem.getElementsByTagName )
				{
					var e = elem.getElementsByTagName(settings.name);
					if ( e.length )
						data = $.trim(e[0].innerHTML);
				}
			}
			
			if( data && settings.cre.exec(data))
			{
				data = RegExp.$1;
			}
			else
				data = "{}";
			
			data = eval("(" + data + ")");
			
			$.data( elem, settings.single, data );
			return data;
		}
	}
});

$.fn.metadata = function( opts ){
	return $.metadata.get( this[0], opts );
};

/* fixPng */
$.fn.fixPng = function(settings) {
	// Settings
	var settings = $.extend({ blankgif: "/html/img/blank.gif" }, settings);

	if ($.browser.msie && ($.browser.version == "5.5" || $.browser.version == "6.0"))
	{
		//fix images with png-source
		this.find("img[@src*=.png]").each(function() {
			var z = $(this);
			
			z.attr('width', z.width());
			z.attr('height', z.height());
			
			var png = z.attr("src");
			z.attr("src", settings.blankgif)
			this.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + png + "',sizingMethod='scale')";
		});

		// fix css background pngs
		this.find("*").each(function(){
			var z = $(this);
			var bgIMG = z.css("background-image");
			if(bgIMG != "none")
			{
				// 匹配url("path/image.png")格式，其中单引号或双引号由\1作后向引用
				var regex = new RegExp("url\\((['\"])(\\S+\\.png)\\1\\)", "i");
				if(bgIMG.match(regex)){
					bgIMG = RegExp.$2;
					z.css('background-image', 'none');
					z.get(0).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + bgIMG + "',sizingMethod='scale')";
				}
			}
		});
		
		//fix input with png-source
		this.find("input[@src*=.png]").each(function() {
			var z = $(this);
			var bgIMG = z.attr('src');
			z.get(0).runtimeStyle.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader' + '(src=\'' + bgIMG + '\', sizingMethod=\'scale\')';
   			z.attr('src', settings.blankgif);
		});
	}

	return this;
};

/*
 * $ Color Animations
 * Copyright 2007 John Resig
 * Released under the MIT and GPL licenses.
 */

// We override the animation for all of these color styles
$.each(['backgroundColor', 'borderBottomColor', 'borderLeftColor', 'borderRightColor', 'borderTopColor', 'color', 'outlineColor'], function(i,attr){
	$.fx.step[attr] = function(fx){
		if ( fx.state == 0 ) {
			fx.start = $.color.getColor( fx.elem, attr );
			fx.end = $.color.getRGB( fx.end );
		}

		fx.elem.style[attr] = "rgb(" + [
			Math.max(Math.min( parseInt((fx.pos * (fx.end[0] - fx.start[0])) + fx.start[0]), 255), 0),
			Math.max(Math.min( parseInt((fx.pos * (fx.end[1] - fx.start[1])) + fx.start[1]), 255), 0),
			Math.max(Math.min( parseInt((fx.pos * (fx.end[2] - fx.start[2])) + fx.start[2]), 255), 0)
		].join(",") + ")";
	}
});
	
$.color = {
	// Color Conversion functions from highlightFade
	// By Blair Mitchelmore
	// http://jquery.offput.ca/highlightFade/

	// Parse strings looking for color tuples [255,255,255]
	getRGB : function(color) {
		var result;

		// Check if we're already dealing with an array of colors
		if ( color && color.constructor == Array && color.length == 3 )
			return color;

		// Look for rgb(num,num,num)
		if (result = /rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(color))
			return [parseInt(result[1]), parseInt(result[2]), parseInt(result[3])];

		// Look for rgb(num%,num%,num%)
		if (result = /rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(color))
			return [parseFloat(result[1])*2.55, parseFloat(result[2])*2.55, parseFloat(result[3])*2.55];

		// Look for #a0b1c2
		if (result = /#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(color))
			return [parseInt(result[1],16), parseInt(result[2],16), parseInt(result[3],16)];

		// Look for #fff
		if (result = /#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(color))
			return [parseInt(result[1]+result[1],16), parseInt(result[2]+result[2],16), parseInt(result[3]+result[3],16)];

		// Otherwise, we're most likely dealing with a named color
		return this.colors[$.trim(color).toLowerCase()];
	},
	
	getColor : function(elem, attr) {
		var color;
		do
		{
			color = $.curCSS(elem, attr);
			// Keep going until we find an element that has color, or we hit the body
			if ( color != '' && color != 'transparent' || $.nodeName(elem, "body") )
				break; 

			attr = "backgroundColor";
		} while ( elem = elem.parentNode );

		return this.getRGB(color);
	},
	
	// Some named colors to work with
	// From Interface by Stefan Petre
	// http://interface.eyecon.ro/

	colors : {
		aqua:[0,255,255],
		azure:[240,255,255],
		beige:[245,245,220],
		black:[0,0,0],
		blue:[0,0,255],
		brown:[165,42,42],
		cyan:[0,255,255],
		darkblue:[0,0,139],
		darkcyan:[0,139,139],
		darkgrey:[169,169,169],
		darkgreen:[0,100,0],
		darkkhaki:[189,183,107],
		darkmagenta:[139,0,139],
		darkolivegreen:[85,107,47],
		darkorange:[255,140,0],
		darkorchid:[153,50,204],
		darkred:[139,0,0],
		darksalmon:[233,150,122],
		darkviolet:[148,0,211],
		fuchsia:[255,0,255],
		gold:[255,215,0],
		green:[0,128,0],
		indigo:[75,0,130],
		khaki:[240,230,140],
		lightblue:[173,216,230],
		lightcyan:[224,255,255],
		lightgreen:[144,238,144],
		lightgrey:[211,211,211],
		lightpink:[255,182,193],
		lightyellow:[255,255,224],
		lime:[0,255,0],
		magenta:[255,0,255],
		maroon:[128,0,0],
		navy:[0,0,128],
		olive:[128,128,0],
		orange:[255,165,0],
		pink:[255,192,203],
		purple:[128,0,128],
		violet:[128,0,128],
		red:[255,0,0],
		silver:[192,192,192],
		white:[255,255,255],
		yellow:[255,255,0]
	}
};

})(jQuery);

(function($){
// extend Array prototype if ie version is below 5.5
if ( $.browser.msie && (Number($.browser.version) < 5.5) ){
$.extend(Array.prototype, {
    pop : function() {
        var last;
        if (this.length) {
            last = this[this.length - 1];
            this.length -= 1;
        }
        return last;
    },
    
	push : function() {
        for (var i = 0; i < arguments.length; ++i) {
            this[this.length] = arguments[i];
        }
        return this.length;
    },
    
    shift : function() {
        var first;
        if (this.length) {
            first = this[0];
            for (var i = 0; i < this.length - 1; ++i) {
                this[i] = this[i + 1];
            }
            this.length -= 1;
        }
        return first;
    },
	
	unshift : function() {
        if (arguments.length) {
            var i, len = arguments.length;
            for (i = this.length + len - 1; i >= len; --i) {
                this[i] = this[i - len];
            }
            for (i = 0; i < len; ++i) {
                this[i] = arguments[i];
            }
        }
        return this.length;
    },
	
	splice : function(index, howMany) {
        var elements = [], removed = [], i;
        for (i = 2; i < arguments.length; ++i) {
            elements.push(arguments[i]);
        }
        for (i = index; (i < index + howMany) && (i < this.length); ++i) {
            removed.push(this[i]);
        }
        for (i = index + howMany; i < this.length; ++i) {
            this[i - howMany] = this[i];
        }
        this.length -= removed.length;
        for (i = this.length + elements.length - 1; i >= index + elements.length; --i) {
            this[i] = this[i - elements.length];
        }
        for (i = 0; i < elements.length; ++i) {
            this[index + i] = elements[i];
        }
        return removed;
    }
});
} // end of version below 5.5
})(jQuery);
