jQuery(function() {
	// Menu hover
	jQuery('.fe_menu td').each(function(index, value) {
		if (jQuery('#menu_hover_img_' + jQuery(value).attr('id').substr(5)).length > 0)
			jQuery(value).hover(
				function() { $(this).find('img').attr('src', jQuery('#menu_hover_img_' + jQuery(value).attr('id').substr(5)).attr('src')); },
				function() { $(this).find('img').attr('src', jQuery('#menu_hover_img_' + jQuery(value).attr('id').substr(5)).attr('alt')); }
			);
	});
	// Kommentre válasz
	jQuery('.fe_comments .reply').click(function() {
		jQuery('#replyto').val($(this).attr('id').substr(9));
	});
	// Válasz kinyitása
	jQuery('.fe_comments .reply_head').click(function() {
		var content = jQuery(this).parent().find('.reply_content');
		if (content.is(':hidden')) content.show();
		else content.hide();
	});
	// Keresés
	jQuery('#blogsearch').blur(function() {
		if (!jQuery(this).val()) jQuery(this).val('Keresés a blogon...');
	});
	jQuery('#blogsearch').focus(function() {
		if (jQuery(this).val() == 'Keresés a blogon...') jQuery(this).val('');
	});
})

// fókuszos topstorys
function showThatStuff(id) {
		 if (id != 's_1') {jQuery('#s_1').hide();}
		 if (id != 's_2') {jQuery('#s_2').hide();}
		 if (id != 's_3') {jQuery('#s_3').hide();}
		 if (id != 's_4') {jQuery('#s_4').hide();}
		 
		 if (id == 's_1') {jQuery('#s_1').fadeIn('slow');}
		 if (id == 's_2') {jQuery('#s_2').fadeIn('slow');}
		 if (id == 's_3') {jQuery('#s_3').fadeIn('slow');}
		 if (id == 's_4') {jQuery('#s_4').fadeIn('slow');}
}
// fókuszos topstorys 2
jQuery(function() {
	jQuery("#d_1").click(function(){ hideFocuses(); jQuery('#s_1').fadeIn('slow'); });
	jQuery("#d_2").click(function(){ hideFocuses(); jQuery('#s_2').fadeIn('slow'); });
	jQuery("#d_3").click(function(){ hideFocuses(); jQuery('#s_3').fadeIn('slow'); });
	jQuery("#d_4").click(function(){ hideFocuses(); jQuery('#s_4').fadeIn('slow'); });
})

function hideFocuses(){
	jQuery('#s_1').hide();
	jQuery('#s_2').hide();
	jQuery('#s_3').hide();
	jQuery('#s_4').hide();
}

/****************/
/* Kommentekhez */
/****************/
var clickedB    = 0;
var clickedI    = 0;
var clickedURL  = 0;

var KOMMENTJS = {

	clickB: function() {
		if (clickedB) {
			clickedB = 0;
			document.comment_form.comment_text.value += "[/b]";
			document.comment_form.b.value = "Vastag";
			document.comment_form.comment_text.focus();
		} else {
			clickedB = 1;
			document.comment_form.comment_text.value += "[b]";
			document.comment_form.b.value = "Vastag*";
			document.comment_form.comment_text.focus();
		}
	},

	clickI: function() {
		if (clickedI) {
			clickedI = 0;
			document.comment_form.comment_text.value += "[/i]";
			document.comment_form.i.value = "Dőlt";
			document.comment_form.comment_text.focus();
		} else {
			clickedI = 1;
			document.comment_form.comment_text.value += "[i]";
			document.comment_form.i.value = "Dőlt*";
			document.comment_form.comment_text.focus();
		}
	},

	clickURL: function() {
		var link = prompt("Add meg a linket:", "http://");
		if (link!=null && link!="" && link!="http://") {
			var linkname = prompt("Írd ide a szót amit linkelni akarsz:", "");
			if (linkname!=null && linkname!="") {
				document.comment_form.comment_text.value += "[url="+link+"]"+linkname+"[/url]";
			} else {
				alert("Hibás név!");
			}
		} else {
			alert("Hibás link!");
		}
	},

	closeAll: function() {
		if (clickedURL) { // direkt van elobb az url
			clickedURL = 0;
			document.comment_form.comment_text.value += "[/url]";
			document.comment_form.url.value = "Link";
			document.comment_form.comment_text.focus();
		}
		if (clickedB) {
			clickedB = 0;
			document.comment_form.comment_text.value += "[/b]";
			document.comment_form.b.value = "Vastag";
			document.comment_form.comment_text.focus();
		}
		if (clickedI) {
			clickedI = 0;
			document.comment_form.comment_text.value += "[/i]";
			document.comment_form.i.value = "Dőlt";
			document.comment_form.comment_text.focus();
		}
	},

	smiley: function() {
		//smwin = window.open('/smileys','smwin','resizable=no, scrollbars=yes, menubar=no, width=640, height=480, left=100, top=100');
	},

	ins: function(smiley) {
		document.comment_form.comment_text.value += smiley;
	}
}

// Thumb up-down function
function addVote(article_id, comment_id, thumb) {
	// alert('artID: '+article_id+' - comID: '+comment_id+' - thumb: '+thumb);
    jQuery.ajax({
        type: "POST",
        url: '/ajax/do_thumbs.php',
        data: {article_id: article_id, comment_id: comment_id, thumb: thumb},
        dataType: 'json',
        success: function(msg){
			if (!msg.error) {
				jQuery('#thumbup_'+comment_id).addClass('inactive');
				jQuery('#thumbdown_'+comment_id).addClass('inactive');
				if (msg.plusz > 0) {
					jQuery('#hszvp_'+comment_id).text('('+msg.plusz+')');
				}
				if (msg.minusz > 0) {
					jQuery('#hszvm_'+comment_id).text('('+msg.minusz+')');
				}
			}
        },
        error: function(){
            alert( "Kérlek próbáld újra!" );
        }
    });
}

// Thumb up-down function NEED LOGIN
function needLogin(element) {
	// alert('artID: '+article_id+' - comID: '+comment_id+' - thumb: '+thumb);
	var parent = jQuery(element).parent();
	if (jQuery('.hszneedlogin', parent).length == 0) {
		jQuery(parent).append('<span class="hszneedlogin">Az értékeléshez be kell jelentkezned.</span>');
	}
}

// Thumb up-down function SZAVAZOTT
function youVoted(element) {
	// alert('artID: '+article_id+' - comID: '+comment_id+' - thumb: '+thumb);
	var parent = jQuery(element).parent();
	if (jQuery('.hszneedlogin', parent).length == 0) {
		jQuery(parent).append('<span class="hszneedlogin">Már szavaztál.</span>');
	}
}
