var lapozo_pos = 0;
var hirek;
 /* Intro átméretezés */

atmeretez = function() { 
			x0 = $(window).width() / 2;
			y0 = $(window).height() / 2;
			x1= x0 - 167;
			y1= y0 - 157;

			$(".flekkek").css({
				left:x1+"px",
				top:(y1 - 60)+"px"
			});
			
			$("#intro-pannon-ho-felugro").css({
				top:(y1 - 90)+"px",
				right: parseInt(110 * (Math.max(x0/640,1)))+"px"
			});
			
			$("#intro-pannon-green-felugro").css({
				top:(y1 + 20)+"px",
				left: parseInt(180 * (Math.max(x0/640,1)))+"px"
			});
};

$(window).bind("resize", atmeretez);

$(document).ready(function() {

	/* Általános dolgok */
	$(".inlabel input[type=text]").focus(function() {
		if ($(this).attr("id")!="captcha") {
			$(this).siblings("label").hide();
		}
	});

	$(".inlabel input[type=text]").blur(function() {
		if ($(this).val()=="") {
			$(this).siblings("label").show();
		};
	});

	$(".inlabel input[type=text]").each(function(index) {
			if ($(this).val()!="") {
				$(this).siblings("label").hide();
			};
	});
	$(".inlabel textarea").focus(function() {
		$(this).siblings("label").hide();
	});

	$(".inlabel textarea").blur(function() {
		if ($(this).val()=="") {
			$(this).siblings("label").show();
		};
	});

	$(".inlabel textarea").each(function(index) {
			if ($(this).val()!="") {
				$(this).siblings("label").hide();
			};
	});
	
	/* Intro */
	
	$("#intro-pannon-green, #intro-pannon-ho").mouseenter(function(){
		$(this).find("img.hover").animate({
			"opacity":0
		},500);
		$(this).addClass("felugrok-hover");
		if ($(this).attr("id")=="intro-pannon-ho") {
			$('#bal-flekk').slideDown(700);
		}else{
			$('#jobb-flekk').slideDown(700);
		}
		
	}).mouseleave(function(){
		$(this).find("img.hover").animate({
			"opacity":0.5
		},500);
		$(this).removeClass("felugrok-hover");
		if ($(this).attr("id")=="intro-pannon-ho") {
			$('#bal-flekk').slideUp(700);
		}else{
			$('#jobb-flekk').slideUp(700);
		}
	});
	
	setInterval(function () {
		rejtett = $('#pannonpower-flekk img:hidden');
		lathato = $('#pannonpower-flekk img:visible');
		
		lathato.css("z-index",1);
		rejtett.css("z-index",2);
		
		rejtett.fadeIn(1000,function() {
			lathato.hide();
		});
	},6000);

	atmeretez();


	/* Belső oldalak */
	
	$(".kerdes a").click(function (e) {
		var id = this.id.replace("kerdes_","valasz_");
		$("#"+ id).slideToggle();
	});

	$(".baloldali-menu ul a").click(function(e) {
		e.stopPropagation();
	});
	
	$(".baloldali-menu>li").click(function(e) {
		console.log(e);
		if ($(this).find("ul").children().size()>0) {
			$(this).toggleClass('nyitott');
			return false;
		};
	});
	
	$('.lightbox, .fancybox').fancybox({
		padding: 0,
		overlayOpacity: 0.9,
		overlayColor: '#222'
	});
	
	$('.videobox').fancybox({
		padding: 0,
		overlayOpacity: 0.9,
		overlayColor: '#222',
		width: 640,
		height: 480 
	});
	
	$("#fejlec>ul>li").hover(
		function() {
				$(this).find("ul").css("display","block");
				$(this).addClass("fomenu_hover");
		},
		function() {
				$(this).find("ul").css("display","none");
				$(this).removeClass("fomenu_hover");
	});

	/* Lapozás */
	
	$.ajax({
	  url: '/hirek/getkiemeltek',
	  type: 'GET',
	  dataType: 'json',
	  complete: function(xhr, textStatus) {
	    //called when complete
	  },
	  success: function(data, textStatus, xhr) {
		hirek = data;
		
		if (hirek.length == 1) {
			$('#slider-lapozo').hide();
		};
		
		$('#slider-previous, #slider-next').click(function() {
			if ($(this).attr("id") == "slider-next") {
				$('#slider-previous').removeClass("disabled");
				if (lapozo_pos == hirek.length - 1) return false;
				lapozo_pos++;
				if (lapozo_pos == hirek.length - 1) {
					$('#slider-next').addClass("disabled");
				};
			}else{
				$('#slider-next').removeClass("disabled");
				if (lapozo_pos == 0) return false;
				lapozo_pos--;
				if (lapozo_pos == 0) {
					$('#slider-previous').addClass("disabled");
				};
			}
			$(".pos").text(lapozo_pos);
			$szoveg = $("#slider-szoveg");
			$szoveg.find("h2 a").text(hirek[lapozo_pos].SliderCim);
			$szoveg.find("h2 a").attr("href",hirek[lapozo_pos].Link);
			$szoveg.find("p").text(hirek[lapozo_pos].Lead);
			$szoveg.find("span").text((lapozo_pos+1)+"/"+hirek.length);
			return false;
		});
	  },
	  error: function(xhr, textStatus, errorThrown) {
	    $('#slider-lapozo').hide();
	  }
	});
	
	$(".videok").flowplayer("/media/vendor/flowplayer/flowplayer-3.2.7.swf", {
	    clip: {autoPlay: false, autoBuffering: true}
	});
	
	$('.ujablak a').attr("target","_blank");

});
