// share script

//CBS.OAS.BLOG{}

$(function(){



	/* SHOW BOOKMARKS */
	jQuery(".share").toggle(
		function(){
			//alert('toggle being called');
			jQuery(this).addClass('on');
			jQuery(this).animate({width:"+=320px"}, 1000);
			jQuery(this).find('.bookmarks').fadeIn(1000);
			jQuery(this).find('.bookmarks li').fadeIn(1000);
			
			jQuery(this).find('.controller').html('-');
			
		},
		
		function(){

		//	count++;
		//	alert("count is: " + count);
			
			jQuery(this).removeClass('on');
			jQuery(this).animate({width:"-=320px"}, 1000);
			jQuery(this).find('.bookmarks').fadeOut(1000);
			jQuery(this).find('.bookmarks li').fadeOut(1000);

			jQuery(this).find('.controller').html('+');

		}		
	);
	//end toggle



	//share button
	jQuery('.share .button').bind('click', function(){
	
		//grab the entry ID value from the share button. and store it so it can be used to refer to other values.
		// this creates a more direct chain vs. using $(this).parent().parent().parent().find('.entry-title').text();
		var name = '#' + jQuery(this).parent('.share').attr('name');
		
		//Store the values from the current entry as variables to pass to article share function,
		var title 			= 	escape(jQuery(name + ' .entry-title').text());
		var URL 			=	escape(jQuery(name + ' .entry-title a').attr('href'));
		var description 	= 	escape(jQuery(name + ' .asset-body p:first').text());
		var pub_date 		=	escape(jQuery(name + ' .published').text());	

	

		
		
		shareArticle = function(network){
				
			function share_popup(url, name, params) {
				var win = window.open(url, name, params);
			}		
	
			var openers = {
			
				facebook : function() {
						share_popup('http://www.facebook.com/sharer.php?u=' + URL + '&t=' + title, 'facebook', 'toolbar=0,status=0,height=436,width=646,scrollbars=yes,resizable=yes');
				},
				
				digg : function () {
						share_popup('http://digg.com/remote-submit?phase=2&url=' + URL + '&title=' + title + '&bodytext=' + description, 'digg', 'toolbar=0,status=0,height=450,width=650,scrollbars=yes,resizable=yes');
				},
				
				delicious : function () {
						share_popup('http://del.icio.us/post?v=4&partner=CBSsports&noui&jump=close&url=' + URL + '&title=' + title + '&bodytext=' + description, 'delicious', 'toolbar=0,status=0,height=400,width=700,scrollbars=yes,resizable=no');
				},
	
				myspace: function () {
					share_popup('http://www.myspace.com/index.cfm?fuseaction=postto&u=' + URL + '&t=' + title + '&c=' + description, 'myspace', 'toolbar=0,status=0,height=436,width=880,scrollbars=yes,resizable=yes');
				},
	
				yahoobuzz : function () {
						share_popup( 'http://buzz.yahoo.com/buzz?publisherurn=CBSsports&targetUrl=' + URL, 'yahoobuzz', 'scrollbars=yes,resizable=yes');
				},
		
				mixx : function () {
						share_popup( 
						   'http://mini.mixx.com/submit/story'
						   + '?page_url='    + URL
						   + '&title='       + title
						   + '&partner='     + 'CBSsports'
						   ,
						   'mixx',
						   'toolbar=0,status=0,height=550,width=700,scrollbars=yes,resizable=no'
						);
				},
		
				linkedin : function () {
					share_popup(
					 'http://www.linkedin.com/shareArticle?mini=true'
					   + '&url='         + URL
					   + '&title='       + title
					   + '&summary='     + description
					   + '&source='      + 'CBS Sports'
					   ,
					   'Linkedin',
					   'toolbar=0,status=0,height=550,width=700,scrollbars=yes,resizable=no'
					);
				},
				
				reddit : function(){
					share_popup('http://www.reddit.com/submit?url=' + URL,'reddit','scrollbars=yes,resizable=yes');
				
				},
				
				googlebookmark : function(){
					share_popup('http://www.google.com/bookmarks/mark?op=edit&output=popup&bkmk=' + URL + '&title=' + title,
					'googlebookmarks',
					'toolbar=0,status=0,height=420,width=550,scrollbars=yes,resizable=no'
					)
				},
				
				stumbleupon : function(){
					share_popup('http://www.stumbleupon.com/submit?url=' + URL,
					'stumbleupon',
					'toolbar=0,status=0,height=420,width=550,scrollbars=yes,resizable=no'
					)
				},
				
				twitter : function(){
					share_popup('http://twitter.com/home?status=' + title + ': ' + URL);
				}
			
			}
		
			openers[network]();
		
		}		
	

		/* use this to help with share button */
		jQuery(".share .bookmarks li").click(function(){		

			//pass var to appropriate function based on li attribute name
			shareArticle(jQuery(this).attr('name'));
									

		});
		//end share article
		
			
	});	
	//end click
	
});	
//end function()