
var Omana = {
	initPage: function(){
		this.settings();
		this.loading(true);
		this.initNavi();
		this.initExternalLink();
		this.initParallax();
	},
	initNavi: function(){
		var menuLinks = $('#menu a');
		
		menuLinks.bind('click', function(){
			var self = this;
			$.scrollTo( self.hash, 1000,{ 
				onAfter:function(){ location.hash = self.hash}
			});
			
			return false;
		});
		
		$('.logo a').click(function(){
			$.scrollTo( $('body'), 1000);
			location.hash = this.hash
		});

		$(document).bind('scroll', function(){
			var pagesCords = [];
			
			for(var i = 0; i < menuLinks.length; i++){
				var pagePosition = $(menuLinks.eq(i).attr('href')+'-wrap').position();
				pagesCords.push(parseInt(pagePosition.top, 10))
				
			}
			
			var navi = $('#navegacion');
			var position = navi.position();
			
			for(var i = 0; i < pagesCords.length; i++){
				
				if(position.top >= pagesCords[i] && position.top < pagesCords[i+1]){
					menuLinks.removeClass('active');
					menuLinks.eq(i).addClass('active');
				}
				
			}
			

			if(position.top < pagesCords[0]){
				menuLinks.removeClass('active');
			}else if(position.top >= pagesCords[7]){
				menuLinks.removeClass('active');
				menuLinks.eq(7).addClass('active');
			}
		});
	},
	
	
		
		
	
	
	initExternalLink: function(){
		var anchors = $('a');
		for (var i=0; i<anchors.length; i++) {
			var anchor = anchors[i];
			if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external")
				anchor.target = "_blank";
		}
	},
	settings: function(){
		this.loaderImage = '';
		this.loader = $();
	},
	loading: function(bool, place) {
		var self = this;
		if(bool) {
			var loaderPosition = place || 'body';
			$(loaderPosition).prepend(self.loader);
			self.loader.show();
		} else {
			var delay = setTimeout(function() {
                self.loader.remove();
            }, 500);
			
		};
	},
	
	initParallax: function(){
		$('#visual-2').parallax({
	      'elements': [
	        {
	          'selector': '.aegon-eye',
	          'properties': {
	            'x': {
	              'background-position-x': {
	                'initial': 70,
	                'multiplier': 0.05,
	                'unit': '%',
	                'invert': false
	              }
	            },
	            'y': {
	              'background-position-y': {
	                'initial': 50,
	                'multiplier': 0.12,
	                'unit': '%',
	                'invert': false
	              }
	            }
	          }
	        }
	      ]
	    });
	}
};

$(function(){
	Omana.initPage();
	Omana.loading(false);
});

if ($.browser.msie && $.browser.version < 7 ){
	alert('Oops! Your browser is too old to handle this website. Please upgrade to a modern browser. IE6 was built for an era that did not anticipate sites like Google Maps and YouTube, and long before Twitter and iPhone rocked our world. Modern web browsers are safer, more productive, and better equipped for todays content and applications. If your IT department still requires you to use IE6, consider asking them for an upgrade.');
	location.href = 'http://www.google.com/chrome'
}


