$().ready(function() {

	
	//alert($('.sub').height() - $('.content').height());
	
	//fix name
	$('.positionTop').each(function(){
		$(this).css('left', $(this).css('left').replace('px','')*1 + $('.top').offset().left);
	});



	$('.ico').hover(function(){
		$('span', $(this)).fadeIn();
		$('img', $(this)).animate({opacity: 0.9}, 'slow');
	}, function(){
		$('span', $(this)).fadeOut();
		$('img', $(this)).animate({opacity: 0.3}, 'slow');
	})


	//everything but IE
	if($.browser.ie == undefined){


		$('*[data-fadedscroll]').each(function(){
			$(this).css('opacity', 0);
		});

		
		window['onscroll'] = function(){
			opacity();
		}
	//	repeatOpacity();

		$(window).resize(function(){
			place();

	//		location.reload(true);

		});


setTimeout(function(){
		opacity();
		place();


},10)
	
	}else{
		$('.positionTop').addClass('noAnimate');
		$('.positionTop').css('top',$(window).height() + 125);
		$(window).resize(function(){
			$('.positionTop').css('top',$(window).height() +'px');
			//fix name
			$('.positionTop').each(function(){
			$(this).css('left', 520 + $('.top').offset().left);
		});




		})

		$('.footer').append($('<span>Try Firefox or Safari for the effect!</span>'))
	}
$('.content').css('margin-top', $('.sub').height() - $('.content').height());
});


function place(){

	$('.positionTop').each(function(){
		$(this).css('left', 524+  $('.top').offset().left +'px').css('position', 'fixed');
	});





	if($('.positionTop').css('top').replace('px','') < 56){
		$('.positionTop').css('top', '56px');

	}else{
		//$('.positionTop').css('top', '');
	}

	$('.top:not(.back)').css('height', ($('.topWrap').height()));


	$('.positionTop').css('margin-top', ($('.topWrap').height()-$('.top').height()));

	if(navigator.platform == 'iPad' || navigator.platform == 'iPhone' || navigator.platform == 'iPod'){
		$('.positionTop').addClass('mobile');
	}



}


function opacity(){
	var number = $(document).scrollTop();

	$('*[data-fadedscroll]').each(function(){
		var opacity = number / $(this).attr('data-fadedscroll') ;
		if(opacity > 1)
			opacity = 1
		//$(this).html(opacity);
		$(this).css('opacity', opacity);
	});
}

