var basePath = '';
var lastScrollPos = 0;

if (!window.requestAnimationFrame) {
	window.requestAnimFrame = (function() {
		return  window.requestAnimationFrame   ||
			window.webkitRequestAnimationFrame ||
			window.mozRequestAnimationFrame    ||
			window.oRequestAnimationFrame      ||
			window.msRequestAnimationFrame     ||
			function(callback, element) {
				window.setTimeout(callback, 1000 / 60);
			};
	})();
};

(function(jQuery) {
	jQuery.fn.shuffle = function() {
		return this.each(function(){
			var items = jQuery(this).children();
			return (items.length)?jQuery(this).html(jQuery.shuffle(items)):this;
		});
	};
	jQuery.shuffle = function(arr) {
		for (var j, x, i = arr.length; i; j = parseInt(Math.random() * i), x = arr[--i], arr[i] = arr[j], arr[j] = x);
		return arr;
	};
})(jQuery);

(function(jQuery) {
	var pageHeight = 0,

	page = (function() {
		var init = function() {
			helpers.setBasePath();
			helpers.detectBrowser();
			(helpers.cookieNodes.get('totalScroll') == false)?helpers.cookieNodes.set('totalScroll', 0 ,'/'):'';
			jQuery(window).load(function() {
				pageHeight = jQuery('#page').height();

				jQuery.when(fontsRendering(), renderBlocks()).done(function(){
					if (jQuery('canvas[id^="nodes-"]').length > 0) {
						nodes.init('nodes-bg', 6);
						nodes.init('nodes-cnt', 3);
					} else if (jQuery('canvas[id^="brands-"]').length > 0) {
						brands.init();
					};
					jQuery('#page').animate({'opacity': 1});
					jQuery('.languages nav a').filter('.'+jQuery('#language').attr('class')).addClass('active');
					jQuery('#runner').css({
						'left': ((jQuery('menu li a.active').length > 0)?(jQuery('menu li a.active').position().left - 5 + jQuery('menu li a.active').outerWidth(true) / 2):(-9999)) +'px'
					}).animate({
						'bottom': '+=5px',
						'opacity': 1
					}, 1500);
					makeCounters.init();
					if (jQuery('#frontpageSlider').length > 0) {
		  				frSlider.init();
					};
					if (jQuery('#previewImageSlider').length > 0) {
						previewImageSlider.init();
					};
					if (jQuery('#map').length > 0) {
						gMap.init();
					};
				});
				pageEvents();
				windowEvents();
			});
		},

		scrollCnt = function() {
			if (jQuery('#scroll').length > 0) {
  				var scrollMax = jQuery('#scroll-area').height() - jQuery('#scroll').height() -70,
					scrollVal = jQuery(window).scrollTop() - jQuery('#scroll-area').offset().top;

				if ((scrollVal > 0) && (scrollMax > 0)) {
  					if (scrollVal < scrollMax) {
						if (jQuery('.followhere').length > 0) {
							var offsetTop = jQuery('.followhere').offset().top - jQuery('#scroll').offset().top,
							offsetLeft = jQuery('.followhere').offset().left;
		
							jQuery('.followhere').css({
								'position'	: 'fixed',
								'margin-top': 0 +'px',
								'left'		: offsetLeft +'px',
								'top'		: offsetTop +'px'
							});
						};
						if (jQuery('.preview-nav').length > 0) {
							var offsetTop = jQuery('.preview-nav').offset().top - jQuery('#scroll').offset().top,
							offsetLeft = jQuery('.preview-nav').offset().left;

							jQuery('.preview-nav').css({
								'position'	: 'fixed',
								'margin-top': 0 +'px',
								'left'		: offsetLeft +'px',
								'top'		: offsetTop +'px'
							});
						};
						jQuery('#scroll').css({
							'position'	: 'fixed',
							'margin-top': 0 +'px'
						});
						if (jQuery('.our-activities').length > 0) {
							jQuery('.our-activities').css({'height': jQuery('#scroll').height()+scrollMax + 'px'});
						};
					} else {
						if (jQuery('.followhere').length > 0) {
							jQuery('.followhere').removeAttr('style').css({
								'margin-top': scrollMax +'px'
							});
						};
						if (jQuery('.preview-nav').removeAttr('style').length > 0) {
							jQuery('.preview-nav').css({
								'margin-top': scrollMax +'px'
							});
						};
						jQuery('#scroll').removeAttr('style').css({
							'margin-top': scrollMax +'px'
						});
					};
				} else {
					if (jQuery('.followhere').length > 0) {
						jQuery('.followhere').removeAttr('style');
					};
					if (jQuery('.preview-nav').length > 0) {
						jQuery('.preview-nav').removeAttr('style');
					};
					jQuery('#scroll').removeAttr('style');
				};
			};
		},
		
		pageEvents = function() {
			jQuery('.offer').on('mouseover mouseout click', '.icon', function(e) {
				var $this = jQuery(this);

				switch (e.type) {
					case 'mouseover':
						$this.animate({
							'top': '-=20px'
						});
						break;
					case 'mouseout':
						$this.animate({
							'top': '+=20px'
						});
						break;
					case 'click':
						window.location = jQuery('.offer').data('url');
						break;
				};
			});

			jQuery('.brands').on('click', '.more', function(e) {
				window.location = jQuery(this).data('url');
			});

			jQuery('menu li').on('mouseover mouseout', 'a', function(e) {
				var $this 	= jQuery(this);
        
				switch (e.type) {
					case 'mouseover':
						jQuery('menu').data('hovered', true);
						jQuery('#runner').stop(true).animate({
							'left': $this.position().left - 5 + $this.outerWidth(true) / 2 +'px'
						});
					break;
					case 'mouseout':
						setTimeout(function() {
							if (jQuery('menu').data('hovered') == undefined) {
								jQuery('#runner').stop(true).animate({
									'left': ((jQuery('menu li a.active').length > 0)?(jQuery('menu li a.active').position().left - 5 + jQuery('menu li a.active').outerWidth(true) / 2):(-9999)) +'px'
								}, function() {
									jQuery('menu').removeData('hovered');	
								});
							};
			       		}, 1500);
					break;
				};
			});

			jQuery(document).on('mouseover mouseout', '#language', function(e) {
				switch (e.type) {
					case 'mouseover':
						jQuery('nav').fadeIn();
					break;
					case 'mouseout':
						setTimeout(function() {
							if (jQuery('#language').data('hovered') == undefined) {
								jQuery('nav').fadeOut();
							} else {
								jQuery('#language').trigger('mouseout');
							};
			       		}, 1500);
					break;
				};
			});

			jQuery(document).on('mouseover mouseout', 'nav', function(e) {
				switch (e.type) {
					case 'mouseover':
						jQuery('#language').data('hovered', true);
					break;
					case 'mouseout':
						jQuery('#language').removeData('hovered');
					break;
				};
			});
		},

		windowEvents = function() {
			reBuild();
			jQuery(window).on('scroll', function(e) {
				scrollCnt();

				var vscroll = jQuery(window).scrollTop();
                helpers.cookieNodes.set('totalScroll', Number(helpers.cookieNodes.get('totalScroll')) + Math.abs(lastScrollPos - vscroll), '/');
                lastScrollPos = vscroll;
			});

			jQuery(window).on('resize', function() {
				jQuery('#background').empty();
				jQuery('.border-shadow').remove();

				jQuery.when(renderBlocks()).done(function() {
					if (jQuery('canvas[id^="nodes-"]').length > 0) {
						nodes.init('nodes-bg', 6);
						nodes.init('nodes-cnt', 3);
					} else if (jQuery('canvas[id^="brands-"]').length > 0) {
						brands.init();
					};
				});

				if (jQuery('#frontpageSlider .wrapper').length > 0) {
					frSlider.rebuildScenes();
				};
			});
		},

		reBuild = function() {
			changes = setTimeout(function() {
				if (jQuery('#page').height() !== pageHeight) {
					pageHeight = jQuery('#page').height();
					jQuery('#background').empty();
					jQuery('.border-shadow').remove();
					renderBlocks();
				};
				reBuild();
       		}, 1000);
		},

		fontsRendering = function() {
			return jQuery.Deferred(
				function(dfd) {
					Cufon.replace('a.btn span, .container .shadow > header menu li a, .container .shadow > header .languages a, .container .main section .mapdescr h3, .container .main section .mapdescr p, .container .main section .maplinks a, .container .main section .case article h2, .container .main section .case article h4, .container .main section .case article p, .container .main section .frontpageSlider .screen h5, .container .main section .frontpageSlider .screen h3, .container .main section .frontpageSlider .screen .article h3, .container .main section .frontpageSlider .screen .article a, .container .main aside .visitor-o-meter h5, .container .main aside .visitor-o-meter p, .container .main aside .visitor-o-meter .meter .count, .container .main aside .cases h3, .container .main aside .cases p, .container .main aside .contacts h3, .container .main aside .contacts p, .container .main aside .social h3, .container .main aside .headline h2, .container .main aside .blog h3, .container .main aside .blog article h1, .container .main aside .blog article h2,	.container .main aside .blog article h5, .container .main aside .blog .pagination ol li, .container .main aside .blog .post article header p, .container .main aside .blog .post article footer p, .container .main aside .blog .our-activities h3, .container .main .adviser .brands h3, .container .main .adviser .offer h4, .container .main > footer', {fontFamily: 'AlteHaasGrotesk',hover: 'true'});
					dfd.resolve();
				}).promise();
		},

		renderBlocks = function() {
			var appBg	= '';

			return jQuery.Deferred(
				function(dfd) {
					jQuery('.grad').each(function() {
						var $this 	= jQuery(this),
							dHeight	= (($this.data('top') !== undefined)?$this.data('top'):0) - (($this.data('bottom') !== undefined)?$this.data('bottom'):0),
							bHeight = $this.outerHeight(true) + dHeight;

						if ($this.data('width') !== undefined) {
							var margins = Math.ceil((jQuery(window).width() - 980) / 2);
							$this.css({
								'margin-left'	: -margins +'px',
								'margin-right'	: -margins +'px',
								'width'			: jQuery(window).width() + 'px'
							}).append('<div class="border-shadow sh-l" style="width:'+ (margins + 10) +'px"><div class="sh-t"></div><div class="sh-b"></div><div class="sh"></div></div><div class="border-shadow sh-r" style="width:'+ (margins + 10) +'px"><div class="sh-t"></div><div class="sh-b"></div><div class="sh"></div></div>');
						};

						appBg += '<div class="grad '+ (($this.data('grad') !== undefined)?$this.data('grad'):'') +'" style="height:'+ bHeight +'px">'+ (($this.data('role') == 'nodes')?'<canvas id="nodes-bg"></canvas>':'') + (($this.data('role') == 'brands')?'<canvas id="brands-bg"></canvas>':'') +'</div>';
					});

					appBg += '<div class="grad grad-grey" style="height:139px"></div>';
					jQuery('#background').append(appBg);
					dfd.resolve();
			}).promise();
		};

		return {
			init	 		: init,
			scrollCnt		: scrollCnt
		};
	})(),

	helpers	= (function() {
		var formatValues = function(val) {
			return val.toString().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,"); 
		},

		minArray = function(data) {
			return Math.min.apply(Math, data);
		},

		maxArray = function(data) {
			return Math.max.apply(Math, data);
		},

		setBasePath = function() {
			var name	= 'functions.js',
				scripts = document.getElementsByTagName('script');

			for (var i=scripts.length - 1; i>=0; --i) {
				var src		= scripts[i].src,
					l		= src.length,
					length 	= name.length;

				if (src.substr(l - length) == name) {
					basePath = src.substr(0, l - length)+'../';
				};
			};
		},

		cookieNodes = (function() {
			var set = function(name, value, path, domain, expires, secure) {
				if (!name || !value) return false;
				var str = name + '=' + encodeURIComponent(value);
	
				if (expires)	str += '; expires=' + expires.toGMTString();
				if (path)		str += '; path=' + path;
				if (domain)		str += '; domain=' + domain;
				if (secure)		str += '; secure';
	
				document.cookie = str;
				return true;
			},
		
			get = function(name) {
				var pattern = '(?:; )?' + name + '=([^;]*);?', 
					regexp  = new RegExp(pattern);
	
				if (regexp.test(document.cookie))
					return decodeURIComponent(RegExp["$1"]);
	
				return false;
			};
		
			return {
				set	: set,
				get	: get
			};
		})(),
		
		detectBrowser = function() {
			var userAgent = navigator.userAgent.toLowerCase(),
				  version = 0;
			
			jQuery.browser.chrome = /chrome/.test(navigator.userAgent.toLowerCase());

			if(jQuery.browser.chrome){
				userAgent = userAgent.substring(userAgent.indexOf('chrome/') +7);
				userAgent = userAgent.substring(0,userAgent.indexOf('.'));
				version = userAgent;
				jQuery('body').addClass('chrome chrome'+version);
			} else if(jQuery.browser.safari){
				userAgent = userAgent.substring(userAgent.indexOf('safari/') +7);
				userAgent = userAgent.substring(0,userAgent.indexOf('.'));
				version = userAgent;
				jQuery('body').addClass('safari safari'+version);
			} else if(jQuery.browser.mozilla){
				userAgent = userAgent.substring(userAgent.indexOf('firefox/') +8);
				userAgent = userAgent.substring(0,userAgent.indexOf('.'));
				version = userAgent;
				jQuery('body').addClass('ff ff'+version);
			} else if(jQuery.browser.opera){
				userAgent = userAgent.substring(userAgent.indexOf('version/') +8);
				userAgent = userAgent.substring(0,userAgent.indexOf('.'));
				version = userAgent;
				jQuery('body').addClass('opera opera'+version);
			};
		},

		loadImages = function(count, arr) {
			return jQuery.Deferred(
				function(dfd) {
					var loaded = 0;
					
					for (var i=0; i<count; ++i) {
						jQuery('<img/>').load(function() {
							++loaded;
							if (loaded === count) {
								dfd.resolve();
							};
						}).attr('src' , arr[i]);
					};
			}).promise();
		},

		adjustImageSize = function($cnt, $items) {
			var wCnt = $cnt.outerWidth(true),
				hCnt = $cnt.outerHeight(true),
				rCnt = hCnt / wCnt;
				
			return jQuery.Deferred(
				function(dfd) {
					$items.each(function() {
						var $img = jQuery(this),
							wImg  = $img.width(),
							hImg  = $img.height(),
							rImg  = hImg / wImg,
							wNew, hNew, lNew, tNew;
						
						if (rCnt > rImg) {
							hNew = hCnt;
							wNew = hCnt / rImg;
						} else {
							hNew = wCnt * rImg;
							wNew = wCnt;
						};
								
						$img.css({
							'width'	: wNew + 'px',
							'height': hNew + 'px',
							'left'	: (wCnt - wNew) / 2 +'px',
							'top'	: (hCnt - hNew) / 2 +'px'
						});
					});
					dfd.resolve();	
				}).promise();	
			};

		return {
			formatValues	: formatValues,
			minArray		: minArray,
			maxArray		: maxArray,
			setBasePath		: setBasePath,
			cookieNodes		: cookieNodes,
			detectBrowser 	: detectBrowser,
			loadImages  	: loadImages,
			adjustImageSize	: adjustImageSize
		};
	})(),

	nodes = (function() {
		var init = function(id, count) {
			function h(a, b) {
	    		this.set(a, b)
			};
			h.prototype = {
    			set: function (a, b) {
        			this.x = a || 0;
	        		this.y = b || 0
		    	},
			    l: function (a) {
    			    this.x += a.x;
        			this.y += a.y
			    },
    			r: function (a) {
        			this.x -= a.x;
	        		this.y -= a.y
		    	},
			    scale: function (a) {
    			    this.x *= a;
        			this.y *= a
			    },
    			t: function () {
	    		    return this.x * this.x + this.y * this.y
	    		},
			    w: function () {
    			    return Math.atan2(this.y, this.x)
			    }
			};

			function i(a, b, c, d) {
    			this.a = new h(a, b);
	    		this.d = new h;
	    		this.b = new h;
			    this.u = c || 1;
    			this.v = 1 / this.u;
			    this.j = d || 20;
    			this.fixed = !1;
		    	this.color = j[Math.floor(Math.random() * j.length)]
			};

			var j = ["#FFFFFF"];
			i.prototype = {
    			update: function () {
	        		this.fixed || (this.d.scale(this.v), this.b.l(this.d), this.a.l(this.b), this.b.scale(0.9), this.d.set(0, 0))
		    	},
			    i: function (a) {
    			    a.save();
	        		a.translate(this.a.x, this.a.y);
	    	    	a.rotate(this.b.w());
			        var b = this.b.t();
    			    a.strokeStyle = "rgba(255,255,255," + (0.02 + Math.min(0.5, b * 8.0E-4)) + ")";
	    	    	a.lineWidth = 10 + Math.min(60, b);
	    		    a.beginPath();
		        	a.arc(0, 0, this.j, 0, Math.PI * 2, !1);
	    		    a.closePath();
		        	a.stroke();
	    		    a.fillStyle = this.color;
		    	    a.fill();
	    		    a.restore()
			    }
			};

			function k(a, b, c, d, f) {
    			this.f = a;
	    		this.g = b;
	    		this.A = d || 0.1;
			    this.z = c || 200;
    			this.n = f || 0.01;
			    this.e = new h
			};
			k.prototype = {
			    update: function () {
    			    var a = this.f.a.x - this.g.a.x,
	        		    b = this.f.a.y - this.g.a.y,
	    	        	c = a * a + b * b;
	    	    	if (c > 0.001) {
		    	        var c = Math.sqrt(c),
    		    	        d = (c - this.z) * this.A;
        		    	this.e.set(d, d);
		        	    a /= c;
    		        	b /= c;
	        		    this.e.x += this.n * (this.f.b.x - this.g.b.x) * a;
		        	    this.e.y += this.n * (this.f.b.y - this.g.b.y) * b;
    		        	this.e.x *= -a;
	        		    this.e.y *= -b;
		        	    this.f.d.l(this.e);
    		        	this.g.d.r(this.e)
	        		};
			    },
			    i: function (a) {
			        a.strokeStyle = "rgba(255,255,255,0.2)";
					a.lineWidth = 3;
					a.beginPath();
					a.beginPath();
	    	    	a.moveTo(this.f.a.x, this.f.a.y);
	    		    a.lineTo(this.g.a.x, this.g.a.y);
	    	    	a.closePath();
		    	    a.stroke()
	    		}
			};

			function l(a, b, c, d) {
			    this.k = Math.random() * Math.PI;
    			this.q = 0.25 + Math.random() * 2.5;
		    	this.p = 0.25 + Math.random() * 1;
	    		i.call(this, a, b, c, d)
			}
			l.prototype = new i;
			l.prototype.B = i.prototype;
			l.prototype.update = function () {
    			this.k += -this.q + Math.random() * this.q * 2;
		    	this.d.x += Math.cos(this.k) * this.p;
	    		this.d.y += Math.sin(this.k) * this.p;
			    this.B.update.call(this)
			};

			function m(num) {
		    	this.c = [];
			    this.h = [];
    			this.o = !1;

				var cw = document.getElementById(id).width,
					ch = document.getElementById(id).height;

				if (id == 'nodes-bg') {
					this.x = Math.floor(((num<=Math.floor(count/2))?25:((cw+960)/2+25)) + Math.random()*((cw-960)/2 + 1));
				} else {
					this.x = cw/2+25+Math.floor(Math.random()*50+70);
				};
				
				this.y = Math.floor(25 + Math.random()*(ch + 1));
	    		this.color = j[Math.floor(Math.random() * j.length)];
	    		this.m()
			};
			m.prototype = {
			    m: function () {
    			    var a, b, c = Math.floor(2 + Math.random() * 5);
	        		for (a = 0; a < c; ++a) b = 2 + Math.random() * 20, a === 0 && (b += Math.random() * 30), b = new l(this.x, this.y, 0.4 + Math.random() * 2.2, b), b.color = this.color, a > 0 && (this.h.push(new k(b, this.c[Math.floor(Math.random() * a)], Math.random() * 50, 0.01 + Math.random() * 0.1, 0.01 + Math.random() * 0.1)), Math.random() < 0.5 && this.h.push(new k(b, this.c[Math.floor(Math.random() * a)], Math.random() * 360))), this.c.push(b)
		    	},
			    update: function () {
    			    var a, b, c, d = Number.MAX_VALUE,
		    	        f = Number.MAX_VALUE,
    		    	    e = Number.MIN_VALUE,
        		    	g = Number.MIN_VALUE;
			        a = 0;
    			    for (b = this.c.length; a < b; ++a) c = this.c[a], d = Math.min(d, c.a.x + c.j), e = Math.max(d, c.a.x - c.j), f = Math.min(f, c.a.y + c.j), g = Math.max(f, c.a.y - c.j), c.update();
        			a = 0;
	        		for (b = this.h.length; a < b; ++a) this.h[a].update();

					if (e < 0 || d >  document.getElementById(id).width || g < 0 || f > document.getElementById(id).height) this.o = !0
			    },
		    	i: function (a) {
	    		    var b, c;
    	    		b = 0;
	    	    	for (c = this.h.length; b < c; ++b) this.h[b].i(a);
	    	    	b = 0;
		        	for (c = this.c.length; b < c; ++b) this.c[b].i(a)
			    },
	    		s: function () {
		        	this.h = this.c = null
	    		}
			};

			(new function () {
			    function a() {
			        var e, g, n = d.length;
			        if (f) {
						for (e = 0; e < n; ++e) g = d[e], g.o ? (g.s(), d[e] = new m(e)) : g.update();
					} else {
	    	    	    b.width = b.width;
    	    	    	c.globalAlpha = 0.2;
			            c.globalCompositeOperation = 'lighter';
            			for (e = 0; e < n; ++e) d[e].i(c)
			        };

			        f = !f;
			        requestAnimFrame(a, b)
			    };

			    var b = document.getElementById(id);

		        if(typeof G_vmlCanvasManager != 'undefined') {
					b = G_vmlCanvasManager.initElement(b);
				};
					
				var	c = b.getContext('2d'),
			        d = [],
			        f = !0;

			    this.m = function () {
			        b.width = jQuery(b).parent().width();
			        b.height = jQuery(b).parent().height();
			        for (var c = 0; c < count; c++) {
						d.push(new m(c));
					};
			        a();
			    }
			}).m();
		};

		return {
			init: init
		};
	})(),

	brands = (function() {
		var bubbles = [],
			$images = jQuery('#brands img'),
			C = 600000000, k = 5, factor = 0.91, iteration = 0, step = 0,
			itm = -1, relx, rely, canvas, ctx, cw, ch,

		init = function() {
			canvas = document.getElementById('brands-bg');
			if(typeof G_vmlCanvasManager != 'undefined') {
				canvas = G_vmlCanvasManager.initElement(canvas);
			};
			
			ctx = canvas.getContext('2d');

			canvas.width 	= cw = jQuery(canvas).parent().width();
			canvas.height 	= ch = jQuery(canvas).parent().height();

			$images.each(function(i) {
				var $this = jQuery(this),
				maxRadius = Math.sqrt($this.width()*$this.width() + $this.height()*$this.height())/2.;

				bubbles[i] = new bubble(
					cw/2. + Math.floor(-maxRadius + Math.random()*(cw - maxRadius + 1)),
					ch/2. + Math.floor(-maxRadius + Math.random()*(ch - maxRadius + 1)),
					maxRadius - Math.floor(40*Math.random()),
					i,
					$this.attr('src')
				);
			});

			jQuery.when(renderBubbles()).done(function(){
				animate();
				bubblesEvents();
       		});
		},

		bubblesEvents = function() {
			hoverBubbles();

			jQuery(document).on('mousedown mouseup', '#brands-bg', function(e) {
				var i = getBubbleFromPos(e);

		    	if (i!=-1) {
					itm = i;

					jQuery(document).off('mousemove', '#brands-bg');

					switch (e.type) {
						case 'mousedown':
							var curs = getCursorPosition(e);

							relx = bubbles[itm].x - curs.x,
							rely = bubbles[itm].y - curs.y;

							jQuery(document).on('mousemove', '#brands-bg', function(e) {
								var curs = getCursorPosition(e);

								bubbles[itm].vx = curs.x + relx - bubbles[itm].x;
							    bubbles[itm].vy = curs.y + rely - bubbles[itm].y;
							    bubbles[itm].x = curs.x + relx;
							    bubbles[itm].y = curs.y + rely;
							});
						break;
						case 'mouseup':
  							jQuery(document).off('mousemove', '#brands-bg');
							itm = -1;
							hoverBubbles();
						break;
					};
				} else {
					itm = -1;
				};
			});
		},

		renderBubbles = function() {
			return jQuery.Deferred(
				function(dfd) {
  					for (var j=0; j<300; j++){
						var mx=0,my=0,
							i;

						for (i=0; i<bubbles.length; i++) {
    		  				bubbles[i].nextPos();
							mx += bubbles[i].x;
							my += bubbles[i].y;
						};

						mx /= bubbles.length;
						my /= bubbles.length;

						for (i=0; i<bubbles.length; i++) {
        					bubbles[i].x += cw/2.-mx;
        					bubbles[i].y += ch/2.-my;
						};

						if (j == 299)
							dfd.resolve();
					};
				}).promise();
		},

		animate = function() {
			requestAnimFrame(animate, canvas);

			if (step<bubbles.length) {
				if ((iteration % 2) == 0) {
					bubbles[step].r = 0;
					step = step + 1;
				};

				iteration = iteration + 1;
			};

    		for (i=0; i<bubbles.length; i++) {
      			bubbles[i].nextPos();
			};

			draw();
		},

		draw = function() {
			clearCanvas();

			var mx=0,my=0,
				i;

			ctx.save();
			ctx.strokeStyle = 'rgba(0, 0, 0, 0.2)';
			ctx.fillStyle 	= '#ffffff';

			for (i=0; i<bubbles.length; i++) {
				mx += bubbles[i].x;
				my += bubbles[i].y;
			};

			mx /= bubbles.length;
			my /= bubbles.length;

			for (i=0; i<step; i++) {
				if (i!=itm) {
        			bubbles[i].x += cw/2.-mx;
        			bubbles[i].y += ch/2.-my;
				};

				bubbles[i].draw();
    		};

			ctx.restore();
  		},

		getCursorPosition = function(e) {
		    var canvasOffset = jQuery('#brands-bg').offset();

    		return {
				x: e.pageX - canvasOffset.left,
				y: e.pageY - canvasOffset.top
			};
		},

		getBubbleFromPos = function(e) {
			var xy = getCursorPosition(e);

			for (i=0; i<bubbles.length; i++) {
				if (Math.sqrt((xy.x-bubbles[i].x)*(xy.x-bubbles[i].x) + (xy.y-bubbles[i].y)*(xy.y-bubbles[i].y))<=bubbles[i].r) {
					return i;
				};
			};

			return -1;
		},

		hoverBubbles = function() {
			jQuery(document).on('mousemove mouseout', '#brands-bg', function(e) {
				switch (e.type) {
					case 'mousemove':
						var i = getBubbleFromPos(e);

			    		if (i!=-1) {
							itm = i;
						} else {
							itm = -1;
						};
					break;
					case 'mouseout':
						itm = -1;
					break;
				};
			});
		},

		bubble = function(x, y, r, i, src) {
			this.x		= x;
			this.y		= y;
			this.cor	= r/100.;
			this.r 		= r;
			this.sr		= r / 16.;
			this.i 		= i;
			this.factor = factor;
			this.vx 	= 0;
			this.vy 	= 0;

			this.draw = function() {
				var img = new Image(),
					ratio = 1, border = 0, ratio = 1, iwNew, ihNew;

				img.src = src;

				var iw = img.width,
					ih = img.height;

				ctx.beginPath();

				this.r = ((this.r + this.sr) < 16*this.sr)?(this.r + this.sr):16*this.sr;

				border = 5*this.r / (8*this.sr);

				ctx.lineWidth = (this.i == itm)?2*border:border;
				ctx.arc(this.x, this.y,	this.r, 0, Math.PI*2, false);
				ctx.closePath();
				ctx.stroke();
				ctx.fill();

				ratio = iw/ih;

				ihNew = 2*this.r/Math.sqrt(ratio*ratio + 1);
				iwNew = ihNew * ratio;

				ctx.drawImage(img, this.x-iwNew/2, this.y-ihNew/2, iwNew, ihNew);
			};

			this.nextPos = function() {
				if (this.i == itm) {
        			return;
				};

				var fx = 0,
					fy = 0;

				for (i=0; i<bubbles.length;++i) {
					if (i!=this.i) {
						if (this.x==bubbles[i].x&&this.y==bubbles[i].y) {
							this.x += 10;
							this.y += 10;
						};
          				var xx 			= (this.x-bubbles[i].x),
							yy 			= (this.y-bubbles[i].y),
							signx 		= (xx<0)?-1:1,
							signy 		= (yy<0)?-1:1,
							r 			= xx*xx + yy*yy,
							sqr 		= Math.sqrt(r),
							intensity 	=  C/r - k*this.cor*sqr,
							alpha 		= Math.atan(yy/xx);

						fx += intensity * Math.abs(Math.cos(alpha)) * signx *((i == itm)?10:1);
						fy += intensity * Math.abs(Math.sin(alpha)) * signy *((i == itm)?10:1);
					};
				};

				fx *= .01;
				fy *= .01;

				this.vx = (this.vx + fx) * this.factor;
				this.vy = (this.vy + fy) * this.factor;

				this.x += .01 * this.vx;
				this.y += .01 * this.vy;
			};
		},

		clearCanvas = function() {
			ctx.clearRect(0, 0, cw, ch);
		};

		return {
			init: init
		};
	})(),

	previewImageSlider	= (function() {
		var $cnt	 = jQuery('#previewImageSlider'),
			$wrapper = jQuery('#previewImageSlider .wrapper'),
			count	 = $wrapper.find('img').length,
			time	 = 4000,

		init = function() {
			if (count > 1) {
				jQuery.when(jQuery('#previewImageSlider-prev').show(0),jQuery('#previewImageSlider-next').show(0)).done(function(){
					previewImageAutoSlide();
					previewImageSliderEvents();
				});
			};
		},

		reverseImages = function(dir) {
			return jQuery.Deferred(
				function(dfd) {
					if (((dir == -1) && ($wrapper.data('isReversed') == undefined)) || ((dir == 1) && ($wrapper.data('isReversed') == true))) {
						(dir == 1)?$wrapper.removeData('isReversed'):$wrapper.data('isReversed', true);
						for (var i=count - 2; i>=1; --i) {
							jQuery('#previewImageSlider .wrapper').append(jQuery('#previewImageSlider .wrapper img').eq(i));
							if (i == 1) {
								dfd.resolve();
							};
						};
					} else {
						dfd.resolve();
					};
			}).promise();
		},

		previewImageAutoSlide = function() {
			timer = setTimeout(function() {
				jQuery.when(previewImageSlide(1)).done(function(){
					previewImageAutoSlide();
				});
       		}, time);
		},

		previewImageSlide = function(dir) {
			return jQuery.Deferred(
				function(dfd) {
					jQuery.when(reverseImages(dir)).done(function(){
						var $current = jQuery('#previewImageSlider .wrapper img:first');

						$current.fadeOut(500, function() {
							jQuery('#previewImageSlider .wrapper').append($current).find('img:first').fadeIn(500, function() {
								dfd.resolve();
							});
						});
					});
			}).promise();
		},

		previewImageSliderEvents = function() {
			jQuery(document).on('click', '#previewImageSlider-prev', function(e) {
				e.preventDefault();
				e.stopPropagation();
				clearTimeout(timer);
				previewImageSlide(-1);
			});
			jQuery(document).on('click', '#previewImageSlider-next', function(e) {
				e.preventDefault();
				e.stopPropagation();
				clearTimeout(timer);
				previewImageSlide(1);
			});
		};

		return {
			init: init
		};
	})(),

	makeCounters = (function() {
		var valCounter = jQuery('#digits-container').html(),

		init = function() {
			jQuery('#digits-container').html('<div class="back"><div class="top"></div><div class="bottom"></div></div><div class="front"><div class="top"></div><div class="bottom"></div></div>');

			if (valCounter === '') {
				var likesLastHour = 0,
					likesEachMinute = 0,
				    likesEachSecond = 0,
				    secondsBetweenLikes = 0,
				    first = 0, second = 0,
				    numCurrent = 0;

				if (jQuery('#digits-container').hasClass('count-contacts')) {
					numCurrent = parseInt(helpers.cookieNodes.get('totalScroll'));
					jQuery.when(buildCurrent(helpers.formatValues(numCurrent)), buildNext(helpers.formatValues(numCurrent))).done(function(){
						var widthNew = 0;

						jQuery('.count .front .bottom span').each(function() {
							widthNew += jQuery(this).outerWidth(true);
						});

						jQuery('#loader-counter').fadeOut(1500, function() {
							jQuery('#digits-container').css('width', widthNew +'px').fadeIn(500);
						});
					});

					executor = setInterval(function() {
						var numNext	= parseInt(helpers.cookieNodes.get('totalScroll'));

						if (numCurrent != numNext) {
						    jQuery('#digits-container').html('<div class="back"><div class="top"></div><div class="bottom"></div></div><div class="front"><div class="top"></div><div class="bottom"></div></div>');
						    buildCurrent(helpers.formatValues(numCurrent));
						   	buildNext(helpers.formatValues(numNext));
						    switchNumbers(helpers.formatValues(numCurrent), helpers.formatValues(numNext));
						   	numCurrent = numNext;

							var widthNew = 0;
							jQuery('.count .front .bottom span').each(function() {
								widthNew += jQuery(this).outerWidth(true);
							});
							jQuery('#digits-container').css('width', widthNew +'px');
						};
				    }, 1000);
				} else {
					jQuery.when(jQuery.getJSON('/like-counter.json')).done(function(data) {
						var impData = data, i = 0,
							firstDate, secondDate;

					    for (var key in data) {
							switch(i) {
							    case 0:
									first = parseInt(data[key]);
									firstDate = key;
									break;
							    case 1:
									second = data[key];
									secondDate = key;
									break;
							}
							i++;
					    };

						var tempDate = secondDate.replace(/-/g, ' ');
		    			tempDate = tempDate.replace(/:/g, ' ');
					    tempDate = tempDate.split(' ');

					    var now = new Date();
					    now.setHours(now.getHours() - 1);
				    	var unixtime_ms = now.getTime();
					    var current_unixtime = parseInt(unixtime_ms / 1000);

					    var feed_time = new Date(tempDate[0],(tempDate[1]-1),tempDate[2],tempDate[3],tempDate[4],tempDate[5]);
						var unixtime_ms = feed_time.getTime();
					    var feed_unixtime = parseInt(unixtime_ms / 1000);

					    var secondsSinceUpdate = current_unixtime - feed_unixtime;

						likesLastHour = first - second;
					    likesEachMinute = likesLastHour/60;
					    likesEachSecond = likesEachMinute/60;
					    secondsBetweenLikes = Math.round(1/likesEachSecond);

					    var likesPerUpdate = 1;
					    if (secondsBetweenLikes == 0) {
							likesPerUpdate = Math.round(likesEachSecond) + Math.round(likesEachSecond);
							secondsBetweenLikes = 2;
					    };

						var catchUp = Math.round(secondsSinceUpdate/secondsBetweenLikes);

						numCurrent = parseInt(second)+parseInt(catchUp);

						jQuery.when(buildCurrent(helpers.formatValues(numCurrent)), buildNext(helpers.formatValues(numCurrent))).done(function(){
							var widthNew = 0;

							jQuery('.count .front .bottom span').each(function() {
								widthNew += jQuery(this).outerWidth(true);
							});

							jQuery('#loader-counter').fadeOut(1500, function() {
								jQuery('#digits-container').css('width', widthNew +'px').fadeIn(500);
							});
						});

					    var numNext = (parseInt(numCurrent)+parseInt(likesPerUpdate));

						var executor = setInterval(function() {
							if (numCurrent != numNext) {
							    jQuery('#digits-container').html('<div class="back"><div class="top"></div><div class="bottom"></div></div><div class="front"><div class="top"></div><div class="bottom"></div></div>');
							    buildCurrent(helpers.formatValues(numCurrent));
						    	buildNext(helpers.formatValues(numNext));
							    switchNumbers(helpers.formatValues(numCurrent), helpers.formatValues(numNext));
						    	numCurrent = numNext;
							    numNext = numNext+parseInt(likesPerUpdate);

								var widthNew = 0;
								jQuery('.count .front .bottom span').each(function() {
									widthNew += jQuery(this).outerWidth(true);
								});
								jQuery('#digits-container').css('width', widthNew +'px');
							};
					    }, secondsBetweenLikes+'000');
					});
				};
			} else {
				jQuery.when(buildCurrent(helpers.formatValues(valCounter)), buildNext(helpers.formatValues(valCounter))).done(function(){
					var widthNew = 0;

					jQuery('.count .front .bottom span').each(function() {
						widthNew += jQuery(this).outerWidth(true);
					});

					jQuery('#loader-counter').fadeOut(1500, function() {
						jQuery('#digits-container').css('width', widthNew +'px').fadeIn(500);
					});
				});
			};
		},

		buildCurrent = function(current) {
			return jQuery.Deferred(
				function(dfd) {
				    var serverNumCurrentSplited = current.split(''),
						topAppend = '', bottomAppend = '';

					for (var i=0; i<serverNumCurrentSplited.length; i++) {
        				if(serverNumCurrentSplited[i] == ',') {
				            topAppend 	 += '<span class="delimiter"><img src="'+ basePath +'img/numbers/delimiter.png" /></span>';
							bottomAppend += '<span class="delimiter"><img src="'+ basePath +'img/numbers/delimiter.png" /></span>';
		        		} else {
				            topAppend 	 += '<span><img src="'+ basePath +'img/numbers/'+Number(serverNumCurrentSplited[i])+'-up.png"/></span>';
							bottomAppend += '<span><img src="'+ basePath +'img/numbers/'+Number(serverNumCurrentSplited[i])+'-down.png"/></span>';
		        		};
				    };

					jQuery('#digits-container .front .top').append(topAppend);
		   		    jQuery('#digits-container .back .bottom').append(bottomAppend);
					dfd.resolve();
			}).promise();
		},

		buildNext = function(next) {
			return jQuery.Deferred(
				function(dfd) {
				    var serverNumNextSplited = next.split(''),
						topAppend = '', bottomAppend = '';

					for (var i=0; i<serverNumNextSplited.length; i++) {
        				if(serverNumNextSplited[i] == ',') {
		        		    topAppend 	 += '<span class="delimiter"><img src="'+ basePath +'img/numbers/delimiter.png"/></span>';
							bottomAppend += '<span class="delimiter"><img style="height:0px;" src="'+ basePath +'img/numbers/delimiter.png"/></span>';
				        } else {
		        		    topAppend 	 += '<span><img src="'+ basePath +'img/numbers/'+Number(serverNumNextSplited[i])+'-up.png"/></span>';
							bottomAppend += '<span><img style="height:0px;" src="'+ basePath +'img/numbers/'+Number(serverNumNextSplited[i])+'-down.png"/></span>';
				        };
				    };

					jQuery('#digits-container .back .top').append(topAppend);
   				    jQuery('#digits-container .front .bottom').append(bottomAppend);
					dfd.resolve();
			}).promise();
		},

		switchNumbers = function(current, next) {
		    var serverNumCurrentSplited = current.split(''),
				serverNumNextSplited 	= next.split(''),
				firstSwitchingElement 	= new Number;

			for (var i=0; i<serverNumNextSplited.length; i++) {
		        firstSwitchingElement = i+1;
        		if (serverNumCurrentSplited[i] != serverNumNextSplited[i])
		            break;
		    };

		    jQuery('#digits-container .front .top span:nth-child('+ firstSwitchingElement +') img').animate({'height': 0}, 200, function() {
           		jQuery('.count .front .bottom span:nth-child('+firstSwitchingElement+') img').animate({'height': '28px'}, 200, function() {
                    serverNumCurrentSplited[firstSwitchingElement - 1] = serverNumNextSplited[firstSwitchingElement - 1];
   		            if (serverNumCurrentSplited.join('') !== serverNumNextSplited.join('')) {
           		        switchNumbers(serverNumCurrentSplited.join(''), serverNumNextSplited.join(''));
               		};
				});
    		});
		};

		return {
			init: init
		};
	})();

	gMap = (function() {
		var init = function() {
			jQuery('#maplinks a').data('active', 0);
			jQuery.when(appendScript()).done(function() {
				gMapSwitch(jQuery('#maplinks a').data('active'));
				gMapEvents();
			});
		},

		appendScript = function() {
			return jQuery.Deferred(
				function(dfd) {
					var script = document.createElement("script");

					script.type	= "text/javascript";
					script.src	= "//maps.googleapis.com/maps/api/js?sensor=false&callback=showMap";

					document.body.appendChild(script);
					dfd.resolve();
				}).promise();
		},

		gMapSwitch = function(index) {
			return jQuery.Deferred(
				function(dfd) {
					jQuery('#maplinks a').eq(jQuery('#maplinks a').data('active')).show(0, function() {
						jQuery('#maplinks a').eq(index).hide(0, function() {
							jQuery('#mapdescr').html(jQuery('#maplinks a').eq(index).data('pointDescr'));
							jQuery('#maplinks a').data('active', index);
						});
					});
					dfd.resolve();
				}).promise();
		},

		gMapEvents = function() {
			jQuery('#maplinks').on('click', 'a', function(e) {
				e.preventDefault();
				e.stopPropagation();

				var $this = jQuery(this),
					index = jQuery('#maplinks a').index($this);

				jQuery.when(gMapSwitch(index)).done(function() {
					showMap($this.data('pointLatlng'));
				});
			});
		};

		return {
			init: init
		};
	})(),

	FBpart = (function() {
		var init = function() {
			var canvas, ctx, size, value;

			jQuery('#fbPart canvas').each(function() {
				$this = jQuery(this);

				canvas = document.getElementById($this.attr('id'));
				
				if(typeof G_vmlCanvasManager != 'undefined') {
					canvas = G_vmlCanvasManager.initElement(canvas);
				};
				
				ctx = canvas.getContext('2d');
				canvas.width	= $this.width();
				canvas.height	= $this.height();

				size = $this.width()/2;
				value = parseInt($this.data('value'));
				ctx.fillStyle 	= '#ffffff';
				ctx.beginPath();
				ctx.moveTo(size, size);
				ctx.arc(size, size, size, -Math.PI/2, -Math.PI/2 + value*Math.PI/50, false);
				ctx.lineTo(size, size);
				ctx.closePath();
				ctx.fill();
			});
		};

		return {
			init: init
		};
	})(),

	frSlider = (function() {
		var $cnt		= jQuery('#frontpageSlider .wrapper'),
			$scenes 	= jQuery('#frontpageSlider .wrapper .screen'),
			$images 	= $scenes.find('img'),
			time = 28000, numHover = 0, scenesTempNum = [0, 2], imagesOrig = [];

		$images.each(function() {
			var $this = jQuery(this);

			$this.attr('data-bw', $this.attr('src'));
			imagesOrig.push($this.data('orig'));
		});

		var init = function() {
			jQuery.when(rebuildScenes(), helpers.loadImages($images.length, imagesOrig)).done(function() {
				jQuery.when(renderStyles()).done(function() {
					$cnt.fadeIn(function() {
						frontpageSliderAutoHover();
						frontpageSliderEvents();
					});
				});
			});
		},

		addScene = function(dir) {
			return jQuery.Deferred(
				function(dfd) {
					switch (dir) {
						case 1:
							$cnt.append($scenes.eq(scenesTempNum[0]).clone().hide().find('.grid-item').removeAttr('style').end().shuffle());
							scenesTempNum[0] = (scenesTempNum[0] == 2)?0:(scenesTempNum[0]+1);
							Cufon.refresh();
							dfd.resolve();
							break;
						case -1:
							$cnt.prepend($scenes.eq(scenesTempNum[1]).clone().hide().find('.grid-item').removeAttr('style').end().shuffle());
							scenesTempNum[1] = (scenesTempNum[1] == 0)?2:(scenesTempNum[1]-1);
							Cufon.refresh();
							dfd.resolve();
							break;
					};
			}).promise();
		},

		rebuildScenes = function() {
			return jQuery.Deferred(
				function(dfd) {
					var count = jQuery('#frontpageSlider .wrapper .screen').length;

					if ((count*954+6) < jQuery(window).width()) {
						addScene(1); addScene(-1);
					};

					var current = ($cnt.position().left < 0)?Math.ceil($cnt.position().left / -954):1;

					$cnt.css({'left': -954*(count-2) + (jQuery(window).width()-960)/2 + 5 +'px'});
					dfd.resolve();
			}).promise();
		},

		renderStyles = function() {
			return jQuery.Deferred(
				function(dfd) {
					var count = jQuery('#frontpageSlider .wrapper .screen').length;

					$cnt.css({'width': count*954+6 +'px'});

					jQuery('#frontpageSlider .screen.view-1')
						.find('.s2:last').css({'left': 367 +'px', 'top'	: 5 +'px'}).end()
						.find('.s4:first').css({'left': 6 +'px', 'top': 162 +'px'}).end()
						.find('.s4:last').css({'left': 728 +'px', 'top': 319 +'px'});
					jQuery('#frontpageSlider .screen.view-2')
						.find('.s2:last').css({'left': 366 +'px', 'top': 319 +'px'}).end()
						.find('.s4:first').css({'left': 495 +'px', 'top': 5 +'px'}).end()
						.find('.s4:last').css({'left': 727 +'px', 'top': 319 +'px'});
					jQuery('#frontpageSlider .screen.view-3')
						.find('.s2:last').css({'left': 601 +'px', 'top': 5 +'px'}).end()
						.find('.s4:first').css({'left': 368 +'px', 'top': 5 +'px'}).end()
						.find('.s4:last').css({'left': 239 +'px', 'top': 319 +'px'});
					dfd.resolve();
			}).promise();
		},

		changeImage = function($cnt, source) {
			return jQuery.Deferred(
				function(dfd) {
					$cnt.attr('src', source);
					dfd.resolve();
			}).promise();
		},

		frontpageSlide = function(dir) {
			var $current = $cnt.data('active');

			return jQuery.Deferred(
				function(dfd) {
					switch (dir) {
						case 1:
							$cnt.animate({'left': '-=954px'}, 250, function() {
								jQuery.when(addScene(1)).done(function() {
									jQuery.when(renderStyles()).done(function() {
										jQuery('#frontpageSlider .screen:last').fadeIn(250, function() {
											dfd.resolve();
										});
									});
								});
							});
							break;
						case -1:
							$cnt.animate({'left': '+=954px'}, 250, function() {
								jQuery.when(addScene(-1)).done(function() {
									jQuery.when(renderStyles()).done(function() {
										$cnt.css({'left': '-=954px'});
										jQuery('#frontpageSlider .screen:first').fadeIn(250, function() {
											dfd.resolve();
										});
									});
								});
							});
							break;
					};
			}).promise();
		},

		frontpageSliderAutoHover = function() {
			var	$this	= jQuery('#frontpageSlider .screen').eq(Math.ceil($cnt.position().left / -954)).find('.grid-item').eq(numHover),
				$img	= $this.find('img');
			
			timer = setTimeout(function() {
				/*
				jQuery.when(changeImage($img, $img.data('orig'))).done(function() {
					$this.stop(true).animate({'opacity': 1}, 250, function() {
						jQuery('.descr', this).stop(true).animate({'bottom': 0 +'px'}, 500);
						setTimeout(function() {
							jQuery.when(changeImage($img, $img.data('bw'))).done(function() {
								$this.stop(true).animate({'opacity': 0.3}, 250, function() {
									jQuery('.descr', this).stop(true).animate({'bottom': -151 +'px'}, 500, function() {
										numHover = (numHover == 6)?0:(numHover+1);
										frontpageSliderAutoHover();	
									});								
								});
							});
						}, 3500);
					});
				});
				*/
       		}, 500);
		},			
		
		frontpageSliderEvents = function() {
			jQuery(document).on('mouseover mouseout', '#frontpageSlider .screen .grid-item', function(e) {
				var $this	= jQuery(this),
					$img	= $this.find('img');
					
				switch (e.type) {
					case 'mouseover':
						clearTimeout(timer);
						jQuery.when(changeImage($img, $img.data('orig'))).done(function() {
							$this.stop(true).animate({'opacity': 1}, 250, function() {
								jQuery('.descr', this).stop(true).animate({'bottom': 0 +'px'}, 500);
							});
						});
						break;
					case 'mouseout':
						jQuery.when(changeImage($img, $img.data('bw'))).done(function() {
							$this.stop(true).animate({'opacity': 0.3}, 250, function() {
								jQuery('.descr', this).stop(true).animate({'bottom': -151 +'px'}, 500, function() {
									setTimeout(frontpageSliderAutoHover(), 2000);	
								});								
							});
						});
						break;
				};
			});
			
			jQuery(document).on('click', '#frontpageSlider-prev', function(e) {
				if ($cnt.is(':animated'))
					return false;

				clearTimeout(timer);
				jQuery.when(frontpageSlide(-1)).done(function(){
					setTimeout(frontpageSliderAutoHover(), 2000);
				});
	        });
			
			jQuery(document).on('click', '#frontpageSlider-next', function(e) {
				if ($cnt.is(':animated'))
					return false;

				clearTimeout(timer);
				jQuery.when(frontpageSlide(1)).done(function(){
					setTimeout(frontpageSliderAutoHover(), 2000);
				});
	        });
		};

		return {
			rebuildScenes	: rebuildScenes,
			init 			: init
		};
	})();

    jQuery(function() {
		page.init();
	});
})(jQuery);

function showMap(point) {
	var pointSet 	 = jQuery('#maplinks a').eq(jQuery('#maplinks a').data('active')).data('pointLatlng').split(','),
		point_marker = new google.maps.LatLng(pointSet[0],pointSet[1]),
		point 		 = new google.maps.LatLng(pointSet[0],parseFloat(pointSet[1])+0.003),
		mapOptions = {
			disableDefaultUI	: true,
			scaleControl		: false,
			zoom				: 16,
			center				: point,
			mapTypeId			: google.maps.MapTypeId.ROADMAP
		},
		image = new google.maps.MarkerImage(basePath + 'img/bg-map-marker.png',
			new google.maps.Size(93,73),
			new google.maps.Point(0,0),
			new google.maps.Point(27,73)
		),
		map = new google.maps.Map(document.getElementById('map'), mapOptions),
		marker = new google.maps.Marker({
			draggable	: false,
			clickable	: false,
			icon		: image,
			map			: map,
			position	: point_marker
		});
	google.maps.event.addListener(map, 'bounds_changed', function() { 
		setTimeout(function() {
			jQuery('#map > div > div').eq(1).css({'bottom': 10+'px'}).end()
									  .eq(2).css({'bottom': 10+'px'});
		}, 2000);
	}); 
};
