/*
 * lapozo
 */
var lapozo = {};
lapozo.set = function() {
	$('.lapozo a').click(function(e) {
		e.preventDefault();
		var pageElem = this.toString();
		var page = pageElem.split("/");
		$('.right').height($('.modul').height());
		$('.modul').fadeOut(200);

		$.ajax({
			url: window.location.pathname,
			type: 'POST',
			data: {ajax_page:page[page.length-1]},
			success: function(msg) {
				$('.modul').html(msg);
				$('.right').height('auto');
				$('.modul').fadeIn('slow');
				$('html, body').animate({scrollTop:0}, 'slow');
				lapozo.set();
				albumSet.release();
			}
		});
	});
};

/*
 * naptar funkcio, ajaxosan lapozza a honapokat, eveket
 *
 */
var Calendar = {};
Calendar.set = function() {
	$('.dateselect a').click(function(e) {
		e.preventDefault();

		var _url = $(this).attr('href');

		$('.calendar_content').fadeOut(200);

		$.ajax({
			url: _url,
			type: 'POST',
			data: {type:'ajax'},
			success: function(msg) {
				$('.calendar_content').html(msg);
				$('.calendar_content').fadeIn('slow');
			}
		});
	});
};
/*
 * beallitja, hogy a a fooldalon mindig a slideshow
 * aktualis hir url-je legyen a tovabb-nal
 */
var MainNewURL = {};
MainNewURL.set = function() {
	_url = $('a', this).attr("href");
	$('.rotatorhir-tovabb').attr("href", _url);
};

var albumSet = {};
albumSet.release = function() {
	$('.album').click(function(e) {
		e.preventDefault();
		$(window.location).attr('href', $('.obj_link', this).attr('href'));
	});
	$('.album .thumbnail').cycle({
		fx:		'scrollRight',
		speed:	400,
		timeout:    1500
	}).cycle("pause");
	$('.album').hover(function() {
		$('.thumbnail', this).cycle('resume');
	},function() {
		$('.thumbnail', this).cycle('pause');
	});
	$('.loading').hide();
	$('.loading').load(function() {
		$(this).fadeIn('slow');
	});
	$("a.nagy").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'easingIn'		:	'easeOutBack',
		'easingOut'		:	'easeInBack',
		'overlayShow'	:	false,
		'titlePosition'	:	'over'
	});
	$("a.open_images").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'easingIn'		:	'easeOutBack',
		'easingOut'		:	'easeInBack',
		'overlayShow'	:	false,
		'titlePosition'	:	'over',
		'titleFormat': function(title) {
			return "<span id='fancybox-title-over'>" + title + "<br /><iframe src='http://www.facebook.com/plugins/like.php?href=" + encodeURI($(this).attr('href')) + "&amp;layout=button_count&amp;show_faces=false&amp;width=80&amp;action=like&amp;font=arial&amp;colorscheme=light&amp;height=22' scrolling='no' frameborder='0' style='border:none; overflow:hidden; width:120px; height:22px; margin-top: 5px;' allowTransparency='true'></iframe></span>";
		}
	});
}

/*
 * altalanos dolgok
 */
$(document).ready(function() {
	var url = $(location).attr('href');
	var main_page = false;
	var search_str = $('.search_val').val();

	$('.figures').cycle({
		fx:    'fade',
		speed:  2500
	});
	$('.headerright').cycle({
		fx:    'fade',
		speed:  2500
	});
	$('.album').click(function(e) {
		e.preventDefault();
		$(window.location).attr('href', $('.obj_link', this).attr('href'));
	});
	$('.album .thumbnail').cycle({
		fx:		'scrollRight',
		speed:	400,
		timeout:    1500
	}).cycle("pause");
	$('.album').hover(function() {
		$('.thumbnail', this).cycle('resume');
	},function() {
		$('.thumbnail', this).cycle('pause');
	});
	$('.loading').hide();
	$('.loading').load(function() {
		$(this).fadeIn('slow');
	});
	$("a.nagy").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'easingIn'		:	'easeOutBack',
		'easingOut'		:	'easeInBack',
		'overlayShow'	:	false,
		'titlePosition'	:	'over'
	});
	$("a.open_images").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'easingIn'		:	'easeOutBack',
		'easingOut'		:	'easeInBack',
		'overlayShow'	:	false,
		'titlePosition'	:	'over',
		'titleFormat': function(title) {
			return "<span id='fancybox-title-over'>" + title + "<br /><iframe src='http://www.facebook.com/plugins/like.php?href=" + encodeURI($(this).attr('href')) + "&amp;layout=button_count&amp;show_faces=false&amp;width=80&amp;action=like&amp;font=arial&amp;colorscheme=light&amp;height=22' scrolling='no' frameborder='0' style='border:none; overflow:hidden; width:120px; height:22px; margin-top: 5px;' allowTransparency='true'></iframe></span>";
		}
	});
	$('a.youtube_video').click(function(e) {
		e.preventDefault();

		var _title = $(this).attr("title");

		$.fancybox({
			'transitionIn'	:	'elastic',
			'transitionOut'	:	'elastic',
			'easingIn'		:	'easeOutBack',
			'easingOut'		:	'easeInBack',
			'overlayShow'	:	false,
			'titlePosition'	:	'over',
			'width'			:	680,
			'height'		:	430,
			'type'			:	'iframe',
			'titlePosition'	:	'over',
			'href'			:	$(this).attr("href") + "/frame",
			'titleFormat': function() {
				return "<span id='fancybox-title-over'>" + _title + "<br /><iframe src='http://www.facebook.com/plugins/like.php?href=" + encodeURI($(this).attr('href')) + "&amp;layout=button_count&amp;show_faces=false&amp;width=80&amp;action=like&amp;font=arial&amp;colorscheme=light&amp;height=22' scrolling='no' frameborder='0' style='border:none; overflow:hidden; width:120px; height:22px; margin-top: 5px;' allowTransparency='true'></iframe></span>";
			}
		});
	});
	$('.imagebox').cycle({
		fx:    'fade',
		speed:  1000,
		timeout:6000
	});
	$('.rotatorhir').cycle({
		fx:		'scrollRight',
		speed:	1000,
		timeout:    6000,
		pager:	'.rotator-selector',
		after: MainNewURL.set
	});
	$('.rotator-selector a').click(function(){
		s = parseInt($(this).html());
		$('.imagebox').cycle(s-1);
	});
	$('.menu ul li a').each(function() {
		if (url.indexOf($(this).attr("href")) > 0) {
			$('.menuitem', this).addClass("current");
			main_page = true;
		}
	});

	if (main_page == false) {
		$('.menu ul li a').each(function() {
			if (url.indexOf('kezdooldal') > 0) {
				$('.menuitem', this).addClass("current");
			}
		});
	}

	$('.search_val').focus(function () {
		if ($(this).val() == "Keresés...") {
			$(this).val('');
		}
	});
	$('.search_val').blur(function () {
		if ($(this).val() == "") {
			$(this).val(search_str);
		}
	});
	$('.links a').click(function(e) {
		e.preventDefault();

		_url = $(this).attr("href");

		$.ajax({
			url: window.location.pathname,
			type: 'POST',
			data: {type:'ajax', url:$(this).attr("href")},
			success: function(msg) {
				$(window.location).attr('href', _url);
			}
		});
	});
	lapozo.set();
	Calendar.set();
});
