jQuery(document).ready(function(){
	
	
	if(!(navigator.platform == 'iPad' || navigator.platform == 'iPhone' || navigator.platform == 'iPod')) 
	{
		jQuery.stickyBar($('.main_navigation'));
	}
	
	$('.main_navigation a, .bottom_nav_wrapper a').
    click(function(){
        var target = $($(this).attr('href'));
        var hash = $(this).attr('href');
        if (target.length)
        {
            var top = target.offset().top;
            $('html,body').animate({scrollTop: top}, 1000,function(){ document.location.hash = hash; });
            return false;
        }
    });
    
	
	jQuery(window).resize(function(){
		jQuery(document).scrollTo(document.location.hash,0);
	})
	var pos = 0;
	
	jQuery(window).scroll(function(){
		var navPosition = jQuery(".main_navigation").offset();
		var windowHalf = Math.round(jQuery(window).height()/2);
		
		
		/** paralax scroll **/
		
		var pos = Math.round(-navPosition.top/2);

		jQuery("#glocal").css({backgroundPosition:"0px "+pos+"px"});
		
		jQuery(".slide").each(function(index){
			var slidePosition = jQuery(this).offset();
			var slideHeight = jQuery(this).height();
			var id = jQuery(this).attr("id");
			var btn = jQuery('a[href$="'+id+'"]');
			
			
			if(navPosition.top+windowHalf  > slidePosition.top && navPosition.top+windowHalf < slidePosition.top + slideHeight)
			{
				btn.addClass("active");
			}
			else
			{
				btn.removeClass("active");
			}
			
				
		});
		
	})
	
	middle()
	function middle()
	{
		 jQuery(".middle").each(function(index){
		 	var middleHeight = jQuery(this).height()/2;
			jQuery(this).attr("style","position:absolute; top:50%; margin-top:-"+middleHeight+"px");
		 })
	}
	
});



