(function(c){function p(){var d,a={height:h.innerHeight,width:h.innerWidth};if(!a.height&&((d=i.compatMode)||!c.support.boxModel))d=d==="CSS1Compat"?k:i.body,a={height:d.clientHeight,width:d.clientWidth};return a}var m={},e,a,i=document,h=window,k=i.documentElement,j=c.expando;c.event.special.inview={add:function(a){m[a.guid+"-"+this[j]]={data:a,$element:c(this)}},remove:function(a){try{delete m[a.guid+"-"+this[j]]}catch(c){}}};c(h).bind("scroll resize",function(){e=a=null});setInterval(function(){var d=
c(),j,l=0;c.each(m,function(a,b){var c=b.data.selector,e=b.$element;d=d.add(c?e.find(c):e)});if(j=d.length){e=e||p();for(a=a||{top:h.pageYOffset||k.scrollTop||i.body.scrollTop,left:h.pageXOffset||k.scrollLeft||i.body.scrollLeft};l<j;l++)if(c.contains(k,d[l])){var g=c(d[l]),f={height:g.height(),width:g.width()},b=g.offset(),n=g.data("inview"),o;if(!a||!e)break;b.top+f.height>a.top&&b.top<a.top+e.height&&b.left+f.width>a.left&&b.left<a.left+e.width?(o=a.left>b.left?"right":a.left+e.width<b.left+f.width?
"left":"both",f=a.top>b.top?"bottom":a.top+e.height<b.top+f.height?"top":"both",b=o+"-"+f,(!n||n!==b)&&g.data("inview",b).trigger("inview",[!0,o,f])):n&&g.data("inview",!1).trigger("inview",[!1])}}},250)})(jQuery);
/*!
 * Copyright (c) 2010 Brandon Aaron (http://brandonaaron.net)
 * backgroundPosition cssHook for jquery. Necessary to combat different css property names between browsers
 * https://github.com/brandonaaron/jquery-cssHooks
 * Licensed under the MIT License (LICENSE.txt).
 */
(function($) {
    // backgroundPosition[X,Y] get hooks
    var $div = $('<div style="background-position: 3px 5px">');
    $.support.backgroundPosition   = $div.css('backgroundPosition')  === "3px 5px" ? true : false;
    $.support.backgroundPositionXY = $div.css('backgroundPositionX') === "3px" ? true : false;
    $div = null;

    var xy = ["X","Y"];

    // helper function to parse out the X and Y values from backgroundPosition
    function parseBgPos(bgPos) {
        var parts  = bgPos.split(/\s/),
            values = {
                "X": parts[0],
                "Y": parts[1]
            };
        return values;
    }

    if (!$.support.backgroundPosition && $.support.backgroundPositionXY) {
        $.cssHooks.backgroundPosition = {
            get: function( elem, computed, extra ) {
                return $.map(xy, function( l, i ) {
                    return $.css(elem, "backgroundPosition" + l);
                }).join(" ");
            },
            set: function( elem, value ) {
                $.each(xy, function( i, l ) {
                    var values = parseBgPos(value);
                    elem.style[ "backgroundPosition" + l ] = values[ l ];
                });
            }
        };
    }

    if ($.support.backgroundPosition && !$.support.backgroundPositionXY) {
        $.each(xy, function( i, l ) {
            $.cssHooks[ "backgroundPosition" + l ] = {
                get: function( elem, computed, extra ) {
                    var values = parseBgPos( $.css(elem, "backgroundPosition") );
                    return values[ l ];
                },
                set: function( elem, value ) {
                    var values = parseBgPos( $.css(elem, "backgroundPosition") ),
                        isX = l === "X";
                    elem.style.backgroundPosition = (isX ? value : values[ "X" ]) + " " + 
                                                    (isX ? values[ "Y" ] : value);
                }
            };
            $.fx.step[ "backgroundPosition" + l ] = function( fx ) {
                $.cssHooks[ "backgroundPosition" + l ].set( fx.elem, fx.now + fx.unit );
            };
        });
    }
})(jQuery);

/*!
 * Scroll-based parallax plugin for jQuery
 * Copyright (c) 2011 Dave Cranwell (http://davecranwell.com)
 * Licensed under the MIT License.
 * 2011-05-18
 * version 1.0
 */
(function($){
	$.fn.scrollParallax = function(options) {
		var settings = {
			'speed': 0.2,
			'axis': 'x,y',
			'debug': false
		}

		function debug(msg){
			if(settings.debug && 'console' in window && 'log' in window.console){
				console.log(msg);
			}
		}
		
		return this.each(function() {
			//defined accessible $this var in standard way for use within functions
			var $this = $(this);
			
			//extend options in standard way
			if (options) {
				$.extend(settings, options);
			}
			
			$this.bind('inview', function (event, visible) {
				if (visible == true) {
					$this.addClass("inview");
					debug("in view");
				}else{
					$this.removeClass("inview");
					debug("out of view");
				}
			});
	
			//find current position so parallax can be relative to it
			var currentPosArray=$this.css("backgroundPosition").split(" ");
			var currentXPos=parseInt(currentPosArray[0].replace(/[^0-9\-]/g, ""));
			var currentYPos=parseInt(currentPosArray[1].replace(/[^0-9\-]/g, ""));
						
			//recalculate position on scroll
			$(window).bind('scroll', function(){
				if($this.hasClass("inview")){			
					var offset = $this.offset();

					//calculate new position
					/*if(settings.axis.match(/x/)){
						var Xpos = offset.left - $(window).scrollLeft();
						var newXPos = (-(Xpos) * settings.speed) + currentXPos;
					}else{
						var newXPos = currentXPos;
					} */
					newXPos = "50";
					if(settings.axis.match(/y/)){
						var Ypos = offset.top - $(window).scrollTop();
						var newYPos = (-(Ypos) * settings.speed) + currentYPos;
					}else{
						var newYPos = currentYPos;
					}
					//newYPos += "px";
					
					debug("new X position: "+ newXPos);
					debug("new Y position: "+ newYPos);
					
					$this.css({'backgroundPosition':  parseInt(newXPos) + "% " + parseInt(newYPos) +"px"}); 
				}
			});
		});
	};
	
})(jQuery);
