/************************************************************************
 * @name: bPopup
 * @author: (c) Bjoern Klinggaard (http://dinbror.dk/bpopup)
 * @version: 0.5.1.min
 ************************************************************************/
(function(a){a.fn.bPopup=function(h,j){function s(){b.css({left:!o.follow[1]&&k?d:c.scrollLeft()+d,position:"absolute",top:!o.follow[0]&&l?e:c.scrollTop()+e,"z-index":o.zIndex}).appendTo(o.appendTo).hide(1,function(){a.isFunction(o.onOpen)&&o.onOpen.call(b);if(o.loadUrl!=null)switch(o.contentContainer=o.contentContainer==null?b:a(o.contentContainer),o.content){case "iframe":a('<iframe scrolling="no" frameborder="0"></iframe>').attr("src",o.loadUrl).appendTo(o.contentContainer);break;default:o.contentContainer.load(o.loadUrl)}}).fadeIn(o.fadeSpeed,function(){a.isFunction(j)&&j()});t()}function i(){o.modal&&a("#bModal").fadeOut(o.fadeSpeed,function(){a("#bModal").remove()});b.fadeOut(o.fadeSpeed,function(){o.loadUrl!=null&&o.contentContainer.empty()});o.scrollBar||a("html").css("overflow","auto");a("."+o.closeClass).die("click");a("#bModal").die("click");c.unbind("keydown.bPopup");f.unbind(".bPopup");b.data("bPopup",null);a.isFunction(o.onClose)&&setTimeout(function(){o.onClose.call(b)},o.fadeSpeed);return!1}function u(){if(n||v){var a=[c.height(),c.width()];return{"background-color":o.modalColor,height:a[0],left:m(),opacity:0,position:"absolute",top:0,width:a[1],"z-index":o.zIndex-1}}else return{"background-color":o.modalColor,height:"100%",left:0,opacity:0,position:"fixed",top:0,width:"100%","z-index":o.zIndex-1}}function t(){a("."+o.closeClass).live("click",i);o.modalClose&&a("#bModal").live("click",i).css("cursor","pointer");(o.follow[0]||o.follow[1])&&f.bind("scroll.bPopup",function(){b.stop().animate({left:o.follow[1]?c.scrollLeft()+d:d,top:o.follow[0]?c.scrollTop()+e:e},o.followSpeed)}).bind("resize.bPopup",function(){if(o.modal&&n){var a=[c.height(),c.width()];p.css({height:a[0],width:a[1],left:m()})}g=q(b,o.amsl);o.follow[0]&&(e=l?e:c.scrollTop()+g[0]);o.follow[1]&&(d=k?d:c.scrollLeft()+g[1]);b.stop().animate({left:d,top:e},o.followSpeed)});o.escClose&&c.bind("keydown.bPopup",function(a){a.which==27&&i()})}function m(){return f.width()<a("body").width()?0:(a("body").width()-f.width())/2}function q(a,b){var c=(f.height()-a.outerHeight(!0))/2-b,d=(f.width()-a.outerWidth(!0))/2+m();return[c<20?20:c,d]}a.isFunction(h)&&(j=h,h=null);o=a.extend({},a.fn.bPopup.defaults,h);o.scrollBar||a("html").css("overflow","hidden");var b=a(this),p=a('<div id="bModal"></div>'),c=a(document),f=a(window),g=q(b,o.amsl),l=o.position[0]!="auto",k=o.position[1]!="auto",e=l?o.position[0]:g[0],d=k?o.position[1]:g[1],r=navigator.userAgent.toLowerCase(),v=r.indexOf("iphone")!=-1,n=/msie 6/i.test(r)&&typeof window.XMLHttpRequest!="object";this.close=function(){o=b.data("bPopup");i()};return this.each(function(){b.data("bPopup")||(o.modal&&p.css(u()).appendTo(o.appendTo).animate({opacity:o.opacity},o.fadeSpeed),b.data("bPopup",o),s())})};a.fn.bPopup.defaults={amsl:50,appendTo:"body",closeClass:"bClose",content:"ajax",contentContainer:null,escClose:!0,fadeSpeed:250,follow:[!0,!0],followSpeed:500,loadUrl:null,modal:!0,modalClose:!0,modalColor:"#000",onClose:null,onOpen:null,opacity:0.7,position:["auto","auto"],scrollBar:!0,zIndex:9999}})(jQuery);



/**
 * 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;
    }
};
