﻿var CORE;

CORE = {

	_galleria_init: false,
	_galleriaBG_html: false,

	// 2 perc
	_galleriaBG_timing: 120*1000,

	initGalleria: function() {

		w = $(window).width();
		h = $(window).height();
		allas = $(window).scrollTop();

		// alert(allas);
		// alert(w + " x " + h);
	
		$("#galleriaImg").css({ height: h, width: w, left: 0, top: allas }).galleria({
			width: w,
			height: h,
			// clicknext: true,
			// maxScaleRatio: 1,
			transition: 'fade',
			transitionSpeed: 1000,
			debug: false,
			extend: function(options) {

				var gallery = this; // "this" is the gallery instance
				$('#galleriaClose').click(function() {

					// háttérkép play
					var galleryBG = Galleria.get(0);
					galleryBG.play();


					gallery.pause();
					CORE.closeGalleria();
					return false;

				});

				$('#galleriaSlideshowPlay').click(function() {

					gallery.play(3000);
					$('#galleriaSlideshowPlay').css('display', 'none');
					$('#galleriaSlideshowPause').css('display', 'block');
					return false;

				});

				$('#galleriaSlideshowPause').click(function() {

					gallery.pause();
					$('#galleriaSlideshowPlay').css('display', 'block');
					$('#galleriaSlideshowPause').css('display', 'none');
					return false;

				});

			}
		});

		CORE._galleria_init = true;
	
	},

	closeGalleria: function() {

		$('#galleriaImg, #galleriaClose, #galleriaSlideshowPlay, #galleriaSlideshowPause').css('display', 'none');
		$('body').css('overflow', 'auto');
	
	},

	kepek: function() {

		// háttérkép pause
		var galleryBG = Galleria.get(0);
		galleryBG.pause();

		$('#galleriaImg, #galleriaClose, #galleriaSlideshowPlay').css('display', 'block');
		$('#galleriaSlideshowPause').css('display', 'none');
		$('body').css('overflow', 'hidden');

		if (CORE._galleria_init == false) CORE.initGalleria();

		// escape gomb
		$(document).keyup(function(e) {

			if(e.keyCode == 27) CORE.closeGalleria();

		});

		return false;
	
	},

	initGalleriaBG: function(w, h) {

		// alsó menü miatt
		h -= 40;

		// alert(w + " * " + h);

		if (CORE._galleriaBG_html != false) {
	
			// visszatöltjük a képeket
			$("#galleriaImgBG").css({ height: h, width: w }).html(CORE._galleriaBG_html);

		}

		// eltároljuk a képeket
		else CORE._galleriaBG_html = $("#galleriaImgBG").html();
	
		$("#galleriaImgBG").css({ height: h, width: w, display: 'block' }).galleria({
			width: w,
			height: h,
			// clicknext: true,
			// maxScaleRatio: 1,
			transition: 'fade',
			transitionSpeed: 1000,
			showImagenav: false,
			imageCrop: true,
			imagePosition: 'center center',
			debug: false,
			extend: function(options) {

				var gallery = this; // "this" is the gallery instance
				gallery.play(CORE._galleriaBG_timing);
			
			}
		});
	
	},

	forditas: function(index) {

		// sárga kiemelés
		$('.live_forditas_szo').removeClass('most_szerkesztett');
		$('#_forditas_'+index).addClass('most_szerkesztett');

		$('#live_forditas_index_input').val(index);

		$('#live_forditas_input').val($('#_forditas_'+index).html()).unbind().removeAttr('disabled').focus().keyup(function(e) {

			$('#_forditas_'+index).html($(this).val());

		});
		
		$('#live_forditas_submit_input').removeAttr('disabled');
		$('#live_forditas_ok').css('visibility', 'hidden');

		return false;
	
	},
	forditasSubmit: function() {

		index = $('#live_forditas_index_input').val();
		ertek = $('#live_forditas_input').val();

		$('#live_forditas_submit_input, #live_forditas_input').attr('disabled', 'disabled');

		$.post('/adminx/forditas_live.php', { index: index, ertek: ertek },
			function(data) {

				if (data == 'ok') {
					
					$('#live_forditas_input').unbind().val('');
			
					$('.live_forditas_szo').removeClass('most_szerkesztett');

					$('#_forditas_'+index).html(ertek);
					
					$('#live_forditas_' + index).css('opacity', 0.1);
					$('#live_forditas_ok').css('visibility', 'visible');

				}
				else $('#_forditas_'+index).html(data);
				
			});

		return false;
	
	},

	scrollTo: function(id) {

		$('html,body').animate({scrollTop: $("#"+id).offset().top},'slow');

		return false;

	},

	szam_tagolas: function(nStr) {
		
		nStr += '';

		x = nStr.split('.');
		x1 = x[0];
		x2 = x.length > 1 ? '.' + x[1] : '';
		var rgx = /(\d+)(\d{3})/;
		while (rgx.test(x1)) {
			x1 = x1.replace(rgx, '$1' + ' ' + '$2');
		}
		return x1 + x2;

	},

	isset: function(valtozo) {
			
		return eval('typeof(' + valtozo + ') != "undefined"');
	
	},

	initExternalLinks: function() {

		$('a[rel="external"]').click(function(e) {

			e.preventDefault();

			window.open($(this).attr("href"), "_blank");

		});

	},

	initOverlay: function() {

		/*$('.overlay').each(function(index) {

			$(this).attr('overlay', $(this).attr('title'));
			$(this).attr('title', null);
			
			$(this).click(function(evt) {

				evt.preventDefault();

				text = $(this).attr('overlay');
				text = text.replace(/\|/g, '<br />');

				var $modal = $('<div class="overlay_inner">'+text+'</div>').css({
					background: '#fff',
					zIndex: 300000,
					padding: '10px',
					opacity: 1,
					position: 'absolute'
				});

				$(this).overlay({
					effect: 'fade',
					opacity: 0.5,
					closeOnClick: true,
					onShow: function() {
						$('body').append($modal);
						$modal.css({
							top: ($(window).height()-$modal.height())/2,
							left: ($(window).width()-$modal.width())/2
						});
					},
					onHide: function() { $modal.remove(); },
				});

			});

		});*/

	},

	initEmailKukac: function() {

		$('a.email_kukac').each(function(index) {

			cim = $(this).html();

			cim = cim.replace(/\(kukac\)/, "@");

			$(this).html(cim);
			$(this).attr('href', 'mailto:'+cim);
		
		});

	},

	initTooltip: function() {

		$('.tooltip-top').CreateBubblePopup({
			alwaysVisible: true,
			selectable: false,
			position : 'top',
			align	 : 'center',
			innerHtml: ' ? ',
			innerHtmlStyle: { color:'#000000', 'text-align':'left' },
			themeName: 	'orange',
			themePath: 	'include/jquerybubblepopup-theme'
		});

		$('.tooltip-top-s').CreateBubblePopup({
			alwaysVisible: true,
			selectable: true,
			position : 'top',
			align	 : 'center',
			innerHtml: ' ? ',
			innerHtmlStyle: { color:'#000000', 'text-align':'left' },
			themeName: 	'orange',
			themePath: 	'include/jquerybubblepopup-theme'
		});

		$('.tooltip-left').CreateBubblePopup({
			alwaysVisible: true,
			selectable: false,
			position : 'left',
			align	 : 'center',
			innerHtml: ' ? ',
			innerHtmlStyle: { color:'#000000', 'text-align':'left' },
			themeName: 	'orange',
			themePath: 	'include/jquerybubblepopup-theme'
		});

		$('.tooltip-right').CreateBubblePopup({
			alwaysVisible: true,
			selectable: false,
			position : 'right',
			align	 : 'center',
			innerHtml: ' ? ',
			innerHtmlStyle: { color:'#000000', 'text-align':'left' },
			themeName: 	'orange',
			themePath: 	'include/jquerybubblepopup-theme'
		});

		// szöveg a title-ból betöltve
		$('.tooltip-top, .tooltip-top-s, .tooltip-left, .tooltip-right').each(function(index) {

			text = $(this).attr('title');
			text = text.replace(/\|/g, '<br />');
			
			// linkek
			text = text.replace(/\[LINK=/g, '<a href='); // target="_blank"
			text = text.replace(/\"\]/g, '">');
			text = text.replace(/\[\/LINK\]/g, '</a>');
			
			$(this).SetBubblePopupInnerHtml(text, true);
			$(this).attr('title', null);

		});

	},

	regexCheck: function(input, regex, error) {

		if (_input_error) return false;

		if (regex === true) regex = '^.+$';
		else if (regex == 'number') regex = '^[0-9]+$';
		else if (regex == 'numbers') regex = '^[0-9]+(, ?[0-9]+)*$';
		else if (regex == 'email') regex = '^.+@.+$';

		rx = new RegExp(regex, "im");
		data = $("#"+input).val();

		if (!rx.test(data)) {

			$("#"+input).addClass('hibas_input');

			$("#"+input).change(function () {

				$("#"+input).removeClass('hibas_input');
				
			});

			$("#"+input).focus();

			_input_error = true;
			
			alert(error);

			return false;

		}

		else {
			
			$("#"+input).removeClass('hibas_input');
			
			return true;

		}
	
	},

	init: function() {

		// _galleria_inited = false;

		CORE.initEmailKukac();
		CORE.initExternalLinks();
		CORE.initTooltip();
		CORE.initOverlay();

	}

};

// jQuery.noConflict();
jQuery(document).ready(function($){

	CORE.init();

});

Galleria.loadTheme('/include/galleria_125/themes/classic/galleria.classic.min.js');
