

window.log = function(){
	log.history = log.history || [];   // store logs to an array for reference
	log.history.push(arguments);
	arguments.callee = arguments.callee.caller; 
	if(this.console) console.log( Array.prototype.slice.call(arguments) );
};
(function(b){function c(){}for(var d="assert,count,debug,dir,dirxml,error,exception,group,groupCollapsed,groupEnd,info, log,markTimeline,profile,profileEnd,time,timeEnd,trace,warn".split(","),a;a=d.pop();)b[a]=b[a]||c})(window.console=window.console||{});

jQuery(function(){  
	$ = jQuery;

	
});



function resize_background()
{   
	var bg = $('#background .background-image');
	
	var ratio = 8/5;
	bg.width($(window).width());
	bg.height($(window).width() / ratio);
	
	if (bg.height() < $(window).height()) {
		bg.height($(window).height());
		bg.width($(window).height() * ratio);
	}
	
}	

function setSectionPadding(){
	var sectionLength = $(".section").length;
	if(sectionLength == 0) return;
	var winHeight = $(window).height();
	var mainHeight = $('#main').outerHeight();
	var lastSection = $('.section.last');
	var sectionH = 0;

	$('.section').each(function(index){
			sectionH += $(this).outerHeight();
		});
	sectionH -= lastSection.outerHeight();
	var pb = parseInt(lastSection.css('padding-bottom').replace("px", ""));
	
	var buffer = sectionH-(mainHeight-winHeight);
	var padding = buffer+pb;
	lastSection.css('padding-bottom', ""+padding+"px"); 
	
}

$(window).bind('resize', resize_background);
$(window).bind('resize', setSectionPadding);

$(document).ready(function(){
	

	setSectionPadding();

	$("#sidebar-left a").click(function(){
			$("#sidebar-left a").removeClass('active');
			$("#sidebar-left li").removeClass('active');
			$(this).addClass('active');
			$(this).parent().addClass('active');		
		});
	
	$("#sidebar-left a:first").addClass('active');
	$(".menu-event:first").addClass('active');
	
	
	$(window).scroll(function(){
		var scrolltop = $(this).scrollTop();
		var l = $(".section").length;
		var eventMenuLength = $(".menu-event").length;
		
		for(var i=0;i<l;i++){
			if($(".section:eq("+i+")").offset().top - scrolltop < 200){
				if(eventMenuLength > 0){
					$(".menu-event").removeClass('active');
					$(".menu-event:eq("+i+")").addClass('active');
				}else{
					$("#sidebar-left a").removeClass('active');
					$("#sidebar-left a:eq("+i+")").addClass('active');
				}
			}
		}
	});
	
	
	resize_background();
	

});

var appname = navigator.appName;

$(window).load(function(){
	var useHash = (appname == 'Opera') ? false : true;
	
	$.localScroll.hash({
        target: 'body', // Could be a selector or a jQuery object too.
        queue:true,
        duration:1000,
		easing:'easeOutQuint'
    });
	
	$.localScroll({
        target: 'body', // could be a selector or a jQuery object too.
        queue:true,
        duration:1000,
        hash:useHash,
		easing:'easeOutQuint',
        onBefore:function( e, anchor, $target ){
            // The 'this' is the settings object, can be modified
        },
        onAfter:function( anchor, settings ){
            // The 'this' contains the scrolled element (#content)
        }
    });	
});
