
$(document).ready(
	function() {
		
		slideshow();
		
		if($(".kerdoiv2").css("display") == "block"){
				$(".flash-holder .banner img").attr('title', 'Klikkelj, hogy újra nézhesd a videókat!');
			} else {
				$(".flash-holder .banner img").attr('title', 'Klikkelj, hogy kitölthesd a kérdőívünket!');
			}

		tooltip();
		
		if (document.location.hash != "") {
			formFade();
		} else {
			$(".kerdoiv #flash").removeClass("hidden");
		}
		
		validate();
		
		var thumbnailsWidth = $(".thmb-holder").width();
		var ulWidth = $(".thmb-holder ul").width();
		var maxLeft =-(ulWidth - thumbnailsWidth);
		
		var stepp = 112;
		$(".thmbs .prev").click(function(){
			
			var oldpos = $(".thmb-holder ul").css("left");
			newpozicio = parseInt(oldpos.substr(0,oldpos.length-2)) + stepp;
			if (newpozicio <= 0 && newpozicio >= maxLeft){
				$('.thmb-holder ul').animate({left:(newpozicio)}, 500); 
			
			}
		})
		$(".thmbs .next").click(function(){
			
			var oldpos = $(".thmb-holder ul").css("left");
			newpozicio = parseInt(oldpos.substr(0,oldpos.length-2)) - stepp;
			if (newpozicio >= maxLeft){
				$('.thmb-holder ul').animate({left:(newpozicio)}, 500); 
			}
			
		})
		
		var aktQUE = 1
		$(".navig .prev").click(function(){
			
			
			if (aktQUE > 1){
				aktQUE -= 1
				
				$(".navig .send").css('display','none');
				$(".kerdoiv2 .question").css('display','none');
				$(".kerdoiv2 #q"+aktQUE).css('display','block');
				$(".navig .next").css('display','block');
				if (aktQUE == 1){
					$(".navig .prev").css('display','none');
				}
			}
		})
		$(".navig .next").click(function(){
			if (aktQUE < 8){
				aktQUE += 1
				
				$(".navig .send").css('display','none');
				$(".kerdoiv2 .question").css('display','none');
				$(".kerdoiv2 #q"+aktQUE).css('display','block');
				$(".navig .prev").css('display','block');
				if (aktQUE == 8){
					$(".navig .next").css('display','none');
					$(".navig .send").css('display','block');
				}
			}
		})
	
		$(".flash-holder .banner").mouseover(function(e){
			$(this).css({'cursor':'pointer'});
		}).click(function(){
			
			if($(".kerdoiv2").css("display") == "block"){
				
				
				$(".flash-holder .banner img").attr('title', 'Klikkelj, hogy kitölthesd a kérdőívünket!');
				$(".kerdoiv2").css('display','none');
				$(".youtube").css('display','block');
				
			 }else{
				$(".flash-holder .banner img").attr('title', 'Klikkelj, hogy újra nézhesd a videókat!');
				$(".kerdoiv2").css('display','block');
				$(".youtube").css('display','none');
				
			 }
		});
	}
);
function ajaxAgeCheck() {
	document.write('<div id="ageanalytics"></div>');
	ajaxGetUpdate ("ageanalytics", "/ageanalytics", false);
}
function formFade() {
	 $(".formLink").animate({opacity:0}, 150, null, function(){
			$(".formLink").css('display','none');
			$(".flashLink").css({'display':'inline-block', 'opacity':0});
			$(".flashLink").animate({opacity:1}, 150, null);
		});
    $(".kerdoiv #flash").animate({opacity:0}, 150, null, function(){ 
			$(".kerdoiv #flash").css('display','none');
			$(".kerdoiv #formdiv").css({'display':'block', 'opacity':0});
			$(".kerdoiv #formdiv").animate({opacity:1}, 150, null);
		});
}
function flashFade() {
	 $(".flashLink").animate({opacity:0}, 150, null, function(){ 
			$(".flashLink").css('display','none');
			$(".formLink").css({'display':'inline-block', 'opacity':0});
			$(".formLink").animate({opacity:1}, 150, null);
		});
    $(".kerdoiv #formdiv").animate({opacity:0}, 150, null, function(){ 
			$(".kerdoiv #formdiv").css('display','none');
			$(".kerdoiv #flash").css({'display':'block', 'opacity':0});
			$(".kerdoiv #flash").animate({opacity:1}, 150, null);
		});
}
function tooltip() {
	var szoveg = $('span.title').attr("title");
	$('span.title').removeAttr("title")
	$("span.title").mouseover(function(e){
		$('body').append("<div class='tooltip'>"+szoveg+"</div>")
		$("div.tooltip").css({'opacity':0.9});
		$('div.tooltip').css({ "top":e.pageY, "left":e.pageX });
		
		// esem�ny hozz�ad�s:
		$(document).bind('mousemove', tooltip_mozog);
	 }).mouseout(function(){
		$('div.tooltip').remove();
		// esem�ny elv�tel:
		$(document).unbind('mousemove', tooltip_mozog);
	});
}
function tooltip_mozog(e) {
	$('div.tooltip').css({ "top":e.pageY, "left":e.pageX });
}
	

function validate() {
	$('.kerdoiv').css({'overflow-x':'hidden'});
	$('.kerdoiv  #flash').css({'overflow-x':'hidden'});
}

function kerdesekFormValidate(){
	valid = true;
	ret = true;
	for(i=1;i<=8;i++){
		key = "group[" + i +  "]";
		arr = document.getElementsByName(key);		
		if( arr[0].checked || arr[1].checked || arr[2].checked || arr[3].checked ){
			
		}
		else{
			valid = false;
			ret = false;
		}
	}
	if(valid == false){
		alert("Mind a 8 kérdés kitöltése kötelező!");
	}
	return ret;
}

function slideshow() {
	var timer = null; // az idoz�to l�trehoz�s a k�pv�lt�shoz
	if (timer)
		clearInterval(timer); // idoz�to t�rl�se
	var picnum = $("div.slideshow div.thumbnails a").size();
	var actnum = 1;
	var prevnum = 1;

	
	$("div.slideshow div.thumbnails a").click(
			function() {
				if (timer)
					clearInterval(timer);
				prevnum = actnum;
				var ID = parseInt($(this).attr('id'));
				var TITLE = $(this).html();
				
				actnum = ID

				$("div.slideshow div.thumbnails span").removeClass('active');
				$("div.slideshow div.thumbnails span a#" + actnum).parent()
						.addClass('active');
				$("div.slideshow .image").prepend(
						"<img src='/images/utveszto/banner-" + actnum
								+ ".jpg' alt='' id=" + actnum + " title='"
								+ TITLE + "' />");
				$("div.slideshow .image img#" + prevnum).animate( {
					'opacity' : 0
				}, 600, null, function() {
					$('div.slideshow .image img#' + prevnum).remove();
				});
				
				timer = setInterval(function() {

					prevnum = actnum;
					if (actnum == picnum) {
						actnum = 1;
					} else {
						actnum = actnum + 1;
					}
					
					var TITLE = $(
							"div.slideshow div.thumbnails span a#" + actnum)
							.html();

					$("div.slideshow div.thumbnails span")
							.removeClass('active');
					$("div.slideshow div.thumbnails span a#" + actnum).parent()
							.addClass('active');
					$("div.slideshow .image").prepend(
							"<img src='/images/utveszto/banner-" + actnum
									+ ".jpg' alt='' id=" + actnum + " title='"
									+ TITLE + "' />");
					$("div.slideshow .image img#" + prevnum).animate( {
						'opacity' : 0
					}, 600, null, function() {
						$('div.slideshow .image img#' + prevnum).remove();
					});
					
				}, 5 * 1000);
				return false;
			});

	timer = setInterval(function() {
		prevnum = actnum;
		if (actnum == picnum) {
			actnum = 1;
		} else {
			actnum = actnum + 1;
		}
		
		var TITLE = $("div.slideshow div.thumbnails span a#" + actnum).html();

		$("div.slideshow div.thumbnails span").removeClass('active');
		$("div.slideshow div.thumbnails span a#" + actnum).parent().addClass(
				'active');
		$("div.slideshow .image").prepend(
				"<img src='/images/utveszto/banner-" + actnum + ".jpg' alt='' id="
						+ actnum + " title='" + TITLE + "' />");
		$("div.slideshow .image img#" + prevnum).animate( {
			'opacity' : 0
		}, 600, null, function() {
			$('div.slideshow .image img#' + prevnum).remove();
		});
		
	}, 5 * 1000);
	// az anim�ci� v�ge

}
