﻿var ServeName 		= "www.zive.cz";
var ServerOpenOptions 	= '';//'resizable=1, scrollbars=1, toolbar=1, status=1, menubar=1';

//****************************************************************
//* ASYNC LOADER
//****************************************************************
function LoadSocietyPlugin(oUrl)
{
	$(document).ready(function(){
		(function(){
			var s = document.createElement('SCRIPT');
			var c = document.getElementsByTagName('script')[0];
			s.type = 'text/javascript';
			//s.async = true;
			s.src = oUrl;
			c.parentNode.insertBefore(s, c);
		})();
	});
}

function LoadFaceBookPlugin(oUrl, oArticle)
{
	$("a[name='fb_share']").attr("share_url", "http://" + ServeName + oArticle);
	LoadSocietyPlugin(oUrl);	
}

function LoadTweeterPlugin(oUrl, oArticle, oArticleText)
{
	var oA = $("a.twitter-share-button");
	oA.attr("data-url", "http://" + ServeName + oArticle);
	oA.attr("data-text", oArticleText);
	LoadSocietyPlugin(oUrl);	
}

$(document).ready(function(){
	/*
	var ViewAfterWidth = 1528;
	var bbs=screen;
	
	if(! (((bbs.availWidth && bbs.availWidth!="undefined") && bbs.availWidth>=ViewAfterWidth) || ((bbs.width && bbs.width!="undefined") && bbs.width>=ViewAfterWidth)))
	{
		$("#social-plugins").hide();
	}
	*/
	
	$(window).scroll(function(){
			var topHeight = $("#prolinkhdr").height() + $("#adblock-clip").height() + $("#page-navigation").height() + 21; 
			if( $("#adblock-rightside").css("position")!="fixed" && $(window).scrollTop() > topHeight )
			{
				var oClip = $("#page-navigation-main > .block-dim");
				var oM	  = parseInt(oClip.css("marginLeft"));
				if(isNaN(oM))
				{
					oM = 0;
				}
				var oL = oClip.position().left+7+oM-$(window).scrollLeft();
				var oLA = oClip.position().left+1121+oM-$(window).scrollLeft();
				$("#social-plugins").css({"position": "fixed", "left": oL});
				$("#ArticleByMail").css({"position": "fixed"});
				$("#adblock-rightside").css({"position": "fixed", "left": oLA});	
			}
			else if( $(window).scrollTop() <= topHeight )
			{
				$("#social-plugins").css({"position": "absolute", left: 7});
				$("#adblock-rightside").css({"position": "absolute", left: 1121});
				$("#ArticleByMail").css({"position": "absolute"});
			}
			else if( $("#adblock-rightside").css("position")=="fixed" )
			{
				var missHeight 	= $("#adblock-rightside").height()-$(window).height();
				var currPos 	= $(window).scrollTop()+$(window).height();
				var fixOn	= currPos >= ($("form").height()-missHeight);

				if(fixOn)
				{
					$("#adblock-rightside").css({"top": "-" + (currPos - ($("form").height()-missHeight) ) + "px"});
				}
				else
				{
					$("#adblock-rightside").css({"top": "2px"});
				}

				var oClip = $("#page-navigation-main > .block-dim");
				var oM	  = parseInt(oClip.css("marginLeft"));
				if(isNaN(oM))
				{
					oM = 0;
				}
				var oL = oClip.position().left+7+oM-$(window).scrollLeft();
				var oLA = oClip.position().left+1121+oM-$(window).scrollLeft();
				$("#social-plugins").css({"left": oL});
				$("#adblock-rightside").css({"left": oLA});			
			}
		});
});


//****************************************************************
//* FACEBOOK
//****************************************************************

//********************************************
function AddToFaceBook(aTitle, aId){
	u="http://" + ServeName + "/?article=" + aId;
	t=aTitle + " - " + ServeName;
	window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer', ServerOpenOptions);
	return false;
}


//****************************************************************
//* DELICIOUS
//****************************************************************

//********************************************
function AddToDelicious(aTitle, aId){
	u="http://" + ServeName + "/?article=" + aId;
	t=aTitle + " - " + ServeName;
	window.open('http://del.icio.us/post?v=4&noui&jump=close&url='+encodeURIComponent(u)+'&title='+encodeURIComponent(t), 'delicious', ServerOpenOptions);
	return false;
}


//****************************************************************
//* MS LIVE
//****************************************************************

//********************************************
function AddToLive(aTitle, aId){
	u="http://" + ServeName + "/?article=" + aId;
	t=aTitle + " - " + ServeName;
	window.open('https://favorites.live.com/quickadd.aspx?marklet=1&mkt=cs-cz&url='+encodeURIComponent(u)+'&title='+encodeURIComponent(t)+'&top=1', 'live', ServerOpenOptions);
	return false;
}


//****************************************************************
//* MY SPACE
//****************************************************************

//********************************************
function AddToMySpace(aTitle, aId){
	u="http://" + ServeName + "/?article=" + aId;
	t=aTitle + " - " + ServeName;
	window.open('http://www.myspace.com/index.cfm?fuseaction=postto&t=' + encodeURIComponent(t) + '&c=&u=' + encodeURIComponent(u), 'myspace', ServerOpenOptions);
	return false;
}


//****************************************************************
//* GOOGLE BOOKMARKS
//****************************************************************

//********************************************
function AddToGoogle(aTitle, aId){
	u="http://" + ServeName + "/?article=" + aId;
	t=aTitle + " - " + ServeName;
	window.open('http://www.google.com/bookmarks/mark?op=add&title=' + encodeURIComponent(t) + '&bkmk=' + encodeURIComponent(u), 'google', ServerOpenOptions);
	return false;
}

//****************************************************************
//* TWITTER
//****************************************************************

//********************************************
function AddToTwitter(aTitle, aId){
	u="http://" + ServeName + "/?article=" + aId;
	t=aTitle + " - " + ServeName;
	window.open('http://twitter.com/home?status=' + encodeURIComponent(t) + ' - ' + encodeURIComponent(u), 'twitter', ServerOpenOptions);
	return false;
}

//****************************************************************
//* LINKUJ
//****************************************************************

//********************************************
function AddToLinkuj(aTitle, aId){
	u="http://" + ServeName + "/?article=" + aId;
	t=aTitle + " - " + ServeName;
	window.open('http://linkuj.cz/?id=linkuj&title=' + encodeURIComponent(t) + '&url=' + encodeURIComponent(u), 'linkuj', ServerOpenOptions);
	return false;
}

//****************************************************************
//* E-MAIL
//****************************************************************

//********************************************
function ShowCaptchaMailer(x, y)
{
	/*var oPos 	= $("#CaptchaMailer").position();
	$("#ArticleByMail").css({"top" : oPos.top-420, "left" : oPos.left-175}).show();
	$(".ArticleByMail").removeClass("CaptchaLoader").show();*/
	$(".ArticleByMail").show();
	return false;
}
