Cufon.replace('h1');
Cufon.replace('.leftmenu > a');
Cufon.replace('.topmenu > a');
Cufon.replace('.footer > a');
Cufon.replace('.footerbottom > a');

$(document).ready(function() {

	$(document).pngFix();

	Shadowbox.init();

	$('ul.gallery').galleria({
		history   : false, // activates the history object for bookmarking, back-button etc.
		clickNext : true, // helper for making the image clickable
		insert    : '#main_image', // the containing selector for our main image
		onImage   : function(image,caption,thumb) { // let's add some image effects for demonstration purposes

			// fade in the image & caption
			if(! ($.browser.mozilla && navigator.appVersion.indexOf("Win")!=-1) ) { // FF/Win fades large images terribly slow
				image.css('display','none').fadeIn(1000);
			}
			caption.css('display','none').fadeIn(1000);

			// fetch the thumbnail container
			var _li = thumb.parents('li');

			// fade out inactive thumbnail
			_li.siblings().children('img.selected').fadeTo(500,0.3);

			// fade in active thumbnail
			thumb.fadeTo('fast',1).addClass('selected');

			// add a title for the clickable image
			image.attr('title','Next image >>');
		},
		onThumb : function(thumb) { // thumbnail effects goes here

			// fetch the thumbnail container
			var _li = thumb.parents('li');

			// if thumbnail is active, fade all the way.
			var _fadeTo = _li.is('.active') ? '1' : '0.3';

			// fade in the thumbnail when finnished loading
			thumb.css({display:'none',opacity:_fadeTo}).fadeIn(1500);

			// hover effects
			thumb.hover(
				function() { thumb.fadeTo('fast',1); },
				function() { _li.not('.active').children('img').fadeTo('fast',0.3); } // don't fade out if the parent is active
			)
		}
	});

	$(document).click(function() {
		$('#legorduloStore').hide();
	});

	$('#wrap').css('height', $(document).height());

	$('#wrap #ok').click(hidePopUp);

	$('#wrap #megsem').click(hidePopUp);

	$('.wrapimage').click(hidePopUp);

	// Legördülő menü
	$('#legorduloStore').hide();

	$('#legorduloStore, #textfield, #openbtn').click(function(event){
	    event.stopPropagation();
	});

	$('#openbtn').click(function() {
		$('#legorduloStore').slideToggle(0);
	});

	$('#legorduloStore LI').mouseover(function() {
		$('A', this).css('color', 'white');
	});

	$('#legorduloStore LI').mouseout(function() {
		$('A', this).css('color', '#930a0a');
	});

	$('#legorduloStore LI').click(function() {
		$('#textfield').html($('A', this).html());
		$('#legorduloStore').hide();

		var link = $('A', this).attr('href');
		location.href=link;
	});

	$('#keresessubmit').click(function() {
		/*if($('.search_field').val() == 'Keresés' || $('.search_field').val() == '') {
			showPopUp('Információ', 'A kereséshez meg kell adnod egy kulcsszót!', '')
			return;
		}*/
		var checks = '';

		$('.params .pipa:visible').each(function() {
			checks += '&'+$(this).next('INPUT').attr('name') + '=' + $(this).next('INPUT').val();
		});

		$('#checks').val(checks);

		$('#receptform').submit();
	});

	/*$('.search_field').focus(function() {
		if($(this).val() == 'Keresés')
			$(this).val('');
	});

	$('.search_field').blur(function() {
		if($(this).val() == '')
			$(this).val('Keresés');
	});*/

	$('.param .check').each(function() {
		$(this).click(function() {
			$('.pipa', this).slideToggle(0);
		});

		$(this).next('.pt').click(function() {
			$(this).prev('.check').find('.pipa').slideToggle(0);
		});
	});

});

function showPreview(id, message) {
	showPopUp(message, '<img style="padding-top: 10px;" src="/flash/ecard/ecard_pic_'+id+'.jpg" />', 'ecard');
}

function hirlevelSend() {

	if($('#h_nev').val() != '' && $('#h_email').val() != '')
	{
		$.post('/ajax/hirlevel/', {'nev' : $('#h_nev').val(), 'email' : $('#h_email').val()},
			function(data) {
				if(data == 1) {
					alert('Sikeres feliratkozás!');
					hidePopUp();
				}else
					alert(data);
			}
		);
	}
}

function receptSend() {

	if($('#c_nev').val() != '' && $('#c_email').val() != '' && $('#s_nev').val() != '')
	{
		$.post('/ajax/receptkuldes/', {'nev' : $('#c_nev').val(), 'email' : $('#c_email').val(), 'sajatnev' : $('#s_nev').val(), 'url' : location.href},
			function(data) {
				if(data == 1) {
					alert('Sikeres küldés!');
					hidePopUp();
				}else
					alert(data);
			}
		);
	}
}

function ajanlasSend() {

	if($('#sajatnev').val() != '' && $('#cimzettnev').val() != '' && $('#sajatemail').val() != '' && $('#cimzettemail').val() != '') {
		$.post('/ajax/ajanlas/', {'megjegyzes' : $('#megjegyzes').val(), 'sajatnev' : $('#sajatnev').val(), 'sajatemail' : $('#sajatemail').val(), 'cimzettnev' : $('#cimzettnev').val(), 'cimzettemail' : $('#cimzettemail').val()},
			function(data) {
				if(data == 1) {
					alert('Köszönjük ajánlását!');
					hidePopUp();
				}else
					alert(data);
			}
		);
	}
}

function forgotSend() {

	if($('#f_email').val() != '') {
		$.post('/ajax/forgotpass/', {'email' : $('#f_email').val()},
			function(data) {
				if(data == 1) {
					alert('Az új jelszavát hamarosan megkapja a megadott e-mail címére!');
					hidePopUp();
				}else
					alert(data);
			}
		);
	}
}

function showPopUp(title, info, type) {

	$('#wrap').height($(document).height());


	if(type == 'forgotpass') {
		$('.wrapcont').hide();
		$('.ajanlas').hide();
		$('.hirlevel').hide();
		$('.receptkuldes').hide();
		$('.forgotpass').show();

		$('#forgotpassbtn').unbind('click');
		$('#forgotpassbtn').bind('click', forgotSend);

	}else if(type == 'ajanlas') {
		$('.wrapcont').hide();
		$('.ajanlas').show();
		$('.hirlevel').hide();
		$('.receptkuldes').hide();
		$('.forgotpass').hide();

		$('#ajanlasok').unbind('click');
		$('#ajanlasok').bind('click', ajanlasSend);

	}else if(type == 'hirlevel') {
		$('.wrapcont').hide();
		$('.ajanlas').hide();
		$('.hirlevel').show();
		$('.receptkuldes').hide();
		$('.forgotpass').hide();

		$('#hirlevelok').unbind('click');
		$('#hirlevelok').bind('click',hirlevelSend);

	}else if(type == 'recept') {
		$('.wrapcont').hide();
		$('.ajanlas').hide();
		$('.hirlevel').hide();
		$('.receptkuldes').show();
		$('.forgotpass').hide();

		$('#receptok').unbind('click');
		$('#receptok').bind('click',receptSend);

	}else if(type == 'ecard') {

		$('.wrapcont').width(590);
		$('.wrapinfo').height(376);

		$('.wrapcont').show();
		$('.ajanlas').hide();
		$('.hirlevel').hide();
		$('.receptkuldes').hide();
		$('.forgotpass').hide();


		$('.wrapinfo').html(info);
		$('.wraptitle').html(title);
	}else{
		$('.wrapcont').show();
		$('.ajanlas').hide();
		$('.hirlevel').hide();
		$('.receptkuldes').hide();
		$('.forgotpass').hide();

		$('.wrapinfo').html(info);
		$('.wraptitle').html(title);
	}

	$('.wrapimage').hide();
	$('#megsem').show();
	$('#wrap').fadeIn(300);


	var w = $('.wrapcont').css('width').split('px');
	var h = $('.wrapcont').height();

	var left = ($(window).width()/2-w[0]/2)+'px';
	var top = ($(window).height()/2-h/2)+$(document).scrollTop()+'px';
	$('.wrapcont').css('left', left);
	$('.wrapcont').css('top', top);
	$('.wrapcont').css('margin', '0');

}



function hidePopUp() {

	$('#wrap').fadeOut(300);

}

function vote(id) {
	$.post('/main/vote/', {'id' : id},
		function(data) {
			window.location.reload()
		}
	)
}