$(function(){

	$("#simplerssfeedswidget-2 h2").unwrap();

	$(".rss ul li a").click(function(){
		window.open($(this).attr('href'));
		return false;
	})

	$(".order-radio").click(function(){
		$(".fizetendo span").html($(this).attr('rel'));
	});

	$("input[type=radio]").click(function(){
			ar = 0;
		$("input[type=radio]:checked").each(function(k,v){
			ar = ar + parseInt($(v).attr('rel'));
		})
		$(".fizetendo span").html(ar);
		$("#f_32").val(ar + ' Ft');
	});
	
	$("#callback").click( callBackEvent );

	$('#callbacknumber').keypress(function(e) {
		if(e.keyCode == 13) {
			callBackEvent();
		}
	});

	$("#eco-cal tr.eco-info").hide();

	$("#eco-cal .arrow").click(function(){
		id = "ei" + $(this).attr("id");
		$("#" + id).toggle();
		$(this).toggleClass("minus");
	});

	$("#contact-form,#form-platform,#form-free,#course-form,#feliratkozo_form_20").validationEngine();

	$("#contact-button").click(clickContactSend);

	$("#newsletter-submit").click(clickNewsletter);

	if ( $("#currencies").lenght > 0 )
		setTimeout("refreshCurrencies()", 5000);

	//$("#sign-in").click(clickCourse);

	$('#nav li').hover(
			function () {
				//show its submenu
				$('ul', this).slideDown(100);

			}, 
			function () {
				//hide its submenu
				$('ul', this).slideUp(100);			
			}
		);

		
		$(".fade").fadeTo(0,0.8).hover(
			function(){
				$(this).fadeTo(500,1);
			},
			function(){
				$(this).fadeTo(500,0.8);
			}
		);

		$('.flexslider').flexslider({
			animation: "fade",
			slideshow: true,         
			slideshowSpeed: 6000,
			animationDuration: 1000,
			pauseOnAction: true,
			pauseOnHover: true,
			controlNav: true
		});

		refreshCurrencies();



});

function callBackEvent(){

		var number = $("#callbacknumber").val();
		if ( number.length < 5 ){
			$.msg({ content: 'Kérem, adja meg helyesen a telefonszámát!' });
		}else
		{
			$.post("http://privatfx.hu/privatfx/wp-content/themes/privatfx/callback.php", {"number": number}, function(){
				$.msg({ content: 'Köszönjük érdeklődését! Munkatársunk hamarosan felhívja Önt!' });
				$("#callbacknumber").val('');
			})
		}
	
}

function clickCourse() {
	var valid = $("#course-form").validationEngine('validate');
	return valid;
}

function refreshCurrencies(){
	$("#ccontainer").load("http://privatfx.hu/privatfx/wp-content/themes/privatfx/forex.php #cross_rate_1", function(){
		$("#cross_rate_1").css({width:"310px"});
	});

	setTimeout("refreshCurrencies()", 3000);
}

function clickNewsletter(){
	var valid = $("#newsletter").validationEngine('validate');
	return valid;
}

function clickFreeCourse(){
	
	var valid = $("#form-free").validationEngine('validate');

	if ( valid ){

		$.post('http://privatfx.hu/privatfx/wp-content/themes/privatfx/form-free.php', $("#form-free").serialize(), function(d,t){
			checkCaptcha(d,t,'#form-free','Sikeresen fogadtuk a jelentkezését! A részletekről emailben is tájékoztattuk.');
		});
		
	}
}

function clickPlatformDown(){
	
	var valid = $("#form-platform").validationEngine('validate');

	if ( valid ){

		$.post('http://privatfx.hu/privatfx/wp-content/themes/privatfx/form-platform.php', $("#form-platform").serialize(), function(d,t){
			checkCaptcha(d,t,'#form-platform','A platform letöltési linkjét elküldtük Önnek<br />a megadott email címére!');
		});
		
	}
}


function clickContactSend(){

	var valid = $("#contact-form").validationEngine('validate');

	if ( valid ){
		
		$.post('http://privatfx.hu/privatfx/wp-content/themes/privatfx/form-contact.php', $("#contact-form").serialize(), function(d,t){
			checkCaptcha(d,t,'#contact-form','Köszönjük megtisztelő megkeresését! Hamarosan felvesszük Önnel a kapcsolatot.');
		});
		
	}

}

function checkCaptcha(d,t,form,msg){
	
	if ( d != 0 )
	{
		//$.msg('unblock',0,1);

		if ( d == "wrong captcha" )
			$.msg({content:'Hibás ellenőrző kód! Kérem, adja meg helyesen a kódot!'});
		else
			$.msg({content:'A küldés nem sikerült! Kérem, próbálja újra.'});

		$("#reCaptcha").click();
		$("#captcha").val('');
		
	}else
	{
		$.msg({
			content: msg,
			beforeUnblock: function(){
				$(form)[0].reset();
				$("#reCaptcha").click();
			}
		});
	}
		
}



function cwCreateCookie(name,value,days) {

	if (days) {

		var date = new Date();

		date.setTime(date.getTime()+(days*24*60*60*1000));

		var expires = "; expires="+date.toGMTString();

	}

	else var expires = "";

	document.cookie = name+"="+value+expires+"; path=/";

}



function cwReadCookie(name) {

	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {

		var c = ca[i];

		while (c.charAt(0)==' ') c = c.substring(1,c.length);

		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);

	}

	return null;

}
