/**
 * Cookie plugin
 *
 * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */

/**
 * Create a cookie with the given name and value and other optional parameters.
 *
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Set the value of a cookie.
 * @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
 * @desc Create a cookie with all available options.
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Create a session cookie.
 * @example $.cookie('the_cookie', null);
 * @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain
 *       used when the cookie was set.
 *
 * @param String name The name of the cookie.
 * @param String value The value of the cookie.
 * @param Object options An object literal containing key/value pairs to provide optional cookie attributes.
 * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
 *                             If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
 *                             If set to null or omitted, the cookie will be a session cookie and will not be retained
 *                             when the the browser exits.
 * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).
 * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
 * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will
 *                        require a secure protocol (like HTTPS).
 * @type undefined
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */

/**
 * Get the value of a cookie with the given name.
 *
 * @example $.cookie('the_cookie');
 * @desc Get the value of a cookie.
 *
 * @param String name The name of the cookie.
 * @return The value of the cookie.
 * @type String
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

/* 
jquery.event.drag.js ~ v1.5 ~ Copyright (c) 2008, Three Dub Media (http://threedubmedia.com)  
Liscensed under the MIT License ~ http://threedubmedia.googlecode.com/files/MIT-LICENSE.txt
*/
(function(E){E.fn.drag=function(L,K,J){if(K){this.bind("dragstart",L)}if(J){this.bind("dragend",J)}return !L?this.trigger("drag"):this.bind("drag",K?K:L)};var A=E.event,B=A.special,F=B.drag={not:":input",distance:0,which:1,dragging:false,setup:function(J){J=E.extend({distance:F.distance,which:F.which,not:F.not},J||{});J.distance=I(J.distance);A.add(this,"mousedown",H,J);if(this.attachEvent){this.attachEvent("ondragstart",D)}},teardown:function(){A.remove(this,"mousedown",H);if(this===F.dragging){F.dragging=F.proxy=false}G(this,true);if(this.detachEvent){this.detachEvent("ondragstart",D)}}};B.dragstart=B.dragend={setup:function(){},teardown:function(){}};function H(L){var K=this,J,M=L.data||{};if(M.elem){K=L.dragTarget=M.elem;L.dragProxy=F.proxy||K;L.cursorOffsetX=M.pageX-M.left;L.cursorOffsetY=M.pageY-M.top;L.offsetX=L.pageX-L.cursorOffsetX;L.offsetY=L.pageY-L.cursorOffsetY}else{if(F.dragging||(M.which>0&&L.which!=M.which)||E(L.target).is(M.not)){return }}switch(L.type){case"mousedown":E.extend(M,E(K).offset(),{elem:K,target:L.target,pageX:L.pageX,pageY:L.pageY});A.add(document,"mousemove mouseup",H,M);G(K,false);F.dragging=null;return false;case !F.dragging&&"mousemove":if(I(L.pageX-M.pageX)+I(L.pageY-M.pageY)<M.distance){break}L.target=M.target;J=C(L,"dragstart",K);if(J!==false){F.dragging=K;F.proxy=L.dragProxy=E(J||K)[0]}case"mousemove":if(F.dragging){J=C(L,"drag",K);if(B.drop){B.drop.allowed=(J!==false);B.drop.handler(L)}if(J!==false){break}L.type="mouseup"}case"mouseup":A.remove(document,"mousemove mouseup",H);if(F.dragging){if(B.drop){B.drop.handler(L)}C(L,"dragend",K)}G(K,true);F.dragging=F.proxy=M.elem=false;break}return true}function C(M,K,L){M.type=K;var J=E.event.handle.call(L,M);return J===false?false:J||M.result}function I(J){return Math.pow(J,2)}function D(){return(F.dragging===false)}function G(K,J){if(!K){return }K.unselectable=J?"off":"on";K.onselectstart=function(){return J};if(K.style){K.style.MozUserSelect=J?"":"none"}}})(jQuery);

/* jquery.event.drop.js * v1.2
Copyright (c) 2008-2009, Three Dub Media (http://threedubmedia.com)  
Liscensed under the MIT License (http://threedubmedia.googlecode.com/files/MIT-LICENSE.txt)
*/
(function(F){F.fn.drop=function(I,H,G){if(H){this.bind("dropstart",I)}if(G){this.bind("dropend",G)}return !I?this.trigger("drop"):this.bind("drop",H?H:I)};F.dropManage=function(G){G=G||{};C.data=[];C.filter=G.filter||"*";C.delay=G.delay||C.delay;C.tolerance=G.tolerance||null;C.mode=G.mode||C.mode||"intersect";return C.$targets.filter(C.filter).each(function(){C.data[C.data.length]=C.locate(this)})};var D=F.event,B=D.special,C=B.drop={delay:100,mode:"intersect",$targets:F([]),data:[],setup:function(){C.$targets=C.$targets.add(this);C.data[C.data.length]=C.locate(this)},teardown:function(){var G=this;C.$targets=C.$targets.not(this);C.data=F.grep(C.data,function(H){return(H.elem!==G)})},handler:function(H){var G=null,I;H.dropTarget=C.dropping||undefined;if(C.data.length&&H.dragTarget){switch(H.type){case"drag":C.event=H;if(!C.timer){C.timer=setTimeout(E,20)}break;case"mouseup":C.timer=clearTimeout(C.timer);if(!C.dropping){break}if(C.allowed){I=A(H,"drop",C.dropping)}G=false;case C.dropping&&"dropstart":G=G===null&&C.allowed?true:false;case C.dropping&&"dropend":A(H,"dropend",C.dropping);C.dropping=null;if(I===false){H.dropTarget=undefined}if(!G){break}case C.allowed&&"dropstart":H.dropTarget=this;C.dropping=A(H,"dropstart",this)!==false?this:null;break}}},locate:function(J){var H=F(J),K=H.offset(),I=H.outerHeight(),G=H.outerWidth();return{elem:J,L:K.left,R:K.left+G,T:K.top,B:K.top+I,W:G,H:I}},contains:function(G,H){return((H[0]||H.L)>=G.L&&(H[0]||H.R)<=G.R&&(H[1]||H.T)>=G.T&&(H[1]||H.B)<=G.B)},modes:{intersect:function(H,G,I){return this.contains(I,[H.pageX,H.pageY])?I:this.modes.overlap.apply(this,arguments)},overlap:function(H,G,I){I.overlap=Math.max(0,Math.min(I.B,G.B)-Math.max(I.T,G.T))*Math.max(0,Math.min(I.R,G.R)-Math.max(I.L,G.L));if(I.overlap>((this.best||{}).overlap||0)){this.best=I}return null},fit:function(H,G,I){return this.contains(I,G)?I:null},middle:function(H,G,I){return this.contains(I,[G.L+G.W/2,G.T+G.H/2])?I:null}}};function A(K,I,J){K.type=I;try{var G=D.handle.call(J,K)}catch(H){}return G===false?false:G||K.result}function E(){var H=0,G,I,J=[C.event.pageX,C.event.pageY],K=C.locate(C.event.dragProxy);C.tolerance=C.tolerance||C.modes[C.mode];do{if(G=C.data[H]){I=C.tolerance?C.tolerance.call(C,C.event,K,G):C.contains(G,J)?G:null}}while(++H<C.data.length&&!I);C.event.type=(I=I||C.best)?"dropstart":"dropend";if(C.event.type=="dropend"||I.elem!=C.dropping){C.handler.call(I?I.elem:C.dropping,C.event)}if(C.last&&J[0]==C.last.pageX&&J[1]==C.last.pageY){delete C.timer}else{C.timer=setTimeout(E,C.delay)}C.last=C.event;C.best=null}})(jQuery);

$.dropManage({ mode:'middle' });
