$(document).ready(function(){

	homeSlider();

	$('a.sendEmail').bind('click', function(){
		var to = $(this).attr('data-to');

		$.ajax({
			type: "POST",
			url: document.URL,
			data: { ajaxFromTemplate: 'modules/send_email', to: to },
			success: function( data ) {
				Shadowbox.open({
					content:    '<div style="background:white;width:'+405+'px;height:'+270+'px;padding:10px;display:block;overflow:hidden">'+data+'</div>',
					player:     "html",
					title:      'E-mail küldése',
					height:     290,
					width:      425,
					options: 	{
						enableKeys: false,
						overlayOpacity: 0.7,
						onFinish: function() {
							$.formProcessor();
						}
					}
				});

			}
		});

		return false;
	});

	$('a.copyUserData').bind('click', function(){
		var from = $(this).attr('data-from');
		var to = $(this).attr('data-to');

		$('#db_users'+ to +'_country').val( $('#db_users'+ from +'_country').val() );
		$('#db_users'+ to +'_zip').val( $('#db_users'+ from +'_zip').val() );
		$('#db_users'+ to +'_city').val( $('#db_users'+ from +'_city').val() );
		$('#db_users'+ to +'_address').val( $('#db_users'+ from +'_address').val() );
	});

});


function homeSlider() {
	var $slideTime = 400;

	// add slide-arrows
	$('#header-image .header-slide').append( $('<a/>', {'class': 'header-slide-arrow' }) );

	$('#header-slide3, #header-slide3 .header-slide-arrow').bind('click', function(){
		$('#header-slide1').animate({'left': '0px'}, $slideTime);
		$('#header-slide2').animate({'left': '0px'}, $slideTime);
		$('#header-slide3').animate({'left': '0px'}, $slideTime);

		$('#header-slide1 div').fadeOut();
		$('#header-slide2 div').fadeOut();
		$('#header-slide3 div').fadeIn();
	});

	$('#header-slide2, #header-slide2 .header-slide-arrow').click(function(){
		$('#header-slide1').animate({'left': '0px'}, $slideTime);
		$('#header-slide2').animate({'left': '0px'}, $slideTime);
		$('#header-slide3').animate({'left': '280px'}, $slideTime);

		$('#header-slide1 div').fadeOut();
		$('#header-slide3 div').fadeOut();
		$('#header-slide2 div').fadeIn();
	});

	$('#header-slide1, #header-slide1 .header-slide-arrow').click(function(){
		$('#header-slide1').animate({'left': '0px'}, $slideTime);
		$('#header-slide2').animate({'left': '280px'}, $slideTime);
		$('#header-slide3').animate({'left': '280px'}, $slideTime);

		$('#header-slide3 div').fadeOut();
		$('#header-slide2 div').fadeOut();
		$('#header-slide1 div').fadeIn();
	});

	$('#header-slide1').click();
}

function registration(){
	$('#affiliateCode').bind('change',function(){
		$.ajax({
			type: "POST",
			url: document.URL,
			data: { ajaxFunction: 'getAffNameFromUsername', ajaxFile: 'regisztracio.php', username: $(this).val() },
			success: function( data ) { $('#affiliateName').css('display','inline').html(data); }
		});
	});
	$('#affiliateCode').change();
}
