
/**
 * jQuery.ScrollTo - Easy element scrolling using jQuery.
 * Copyright (c) 2007-2009 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
 * Dual licensed under MIT and GPL.
 * Date: 5/25/2009
 * @author Ariel Flesler
 * @version 1.4.2
 *
 * http://flesler.blogspot.com/2007/10/jqueryscrollto.html
 */
;(function(d){var k=d.scrollTo=function(a,i,e){d(window).scrollTo(a,i,e)};k.defaults={axis:'xy',duration:parseFloat(d.fn.jquery)>=1.3?0:1};k.window=function(a){return d(window)._scrollable()};d.fn._scrollable=function(){return this.map(function(){var a=this,i=!a.nodeName||d.inArray(a.nodeName.toLowerCase(),['iframe','#document','html','body'])!=-1;if(!i)return a;var e=(a.contentWindow||a).document||a.ownerDocument||a;return d.browser.safari||e.compatMode=='BackCompat'?e.body:e.documentElement})};d.fn.scrollTo=function(n,j,b){if(typeof j=='object'){b=j;j=0}if(typeof b=='function')b={onAfter:b};if(n=='max')n=9e9;b=d.extend({},k.defaults,b);j=j||b.speed||b.duration;b.queue=b.queue&&b.axis.length>1;if(b.queue)j/=2;b.offset=p(b.offset);b.over=p(b.over);return this._scrollable().each(function(){var q=this,r=d(q),f=n,s,g={},u=r.is('html,body');switch(typeof f){case'number':case'string':if(/^([+-]=)?\d+(\.\d+)?(px|%)?$/.test(f)){f=p(f);break}f=d(f,this);case'object':if(f.is||f.style)s=(f=d(f)).offset()}d.each(b.axis.split(''),function(a,i){var e=i=='x'?'Left':'Top',h=e.toLowerCase(),c='scroll'+e,l=q[c],m=k.max(q,i);if(s){g[c]=s[h]+(u?0:l-r.offset()[h]);if(b.margin){g[c]-=parseInt(f.css('margin'+e))||0;g[c]-=parseInt(f.css('border'+e+'Width'))||0}g[c]+=b.offset[h]||0;if(b.over[h])g[c]+=f[i=='x'?'width':'height']()*b.over[h]}else{var o=f[h];g[c]=o.slice&&o.slice(-1)=='%'?parseFloat(o)/100*m:o}if(/^\d+$/.test(g[c]))g[c]=g[c]<=0?0:Math.min(g[c],m);if(!a&&b.queue){if(l!=g[c])t(b.onAfterFirst);delete g[c]}});t(b.onAfter);function t(a){r.animate(g,j,b.easing,a&&function(){a.call(this,n,b)})}}).end()};k.max=function(a,i){var e=i=='x'?'Width':'Height',h='scroll'+e;if(!d(a).is('html,body'))return a[h]-d(a)[e.toLowerCase()]();var c='client'+e,l=a.ownerDocument.documentElement,m=a.ownerDocument.body;return Math.max(l[h],m[h])-Math.min(l[c],m[c])};function p(a){return typeof a=='object'?a:{top:a,left:a}}})(jQuery);
/*
 * jQuery UI Position 1.8.2
 *
 * Copyright (c) 2010 AUTHORS.txt (http://jqueryui.com/about)
 * Dual licensed under the MIT (MIT-LICENSE.txt)
 * and GPL (GPL-LICENSE.txt) licenses.
 *
 * http://docs.jquery.com/UI/Position
 */
(function(c){
    c.ui = c.ui || {};
    var m = /left|center|right/, n = /top|center|bottom/, p = c.fn.position, q = c.fn.offset;
    c.fn.position = function(a){
        if (!a || !a.of) 
            return p.apply(this, arguments);
        a = c.extend({}, a);
        var b = c(a.of), d = (a.collision || "flip").split(" "), e = a.offset ? a.offset.split(" ") : [0, 0], g, h, i;
        if (a.of.nodeType === 9) {
            g = b.width();
            h = b.height();
            i = {
                top: 0,
                left: 0
            }
        }
        else 
            if (a.of.scrollTo && a.of.document) {
                g = b.width();
                h = b.height();
                i = {
                    top: b.scrollTop(),
                    left: b.scrollLeft()
                }
            }
            else 
                if (a.of.preventDefault) {
                    a.at = "left top";
                    g = h = 0;
                    i = {
                        top: a.of.pageY,
                        left: a.of.pageX
                    }
                }
                else {
                    g = b.outerWidth();
                    h = b.outerHeight();
                    i = b.offset()
                }
        c.each(["my", "at"], function(){
            var f = (a[this] || "").split(" ");
            if (f.length === 1) 
                f = m.test(f[0]) ? f.concat(["center"]) : n.test(f[0]) ? ["center"].concat(f) : ["center", "center"];
            f[0] = m.test(f[0]) ? f[0] : "center";
            f[1] = n.test(f[1]) ? f[1] : "center";
            a[this] = f
        });
        if (d.length === 1) 
            d[1] = d[0];
        e[0] = parseInt(e[0], 10) || 0;
        if (e.length === 1) 
            e[1] = e[0];
        e[1] = parseInt(e[1], 10) || 0;
        if (a.at[0] === "right") 
            i.left += g;
        else 
            if (a.at[0] === "center") 
                i.left += g / 2;
        if (a.at[1] === "bottom") 
            i.top += h;
        else 
            if (a.at[1] === "center") 
                i.top += h / 2;
        i.left += e[0];
        i.top += e[1];
        return this.each(function(){
            var f = c(this), k = f.outerWidth(), l = f.outerHeight(), j = c.extend({}, i);
            if (a.my[0] === "right") 
                j.left -= k;
            else 
                if (a.my[0] === "center") 
                    j.left -= k / 2;
            if (a.my[1] === "bottom") 
                j.top -= l;
            else 
                if (a.my[1] === "center") 
                    j.top -= l / 2;
            j.left = parseInt(j.left);
            j.top = parseInt(j.top);
            c.each(["left", "top"], function(o, r){
                c.ui.position[d[o]] &&
                c.ui.position[d[o]][r](j, {
                    targetWidth: g,
                    targetHeight: h,
                    elemWidth: k,
                    elemHeight: l,
                    offset: e,
                    my: a.my,
                    at: a.at
                })
            });
            c.fn.bgiframe && f.bgiframe();
            f.offset(c.extend(j, {
                using: a.using
            }))
        })
    };
    c.ui.position = {
        fit: {
            left: function(a, b){
                var d = c(window);
                b = a.left + b.elemWidth - d.width() - d.scrollLeft();
                a.left = b > 0 ? a.left - b : Math.max(0, a.left)
            },
            top: function(a, b){
                var d = c(window);
                b = a.top + b.elemHeight - d.height() - d.scrollTop();
                a.top = b > 0 ? a.top - b : Math.max(0, a.top)
            }
        },
        flip: {
            left: function(a, b){
                if (b.at[0] !== "center") {
                    var d = c(window);
                    d = a.left + b.elemWidth - d.width() - d.scrollLeft();
                    var e = b.my[0] === "left" ? -b.elemWidth : b.my[0] === "right" ? b.elemWidth : 0, g = -2 * b.offset[0];
                    a.left += a.left < 0 ? e + b.targetWidth + g : d > 0 ? e - b.targetWidth + g : 0
                }
            },
            top: function(a, b){
                if (b.at[1] !== "center") {
                    var d = c(window);
                    d = a.top + b.elemHeight - d.height() - d.scrollTop();
                    var e = b.my[1] === "top" ? -b.elemHeight : b.my[1] === "bottom" ? b.elemHeight : 0, g = b.at[1] === "top" ? b.targetHeight : -b.targetHeight, h = -2 * b.offset[1];
                    a.top += a.top < 0 ? e + b.targetHeight + h : d > 0 ? e + g + h : 0
                }
            }
        }
    };
    if (!c.offset.setOffset) {
        c.offset.setOffset = function(a, b){
            if (/static/.test(c.curCSS(a, "position"))) 
                a.style.position = "relative";
            var d = c(a), e = d.offset(), g = parseInt(c.curCSS(a, "top", true), 10) || 0, h = parseInt(c.curCSS(a, "left", true), 10) || 0;
            e = {
                top: b.top - e.top + g,
                left: b.left - e.left + h
            };
            "using" in b ? b.using.call(a, e) : d.css(e)
        };
        c.fn.offset = function(a){
            var b = this[0];
            if (!b || !b.ownerDocument) 
                return null;
            if (a) 
                return this.each(function(){
                    c.offset.setOffset(this, a)
                });
            return q.call(this)
        }
    }
})(jQuery);
;
/*
 * Special event for image load events
 * Needed because some browsers does not trigger the event on cached images.

 * MIT License
 * Paul Irish     | @paul_irish | www.paulirish.com
 * Andree Hansson | @peolanha   | www.andreehansson.se
 * 2010.
 *
 * Usage:
 * $(images).bind('load', function (e) {
 *   // Do stuff on load
 * });
 * 
 * Note that you can bind the 'error' event on data uri images, this will trigger when
 * data uri images isn't supported.
 * 
 * Tested in:
 * FF 3+
 * IE 6-8
 * Chromium 5-6
 * Opera 9-10
 */

(function($){
    $.event.special.load = {
        add: function(hollaback){
            if (this.nodeType === 1 && this.tagName.toLowerCase() === 'img' && this.src !== '') {
                // Image is already complete, fire the hollaback (fixes browser issues were cached
                // images isn't triggering the load event)
                if (this.complete || this.readyState === 4) {
                    hollaback.handler.apply(this);
                }
                
                // Check if data URI images is supported, fire 'error' event if not
                else 
                    if (this.readyState === 'uninitialized' && this.src.indexOf('data:') === 0) {
                        $(this).trigger('error');
                    }
                    
                    else {
                        $(this).bind('load', hollaback.handler);
                    }
            }
        }
    };
}(jQuery));

/*
 * jQuery Resize
 *
 * Author: Adeel Ejaz (http://adeelejaz.com/)
 * Version: 2.0.0
 * License: Dual licensed under MIT or GPL licenses.
 * 
 * Introduction
 * aeImageResize is a jQuery plugin to dynamically resize the images without distorting the proportions.
 * 
 * Usage:
 * .aeImageResize( height, width )
 * 
 * height
 * An integer representing the maximum height for the image.
 * 
 * width
 * An integer representing the maximum width for the image.
 * 
 * Example
 * $(function() {
 * 	$(".resizeme").aeImageResize({height: 250, width: 250});
 * });
 */
(function( $ ) {

	$.fn.aeImageResize = function( options ) {

		var self = $( this )
		,	mathFloor = Math.floor
		,	browser = $.browser
		,	isIE6 = browser.msie && (parseInt(browser.version) == 6)
		,	aspectRatio = 0
		,	params = $.extend({
				height: 0,
				width: 0
			}, options)
		;

		// We cannot do much unless we have one of these
		if ( !params.height && !params.width ) {
			return self;
		}

		// Calculate aspect ratio now, if possible
		if ( params.height && params.width ) {
			aspectRatio = params.width / params.height;
		}

		// Attach handler to load
		// Handler is executed just once per element
		// Load event required for Webkit browsers
		return self.one( "load", function() {

			// Remove all attributes and CSS rules
			$( this ).removeAttr( "height" )
					 .removeAttr( "width" )
					 .css({
						 height: "",
						 width: ""
					 });

			var imgHeight = this.height
			,	imgWidth = this.width
			,	imgAspectRatio = imgWidth / imgHeight
			,	bxHeight = params.height
			,	bxWidth = params.width
			,	bxAspectRatio = aspectRatio;
				
			// Work the magic!
			// If one parameter is missing, we just force calculate it
			if ( !bxAspectRatio ) {
				if ( bxHeight === 0 ) {
					bxAspectRatio = imgAspectRatio - 1;
				} else {
					bxAspectRatio = imgAspectRatio + 1;
				}
			}

			// Only resize the images that need resizing
			if ( (bxHeight && imgHeight > bxHeight) || (bxWidth && imgWidth > bxWidth) ) {

				if ( imgAspectRatio > aspectRatio ) {
					bxHeight = mathFloor( imgHeight / imgWidth * bxWidth );
				} else {
					bxWidth = mathFloor( imgWidth / imgHeight * bxHeight );
				}

				$( this ).attr({
					"height": bxHeight,
					"width": bxWidth
				});
			}
		}).each(function() {

			// Trigger load event (for Gecko and MSIE)
			if ( this.complete || isIE6 ) {
				$( this ).trigger( "load" );
			}
		});
	};
})( jQuery );
(function($) {
    $.fn.resize = function(options) {
 
        var settings = $.extend({
            scale: 1,
            maxWidth: null,
			maxHeight: null
        }, options);
 
        return this.each(function() {
			
			if(this.tagName.toLowerCase() != "img") {
				// Only images can be resized
				return $(this);
			} 

			var width = this.naturalWidth;
			var height = this.naturalHeight;
			if(!width || !height) {
				// Ooops you are an IE user, let's fix it.
				var img = document.createElement('img');
				img.src = this.src;
				
				width = img.width;
				height = img.height;
			}
			
			if(settings.scale != 1) {
				width = width*settings.scale;
				height = height*settings.scale;
			}
			
			var pWidth = 1;
			if(settings.maxWidth != null) {
				pWidth = width/settings.maxWidth;
			}
			var pHeight = 1;
			if(settings.maxHeight != null) {
				pHeight = height/settings.maxHeight;
			}
			var reduce = 1;
			
			if(pWidth < pHeight) {
				reduce = pHeight;
			} else {
				reduce = pWidth;
			}
			
			if(reduce < 1) {
				reduce = 1;
			}
			
			var newWidth = width/reduce;
			var newHeight = height/reduce;
			
			return $(this)
				.attr("width", newWidth)
				.attr("height", newHeight);
			
        });
    }
})(jQuery);
(function( $ ) {
$.fn.image = function(src, f){
  return this.each(function(){
    $("<img />").appendTo(this).each(function(){
			this.onload = f;
            this.src = src;
            
    });
  });
}
})( jQuery );

