// JavaScript Document
$(document).ready(function(){
	// topc is the top in px of the first section after header
	var topc = 202;
	if($.client.os == "Windows"){
		if($.client.browser == "Safari" || $.client.browser == "Chrome"){
			topc = 212;
		}
	}
	
	var socialClasses = ['social1', 'social2', 'social3', 'social4'];
	$('#social li').each(function(index) {
		//alert(index + ': ' + $(this).text());
		$(this).addClass(socialClasses[index]);
		$(this).hover(
			function () {
				$(this).stop(true);
				$(this).animate({ opacity: 0.25 }, 500, function() {
					// Animation complete.
				});
			}, 
			function () {
				$(this).stop(true);
				$(this).animate({ opacity: 1 }, 500, function() {
					// Animation complete.
				});
			}
		);
	});
		
	var vtop = topc - $(window).scrollTop();
	var center = $(window).width() / 2;
	var wrapperm = $("#wrapper").width() / 2;
	
	var pright = center - wrapperm - 60;
	
	if(vtop < 30){
		vtop = 30;
		$('div#toTop').stop(true,true).css('cursor','pointer').animate({opacity:1},500,'swing');
	}else{
		$('div#toTop').stop(true,true).css('cursor','default').animate({opacity:0},500,'swing');
	}
	
	$('#social').css({"top":vtop, "right":pright});
	$('div#toTop').css({"top":vtop+114, "right":pright});
	
	$('div#toTop').click(function() {
		$('html, body').animate({ scrollTop: 0 }, 'slow', 'swing');
	});
	
	$(window).scroll(function() {
		// 197 is the top in px of the first section after header
		var vtop = topc - $(window).scrollTop();
		var center = $(window).width() / 2;
		var wrapperm = $("#wrapper").width() / 2;
		
		var pright = center - wrapperm - 60;
		
		if(vtop < 30){
			vtop = 30;
			$('div#toTop').stop(true,true).css('cursor','pointer').animate({opacity:1},500,'swing');
		}else{
			$('div#toTop').stop(true,true).css('cursor','default').animate({opacity:0},500,'swing');
		}
		
		if(vtop < 30){
			$('#social').css({"top":vtop, "right":pright});
			$('div#toTop').css({"top":vtop+114, "right":pright});
		}else{
			$('#social').stop(true,true).animate({top:vtop},'fast','swing');
			$('div#toTop').stop(true,true).animate({top:vtop+114},'fast','swing');			
		}		
	});
	
	$(window).resize(function() {
		var vtop = topc - $(window).scrollTop();
		var center = $(window).width() / 2;
		var wrapperm = $("#wrapper").width() / 2;
		
		var pright = center - wrapperm - 60;
		
		if(vtop < 30){
			vtop = 30;
			$('div#toTop').stop(true,true).css('cursor','pointer').animate({opacity:1},500,'swing');
		}else{
			$('div#toTop').stop(true,true).css('cursor','default').animate({opacity:0},500,'swing');
		}
		
		$('#social').css({"top":vtop, "right":pright});
		$('div#toTop').css({"top":vtop+114, "right":pright});
	});
	
	
});
