var aktpopup = "";

function refresh_lapozo_referenciak(mellik) {

	jQuery('#' + mellik).jcarousel({
		scroll: 1,
		visible: 4
	});

	jQuery('#' + mellik).children("li").mouseenter(function() {

		jQuery(this).children("a").children(".car_img").css("background-color", "#fe8300");

		jQuery(this).children("a").children(".car_akt").children("img").attr("src", "images/lapozo_akt.jpg");

		jQuery(this).children("a").children(".car_cim").css("color", "#fe5400");

		if (jQuery.browser.msie) {
			jQuery(this).children("a").children(".car_img").children("div").children("div").show();
		}

		else {
			jQuery(this).children("a").children(".car_img").children("div").children("div").fadeIn(300);
		}
	});

	jQuery('#' + mellik).children("li").mouseleave(function() {

		jQuery(this).children("a").children(".car_img").css("background-color", "#ffffff");

		jQuery(this).children("a").children(".car_akt").children("img").attr("src", "images/lapozo_inakt.jpg");

		jQuery(this).children("a").children(".car_cim").css("color", "#4c4c4c");

		if (jQuery.browser.msie) {
			jQuery(this).children("a").children(".car_img").children("div").children("div").hide();
		}

		else {
			jQuery(this).children("a").children(".car_img").children("div").children("div").fadeOut(300);
		}
	});

	jQuery("a[rel='lightbox']").colorbox();
}

function refresh_lapozo_helyszinek() {
	jQuery('#mycarousel-onecell').jcarousel({
		scroll: 1,
		visible: 1
	});

	jQuery(".helyszin_img").mouseenter(function() {
		if(jQuery(this).children(".nincs_kep").length == 0) {
			jQuery(this).css("background-color", "#fe8300");

			if (jQuery.browser.msie) {
				jQuery(this).children("a").children("div").children("div").show();
			}

			else {
				jQuery(this).children("a").children("div").children("div").fadeIn(300);
			}
		}
	});

	jQuery(".helyszin_img").mouseleave(function() {
		if(jQuery(this).children(".nincs_kep").length == 0) {
			jQuery(this).css("background-color", "#ffffff");

			if (jQuery.browser.msie) {
				jQuery(this).children("a").children("div").children("div").hide();
			}

			else {
				jQuery(this).children("a").children("div").children("div").fadeOut(300);
			}
		}
	});

	jQuery(".helyszin_img a").colorbox();
}

function showpopup(name, lang) {

	if(name != aktpopup) {

		if (aktpopup == "") { // a popup hátteret csak egyszer jelenítjük meg, mivel a design kötött
			if (jQuery.browser.msie) {
				jQuery("#popup_bg").show();
			}

			else {
				jQuery("#popup_bg").fadeIn(600);
			}
		}


		if (jQuery.browser.msie) {
			jQuery("#" + aktpopup + "_popup").hide();
		}

		else {
			jQuery("#" + aktpopup + "_popup").fadeOut(600);
		}


		img = name;

		if(name.indexOf("tevekenysegek") != "-1") {
			img = "tevekenysegek";
		}

		if(name.indexOf("referenciak") != "-1") {
			img = "referenciak";
		}
		
		jQuery("#fejlec_focim").attr("src", "images/" + img + "_flash_focim" + lang + ".png");


		if (jQuery.browser.msie) {

			jQuery("#" + name + "_popup").show();

			if(name != "referenciak") {
				jQuery("#" + name + "_popup_disz").show();
			}

			else {
				jQuery("#referenciak_popup_disz_swirls1").show();
				jQuery("#referenciak_popup_disz_figura").show();
			}
		}

		else {
			jQuery("#" + name + "_popup").fadeIn(600, function() {

				if(name != "referenciak") {
					jQuery("#" + name + "_popup_disz").fadeIn(600);
				}

				else {
					jQuery("#referenciak_popup_disz_swirls1").fadeIn(600, function() {
						jQuery("#referenciak_popup_disz_figura").fadeIn(600);
					});
				}
			});
		}


		if(name == "referenciak") {
			refresh_lapozo_referenciak("mycarousel");
		}

		if(name == "helyszinek") {
			refresh_lapozo_helyszinek();
		}

		if(name == "kapcsolat") {

			la = "hu";

			if(lang == "_eng") {
				la = "en";
			}

			jQuery("#googlemap").html('<iframe width="418" height="420" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=' + la + '&amp;geocode=&amp;q=1101+Budapest,+Albertirsai+%C3%BAt+10,+Magyarorsz%C3%A1g&amp;aq=0&amp;sll=37.0625,-95.677068&amp;sspn=42.310334,93.076172&amp;ie=UTF8&amp;hq=&amp;hnear=1101+Budapest,+X.+ker%C3%BClet,+Albertirsai+%C3%BAt+10,+Magyarorsz%C3%A1g&amp;ll=47.497836,19.123936&amp;spn=0.024355,0.036478&amp;z=14&amp;iwloc=lyrftr:m,7665321274823579038,47.491689,19.123678&amp;output=embed" style="border: 1px solid #cacaca;"></iframe>');
		}
	
		// fleXenv.initByClass("popup_content_gorgeto");

		aktpopup = name;
	}
}

function melyik_nem_latszik() {
	return (img_latszik == 1) ? img_nem_latszik = 2 : img_nem_latszik = 1;
}

var img_latszik = 1;
var anim = 0;

function background_update(name) {

	if(anim != 1) {

		anim = 1;

		var img_nem_latszik = melyik_nem_latszik();

		jQuery("#page_bg_" + img_latszik).css("z-index", "2");
		jQuery("#page_bg_" + img_nem_latszik).css("z-index", "1");

		jQuery("#page_bg_" + img_nem_latszik).show();
		jQuery("#bg_img_" + img_nem_latszik).attr("src", "images/" + name + "_bg.jpg");

		jQuery("#page_bg_" + img_latszik).fadeOut(600, function() {
			anim = 0;

			img_latszik = img_nem_latszik;
		});
	}
}

function refleptet(lapszam, rid, vissza) {

	new Ajax.Request('ajax_refleptet.php?lapszam=' + lapszam + '&rid=' + rid,
	  {
		method:'get',
		onSuccess: function(transport){
			var response = transport.responseText || "no response text";

			var referencia_osszpage = jQuery('#referenciak' + rid + '_osszpage_tmp').attr("value"); // összes oldal száma (galériával együtt)

			if(lapszam != referencia_osszpage) {
				var uj_tartalom = jQuery('#referenciak' + rid + '_popup .popup_content #referenciak' + rid + '_' + lapszam).html();
			}

			else { // ha galéria
				var uj_tartalom = jQuery('#referenciak' + rid + '_gal_popup').html();
			}

			var hova_div = jQuery('#referenciak' + rid + '_popup .popup_content .popup_child_tartalom');

			jQuery('#referenciak' + rid + '_popup .popup_child_lapozo_rel1 .popup_child_lapozo_rel2').html(response);

			jQuery("#referenciak_popup_disz_swirls2_" + rid).hide();
			jQuery("#referenciak_popup_disz_figura_" + rid).hide();

			if(vissza == "") {
				if (jQuery.browser.msie) {

					hova_div.html(uj_tartalom);

					if(lapszam == referencia_osszpage) {
						
						jQuery("#referenciak_popup_disz_swirls2_" + rid).show();
						jQuery("#referenciak_popup_disz_figura_" + rid).show();
						
						refresh_lapozo_referenciak("mycarousel_gal" + rid);

						createImgHovers('.popup_child_lapozo_rel2');
					}
				}

				else {
					if(lapszam == referencia_osszpage) {
						hova_div.fadeOut(300, function() {

							hova_div.html(uj_tartalom);

							hova_div.show();

							jQuery("#referenciak_popup_disz_swirls2_" + rid).fadeIn(600, function() {
								jQuery("#referenciak_popup_disz_figura_" + rid).fadeIn(600);
							});

							createImgHovers('.popup_child_lapozo_rel2');
							
							refresh_lapozo_referenciak("mycarousel_gal" + rid);
						});
					}

					else {
						hova_div.fadeOut(300, function() {

							hova_div.html(uj_tartalom);

							hova_div.fadeIn(300);

							createImgHovers('.popup_child_lapozo_rel2');
						});
					}	
				}
			}

			else { // a vissza gombra kattintott, ezért az első oldalt beállítjuk kezdőlapnak
				hova_div.html(uj_tartalom);

				createImgHovers('.popup_child_lapozo_rel2');
			}
		},
		onFailure: function(){
			alert('Szerver Hiba 0075!');
		}
	  });
}

function tevleptet(lapszam, focsop_id, vissza) {

	new Ajax.Request('ajax_tevleptet.php?lapszam=' + lapszam + '&focsop_id=' + focsop_id,
	  {
		method:'get',
		onSuccess: function(transport){
			var response = transport.responseText || "no response text";

			var uj_tartalom = jQuery('#tevekenysegek_focsop' + focsop_id + '_popup .popup_content #tevekenysegek_focsop' + focsop_id + '_' + lapszam).html();
			var hova_div = jQuery('#tevekenysegek_focsop' + focsop_id + '_popup .popup_content .popup_child_tartalom');

			jQuery('#tevekenysegek_focsop' + focsop_id + '_popup .popup_child_lapozo_rel1 .popup_child_lapozo_rel2').html(response);

			if(vissza == "") {
				if (jQuery.browser.msie) {
					hova_div.html(uj_tartalom);

					createImgHovers('.popup_child_lapozo_rel2');
				}

				else {
					hova_div.fadeOut(300, function() {

						hova_div.html(uj_tartalom);

						hova_div.fadeIn(300);

						createImgHovers('.popup_child_lapozo_rel2');
					});
				}
			}

			else { // a vissza gombra kattintott, ezért az első oldalt beállítjuk kezdőlapnak
				hova_div.html(uj_tartalom);

				createImgHovers('.popup_child_lapozo_rel2');
			}			
		},
		onFailure: function(){
			alert('Szerver Hiba 0075!');
		}
	  });
}

function csapleptet(merre) {

	aktpage = jQuery("#csappage_tmp").attr("value");

	new Ajax.Request('ajax_csapleptet.php?merre=' + merre + '&lapszam=' + aktpage,
	  {
		method:'get',
		onSuccess: function(transport){
			var response = transport.responseText || "no response text";

			if (jQuery.browser.msie) {
				jQuery('#popup_content_csapatunk').html(response);

				jQuery("#popup_content_csapatunk").show();
			}

			else {
				jQuery("#popup_content_csapatunk").fadeOut(300, function() {

					jQuery('#popup_content_csapatunk').html(response);

					jQuery("#popup_content_csapatunk").fadeIn(300);
				});
			}
		},
		onFailure: function(){
			alert('Szerver Hiba 0075!');
		}
	  });
}

function createImgHovers(mellik) {

	csop = jQuery('img[data-hover]');

	if(mellik != "") {
		csop = jQuery(mellik + ' img[data-hover]');
	}

	csop.hover(function() {
        jQuery(this).attr('tmp', jQuery(this).attr('src')).attr('src', jQuery(this).attr('data-hover')).attr('data-hover', jQuery(this).attr('tmp')).removeAttr('tmp');
    }).each(function() {
        jQuery('<img />').attr('src', jQuery(this).attr('data-hover'));
    });
}

jQuery(function() {
  var cache = [];
  
  jQuery.preLoadImages = function() {
    var args_len = arguments.length;

    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
});

jQuery(window).load(function() {

	createImgHovers("");

	jQuery("#lava1").lavaLamp({
		fx: "backout", 
		speed: 700
	});

	// Hátterek előtöltése
	jQuery.preLoadImages("images/nyito_bg.jpg", "images/magunkrol_bg.jpg", "images/tevekenysegek_bg.jpg", "images/helyszinek_bg.jpg", "images/referenciak_bg.jpg", "images/csapatunk_bg.jpg", "images/kapcsolat_bg.jpg");

	// Főcímek előtöltése
	jQuery.preLoadImages("images/magunkrol_flash_focim.png", "images/tevekenysegek_flash_focim.png", "images/helyszinek_flash_focim.png", "images/referenciak_flash_focim.png", "images/csapatunk_flash_focim.png", "images/kapcsolat_flash_focim.png");

	// jcarousel gombok előtöltése
	jQuery.preLoadImages("images/lapozo_bal_h.jpg", "images/lapozo_jobb_h.jpg", "images/oldal_lapozo_left_h.png", "images/oldal_lapozo_right_h.png", "images/vissza_a_tevekenysegekhez_button_h.png", "images/tevekenysegek_focim_bg_h.png");

	// tevékenységek oldal főcím rolloverek

	jQuery(".tevekenysegek_focim_bg_n").mouseenter(function() {
		jQuery(".tevekenysegek_focim_bg_h").removeClass("tevekenysegek_focim_bg_h");
		jQuery(this).addClass("tevekenysegek_focim_bg_h");
	});

	jQuery(".tevekenysegek_focim_bg_n").mouseleave(function() {
		jQuery(".tevekenysegek_focim_bg_h").removeClass("tevekenysegek_focim_bg_h");
		jQuery(this).addClass("tevekenysegek_focim_bg_n");
	});

	jQuery(".tevekenysegek_focim_bg_n").click(function() {
		var id = jQuery(this).attr("id");
		var lang = jQuery("#aktlang").attr("value");

		showpopup(id, lang);
	});
});

jQuery.noConflict(); // anti prototype
