/* mooSocialize - 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 disposed */
/* same goes for the link to this tool */

window.addEvent('domready', function(){

    var items = $$('.socializer', '.socializermail');
    items.each(function( item ) {
    	item.addEvent('click', function(e){
    	e.preventDefault();
        if (document.getElementById('containerx') == null) {
        	
            // define container pos
            var top = this.getCoordinates().top.toInt();
            var bottom = this.getCoordinates().bottom.toInt();
            var height = this.getCoordinates().height.toInt();
            var left = this.getCoordinates().left.toInt();
            var pos = top + height + 20;
            var div = new Element('div');
            div.addClass('soc_container');
            div.setAttribute('id', 'containerx');
            div.injectInside(document.body);
            
            $(div).addEvent('blur', function(){
                this.dispose();
            })
            
            // close button
            var closeme = new Element('img');
            closeme.src = "typo3conf/ext/ge_socialbookmarks/res/images/close.gif";
            closeme.setAttribute('id', 'close');
            closeme.injectInside(div);
            closeme.addEvent('click', function(){
                div.dispose();
            })
            
            var title = escape(this.title);
            var url = escape(document.location.href);
            
            var name = new Element('h2');
            name.innerHTML = 'Wählen Sie Ihr Social Network';
            name.addClass('socialbookmark')
            name.injectInside(div);
            var left = new Element('div');
            left.addClass('soc_left');
            left.injectInside(div);
            
            linklist = [            // blinklist.com
            {
                'href': 'http://blinklist.com/index.php?Action=Blink/addblink.php&Name=' + title + '&Url=' + url,
                'title': 'Bookmark auf Blinklist',
                'html': 'Blinklist',
                'class': 'blinklist'
            },            //bookmark.it
            {
                'href': 'http://www.bookmark.it/bookmark.php?url=' + url,
                'title': 'Bookmark auf Bookmark.it',
                'html': 'Bookmark.it',
                'class': 'bookmarkit'
            },            // del.icio.us
            {
                'href': 'http://del.icio.us/post?url=' + url + '&title=' + title,
                'title': 'Bookmark auf Del.icio.us',
                'html': 'Del.icio.us',
                'class': 'delicious'
            },            // digg.com
            {
                'href': 'http://digg.com/submit?phase=2&url=' + url + '&title=' + title,
                'title': 'Bookmark auf Digg',
                'html': 'Digg',
                'class': 'digg'
            },            // furl.net
            {
                'href': 'http://furl.net/storeIt.jsp?t=' + title + '&u=' + url,
                'title': 'Bookmark auf Furl',
                'html': 'Furl',
                'class': 'furl'
            },            // reddit.com
            {
                'href': 'http://reddit.com/submit?url=' + url + '&title=' + title,
                'title': 'Bookmark auf Reddit',
                'html': 'Reddit',
                'class': 'reddit'
            },            // feedmelinks.com
            {
                'href': 'http://feedmelinks.com/categorize?from=toolbar&op=submit&name=' + title + '&url=' + url,
                'title': 'Bookmark auf Feedmelinks',
                'html': 'Feedmelinks',
                'class': 'feedmelinks'
            },            // technorati.com
            {
                'href': 'http://www.technorati.com/faves?add=' + url,
                'title': 'Bookmark auf Technorati',
                'html': 'Technorati',
                'class': 'technorati'
            },            // yahoo.com
            {
                'href': 'http://myweb2.search.yahoo.com/myresults/bookmarklet?u=' + url + '&t=' + title,
                'title': 'Bookmark auf Yahoo',
                'html': 'Yahoo',
                'class': 'yahoo'
            },            // tipd.com
            {
                'href': 'http://tipd.com/submit.php?url=' + url,
                'title': 'Bookmark auf Tipd',
                'html': 'Tipd',
                'class': 'tipd'
            },            // netvouz.com
            
            {
                'href': 'http://netvouz.com/action/submitBookmark?url=' + url + '&title=' + title + '&popup=no',
                'title': 'Bookmark auf Netvouz',
                'html': 'Netvouz',
                'class': 'netvouz'
            },            // rojo.com
            {
                'href': 'http://www.rojo.com/add-subscription/?resource=' + url,
                'title': 'Bookmark auf Rojo',
                'html': 'Rojo',
                'class': 'rojo'
            },            // shadows.com
            {
                'href': 'http://www.shadows.com/shadows.aspx?url=' + url,
                'title': 'Bookmark auf Shadows',
                'html': 'Shadows',
                'class': 'shadows'
            },            // oneview.de
            {
                'href': 'http://www.oneview.de/quickadd/neu/addBookmark.jsf?URL=' + encodeURIComponent(url) + '&title=' + encodeURIComponent(title),
                'title': 'Bookmark auf Oneview',
                'html': 'Oneview',
                'class': 'oneview'
            },            // facebook.com
            {
                'href': 'http://www.facebook.com/share.php?u=' + url,
                'title': 'Bookmark auf Facebook',
                'html': 'Facebook',
                'class': 'facebook'
            },            // buzz.yahoo.com
            {
                'href': 'http://buzz.yahoo.com/buzz?targetUrl=' + url + '&headline=' + title,
                'title': 'Bookmark auf Buzz',
                'html': 'Buzz Up!',
                'class': 'ybuzz'
            },            // Tiny URL -> 'http://tinyurl.com/api-create.php?url='+url
            /*
             var req = new Request({
             url: 'http://tinyurl.com/api-create.php?url='+url,
             method: 'get',
             async: false,
             onComplete: function(response) { alert(response); }
             }).send();
             */
            {
                'href': 'http://twitter.com/timeline/home/?status=' + title + ' http%3A%2F%2Ftinyurl.com%2Fdgw9gs+via+%40ShareThis',
                'title': 'Bookmark auf Twitter',
                'html': 'Twitter',
                'class': 'twitter'
            }, {
                'href': 'https://favorites.live.com/quickadd.aspx?marklet=1&mkt=en-us&url=' + url + '&title=' + title + '&top=1',
                'title': 'Bookmark auf Live',
                'html': 'Live',
                'class': 'windows_live'
            }, {
                'href': 'http://www.myspace.com/Modules/PostTo/Pages/?l=3&u=' + url + '&t=' + title,
                'title': 'Bookmark auf MySpace',
                'html': 'MySpace',
                'class': 'myspace'
            }, {
                'href': 'http://www.mixx.com/submit?page_url=' + url,
                'title': 'Bookmark auf mixx',
                'html': 'Mixx',
                'class': 'mixx'
            }, {
                'href': 'http://cgi.fark.com/cgi/farkit.pl?u=' + url + '&h=' + title,
                'title': 'Bookmark auf Fark',
                'html': 'Fark',
                'class': 'fark'
            }, {
                'href': 'http://www.propeller.com/submit/?U=' + url + '&T=' + title,
                'title': 'Bookmark auf Propeler',
                'html': 'Propeller',
                'class': 'propeller'
            }, {
                'href': 'http://bx.businessweek.com/api/add-article-to-bx.tn?url=' + url,
                'title': 'Bookmark auf Business Week',
                'html': 'Add to BX',
                'class': 'bus_exchange'
            }, {
                'href': 'http://www.linkedin.com/shareArticle?mini=true&url=' + url + '&title=' + title + '&summary=&source=',
                'title': 'Bookmark auf Linkedin',
                'html': 'Linkedin',
                'class': 'linkedin'
            }, {
                'href': 'http://friendfeed.com/share?url=' + url + '&title=' + title,
                'title': 'Bookmark auf FriendFeed',
                'html': 'FriendFeed',
                'class': 'friendfeed'
            }, {
                'href': 'http://www.n4g.com/tips.aspx?url=' + url + '&title=' + title,
                'title': 'Bookmark auf N4G',
                'html': 'N4G',
                'class': 'n4g'
            }, {
                'href': 'http://www.faves.com/Authoring.aspx?u=' + url + '&t=' + title,
                'title': 'Bookmark auf Faves',
                'html': 'Faves',
                'class': 'faves'
            }, {
                'href': 'http://current.com/clipper.htm?url=' + url + '&title=' + title + '&src=',
                'title': 'Bookmark auf Current',
                'html': 'Current',
                'class': 'current'
            }, {
                'href': 'http://www.simpy.com/simpy/LinkAdd.do?href=' + url + '&title=' + title,
                'title': 'Bookmark auf Simpy',
                'html': 'Simpy',
                'class': 'simpy'
            }, {
                'href': 'http://meneame.net/submit.php?url=' + url,
                'title': 'Bookmark auf Meneame',
                'html': 'Meneame',
                'class': 'meneame'
            }, {
                'href': 'http://www.yigg.de/neu?exturl=' + url + '&exttitle=' + title,
                'title': 'Bookmark auf Yigg',
                'html': 'Yigg',
                'class': 'yigg'
            }, {
                'href': 'http://oknotizie.alice.it/post?url=' + url + '&title=' + title,
                'title': 'Bookmark auf Oknotizie',
                'html': 'Oknotizie',
                'class': 'oknotizie'
            }, {
                'href': 'http://ocio.fresqui.com/post?url=' + url + '&title=' + title,
                'title': 'Bookmark auf Fresqui',
                'html': 'Fresqui',
                'class': 'fresqui'
            }, {
                'href': 'http://secure.diigo.com/post?url=' + url + '&title=' + title,
                'title': 'Bookmark auf Diigo',
                'html': 'Diigo',
                'class': 'diigo'
            },            // dzone.com
            {
                'href': 'http://www.dzone.com/links/add.html?description=' + title + '&url=' + url + '&title=' + title,
                'title': 'Bookmark auf Dzone',
                'html': 'Dzone',
                'class': 'dzone'
            },            // newsvine.com
            
            {
                'href': 'http://www.newsvine.com/_wine/save?u=' + url + '&h=' + title,
                'title': 'Bookmark auf Newsvine',
                'html': 'Newsvine',
                'class': 'newsvine'
            },            // ma.gnolia.com
            {
                'href': 'http://ma.gnolia.com/bookmarklet/add?url=' + url + '&title=' + title + '&description=',
                'title': 'Bookmark auf Ma.gnolia.com',
                'html': 'Ma.gnolia',
                'class': 'magnolia'
            },            // stumpleupon.com
            {
                'href': 'http://www.stumbleupon.com/refer.php?url=' + url + '&title=' + title,
                'title': 'Bookmark auf Stumbleupon',
                'html': 'Stumbleupon',
                'class': 'stumbleupon'
            },            // google.com
            {
                'href': 'http://www.google.com/bookmarks/mark?op=edit&output=popup&bkmk=' + url + '&title=' + title,
                'title': 'Bookmark auf Google',
                'html': 'Google',
                'class': 'google_bmarks'
            },            // squidoo.com
            {
                'href': 'http://www.squidoo.com/lensmaster/bookmark?' + url,
                'title': 'Bookmark auf Squidoo',
                'html': 'Squidoo',
                'class': 'squidoo'
            },            // spurl.net
            {
                'href': 'http://www.spurl.net/spurl.php?url=' + url + '&title=' + title + '&blocked=',
                'title': 'Bookmark auf Spurl',
                'html': 'Spurl',
                'class': 'spurl'
            },            // blinkbits.com
            {
                'href': 'http://blinkbits.com/bookmarklets/save.php?v=1&source_url=' + url + '&title=' + title,
                'title': 'Bookmark auf Blinkbits',
                'html': 'Blinkbits',
                'class': 'blinkbits'
            },            // blogmarks.net
            {
                'href': 'http://blogmarks.net/my/new.php?mini=1&simple=1&url=' + url + '&title=' + title,
                'title': 'Bookmark auf Blogmarks',
                'html': 'Blogmarks',
                'class': 'blogmarks'
            },            // bloglines.com
            {
                'href': 'http://www.bloglines.com/sub/' + url,
                'title': 'Bookmark auf Bloglines',
                'html': 'Bloglines',
                'class': 'bloglines'
            },            // co.mments.com
            
            {
                'href': 'http://co.mments.com/track?url=' + url + '&title=' + title,
                'title': 'Bookmark auf Co.mments',
                'html': 'Co.mments',
                'class': 'co-mments'
            },            // scuttle.org
            {
                'href': 'http://www.scuttle.org/bookmarks.php/maxpower?action=add&address=' + url + '&title=' + title + '&description=',
                'title': 'Bookmark auf Scuttle',
                'html': 'Scuttle',
                'class': 'scuttle'
            },            // ask.com
            {
                'href': 'http://mystuff.ask.com/mysearch/QuickWebSave?v=1.2&t=webpages&title=' + title + '&url=' + url,
                'title': 'Bookmark auf Ask',
                'html': 'Ask',
                'class': 'ask'
            },            // slashdot.com
            {
                'href': 'http://slashdot.org/bookmark.pl?title=' + title + '&url=' + url,
                'title': 'Bookmark auf Slashdot',
                'html': 'Slashdot',
                'class': 'slashdot'
            },            // mister-wong.de
            {
                'href': 'http://www.mister-wong.de/index.php?action=addurl&amp;bm_url=' + url + '&amp;bm_description=' + title,
                'title': 'Bookmark auf Mister Wong',
                'html': 'Mister Wong',
                'class': 'mister_wong'
            }, {
                'href': 'http://www.care2.com/news/compose?share[link_url]=' + url + '&share[title]=' + title,
                'title': 'Bookmark auf Care2',
                'html': 'Care2',
                'class': 'care2'
            }, {
                'href': 'http://funp.com/pages/submit/add.php?title=' + title + '&url=' + url + '&via=',
                'title': 'Bookmark auf Funp',
                'html': 'Funp',
                'class': 'funp'
            }, {
                'href': 'http://www.kirtsy.com/submit.php?url=' + url,
                'title': 'Bookmark auf Kirtsy',
                'html': 'Kirtsy',
                'class': 'kirtsy'
            }, {
                'href': 'http://www.xanga.com/private/editorx.aspx?t=' + title + '&u=' + url + '&s=',
                'title': 'Bookmark auf Xanga',
                'html': 'Xanga',
                'class': 'xanga'
            }, {
                'href': 'http://sphinn.com/submit.php?url=' + url,
                'title': 'Bookmark auf Sphinn',
                'html': 'Sphinn',
                'class': 'sphinn'
            }, {
                'href': 'http://dealspl.us/add.php?ibm=1&url=' + url,
                'title': 'Bookmark auf Dealspl.us',
                'html': 'Dealspl.us',
                'class': 'dealsplus'
            }, {
                'href': 'https://www.xing.com/app/user?op=share;url=' + url,
                'title': 'Ihre Xing-Kontakten zeigen',
                'html': 'Xing',
                'class': 'xing'
            }];

            
            function callbackFunc(a, b){
                if (a.html == b.html) {
                    return 0;
                }
                return (a.html < b.html) ? -1 : 1;
            }
            
            linklist.sort(callbackFunc);
            
            var ct = 0;
            
            var cols = 4;
            var maxItems = linklist.length;
            var halfItems = Math.floor(maxItems / cols);
            var over = Math.max(maxItems - halfItems * cols, 0);
            var right = null;
            linklist.each(function(el){
                var myLink = new Element('a', el);
                myLink.setAttribute('target', '_blank');
                if (ct == (halfItems + (over > 0 ? 1 : 0))) {
                    left = new Element('div');
                    left.addClass('soc_left');
                    
                    left.injectInside(div);
                    ct = 0;
                    over = Math.max(over--, 0);
                }
                myLink.injectInside(left);
                ct++;
                
            });
            
           	if (item.hasClass('socializermail')) {
           		var cl = item.getElement('p');
           		if (cl) {
           			cl=cl.clone();
           			cl.inject(div);
					var cl2 = new Element('div',{'class':'geshop-description geshop-maillink','style':'padding: 10px;'});
					cl.inject(cl2);
					cl2.inject(div);        		
				}
				
        	}
            div.position({
                relativeTo: this,
                position: 'bottomLeft',
                edge: 'bottomLeft'
            });
            // fade in
            var eff = new Fx.Morph(div, {
                duration: 300,
                wait: true,
                transition: Fx.Transitions.linear
            }).chain(function(){
                $$('.soc_left').setStyle('visibility', 'visible');
            });
            eff.start({
                'opacity': [0, 1]
            });
            
        }
        else {
            var eff = new Fx.Morph('containerx', {
                duration: 500,
                wait: true,
                transition: Fx.Transitions.linear
            }).chain(function(){
                $('containerx').dispose();
            });
            
            eff.start({
                'opacity': [0, 1]
            });
            
            
        }
    })
    })
})

