



/*
---------------- GO UP --------------------*/
(function() {

function $(id) {
	return document.getElementById(id);
}

function setStyleDisplay(id, status) {
	$(id).style.display = status;
}

function goTop(acceleration, time) {

	acceleration = acceleration || 0.7;
	time = time || 16;

	var dx = 0;
	var dy = 0;
	var bx = 0;
	var by = 0;
	var wx = 0;
	var wy = 0;

	if (document.documentElement) {
		dx = document.documentElement.scrollLeft || 0;
		dy = document.documentElement.scrollTop || 0;
	}
	if (document.body) {
		bx = document.body.scrollLeft || 0;
		by = document.body.scrollTop || 0;
	}
	var wx = window.scrollX || 0;
	var wy = window.scrollY || 0;

	var x = Math.max(wx, Math.max(bx, dx));
	var y = Math.max(wy, Math.max(by, dy));

	var speed = 1 + acceleration;
	window.scrollTo(Math.floor(x / speed), Math.floor(y / speed));
	if(x > 0 || y > 0) {
		var invokeFunction = "MGJS.goTop(" + acceleration + ", " + time + ")"
		window.setTimeout(invokeFunction, time);
	}
}

function switchTab(showPanel, hidePanel, activeTab, activeClass, fadeTab, fadeClass) {
	$(activeTab).className = activeClass;
	$(fadeTab).className = fadeClass;
	setStyleDisplay(showPanel, 'block');
	setStyleDisplay(hidePanel, 'none');
}

window['MGJS'] = {};
window['MGJS']['$'] = $;
window['MGJS']['setStyleDisplay'] = setStyleDisplay;
window['MGJS']['goTop'] = goTop;
window['MGJS']['switchTab'] = switchTab;

})();

function switchImage(imageId, imageUrl, linkId, linkUrl, preview, title, alt) {
	if(imageId && imageUrl) {
		var image = $(imageId);
		image.src = imageUrl;

		if(title) {
			image.title = title;
		}
		if(alt) {
			image.alt = alt;
		}
	}

	if(linkId && linkUrl) {
		var link = $(linkId);
		link.href = linkUrl;
	}
}
/*
-------------------- / GO UP ----------------------*/


/* Социальные закладки */
function share42(u,t){
if(!u)u=location.href;
if(!t)t=document.title;
u=encodeURIComponent(u);
t=encodeURIComponent(t);

var s=new Array(
'http://www.google.com/bookmarks/mark?op=edit&output=popup&bkmk='+u+'&title='+t+'" title="Сохранить закладку в Google"'
,'http://memori.ru/link/?sm=1&u_data[url]='+u+'&u_data[name]='+t+'" title="Сохранить закладку в Memori.ru"'
,'http://vkontakte.ru/share.php?url='+u+'" title="Поделиться ВКонтакте"'
,'http://twitter.com/home?status='+t+' - '+u+'" title="Добавить в Twitter"'
,'http://www.facebook.com/sharer.php?u='+u+'&t='+t+'" title="Поделиться в Facebook"'
,'http://www.google.com/buzz/post?message='+t+'&url='+u+'" title="Добавить в Google Buzz"'
,'http://www.friendfeed.com/share?title='+t+' - '+u+'" title="Добавить в FriendFeed"'
,'http://www.livejournal.com/update.bml?event='+u+'&subject='+t+'" title="Опубликовать в LiveJournal"'
,'http://bobrdobr.ru/add.html?url='+u+'&title='+t+'" title="Забобрить"'
,'http://zakladki.yandex.ru/newlink.xml?url='+u+'&name='+t+'" title="Добавить в Яндекс.Закладки"'
);

document.write('<div style="text-align:right; float:left; padding:5px 0 0 10px;">');
for(i=0; i<s.length; i++)
	document.write('<a style="display:inline-block; width:16px;height:16px; margin:0 7px 0 0; background:url(http://'+window.location.hostname+'/wp-content/themes/f2template/img/social2.png) -'+16*i+'px 0" href="'+s[i]+'" target="_blank"></a>');
document.write('</div>');

}




/*
==================== jQuery скрипты =====================*/  
(function ($){

/* Style Switcher 
------------------------------------------ */
$(function() {
	$('#styleSwitch li#style22').addClass('selected');
	$('#styleSwitch li').bind('click', function() {
		switchStyle(this.id);
		return false;
	});
	var c = readCookie('style');
	if (c) switchStyle(c);
});

function switchStyle(styleName) {
	if (styleName) {
		$('body').removeClass();
		$('#styleSwitch li').removeClass('selected');
		$('#' + styleName).addClass('selected');
		$('body').addClass(styleName);
	}
	createCookie('style', styleName, 365);
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function eraseCookie(name) {
	createCookie(name,"",-1);
}



	

/* appear_menu 2 Админка
---------------------------------------------- */
$(function(){
    $('div.ad-men-holder').hover(
        function() {
            $('ul.t-admin-li').addClass("active");
            $('ul.t-admin-li').css({opacity: 0}).hide();
            $('ul.t-admin-li').animate({opacity: 1}, 300).show();
        },
        function() {
            $('ul.t-admin-li').removeClass("active"); 
            $('ul.t-admin-li').css({opacity: 0}).hide();
        }
    );
});

	




/* добавка стиля к ссылке картинки для поста
------------------------------------------------------- */
$(function() {  
    $('div.maincontent a img').parent().addClass('shutterset');
});

/* зебра для таблиц 
--------------------------------------------- */	
$(function() {  
	$('table.zebra').find('tr:even').addClass('tr3');
});


/* Прячем ссылки */
$(document).ready(function() {
	$('a.hide_l').each(function() {
		var link = $(this).attr('title');
		$(this).attr('href', link).attr('target', '_blank');
	});
})



	
	
	

/* Высплывающее меню 
------------------------------------------ */
$(function(){
    $('ul.topmenu li').hover(
        function() {
            $(this).addClass("active");
            $(this).find('ul').css({opacity: 0}).hide();
            $(this).find('ul').animate({opacity: 1}, 400).show();
        },
        function() {
            $(this).removeClass("active"); 
            $(this).find('ul').css({opacity: 0}).hide();
        }
    );
});




/* Цитирование 
------------------------------------------------ */
$(function() {
	function getSelectedText(){
		if(window.getSelection){
			return window.getSelection().toString();
		}
		else if(document.getSelection){
			return document.getSelection();
		}
		else if(document.selection){
			return document.selection.createRange().text;
		}
	}
	$('.bquote').click(function() {
		if (getSelectedText()) {
			$('textarea[name="comment"]').val($('textarea[name="comment"]').val() + '<blockquote>' + getSelectedText() + '</blockquote>' + '\r\n').focus();
		} else {
			alert ('Вы не выделили текст.');
		}
		return false;
	});
});











/* табы от димы */
$(function() {

  $('ul.tabs').each(function() {
    $(this).find('li').each(function(i) {
      $(this).hover(function(){
		if ($(this).attr('class') != 'current'){
        $(this).addClass('current').siblings().removeClass('current');
		var p = $(this).parents('div.section');
			p.find('div.tbox').css({opacity: 0}).hide();
			p.find('div.tbox:eq('+i+')').animate({opacity: 1}, 500).show();
		}
      });
    });
  });

})

	
	
	

})(jQuery)












