/**
* jQuery Guid v1.0.0-1
* Requires jQuery 1.2.6+ (Not tested with earlier versions).
* Copyright (c) 2010 Aaron E. [jquery at happinessinmycheeks dot com] 
* Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
*	Usage:
*		jQuery.Guid.Value() // Returns value of internal Guid. If no guid has been specified, returns a new one (value is then stored internally).
*		jQuery.Guid.New() // Returns a new Guid and sets it's value internally. Also accepts GUID, Sets it internally.
*		jQuery.Guid.Empty() // Returns an empty Guid 00000000-0000-0000-0000-000000000000.
*		jQuery.Guid.IsEmpty() // Returns boolean. True if empty/undefined/blank/null.
*		jQuery.Guid.IsValid() // Returns boolean. True valid guid, false if not.
*		jQuery.Guid.Set() // Retrns Guid. Sets Guid to user specified Guid, if invalid, returns an empty guid.
*
*/

jQuery.extend({
    Guid: {
        Set: function (val) {
            var value;
            if (arguments.length == 1) {
                if (this.IsValid(arguments[0])) {
                    value = arguments[0];
                } else {
                    value = this.Empty();
                }
            }
            $(this).data("value", value);
            return value;
        },

        Empty: function () {
            return "00000000-0000-0000-0000-000000000000";
        },

        IsEmpty: function (gid) {
            return gid == this.Empty() || typeof (gid) == 'undefined' || gid == null || gid == '';
        },

        IsValid: function (value) {
            rGx = new RegExp("\\b(?:[A-F0-9]{8})(?:-[A-F0-9]{4}){3}-(?:[A-F0-9]{12})\\b");
            return rGx.exec(value) != null;
        },

        New: function () {
            if (arguments.length == 1 && this.IsValid(arguments[0])) {
                $(this).data("value", arguments[0]);
                value = arguments[0];
                return value;
            }

            var res = [], hv;
            var rgx = new RegExp("[2345]");
            for (var i = 0; i < 8; i++) {
                hv = (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
                if (rgx.exec(i.toString()) != null) {
                    if (i == 3) { hv = "6" + hv.substr(1, 3); }
                    res.push("-");
                }
                res.push(hv.toUpperCase());
            }
            value = res.join('');
            $(this).data("value", value);
            return value;
        },

        Value: function () {
            if ($(this).data("value")) {
                return $(this).data("value");
            }
            var val = this.New();
            $(this).data("value", val);
            return val;
        }
    }
})();




/*
* jQuery doTimeout: Like setTimeout, but better! - v1.0 - 3/3/2010
* http://benalman.com/projects/jquery-dotimeout-plugin/
* 
* Copyright (c) 2010 "Cowboy" Ben Alman
* Dual licensed under the MIT and GPL licenses.
* http://benalman.com/about/license/
*/
(function ($) { var a = {}, c = "doTimeout", d = Array.prototype.slice; $[c] = function () { return b.apply(window, [0].concat(d.call(arguments))) }; $.fn[c] = function () { var f = d.call(arguments), e = b.apply(this, [c + f[0]].concat(f)); return typeof f[0] === "number" || typeof f[1] === "number" ? this : e }; function b(l) { var m = this, h, k = {}, g = l ? $.fn : $, n = arguments, i = 4, f = n[1], j = n[2], p = n[3]; if (typeof f !== "string") { i--; f = l = 0; j = n[1]; p = n[2] } if (l) { h = m.eq(0); h.data(l, k = h.data(l) || {}) } else { if (f) { k = a[f] || (a[f] = {}) } } k.id && clearTimeout(k.id); delete k.id; function e() { if (l) { h.removeData(l) } else { if (f) { delete a[f] } } } function o() { k.id = setTimeout(function () { k.fn() }, j) } if (p) { k.fn = function (q) { if (typeof p === "string") { p = g[p] } p.apply(m, d.call(n, i)) === true && !q ? o() : e() }; o() } else { if (k.fn) { j === undefined ? e() : k.fn(j === false); return true } else { e() } } } })(jQuery);



/*!
 *   shadowOn jQuery plugin
 *   Written by David Hansson 2010
 *   http://shadowon.codeplex.com/
 *
 *   Copyright 2010, MIT License
 *   http://shadowon.codeplex.com/license
 *	 This copyright header must be kept intact!
 *
 *   Based on "Javascript Drop Shadows" written by James Player 2009
 *   http://www.springload.co.nz/love-the-web/javascript-drop-shadoww
 */

(function ($) {
	$.fn.shadowOn = function (options) {
		var opts = $.extend({}, $.fn.shadowOn.defaults, options);

		$(this).each(function () {
			if (!/^(?:a|button|div|dl|fieldset|form|h1|h2|h3|h4|h5|h6|hr|iframe|img|input|ol|select|span|table|textarea|ul)$/i.test(this.tagName)) {
				return;
			}
			var imagepath = opts.imagepath;
			var imageset = opts.imageset;
			var autoresize = opts.autoresize;
			var resizetimer = opts.resizetimer;
			var wrapelement = this.tagName == 'DIV' ? false : true;
			var boxWidth = $(this).outerWidth();
			var boxHeight = $(this).outerHeight();
			
			
			var okWidth = boxWidth > 22;
			var okHeight = boxHeight > 21;
			var guid = jQuery.Guid.New();
			var zIndex = $(this).css("zIndex");
			var offset = $(this).offset();
			var position = $(this).css("position");
			if (position.length < 8) position = 'relative';
			zIndex = zIndex == 'auto' ? -1 : (parseInt(zIndex) - 10);

			var workdiv = $(this);
			if (wrapelement) {
				if ($(this).hasClass("shadowOnWrapper")) {
					$("#" + $(this).attr("rel")).remove();
					$(this).removeClass("shadowOnWrapper");
				}
				$(this).attr("rel", guid).addClass("shadowOnWrapper").css("position", position);
				workdiv = $("<div></div>").attr("id", guid).css({ 'position': 'absolute', 'top': offset.top + 'px', 'left': offset.left + 'px', 'width': boxWidth + 'px', 'height': boxHeight + 'px', 'zIndex': zIndex });
			} else {
				$(workdiv).addClass("shadowOn").css("position", position).children("div.shadowOnBit").remove().end();
			}

			$(workdiv).append('<div class="shadowOnBit" style="background:url(' + imagepath + '/set' + imageset + '/tl.png) no-repeat;width:25px;height:25px;position:absolute;top:-10px;left:-12px;margin:0;padding:0;z-index:' + zIndex + '"></div>')
                      .append('<div class="shadowOnBit" style="background:url(' + imagepath + '/set' + imageset + '/tr.png) no-repeat;width:25px;height:25px;position:absolute;top:-10px;left:' + (boxWidth - 9) + 'px;margin:0;padding:0;z-index:' + zIndex + '"></div>')
                      .append('<div class="shadowOnBit" style="background:url(' + imagepath + '/set' + imageset + '/br.png) no-repeat;width:25px;height:25px;position:absolute;top:' + (boxHeight - 6) + 'px;left:' + (boxWidth - 9) + 'px;margin:0;padding:0;z-index:' + zIndex + '"></div>')
                      .append('<div class="shadowOnBit" style="background:url(' + imagepath + '/set' + imageset + '/bl.png) no-repeat;width:25px;height:25px;position:absolute;top:' + (boxHeight - 6) + 'px;left:-12px;margin:0;padding:0;z-index:' + zIndex + '"></div>');

			if (okWidth) {
				$(workdiv).append('<div class="shadowOnBit" style="background:url(' + imagepath + '/set' + imageset + '/t.png) repeat-x;width:' + (boxWidth - 22) + 'px;height:10px;position:absolute;top:-10px;left:13px;margin:0;padding:0;z-index:' + zIndex + '"></div>')
                          .append('<div class="shadowOnBit" style="background:url(' + imagepath + '/set' + imageset + '/b.png) repeat-x;width:' + (boxWidth - 22) + 'px;height:19px;position:absolute;top:' + boxHeight + 'px;left:13px;margin:0;padding:0;z-index:' + zIndex + '"></div>');
			}
			if (okHeight) {
				$(workdiv).append('<div class="shadowOnBit" style="background:url(' + imagepath + '/set' + imageset + '/r.png) repeat-y;width:15px;height:' + (boxHeight - 21) + 'px;position:absolute;top:15px;left:' + (boxWidth) + 'px;margin:0;padding:0;z-index:' + zIndex + '"></div>')
                          .append('<div class="shadowOnBit" style="background:url(' + imagepath + '/set' + imageset + '/l.png) repeat-y;width:12px;height:' + (boxHeight - 21) + 'px;position:absolute;top:15px;left:-12px;margin:0;padding:0;z-index:' + zIndex + '"></div>');
			}

			if (wrapelement) {
				$("body").append(workdiv);
			}

			if (autoresize) {
				var el = $(this);
				jQuery.data(el, 'position', { top: offset.top, left: offset.left, width: boxWidth, height: boxHeight });
				$(el).doTimeout(guid, resizetimer, function () {
					var t = jQuery.data(el, 'position').top;
					var l = jQuery.data(el, 'position').left;
					var w = jQuery.data(el, 'position').width;
					var h = jQuery.data(el, 'position').height;
					var offset1 = $(el).offset();
					if (t != offset1.top || l != offset1.left || w != $(el).outerWidth() || h != $(el).outerHeight()) {
						jQuery.removeData(el);
						$(el).doTimeout(guid);
						$(el).shadowOff();
						$(el).shadowOn({ 'imagepath': imagepath, 'imageset': imageset, 'autoresize': autoresize, 'resizetimer': resizetimer });
						return false;
					}
					return true;
				});
			}
		});
	}

	$.fn.shadowOn.defaults = {
		imagepath: 'images',
		imageset: '4',
		autoresize: true,
		resizetimer: 250
	};

	$.fn.shadowOff = function () {
		return this.each(function (i, e) {
			if ($(e).hasClass("shadowOn")) {
				$(e).removeClass("shadowOn");
				$(e).children("div.shadowOnBit").remove();
			} else if ($(e).hasClass("shadowOnWrapper")) {
				var id = $(e).attr("rel");
				$("#" + id).remove();
				$(e).removeClass("shadowOnWrapper");
				$(e).removeAttr("rel");
			}
		});
	};
})(jQuery);
