﻿;
(function($) {

    $.fn.defaultvalue = function() {

        // Scope
        var elements = this;
        var args = arguments;
        var c = 0;

        return (
			elements.each(function() {

			    // Default values within scope
			    var el = $(this);
			    var def = args[c++];

			    el.val(def).focus(function() {
			        if (el.val() == def) {
			            el.val("");
			        }
			        el.blur(function() {
			            if (el.val() == "") {
			                el.val(def);
			            }
			        });
			    });

			})
		);
    }



    //scrollTo Function
    var $scrollTo = $.scrollTo = function(target, duration, settings) {
        $(window).scrollTo(target, duration, settings);
    };

    $scrollTo.defaults = {
        axis: 'y',
        duration: 1
    };

    // Returns the element that needs to be animated to scroll the window.
    // Kept for backwards compatibility (specially for localScroll & serialScroll)
    $scrollTo.window = function(scope) {
        return $(window).scrollable();
    };

    // Hack, hack, hack... stay away!
    // Returns the real elements to scroll (supports window/iframes, documents and regular nodes)
    $.fn.scrollable = function() {
        return this.map(function() {
            // Just store it, we might need it
            var win = this.parentWindow || this.defaultView,
            // If it's a document, get its iframe or the window if it's THE document
				elem = this.nodeName == '#document' ? win.frameElement || win : this,
            // Get the corresponding document
				doc = elem.contentDocument || (elem.contentWindow || elem).document,
				isWin = elem.setInterval;

            return elem.nodeName == 'IFRAME' || isWin && $.browser.safari ? doc.body
				: isWin ? doc.documentElement
				: this;
        });
    };

    $.fn.scrollTo = function(target, duration, settings) {
        if (typeof duration == 'object') {
            settings = duration;
            duration = 0;
        }
        if (typeof settings == 'function')
            settings = { onAfter: settings };

        settings = $.extend({}, $scrollTo.defaults, settings);
        // Speed is still recognized for backwards compatibility
        duration = duration || settings.speed || settings.duration;
        // Make sure the settings are given right
        settings.queue = settings.queue && settings.axis.length > 1;

        if (settings.queue)
        // Let's keep the overall duration
            duration /= 2;
        settings.offset = both(settings.offset);
        settings.over = both(settings.over);

        return this.scrollable().each(function() {
            var elem = this,
				$elem = $(elem),
				targ = target, toff, attr = {},
				win = $elem.is('html,body');

            switch (typeof targ) {
                // A number will pass the regex 
                case 'number':
                case 'string':
                    if (/^([+-]=)?\d+(px)?$/.test(targ)) {
                        targ = both(targ);
                        // We are done
                        break;
                    }
                    // Relative selector, no break!
                    targ = $(targ, this);
                case 'object':
                    // DOMElement / jQuery
                    if (targ.is || targ.style)
                    // Get the real position of the target 
                        toff = (targ = $(targ)).offset();
            }
            $.each(settings.axis.split(''), function(i, axis) {
                var Pos = axis == 'x' ? 'Left' : 'Top',
					pos = Pos.toLowerCase(),
					key = 'scroll' + Pos,
					old = elem[key],
					Dim = axis == 'x' ? 'Width' : 'Height',
					dim = Dim.toLowerCase();

                if (toff) {// jQuery / DOMElement
                    attr[key] = toff[pos] + (win ? 0 : old - $elem.offset()[pos]);

                    // If it's a dom element, reduce the margin
                    if (settings.margin) {
                        attr[key] -= parseInt(targ.css('margin' + Pos)) || 0;
                        attr[key] -= parseInt(targ.css('border' + Pos + 'Width')) || 0;
                    }

                    attr[key] += settings.offset[pos] || 0;

                    if (settings.over[pos])
                    // Scroll to a fraction of its width/height
                        attr[key] += targ[dim]() * settings.over[pos];
                } else
                    attr[key] = targ[pos];

                // Number or 'number'
                if (/^\d+$/.test(attr[key]))
                // Check the limits
                    attr[key] = attr[key] <= 0 ? 0 : Math.min(attr[key], max(Dim));

                // Queueing axes
                if (!i && settings.queue) {
                    // Don't waste time animating, if there's no need.
                    if (old != attr[key])
                    // Intermediate animation
                        animate(settings.onAfterFirst);
                    // Don't animate this axis again in the next iteration.
                    delete attr[key];
                }
            });
            animate(settings.onAfter);

            function animate(callback) {
                $elem.animate(attr, duration, settings.easing, callback && function() {
                    callback.call(this, target, settings);
                });
            };
            function max(Dim) {
                var attr = 'scroll' + Dim,
					doc = elem.ownerDocument;

                return win
						? Math.max(doc.documentElement[attr], doc.body[attr])
						: elem[attr];
            };
        }).end();
    };

    function both(val) {
        return typeof val == 'object' ? val : { top: val, left: val };
    };

    $.fn.aqTip = function(html, options) {
        var opts = $.extend({}, $.fn.aqTip.defaults, options);

        return this.each(function() {
            var $obj = $(this);

            $('<div class="aqTip"><\/div>').appendTo($obj);

            var $layer = $('.aqTip', $obj);

            $layer.css({ display: 'none', position: 'absolute' }).css(opts.css);

            if (jQuery.isFunction(html)) html($layer);
            else $layer.html(html);

            var p = $obj.position();
            var ow = $obj.width() > $layer.width()
         ? $obj.width() : $layer.width();
            var x = p.left + opts.marginX;
            if (x > document.body.clientWidth)
                x = p.left - ow - opts.marginX;

            $layer.css({ left: x + 'px', top: p.top + opts.marginY + 'px' });

            $obj.hover(function() { $layer.show() }, function() { $layer.hide() });
        });
    };

    $.fn.aqTipOne = function(html, options) {
        var opts = $.extend({}, $.fn.aqTip.defaults, options);
        return this.each(function() {
            if (!$('#aqTip').length) {
                $('<div id="aqTip"><\/div>').appendTo(document.body);
                $('#aqTip').css({ display: 'none', position: 'absolute' })
            .css(opts.css);
            }

            var $obj = $(this);
            if (html) {
                $('#aqTip').html(html);

                var p = $obj.position();
                var ow = $obj.width() > $('#aqTip').width() ? $obj.width() : $('#aqTip').width();
                document.title = ow.toString();
                var x = p.left + opts.marginX;
                if (x > document.body.clientWidth)
                    x = p.left - ow - opts.marginX;

                $('#aqTip').show()
            .css({ left: x + 'px', top: p.top + opts.marginY + 'px' })
            } else
                $('#aqTip:visible').hide()

            return false;
        });
    };

    $.fn.aqTip.defaults = {
        marginX: 10, marginY: 10,
        css: {
            backgroundColor: '#ffc', color: '#444',
            border: '1px solid #ddd', padding: '10px', cursor: 'default'
        }
    };


})(jQuery);




//usually used funtion
function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}





