
var name_1 = "#background";
var name_2 = "#sidebar";
var name_3 = "#background_overlay";
var menuYloc_1 = null;
var menuYloc_2 = null;
var i = 0;

$(document).ready(function(){
	/*
	menuYloc_1 = parseInt($(name_1).css("top").substring(0,$(name_1).css("top").indexOf("px")))
	menuYloc_2 = parseInt($(name_2).css("top").substring(0,$(name_2).css("top").indexOf("px")))
	*/

	if($.browser.msie && ($.browser.version=="6.0" || $.browser.version=="7.0")){
     		$(".browser").css('visibility','visible');
  		}else{ 
  			$(".browser").css('visibility','hidden');
  	}
  		
	menuYloc_1 = parseInt($(name_1).css("top").substring(0,$(name_1).css("top").indexOf("px")))
	
	PositionElements();
	$(window).resize(PositionElements);
	$('#background_overlay_objects').css('opacity','0');
	$("a").hover(function(){$(this).fadeOut(50);$(this).fadeIn(50);});
	
			


	
	function PositionElements(){
		//$("#background").height(764);
		//$("#background").width(1200);
		//$('#output').html(height);
	
		$('.item').width($(window).width()-245);
		$('.item img').width(1000);
		
		
	
		if($(window).width()<1180){
			var percentage = (($(window).width()/1180));
			
			var width = 1000 * (percentage);
		
			var widthDesc = 180 * (percentage);
			var imageX = - ((percentage)-1)*80;
			var x = 735 * (percentage-0.020);
			var itemHeight = $('.item').height() + ((percentage)-1)*80;
			
			$('.description').css('margin-left',x);
			$('.item img').width(width);
			//$('.item').height(itemHeight);
			$('.item img').css('margin-left',imageX);
			$('.description').width(widthDesc);
			//$('.item').css('height',height);
			
		}else{
			$('.description').css('margin-left','735px');
			$('.description').css('width','200px');
		}
	}
	
	$(window).scroll(function (event) { 
		offset_1 = menuYloc_1+$(document).scrollTop()+"px";
		
		percentage = ($(this).scrollTop()/$('#content').height())*2;
		$('#background_overlay_objects').fadeIn('slow', function() {});
		
		$('#background_overlay_objects').css('opacity',percentage*2);
		$('#background_overlay_objects').animate({top:-percentage*500,left:(percentage*500)-1000 }, 0, 'swing', function() {});
		$('#background_overlay').animate({top:-percentage*500}, 50, 'swing', function() {});

		
		post0_height = $('#post-0').height() + 110 ;
		post1_height = $('#post-1').height() + 110 ;
		post2_height = $('#post-2').height() + 110 ;
		post3_height = $('#post-3').height() + 110 ;
		post4_height = $('#post-4').height() + 110 ;
		post5_height = $('#post-5').height() + 110 ;
		post6_height = $('#post-6').height() + 110 ;
		post7_height = $('#post-7').height() + 110 ;
		post8_height = $('#post-8').height() + 110 ;
		post9_height = $('#post-9').height() + 110 ;
				
		post0_center = post0_height/2 - $(window).height()/2;
		post1_center = (post0_height + post1_height/2) - $(window).height()/2;
		post2_center = (post0_height + post1_height + post2_height/2) - $(window).height()/2;
		post3_center = (post0_height + post1_height + post2_height + post3_height/2) - $(window).height()/2;
		post4_center = (post0_height + post1_height + post2_height + post3_height + post4_height/2) - $(window).height()/2;
		post5_center = (post0_height + post1_height + post2_height + post3_height + post4_height + post5_height/2) - $(window).height()/2;
		post6_center = (post0_height + post1_height + post2_height + post3_height + post4_height + post5_height + post6_height/2) - $(window).height()/2;
		post7_center = (post0_height + post1_height + post2_height + post3_height + post4_height + post5_height + post6_height + post7_height/2) - $(window).height()/2;
		post8_center = (post0_height + post1_height + post2_height + post3_height + post4_height + post5_height + post6_height + post7_height + post8_height/2) - $(window).height()/2;		
		post9_center = (post0_height + post1_height + post2_height + post3_height + post4_height + post5_height + post6_height + post7_height + post8_height + post9_height/2) - $(window).height()/2;	
		
		if($(this).scrollTop() < post0_center){			
			opacity = 1;
			$('#post-0').css('opacity', opacity);
			$('#post-1').css('opacity', 1-opacity);
		}
		
		
		if($(this).scrollTop() < post1_center && $(this).scrollTop()> post0_center){
			opacityFactor = 1/(post0_height/2 + post1_height/2);
			
			opacity = 1 + ($(this).scrollTop() - post1_center) * opacityFactor;
			
			$('#post-0 img').css('opacity', 1-opacity);
			$('#post-1 img').css('opacity', opacity*1.5);
		}
		
		
		if($(this).scrollTop() < post2_center && $(this).scrollTop()> post1_center){
			opacityFactor = 1/(post1_height/2 + post2_height/2);
			
			opacity = 1 + ($(this).scrollTop() - post2_center) * opacityFactor;
			
			$('#post-1 img').css('opacity', 1-opacity);
			$('#post-2 img').css('opacity', opacity*1.5);
		}
		
		if($(this).scrollTop() < post3_center && $(this).scrollTop()> post2_center){
			opacityFactor = 1/(post2_height/2 + post3_height/2);
			
			opacity = 1 + ($(this).scrollTop() - post3_center) * opacityFactor;
			
			$('#post-2 img').css('opacity', 1-opacity);
			$('#post-3 img').css('opacity', opacity*1.5);
		}
		
		
		if($(this).scrollTop() < post4_center && $(this).scrollTop()> post3_center){
			opacityFactor = 1/(post3_height/2 + post4_height/2);
			
			opacity = 1 + ($(this).scrollTop() - post4_center) * opacityFactor;
			
			$('#post-3 img').css('opacity', 1-opacity);
			$('#post-4 img').css('opacity', opacity*1.5);
		}
		
		
		if($(this).scrollTop() < post5_center && $(this).scrollTop()> post4_center){
			opacityFactor = 1/(post4_height/2 + post5_height/2);
			
			opacity = 1 + ($(this).scrollTop() - post5_center) * opacityFactor;
			
			$('#post-4 img').css('opacity', 1-opacity);
			$('#post-5 img').css('opacity', opacity*1.5);
		}
		
		if($(this).scrollTop() < post6_center && $(this).scrollTop()> post5_center){
			opacityFactor = 1/(post5_height/2 + post6_height/2);
			
			opacity = 1 + ($(this).scrollTop() - post6_center) * opacityFactor;
			
			$('#post-5 img').css('opacity', 1-opacity);
			$('#post-6 img').css('opacity', opacity*1.5);
		}

		if($(this).scrollTop() < post7_center && $(this).scrollTop()> post6_center){
			opacityFactor = 1/(post6_height/2 + post7_height/2);
			
			opacity = 1 + ($(this).scrollTop() - post7_center) * opacityFactor;
			
			$('#post-6 img').css('opacity', 1-opacity);
			$('#post-7 img').css('opacity', opacity*1.5);
		}
		
		if($(this).scrollTop() < post8_center && $(this).scrollTop()> post7_center){
			opacityFactor = 1/(post7_height/2 + post8_height/2);
			
			opacity = 1 + ($(this).scrollTop() - post8_center) * opacityFactor;
			
			$('#post-7 img').css('opacity', 1-opacity);
			$('#post-8 img').css('opacity', opacity*1.5);
		}
		
		if($(this).scrollTop() < post9_center && $(this).scrollTop()> post8_center){
			opacityFactor = 1/(post8_height/2 + post9_height/2);
			
			opacity = 1 + ($(this).scrollTop() - post9_center) * opacityFactor;
			
			$('#post-8 img').css('opacity', 1-opacity);
			$('#post-9 img').css('opacity', opacity*1.5);
		}
		
		

		
	});
	
	/*
	var img = new Image();
	$(img).load(function () {
    	//$(this).css('display', 'none'); // .hide() doesn't work in Safari when the element isn't on the DOM already
    	$(this).hide();
    	$('#1').removeClass('item').append(this);
    	$(this).css('background-image','url(http://farm3.static.flickr.com/2405/2238919394_4c9b5aa921_o.jpg)');
    	$(this).fadeIn();
	}).error(function () {
    	// notify the user that the image could not be loaded
	}).attr('src', 'http://farm3.static.flickr.com/2405/2238919394_4c9b5aa921_o.jpg');
	*/
}); 

