function getScrollTop() {
           var scrOfY = 0;
           if( typeof( window.pageYOffset ) == 'number' ) {
                   //Netscape compliant
                   scrOfY = window.pageYOffset;
           } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
                   //DOM compliant
                   scrOfY = document.body.scrollTop;
           } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
                   //IE6 Strict
                   scrOfY = document.documentElement.scrollTop;
           }
           return scrOfY;
}


function socializ() {

	var m1 = 140; /* расстояние от начала страницы до плавающей панели */
	var m2 = 20; /* расстояние от верха видимой области страницы до плавающей панели */
	var f = tmplurl + '/images/'; /* путь к папке с изображениями кнопок */




    $(window).addEvent("domready",function(){


        var t       = document.title;
        var u       = location.href;

        var existsRss    = $$('.feedicon')
        var aRss         = false;
        if(existsRss && typeof existsRss != 'undefined' && existsRss.length){
            aRss    = existsRss[0].href;
        };

        u           = u.replace('#mod_search_searchword','');
        u           = encodeURIComponent(u);
        t           = encodeURIComponent(t);



        var Elt = new Element('div',{  'id': 'socializ'});
        $(Elt).inject($("bd"));

        var s                       = $('socializ');

        var myWidth					= 0;

        if( typeof( window.innerWidth ) == "number" ) {
          //Non-IE
		          myWidth			= window.innerWidth;
        } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		          //IE 6+ in "standards compliant mode"
		          myWidth 			= document.documentElement.clientWidth;

        } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		          //IE 4 compatible
		          myWidth 			= document.body.clientWidth;
        };


        myWidth           		    =  Math.floor((myWidth - 400) / 2);

        s.setStyles({'left': myWidth + 'px'});

        /*function margin() {
			var top = getScrollTop();
			if (top+m2 < m1) {
				s.setStyles({'top': m1-top});
			} else {
				s.setStyles({'top': m2});
			}
		}

        $(window).addEvent('scroll',function() { margin(); });
        */

        var lnk                     = location.href.replace(/#(.*)$/,'');

		s.setHTML(
			'<a href="http://twitter.com/share?text=' + t + '&url=' + u + '" title="Добавить в Twitter" class="tsmodal" rel="{handler: \'iframe\', size: {x: 650, y: 375}}"><img src="' + f + 'twitter.png" alt="" /></a>' +
			'<a href="http://www.facebook.com/sharer.php?u=' + u + '" title="Поделиться в Facebook" class="tsmodal" rel="{handler: \'iframe\', size: {x: 650, y: 375}}"><img src="' + f + 'facebook.png" alt="" /></a>' +
			'<a href="http://vkontakte.ru/share.php?url=' + u + '&title= ' + t + '&description=&image= " title="Поделиться ВКонтакте" class="tsmodal" rel="{handler: \'iframe\', size: {x: 650, y: 375}}"><img src="' + f + 'vkontakte.png" alt="" /></a>' +
			'<a href="http://connect.mail.ru/share?share_url=' + u + '" title="Поделиться в Моем Мире" class="tsmodal" rel="{handler: \'iframe\', size: {x: 650, y: 375}}"><img src="' + f + 'moy-mir.png" alt="" /></a>' +
			'<a href="http://www.livejournal.com/update.bml?event=' + u + '&subject=' + t + '" title="Опубликовать в своем блоге livejournal.com" class="tsmodal" rel="{handler: \'iframe\', size: {x: 650, y: 375}}"><img src="' + f + 'livejournal.png" alt="" /></a>' +
			'<a href="http://delicious.com/save?url=' + u + '&title=' + t + '" title="Сохранить закладку в Delicious" class="tsmodal" rel="{handler: \'iframe\', size: {x: 650, y: 375}}"><img src="' + f + 'delicious.png" alt="" /></a>' +
			'<a href="http://www.google.com/bookmarks/mark?op=edit&output=popup&bkmk=' + u + '&title=' + t + '" title="Сохранить закладку в Google" class="tsmodal" rel="{handler: \'iframe\', size: {x: 650, y: 375}}"><img src="' + f + 'google.png" alt="" /></a>' +
            '<a href="'+siteurl+'index.php?option=com_virtuemart&page=shop.cart'+'" title="Перейти в корзину"><img src="' + f + 'cart_icon.png" alt="" /></a>' +
            '<a href="'+lnk+''+'" onclick="return add_favorite(this,event);" title="Добавить в закладки"><img src="' + f + 'favorite.png" alt="" /></a>' +
            '<a href="'+siteurl+'component/search/?searchword=&ordering=&searchphrase=all'+'" title="Поиск"><img src="' + f + 'search.png" alt="" /></a>' +
            (aRss ? '<a href="'+aRss+'"><img src="' + f + 'rss.png" alt="" /></a>' : '') +
            '<a href="'+lnk+'#selflink_top'+'" title="Наверх"><img src="' + f + 'up-arrow.png" alt="" /></a>' +
        '');

        $$('.tsmodal').each(function(el){
           $(el).addEvent('click',function(event){
                var Evt = new Event(event);
                Evt.stop();
                window.open(el.href,'','width=500,height=450,scrollbars=yes,statusbar=no');
           });

        });

        $('socializ').setStyle('opacity','0.85');

        $$('#socializ a').each(function(item){
           $(item).setStyle('opacity','0.8');

           $(item).addEvent('mouseover',function(){
                $(item).setStyle('opacity','1.0');
           });

           $(item).addEvent('mouseout',function(){
                $(item).setStyle('opacity','0.9');
           });
        });
	});

}

socializ();

function add_favorite(a,event) {
  tle               = document.title;
  favLink           = location.href;


  if (typeof(opera)=="object") {
        a.rel="sidebar";
        a.title=tle;
        a.url=favLink;
        return true;
  } else if(document.all) {
        window.external.AddFavorite(favLink, tle);
  } else if( typeof window.sidebar != "undefined" && typeof window.sidebar.addPanel != "undefined"){
        window.sidebar.addPanel(tle, favLink, "");
  } else {
        alert('Нажмите Ctrl-D чтобы добавить страницу в закладки');
  }
        var Evt = new Event(event);
        Evt.stop();
        return false;
}

