
$(function() {

// Megosztasi funkciok inicializalasa. Csak a linket kell elhelyezni az oldalon egy meghatarozott ID-vel, 
// es automatikusan elhelyezi benne a szukseges linket, illetve a mereshez hasznalatos ajax hivast.
// ========================================================================================================
	
	// Megnezzuk az URL-t.
	var u = location.href;
	var t = document.title;
	var uEncoded = encodeURIComponent(location.href);
	var tEncoded = encodeURIComponent(document.title);
	// Lekerdezzuk a cikkId-t. Ezt egy hidden divbe rejtjuk minden cikkoldalon
	var cikkId = $('#cikk_id').html();
	// Ha nincs, akkor legyen 0
	if(cikkId==null) {
		cikkId = 0;
	}
	
	$("a#share_facebook").eq(0).attr('href', 'http://www.facebook.com/sharer.php?u='+uEncoded+'&t='+tEncoded);
	$("a#share_facebook").eq(0).click(function(e) {
		//measureShare('facebook', u);
	} );
	
	$("a#share_twitter").eq(0).attr('href', 'http://twitter.com/home?status='+uEncoded+' '+tEncoded);
	$("a#share_twitter").eq(0).click(function(e) {
		//measureShare('twitter', u);
	} );
	
	$("a#share_google").eq(0).attr('href', 'http://www.google.com/bookmarks/mark?op=edit&bkmk='+uEncoded+'&title='+tEncoded);
	$("a#share_google").eq(0).click(function(e) {
		//measureShare('google', u);
	} );
	
	$("a#share_delicious").eq(0).attr('href', 'http://delicious.com/save?v=5&noui&jump=close&url='+uEncoded+'&title='+tEncoded);
	$("a#share_delicious").eq(0).click(function(e) {
		//measureShare('delicious', u);
	} );
	
	$("a#share_digg").eq(0).attr('href', 'http://digg.com/submit?url='+uEncoded+'&title='+tEncoded+'&media=news&topic=tech_news');
	$("a#share_digg").eq(0).click(function(e) {
		//measureShare('digg', u);
	} );
	
	// A cikkes eset merese nem itt van, hanem a form elkuldese utan merjuk. Merthogy ott sanszos, hogy a user
	// nem kuldi megse tovabb. Illetve a tobbi esetnel is lehetseges, de ott azt nem tudjuk ellenorizni.
	//$("a#share_email").eq(0).attr('href', '/megosztas?url='+uEncoded+'&cikk_id='+cikkId+'&title='+tEncoded);

    //gepadatbazis adatlap tooltip
    $(".helplink").mouseover(function() { 
            var div = $("#" + this.id + "_help");
            var pos = $(this).position();
            div.css("left", (pos.left-38) + "px");
            div.css("top", (pos.top+18) + "px");
            //if(div.width()>120) div.width(120);

            div.show(); });
    $(".helplink").mouseout(function() {
            var div = $("#" + this.id + "_help");
            div.hide(); });

});

/**
 * Ajax-al meri egy elem megosztasat.
 */  
function measureShare(tipus, url) {
	// Ugyanoda postoljuk az adatot, ahonnan indultunk, csak az ajax parameterrel kiegeszitve, mert akkor 
	// a beszedes URL feldolgozo lefut, es megkapjuk a cikkID-t es a csatornaID-t.
	url2 = url.split('?', 2);
	url2 = url2[0];
	$.get(url2+'?ajax=1&block=megosztas_meres', {url: url2, tipus: tipus});
}

