var slideShowEasing = "easeOutExpo";
var slideDuration = 2500;
var slideSpeed = 1000;

mainInit = function(){
	
	
	
	
	lmnopj.scroll.onScroll();
	initSlideShows();
	initFancyBox();
	initEntryProperties();
	highlightContent();
	
	window.onscroll = window.onresize = function() {
		lmnopj.scroll.onScroll();
		highlightContent();
	}
}

initEntryProperties = function(){
	$(".entry-item").each(function(){
      var yy = $(this).offset().top;
      var cp = yy + Math.round($(this).height()*0.5);
      var bp = yy + $(this).height();
      $(this).data("pos", { "orgY":yy, "centerpoint":cp, "bottompoint":bp, "isActive":false});
	  $(this).fadeTo(1, 0.5);
    })
}

initSlideShows = function(){
	
	$(".entry-image").show();
	
	$(".image-slide-show").slides({
		play:slideDuration,
		generatePagination:false,
		bigTarget:true,
		slideSpeed:slideSpeed,
		slideEasing:slideShowEasing
	 });
}

initFancyBox = function(){
	$(".vimeo-window").fancybox({
		'width'				: 900,
		'height'			: 506,
		'autoScale'			: false,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe'
	});
}

highlightContent = function(){
	 $(".entry-item").each(function(){
        if($(this).data("pos").bottompoint >= lmnopj.scroll.windowScroll && $(this).data("pos").orgY <= lmnopj.scroll.windowScroll+lmnopj.scroll.windowH ){
          perc = (($(this).data("pos").centerpoint - lmnopj.scroll.windowScroll) /  lmnopj.scroll.windowH)-0.5;
          percThrottle = 0.4;
          if(Math.abs(perc) < percThrottle && $(this).data("pos").isActive == false){
            $(this).data("pos").isActive = true;
			$(this).fadeTo("slow", 1);
          }else if(Math.abs(perc) > percThrottle && $(this).data("pos").isActive == true){
			$(this).data("pos").isActive = false;
			$(this).fadeTo("slow", 0.5);
		  }
        }
       });
}


if (typeof lmnopj == "undefined") var lmnopj = new Object();

lmnopj.scroll = {
  windowW: 0,
  windowH : 0,
  windowScroll : 0,
  paralaxAmount : 300,

  onScroll : function(){
    lmnopj.scroll.calculateWidthHeightScroll();
  },

  calculateWidthHeightScroll : function(){
    var winW = 1024, winH = 768;
		var winScroll = 0;
		if (document.body && document.body.offsetWidth) {
		 winW = document.body.offsetWidth;
		 winH = document.body.offsetHeight;
		}
		if (document.compatMode=='CSS1Compat' &&
			document.documentElement &&
			document.documentElement.offsetWidth ) {
		  winW = document.documentElement.offsetWidth;
	 	 winH = document.documentElement.offsetHeight;
		}

		if (window.innerWidth && window.innerHeight) {
		 winW = window.innerWidth;
		 winH = window.innerHeight;
		}

		if(window.scrollY) {
			winScroll = window.scrollY;
		} else if(document.documentElement.scrollTop) {
			winScroll = document.documentElement.scrollTop;
		}

		lmnopj.scroll.windowW = winW;
		lmnopj.scroll.windowH = winH;
		lmnopj.scroll.windowScroll = winScroll;		
  }
}

