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


function faszbuk(){
	var src = 'http://www.facebook.com/pages/edit/picture.php?success=1&id=110732935606432#!/pages/Jegkremdesszert-Klub/110732935606432?ref=ts';
	$.post('/ajax/facebook_share', function(data){
		if (data == ''){
				showPopUp('','','csillagBezar');
				$('.csillagBezar a').click(function(){
					window.location = src
				})
		}
		else{
			window.location = src
		}
		
	} )
	
}


$(document).ready(function() {
	if (openCsillag){
		$('#numOfCsillag').html(numCsillag); // ez az index headjebe generalodik be
		Cufon.replace('.cufon');
		showPopUp('','','csillagBezar');
	}
//	showPopUp('','','csillagBezar');
	
	$(document).pngFix();

	Shadowbox.init();
	$.post('/ajax/my_stars', {}, function(data){
		$('#myStars').html(data);
		$('#allStars').html(all_star)
		Cufon.replace('h3');
	} )
	$('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) {
				hidePopUp();
				showPopUp('','','csillagBezar');
				var f = $.evalJSON(data);
//				if(f['feedback'] == 1) {					
//					hidePopUp();
//					showPopUp('','','csillagBezar');
//				}else
//					alert(f['feedback']);
			}
		);
	}
}

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) {
				var f = $.evalJSON(data);
				if(f['feedback'] == 1) {
					if (f['error'] == ''){
						hidePopUp();
						showPopUp('','','csillagBezar');
					}
					else{
						alert('Köszönjük ajánlását!');
						hidePopUp();
					}
				}else
					alert( f['error']);
			}
		);
	}
}

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());
	$('#ok').show();

	if(type == 'paros' || type=='parosuj')
	{
		$('.csillagBezar').hide();
		$('.csillagAllasom').hide()
		$('.wrapcont').show();
		$('.ajanlas').hide();
		$('.hirlevel').hide();
		$('.receptkuldes').hide();
		$('.forgotpass').hide();

		if(type == 'paros')
			$('.wrapinfo').html("A következő link megosztásával, párod ismét beküldheti a most megadott kódot. Nem kell mást tennie, csak a kapott linken keresztül eljutnia az oldalra, majd beküldeni a kódot.<br /><br /><span style='color: #930A0A;'>http://www.jegkremdesszert.hu/paros/" + info + "</span><br /><br />Link küldése e-mailen keresztül: <br /><input type='text' name='kodmail' value='Címzett e-mail címe' id='parosmail' class='kodkuldes'/><br /><input type='text' name='kodcim' value='Címzett neve' id='parosnev' class='kodkuldes'/> <a href='javascript:sendParosMail(\""+info+"\");' style='color: #930A0A; margin-left: 5px;'>KÓD KÜLDÉSE</a><br /><br /><br /><!--br /><br /> Facebookon keresztüli megosztáshoz csak a gombra kell kattintanod, majd kiválasztani kedvesed.<br /><br /><a href='javascript:share()' class='fblogin'></a-->");
		else
			$('.wrapinfo').html(info);

		$('.wraptitle').html(title);

		$('#ok').hide();


		$('#parosmail').focus(function() {
			if($(this).val() == 'Címzett e-mail címe')
				$(this).val('');
		});

		$('#parosmail').blur(function() {
			if($(this).val() == '')
				$(this).val('Címzett e-mail címe');
		});

		$('#parosnev').focus(function() {
			if($(this).val() == 'Címzett neve')
				$(this).val('');
		});

		$('#parosnev').blur(function() {
			if($(this).val() == '')
				$(this).val('Címzett neve');
		});


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

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

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

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

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

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

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

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

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

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

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


		$('.wrapinfo').html(info);
		$('.wraptitle').html(title);
	}
	else if(type == 'csillagBezar'){
//		$('.wrapcont').hide();

		
		$('.csillagBezar').show();
		$('.csillagAllasom').hide()
		$('.wrapcont').hide();
		$('.ajanlas').hide();
		$('.hirlevel').hide();
		$('.receptkuldes').hide();
		$('.forgotpass').hide();
		
	}
	else if (type == 'csillagAllasom'){
		$('.csillagBezar').hide();
		
		$('.wrapcont').hide();
		$('.ajanlas').hide();
		$('.hirlevel').hide();
		$('.receptkuldes').hide();
		$('.forgotpass').hide();
	} 
	else{
		$('.wrapcont').show();
		$('.csillagBezar').hide();
		$('.csillagAllasom').hide()
		$('.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 sendParosMail(kod)
{
	hidePopUp();

	$.post('/main/sendParosMail', {'mail' : $('#parosmail').val(), 'kod' : kod, 'cimzett_neve' : $('#parosnev').val()},
		function(data) {
			showPopUp('Páros kód küldés e-mailben', data);
		}
	);
}



function hidePopUp() {

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

}

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

/**
 *
 * @access public
 * @return void
 **/
function share()
{
  FB.login(function(response) {
    if (response.session && response.perms) {
      $('#fbNotConnected').fadeOut(function() { $('#fbConnected').fadeIn() });
      popupateFields();
    } else {
      $('#fbNotConnected').fadeOut(function() { $('#fbNoPermissions').fadeIn() });
    }
  }, {perms: 'publish_stream'});

  /*FB.ui(
  {
    method: 'feed',
    attachment: {
      name: 'JSSDK',
      caption: 'The Facebook JavaScript SDK',
      description: (
        'A small JavaScript library that allows you to harness ' +
        'the power of Facebook, bringing the user\'s identity, ' +
        'social graph and distribution power to your site.'
      ),
      href: 'http://fbrell.com/'
    },
    action_links: [
      { text: 'fbrell', href: 'http://fbrell.com/' }
    ]
  },
  function(response) {
    if (response && response.post_id) {
      alert('Post was published.');
    } else {
      alert('Post was not published.');
    }
  }
);*/
}

$(document).ready(function() {
	$('.kerdoivpage LI').click(function() {
		var ans = $(this).attr('class').split('_');
		nextQuestion(ans[1]);
	});
});

var answers = new Array();
function nextQuestion(answer)
{
	answers.push(answer);
	
	if(answers.length == 4)
	{
		$.post('/ajax/kerdoiv/', {'answers': answers.toString()}, 
			function(data) {
				if(data == 1){
					showPopUp('', '', 'csillagBezar')
					
				}
			}
		);
	}
	
	$('.pagecontainer').animate({marginLeft: -(answers.length*606)}, 400);
}
