﻿/*
	jQuery CSS Support PLugin
	Scorpio Developer Team (C)2000-2010 Bluelovers Net.
	Dual licensed under the MIT and GPL licenses:

	@Revision: 38 $
	@Author: bluelovers$
	@Date: 2009-11-17$

	http://www.bluelovers.net
*/

jQuery(function($){
	$.fn.extend({
		exist: function() {
			return this.length > 0;
		},

		css2: function(name, value, important) {
			return this.each(function() {
				$.css3._css2(this, name, value, important);
			});
		},

		css3: function(name, value, important) {
			return this.each(function() {
				$.css3.css(this, name, value, important);
			});
		},
	});

	$.extend({
		css3: {
			global: [],
			list: {
//				need jQuery textShadow plugin
				textShadow : 'textShadow',
			},
			PropertyAlias: {
				/*'text-shadow' : 'textShadow',*/
			},
			js2css: function (name) {
				// Only "float" is needed here by jquery
				if ( name.match( /float/i ) )
					name = "float";

				return name !== '' ? name.replace(/([A-Z])/g, "-$1").toLowerCase() : '';
			},
			css2js: function (name) {
				// @todo need fix
				return name !== '' ? name.replace(/(\-[a-z])/ig, function ($0, $1) {
					return $1.toUpperCase();
				}).replace(/^([a-z])/i, function ($0, $1) {
					return $1.toLowerCase();
				}) : '';
			},

			css: function (elem, name, value, important) {
				var _jsname = this.css2js(name);

				if (_jsname && this.list[_jsname] !== undefined) {
					var _eval = '';
					var _func = this.list[_jsname] ? this.list[_jsname] : _jsname;

					switch(_jsname) {
						/*
						case '':
							break;
						*/
						default:
							_eval = 'elem.'+_func+'(value)';
							break;
					}

					return eval(_eval);
				} else {
					return this._css2(elem, name, value, important);
				}
			},

			_css2: function(elem, name, value, important) {
				if (value !== undefined) {
//					value = (value + '');

					if (name != 'cssText' && (value.match( /!\s?important[\s;]*$/i ) || important)) {
						important = 1;
						value = value.replace(/!\s?important[\s;]*$/i, '');
					} else {
						important = 0;
					}

					return important ? $(elem).css('cssText', $(elem).css('cssText') + ';'+ name + ':' + value + ' !important') : $(elem).css(name, value);
				} else {
					return $(elem).css(name);
				}
			},
		}
	});
});

//$$ = $j = jQuery.noConflict();

