/* jSocialize - bookmark tool ©2008 artViper designstudio - all rights reserved */
/* information about this tool and other widgets: info@artviper.net  */
/* the header 'artViper's social bookmark widget has not to be removed */
/* same goes for the link to this tool */
/* add these lines to your document, to make this script work: */
/* <script language="javascript" type="text/ecmascript" src="js/jquery.js"></script>
<script language="javascript" type="text/ecmascript" src="js/jquery.dimensions.js"></script>
<script language="javascript" type="text/ecmascript" src="js/jSocialize.js"></script>
<img src="my_socializer.gif" class="socializer" autoEncode="1"  title="In The News" alt="http://www.espn.com" />
*/

$(document).ready(function() {
	$(".socializer").each(function(i, objElem){
		//jQuery(this, i).socialize();
		$(objElem).socialize();
	});
});

jQuery.fn.socialize = function(settings) {
		settings = jQuery.extend({
		url: null, 
		title: null,
		autoEncode: 1
		}, settings);		
		jQuery(this).click(function () { 
				if ($('#socializer_container'))
					$('#socializer_container').remove();
				
				var top 	= jQuery(this).offset().top;
				var height	= jQuery(this).height();
				var left	= jQuery(this).offset().left;
				var pos 	= top+height+20;
				
				var div = document.createElement("div");
				$(div).hide();
				$(div).attr({ id: "socializer_container"});
				$(div).addClass("socializer_container");
				$(document.body).prepend(div);
				//$(div).left = left;
				$(div).css('left',left+'px');
				$(div).css('top',top+'px');
				
				var closeme = document.createElement('img');
				$(closeme).attr({ id: "socializer_close", src: "/scripts/socializer/images/close.gif"});
				$(closeme).addClass('socializer_close');
				$(div).append(closeme);
				
				$(closeme).click(function(){
					$(div).remove();
				})
				
				var eurl = '';
				var etitle = '';

				var eautoEncode = 1; 
				if (typeof(jQuery(this).attr("socAutoEncode")) != 'undefined' && jQuery(this).attr("socAutoEncode")=='1')
					eautoEncode = 1;
				else if (typeof(jQuery(this).attr("socAutoEncode")) != 'undefined' && jQuery(this).attr("socAutoEncode")=='0')
					eautoEncode = 0;
				else
					eautoEncode = settings.autoEncode;
				if (typeof(jQuery(this).attr("socTitle")) != 'undefined') settings.title = jQuery(this).attr("socTitle");
				if (eautoEncode && settings.title != null) etitle = encodeURIComponent(settings.title);
				else etitle = settings.title;
				//if (settings.url.length<=1) settings.url = document.location.href;   
				if (typeof(jQuery(this).attr("socURL")) != 'undefined') settings.url = jQuery(this).attr("socURL"); 
				if (eautoEncode && settings.url != null) eurl = encodeURIComponent(settings.url);
				else if (!eautoEncode && settings.url != null) eurl = settings.url;
				else eurl = document.location.href;
				
				var name = document.createElement('h2');
				$(name).html('Choose a social network: <a href="'+decodeURIComponent(eurl)+'">[Link Share]</a>');
				$(div).append(name);
				
				function newsitearrayobj(name, image, hrefs) {
					this.name = name;
					this.image = image;
					this.hrefs = hrefs;
				}
				
				//http://www.addthis.com/bookmark.php
				//http://www.addtoany.com/share_save?linkurl=%2FMozilla-Daily%2FMozilla_Firefox_Group_at_Facebook&linkname=Mozilla+Firefox+Group+at+Facebook
				var sitearray = new Array();
				//sitearray.push(new newsitearrayobj('ask', 'ask.png', 'http://mystuff.ask.com/mysearch/QuickWebSave?v=1.2&t=webpages&url={URL}&title={TITLE}'));
				sitearray.push(new newsitearrayobj('ask', 'ask.png', 'http://myjeeves.ask.com/mysearch/BookmarkIt?v=1.2&t=webpages&url={URL}&title={TITLE}'));
				//backflip
				//ballhype
				//bebo
				//blogger
				//sitearray.push(new newsitearrayobj('blinklist', 'blinklist.png', 'http://blinklist.com/index.php?Action=Blink/addblink.php&Url={URL}&Name={TITLE}'));
				sitearray.push(new newsitearrayobj('blinklist', 'blinklist.png', 'http://blinklist.com/index.php?Action=Blink/addblink.php&Url={URL}&Title={TITLE}'));
				sitearray.push(new newsitearrayobj('blinkbits', 'blinkbits.png', 'http://blinkbits.com/bookmarklets/save.php?v=1&source_url={URL}&title={TITLE}'));
				sitearray.push(new newsitearrayobj('blogmarks', 'bmarks.png', 'http://blogmarks.net/my/new.php?mini=1&simple=1&url={URL}&title={TITLE}'));
				sitearray.push(new newsitearrayobj('bloglines', 'bloglines.png', 'http://www.bloglines.com/sub/{URL}'));
				//sitearray.push(new newsitearrayobj('bluedot', 'bluedot.png', 'http://bluedot.us/Authoring.aspx?u={URL}&t={TITLE}'));
				sitearray.push(new newsitearrayobj('bookmark.it', 'bookmark.gif', 'http://www.bookmark.it/bookmark.php?url={URL}'));
				sitearray.push(new newsitearrayobj('co.mments', 'comments.png', 'http://co.mments.com/track?url={URL}&title={TITLE}'));
				//sitearray.push(new newsitearrayobj('connotea', 'connotea.png', 'http://www.connotea.org/addpopup?continue=confirm&uri={URL}&title={TITLE}'));
				sitearray.push(new newsitearrayobj('del.icio.us', 'delicious.png', 'http://del.icio.us/post?url={URL}&title={TITLE}'));
				sitearray.push(new newsitearrayobj('digg', 'digg.png', 'http://digg.com/submit?phase=2&url={URL}&title={TITLE}'));
				//sitearray.push(new newsitearrayobj('diigo', 'diigo.gif', 'http://www.diigo.com/post?url={url}&title={title}'));
				sitearray.push(new newsitearrayobj('dzone', 'dzone.png', 'http://www.dzone.com/links/add.html?url={URL}&description={TITLE}'));
				//sitearray.push(new newsitearrayobj('dzone', 'dzone.png', 'http://www.dzone.com/links/add.html?url={URL}&title={TITLE}'));
				//evernote
				sitearray.push(new newsitearrayobj('facebook', 'facebook.gif', 'http://www.facebook.com/sharer.php?src=sc&pos=top&from_posted=1&u={URL}&t={TITLE}'));
				//sitearray.push(new newsitearrayobj('fark', 'fark.gif', 'http://cgi.fark.com/cgi/fark/submit.pl?new_url={URL}&new_comment={TITLE}'));
				//faves
				//friendfeed
				sitearray.push(new newsitearrayobj('feedmelinks', 'feedmelinks.png', 'http://feedmelinks.com/categorize?from=toolbar&op=submit&url={URL}&name={TITLE}'));
				sitearray.push(new newsitearrayobj('furl', 'furl.png', 'http://furl.net/storeIt.jsp?u={URL}&t={TITLE}'));
				sitearray.push(new newsitearrayobj('gabbr', 'gabbr.gif', 'http://www.gabbr.com/submit/?bookurl={URL}'));
				sitearray.push(new newsitearrayobj('google', 'google.png', 'http://www.google.com/bookmarks/mark?op=edit&output=popup&bkmk={URL}&title={TITLE}'));
				//gmail
				//hatena
				//kaboodle
				//kirtsy
				//linkedin - http://www.linkedin.com/shareArticle?mini=true&url={articleUrl}&title={articleTitle}&summary={articleSummary}&source={articleSource}
				sitearray.push(new newsitearrayobj('Linkedin', 'linkedin.png', 'http://www.linkedin.com/shareArticle?mini=true&url={URL}&title={TITLE}'));
				sitearray.push(new newsitearrayobj('ma.gnolia', 'magnolia.png', 'http://ma.gnolia.com/bookmarklet/add?description=&url={URL}&title={TITLE}'));
				//misterwong
				//mixx
				//multiply
				//myaol
				sitearray.push(new newsitearrayobj('myspace', 'myspace.gif', 'http://www.myspace.com/Modules/PostTo/Pages/?l=1&u={URL}&t={TITLE}'));
				//netvibes
				sitearray.push(new newsitearrayobj('netvouz', 'netvouz.png', 'http://netvouz.com/action/submitBookmark?popup=no&url={URL}&title={TITLE}'));
				sitearray.push(new newsitearrayobj('newsvine', 'newsvine.png', 'http://www.newsvine.com/_wine/save?u={URL}&h={TITLE}'));
				//nujij
				//propeller
				sitearray.push(new newsitearrayobj('rawsugar', 'rawsugar.png', 'http://www.rawsugar.com/tagger/?turl={URL}&tttl={TITLE}'));
				sitearray.push(new newsitearrayobj('reddit', 'reddit.png', 'http://reddit.com/submit?url={URL}&title={TITLE}'));
				sitearray.push(new newsitearrayobj('rojo', 'rojo.png', 'http://www.rojo.com/add-subscription/?resource={URL}'));
				sitearray.push(new newsitearrayobj('scuttle', 'scuttle.png', 'http://www.scuttle.org/bookmarks.php/maxpower?action=add&description=&address={URL}&title={TITLE}'));
				//segnalo
				sitearray.push(new newsitearrayobj('shadows', 'shadows.png', 'http://www.shadows.com/shadows.aspx?url={URL}'));
				//sitearray.push(new newsitearrayobj('shoutwire', 'shoutwire.gif', 'http://www.shoutwire.com/?p=submit&&link={url}'));
				//sphere
				//sitearray.push(new newsitearrayobj('simpy', 'simpy.gif', 'http://www.simpy.com/simpy/LinkAdd.do?href={url}&title={TITLE}'));
				sitearray.push(new newsitearrayobj('slashdot', 'slashdot.png', 'http://slashdot.org/bookmark.pl?url={URL}&title={TITLE}'));
				//sitearray.push(new newsitearrayobj('smarking', 'smarking.gif', 'http://smarking.com/editbookmark/?url={url}'));
				sitearray.push(new newsitearrayobj('spurl', 'spurl.png', 'http://www.spurl.net/spurl.php?blocked=&url={URL}&title={TITLE}'));
				sitearray.push(new newsitearrayobj('squidoo', 'squidoo.png', 'http://www.squidoo.com/lensmaster/bookmark?{URL}'));
				sitearray.push(new newsitearrayobj('stumbleupon', 'stumbleupon.png', 'http://www.stumbleupon.com/refer.php?url={URL}&title={TITLE}'));
				//sitearray.push(new newsitearrayobj('stumbleupon', 'stumbleupon.png', 'http://www.stumbleupon.com/submit?url={url}&title={title}'));
				//sitearray.push(new newsitearrayobj('swik', 'swik.gif', 'http://stories.swik.net/?submitUrl&url={url}'));
				//taggly
				//sitearray.push(new newsitearrayobj('tailrank', 'tailrank.gif', 'http://tailrank.com/share/?link_href={url}&title={title}'));
				sitearray.push(new newsitearrayobj('technorati', 'technorati.png', 'http://www.technorati.com/faves?add={URL}'));
				//tumblr
				sitearray.push(new newsitearrayobj('twitter', 'twitter.gif', 'http://addthis.com/bookmark.php?v=250&pub=&s=twitter&url={URL}&title={TITLE}'));
				//typepad
				//sitearray.push(new newsitearrayobj('winlive', 'winlive.gif', 'https://favorites.live.com/quickadd.aspx?url={url}&title={title}'));
				//sitearray.push(new newsitearrayobj('wists', 'wists.gif', 'http://wists.com/r.php?c=&r={url}&title={title}'));
				//wordpress
				sitearray.push(new newsitearrayobj('yahoo', 'im_yahoo.gif', 'http://myweb2.search.yahoo.com/myresults/bookmarklet?u={URL}&t={TITLE}'));
				//yahoobuzz yahoobookmarks
				//yardbarker
				//yoolink


	
				var left = document.createElement('div');
				$(left).addClass('socializer_left');
				$(div).append(left);
				
				var right = document.createElement('div');
				$(right).addClass('socializer_left');
				$(div).append(right);

				var counterg = 0;
				var isLeft = true;
				
				
				$.each(
					sitearray,
					function( intIndex, objValue ){
						if (counterg > (sitearray.length/2)) isLeft = false;
						var img = document.createElement('img');
						$(img).attr({ alt: 'send to '+objValue.name, src: '/scripts/socializer/images/'+objValue.image, width: '18', height: '18', onerror: 'this.src=\'images/spacer.gif\''  });
						if (isLeft) $(left).append(img);
						else $(right).append(img);
						
						var myLink = document.createElement('a');
						var hrefs =  objValue.hrefs.replace('{URL}', eurl).replace('{TITLE}', (etitle ? etitle : ''));
						$(myLink).attr({ href: hrefs , title: 'send to '+objValue.name, target: '_blank' });
						$(myLink).html(objValue.name);
						if (isLeft) $(left).append(myLink);
						else $(right).append(myLink);
						counterg++;
					}
				);
				
				/*
				for ( var ix in sitearray ) {
					if (counterg > (sitearray.length/2)) isLeft = false;
					var img = document.createElement('img');
					$(img).attr({ alt: 'send to '+sitearray[ix].name, src: 'images/'+sitearray[ix].image, width: '18', height: '18', onerror: 'this.src=\'images/spacer.gif\''  });
					if (isLeft) $(left).append(img);
					else $(right).append(img);
					
					var myLink = document.createElement('a');
					var hrefs =  sitearray[ix].hrefs.replace('{URL}', eurl).replace('{TITLE}', (etitle ? etitle : ''));
					$(myLink).attr({ href: hrefs , title: 'send to '+sitearray[ix].name });
					$(myLink).html(sitearray[ix].name);
					if (isLeft) $(left).append(myLink);
					else $(right).append(myLink);
					counterg++;
				}
				*/
				
				
//				$(".socializer_container").css("visibility","visible");
				$(".socializer_container").fadeIn(500);
					
				// ajax window
				$('.socializer_left a').bind("click",function(e){
					if ($('#socializer_container'))
						$('#socializer_container').fadeOut(500);
					//prevent rest of code in this function (see target=_blank above)
					return;
					
					e.preventDefault();
					var address 	= this;
					var scTop 		= $(window).scrollTop();
                    var width		= 0;									
					
					if(jQuery.browser.msie){
						width = document.body.clientWidth;
					}else{
						width	= window.innerWidth;
					}
				
					var left		= (width - 980) /2;
					var wind 		= document.createElement("div");
			        var cssObj;
					
					if(jQuery.browser.msie){
						 cssObj = {
							top:0,
							width:'980px',
							position:'absolute',
							left: 0,
							border: '1px solid #ccc',
							visibility:'visible'
			
						 }
					}else{
						 cssObj = {
							top:scTop+20,
							width:'980px',
							position:'absolute',
							left: left + 'px'
			
						 }
					}
						
					$(wind).css(cssObj);
					$(wind).addClass('socializer_window');		
				
					var closeX = document.createElement('img');
					$(closeX).attr({ src:"/scripts/socializer/images/close.gif", position:'absolute',top:"0",right:"0" });
					$(closeX).addClass('socializer_close');
					
					$(closeX).click(function(){
						$(wind).remove();											
					})
					
					$(wind).prepend(closeX);
					$(div).append(wind);
					
					var cssObj2 = {
        				width:'980px',
						height:'500px',
						border: 'none',
						position:'absolute',
						overflow:'auto',
						display:'block'
     				 }
					
					var c	 = document.createElement('iframe');		
					$(c).attr("src",this);
					$(c).css(cssObj2);
					$(wind).prepend(c);
					
	       })				
	})		
 }
