
jQuery(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 = jQuery('#cikk_id').html();
	// Ha nincs, akkor legyen 0
	if(cikkId==null) {
		cikkId = 0;
	}
	
	jQuery("a#share_facebook").eq(0).attr('href', 'http://www.facebook.com/sharer.php?u='+uEncoded+'&t='+tEncoded);
	jQuery("a#share_facebook").eq(0).click(function(e) {
		//measureShare('facebook', u);
	} );
	
	jQuery("a#share_twitter").eq(0).attr('href', 'http://twitter.com/home?status='+uEncoded+' '+tEncoded);
	jQuery("a#share_twitter").eq(0).click(function(e) {
		//measureShare('twitter', u);
	} );
	
	jQuery("a#share_google").eq(0).attr('href', 'http://www.google.com/bookmarks/mark?op=edit&bkmk='+uEncoded+'&title='+tEncoded);
	jQuery("a#share_google").eq(0).click(function(e) {
		//measureShare('google', u);
	} );
	
	jQuery("a#share_delicious").eq(0).attr('href', 'http://delicious.com/save?v=5&noui&jump=close&url='+uEncoded+'&title='+tEncoded);
	jQuery("a#share_delicious").eq(0).click(function(e) {
		//measureShare('delicious', u);
	} );
	
	jQuery("a#share_digg").eq(0).attr('href', 'http://digg.com/submit?url='+uEncoded+'&title='+tEncoded+'&media=news&topic=tech_news');
	jQuery("a#share_digg").eq(0).click(function(e) {
		//measureShare('digg', u);
	} );

	jQuery("a#share_iwiw").eq(0).attr('href', 'http://iwiw.hu/pages/share/share.jsp?u='+uEncoded+'&t='+tEncoded);
	jQuery("a#share_iwiw").eq(0).click(function(e) {
		//measureShare('iwiw', 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
    jQuery(".helplink").mouseover(function() { 
            var div = jQuery("#" + this.id + "_help");
            var pos = jQuery(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(); });
    jQuery(".helplink").mouseout(function() {
            var div = jQuery("#" + 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];
	jQuery.get(url2+'?ajax=1&block=megosztas_meres', {url: url2, tipus: tipus});
}

///ajax
var i=1;
function ajax_hivas(url,post_query,id){
	jQuery.ajax({
	   type: "GET",
	   url: url,
	   data: post_query,
	   success: function(msg){
	   		if(id!=''){
				jQuery("#"+id).html(msg);
				i++;
			}       
	   }
	});	
}

function cikk_like(like) {
	var cikk_id = jQuery("#cikk_like_cid").html();
	if (cikk_id) {
		ajax_hivas("index.php","block=cikk_oldal_like&ajax=1&cikk_id="+cikk_id+"&like="+like,"cikk_like");
	}
}

/*
$(function() {
	cikk_like(0);
});
*/


