$(document).ready(function() {
    
    $("a[rel^='prettyPhoto']").prettyPhoto();
    
	setUpDropDown();

	

	// index top kepek forgatasa

	if ( $('.slideshow').length ) {

		$('.slideshow').cycle({

			fx: 'fade',

			timeout: 5000,

			speed: 2000

		});

	}
	
	$("#loginsubmit").click(function(e){
		e.preventDefault();
		var email=$("[name='loginform'] > input[name=email]").val();
		var password=$("[name='loginform'] > input[name=password]").val();
		$.post("felhasznalo/belepes", { 'user[email]' : email, 'user[password]' : password },
              function(data){
                if (data.status == 'ok') {
                    if (data.change_pass == 'yes') {
                        window.location='belepes/jelszo_valtozatatas';
                    } else {
                        document.location.reload();
                    }
                } else {
				    $('#loginerror').html(data.message);
					//$('#login_email').val('');
                    $('#login_pass').val('');
					$('#login_email').addClass('error');
                    $('#login_pass').addClass('error');
                }
              }, "json");
	});

});



function setUpDropDown() {

	// dropdown menu effekt

		$(" #nav ul ").css({display: "none"});

	$(" #nav li").hover(function(){

		$(this).find('ul:first').css({visibility: "visible",display: "none"}).show();

	},function(){

		$(this).find('ul:first').hide();

	});

	

	// ha 2 vagy 3 sorbol all, feljebb pozicionaljuk a menu szoveget

	$("#nav > li > a").each(function() {

		var menutext = $(this).html();

		// ha 2

		if( menutext.search(/\<br/i) != -1 ) {

			$(this).css('padding-top', '8px').css('height', '30px');

			var menutext = menutext.replace(/\<br/i, "");

		}

		// ha 3

		if( menutext.search(/\<br/i) != -1 ) {

			$(this).css('padding-top', '3px').css('height', '35px');

		}

	});
	/*
	$("#nav > li > ul > li a").each(function() {

		var menutext = $(this).html();

		// ha 2

		if( menutext.search(/\<br/i) != -1 ) {

			$(this).css('padding-top', '2px').css('height', '30px').css('line-height', '13px');
			var menutext = menutext.replace(/\<br/i, "");

		}

		// ha 3

		if( menutext.search(/\<br/i) != -1 ) {

			$(this).css('padding-top', '2px').css('height', '42px').css('line-height', '13px');

		}

	});*/

	

	// dropdown menu elemei moge nyilat teszunk ha van benne almenu

	var ext_ul = $(this);

	$("#nav li").each(function() {

		dsfsdfsd = $(this);

		$(this).find('ul:first').each(function() {

			dsfsdfsd.find('a:first').attr('class', 'navicon');

		});

	});

}



function preloadImages(images) {

	for(var i = 0; i<images.length; i++) {

		$("<img>").attr("src", images[i]);

	}

}



function shippingAdressToggle() {

	if($('#shipping_radio').attr("checked") == true)

		$('.shipping_adress').show();

	if($('#shipping_radio').attr("checked") == false)

		$('.shipping_adress').hide();

}
