var social = {
	el: null,
	controller: null,
	angle: 0,
	startAngle: 0,
	slices: Math.PI/6,	// 12 slices
	originX: 160,
	originY: 160,
	values: { 11: 'Digg', 10: 'Reddit', 9: 'Newsvine', 8: 'Delicious', 7: 'Stumbleupon', 6: 'Facebook', 5: 'friendfeed', 4: 'Mixx', 3: 'MySpace', 2: 'Netvibes', 1: 'Technorati', 0: 'Twitter' },

	handleEvent: function (e) {
		if (e.type == 'touchstart') {
			this.rotateStart(e);
		} else if (e.type == 'touchmove') {
			this.rotateMove(e);
		} else if (e.type == 'touchend') {
			this.rotateStop(e);
		}
	},

	init: function() {
		this.el = document.getElementById('social');
		this.controller = document.getElementById('display1');
		this.el.style.webkitTransitionDuration = '0';
		
		this.controller.addEventListener('touchstart', this, false);
	},
	
	rotateStart: function(e) {
		e.preventDefault();
		
		this.el.style.webkitTransitionDuration = '0';
		
		var startX = e.touches[0].pageX - this.originX;
		var startY = e.touches[0].pageY - this.originY;
		this.startAngle = Math.atan2(startY, startX) - this.angle;
		
		this.controller.addEventListener('touchmove', this, false);
		this.controller.addEventListener('touchend', this, false);
	},
	
	rotateMove: function(e) {
		var dx = e.touches[0].pageX - this.originX;
		var dy = e.touches[0].pageY - this.originY;
		this.angle = Math.atan2(dy, dx) - this.startAngle;

		this.el.style.webkitTransform = 'rotateZ(' + this.angle + 'rad)';
	},
	
	rotateStop: function(e) {
		this.controller.removeEventListener('touchmove', this, false);
		this.controller.removeEventListener('touchend', this, false);
		
		if( this.angle%this.slices ) {
			this.angle = Math.round(this.angle/this.slices) * this.slices;
			this.el.style.webkitTransitionDuration = '150ms';
			this.el.style.webkitTransform = 'rotateZ(' + this.angle + 'rad)';
		}
	},
	
	getSelectedValue: function() {
		var selected = Math.floor(Math.abs(this.angle)/this.slices/12);
		if (this.angle < 0)
			selected = -selected;
		
		selected = Math.round(this.angle/this.slices) - selected*12;
		if (selected < 0)
			selected = 12 + selected;
			
		return [selected, this.values[selected]];
	}
};

function loaded() {
	window.scrollTo(0,0);
	var i, lis, theTransform, matrix;
	
	lis = document.getElementsByTagName('li');
	for(i=0; i<lis.length; i+=1) {
		theTransform = window.getComputedStyle(lis[i]).webkitTransform;
		matrix = new WebKitCSSMatrix(theTransform).translate(0, 100);
		lis[i].style.webkitTransform = matrix;
	}


function detectsocial() {

if (social.getSelectedValue() == "10,Reddit") 
	{  
	window.open('http://www.reddit.com/submit?url=' + encodeURIComponent(window.location));
	}
else if 	(social.getSelectedValue() == "11,Digg") 
	{  
	window.open('http://digg.com/submit?url='+document.location.href+'&title='+document.title);
	}
else if (social.getSelectedValue() == "9,Newsvine")
	{
	window.open('http://www.newsvine.com/_tools/seed&save?u='+document.location.href+'&T='+document.title);
	}
else if (social.getSelectedValue() == "8,Delicious")
	{
	window.open('http://del.icio.us/post?v=2&url='+encodeURIComponent(document.location.href)+'&title='+encodeURIComponent(document.title));
	}
else if (social.getSelectedValue() == "7,Stumbleupon")
	{
	window.open('http://www.stumbleupon.com/submit?url='+encodeURIComponent(document.location.href)+'&title='+encodeURIComponent(document.title));
	}
else if (social.getSelectedValue() == "6,Facebook")
	{
	window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(document.location.href)+'&t='+encodeURIComponent(document.title));
	}
else if (social.getSelectedValue() == "5,friendfeed")
	{
	window.open('http://friendfeed.com/share/?url='+encodeURIComponent(document.location.href)+'&title='+encodeURIComponent(document.title));
	}
else if (social.getSelectedValue() == "4,Mixx")
	{
	window.open('http://www.mixx.com/submit?page_url='+window.location);
	}
else if 	(social.getSelectedValue() == "3,MySpace") 
	{  
	window.open('http://www.myspace.com/index.cfm?fuseaction=postto&' + 't=' +encodeURIComponent(document.title)+ '&u=' +encodeURIComponent(document.location.href));
	}
else if 	(social.getSelectedValue() == "2,Netvibes") 
	{  
	window.open('http://www.netvibes.com/subscribe.php?type=rss&url='+encodeURIComponent(document.location.href));
	}
else if 	(social.getSelectedValue() == "1,Technorati") 
	{  
	window.open('http://technorati.com/faves?sub=addfavbtn&add='+encodeURIComponent(document.location.href));
	}
else if 	(social.getSelectedValue() == "0,Twitter") 
	{  
	TwitThis.pop()
	}
else
   {
   alert("Good Evening dear visitor");
   }
   
	}
	
	
	social.init();
	
	document.getElementById('ok').addEventListener('click', detectsocial , false);
}
window.addEventListener("load", function() { setTimeout(loaded, 100); }, true);