$.fn.pulse = function(end, intime, outtime){
	$(this).animate({opacity: end}, outtime, function(){
		$(this).animate({opacity: 1}, intime, function(){
			$(this).pulse(end, intime, outtime)
		})
	})
}

function showData(e){
	$('.right').empty().append($('p', e).text()).hide().fadeIn()
	$('.left h2').empty().append($('h3', e).text()).hide().fadeIn()			
}


function refreshimg()
{
	$('#captchaimage span.captcha-imgholder').load('/async/process.php?action=recaptcha');
}


function initGuestBookForm(){
	if($('#guestbook-form').length > 0){
	
	
		$('body#vendegkonyv #content-right h2').click(function(){
			$("#guestbook-form").toggle(500)
		})
	
	
		$("#guestbook-form").validate({
			rules: {
				name: {
					required: true,
					minlength: 2
				},
				captcha: {
					required: true
				},
				email: {
					required: true,
					email: true
				},
				msg: {
					required: true,
					minlength: 10
				},
				user_agree: "required"
			},
			messages: {
				
				name: {
					required: "Kérem adja meg a nevét!",
					minlength: "A névnek minimum 2 betű hosszúnak kell lennie!"
				},
				msg: {
					required: "Kérem írja be az üzenetét!",
					minlength: "Az üzenetnek minimum 10 betű hosszúnak kell lennie!"
				},
				
				email: {
					required: "Kérem adja meg az e-mail címét!",
					email: "Nem megfeleő az e-mail cím"
				},
				
				captcha: {
					required: "Kérem írja be a képen látható szöveget!"
				}
			}

		});
		

		
	}
}


function slideSwitch() {
    var $active = $('#top-slideshow img.active');

    if ( $active.length == 0 ) $active = $('#top-slideshow img:last');

    var $next =  $active.next().length ? $active.next()
        : $('#top-slideshow img:first');


    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}


$(document).ready(function(){

    setInterval( "slideSwitch()", 15000 );

	$('a.lb').lightBox()

	$('#galeria ul#thumb-list').galleria({
		history   : true, // 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
			image.css('display','none').fadeIn(3000);
			caption.css('display','none').fadeIn(3000);
			
			// 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','Következő kép >>');
		},
		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.6';
			
			// 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.6); } // don't fade out if the parent is active
			)
		}
	});
	
//	var t=setInterval(function(){
//		$.galleria.next()
//		return true
//	},10000);
	
	
	initGuestBookForm();
});

function msg(t){
//	$('#message').stop()
	$('#message').text(t)//.show().fadeOut(2000)
}

function trace() {
	var debug = document.getElementById('debug');
	if (!debug) {
		var debug = document.createElement('div');
		debug.setAttribute('id', 'debug');
		document.body.appendChild(debug);
		
		debug.onclick = function() {
			if (this.closed) {
				this.style.height = '200px';
				this.closed = false;
			} else {
				this.style.height = '2px';
				this.closed = true;
			}
		}
		
	}
	if (debug) {
		var o = '';
		o = 'arguments.length = ' + arguments.length + '<br />';
//		o += arguments;
		for (var i=0; i<arguments.length; i++) {
			o += '<div style="margin-left: 16px;">';
			o += arguments[i];
			for (j in arguments[i]) {
				o += '<div style="margin-left: 16px;">';
				o += '<b>' + j +'</b>&nbsp;=&nbsp;' + String(arguments[i][j]).split('<').join('&lt;').split('>').join('&gt;').split('\"').join('&raquo;');
				o += '</div>';
			}				
			o += '</div>';
		}
		debug.innerHTML = o;
	}
}
