function menu_roll(command, type) {
	if(command == 'start') {
		$(".featured_menu .item:first").addClass('active').append('<div class="select"></div>');	
		$(".promo_box .item").html($(".promo_box .trunk .items:first").html());
		roller = setTimeout('menu_roll("do", "slow");', 5000);
		rsize = $(".featured_menu .item").size();
	}
	if(command == 'do') {
		var next = 0;
		$(".featured_menu .item").each(function(i) {
			if($(this).hasClass("active")) next = i;
		});
		$(".featured_menu .item").removeClass('active');
		$(".featured_menu .select").remove();
		$(".promo_box .bg").html($(".promo_box .item").html());
		$(".promo_box .item").css("opacity", 0);
		next = next;
		if(next == rsize-1) {
			$(".featured_menu .item:first").addClass('active').append('<div class="select"></div>');
			$(".promo_box .item").html($(".promo_box .trunk .items:first").html());
		} else {
			$(".featured_menu .item:eq(" + parseInt(next+1) + ")").addClass('active').append('<div class="select"></div>');
			$(".promo_box .item").html($(".promo_box .trunk .items:eq(" + parseInt(next+1) + ")").html());
		}
		if(type == 'slow') {
			$(".promo_box .item").animate({
				opacity: 1
			}, 400);
		} else {
			$(".promo_box .item").css("opacity", 1);
		}
		roller = setTimeout('menu_roll("do", "slow");', 5000);
	}
	if(command == 'stop') {
		if(roller != 0) clearTimeout(roller);
	}
}

function roll_pic() {
    var rand = Math.floor(Math.random()*5);
    if(rand == rollp) {
	while(rand == rollp) {
	    rand = Math.floor(Math.random()*5);
	}
    }
    if(rollp != '') {
	$(".roller .item.active .good").animate({
	    opacity: 0
	}, 1000, "swing", function() {
	    $(".roller .item.active").hide().removeClass("active");
	    $(".roller .item .bad, .roller .item .good").css("opacity", 0);
	    $(".roller .item:eq("+rand+")").addClass("active").show();
	    $(".roller .item.active .bad").animate({
		opacity: 1
	    }, 1000, "swing", function() {
	    });	    
	});
    } else {
	$(".roller .item .bad, .roller .item .good").css("opacity", 0);
	$(".roller .item:eq("+rand+")").addClass("active").show();
	$(".roller .item.active .bad").animate({
	    opacity: 1
	}, 1000, "swing", function() {
	});
    }
    rollp = rand;
}

var roller = 0;
var rsize = 0;
var rtimer = 0;
var rollp = '';

$(document).ready(function() {
	if($("#core").hasClass("index")) menu_roll('start', '');

	$(".featured_menu .item").hover(
		function() {
			menu_roll('stop', '');
			$(".featured_menu .item").removeClass('active');
			$(this).addClass('active');
			$(".featured_menu .select").remove();
			if($("#core").hasClass("index")) $(this).append('<div class="select"></div>');
			
			var act = 0;
			$(".featured_menu .item").each(function(i) {
				if($(this).hasClass("active")) act = i;
			});
			$(".promo_box .item").html($(".promo_box .trunk .items:eq(" + act + ")").html()).addClass("active");
			if(rtimer != 0) clearTimeout(rtimer);
		}, function() {
			if($("#core").hasClass("index")) rtimer = setTimeout("menu_roll('do', 'slow');", 5000);
			else {
				$(this).removeClass("active");
			}
		}
	);
	
	$(".featured_menu .item").click(function() {
		window.location = $(this).find("a").attr("href");
	});
	
	$(".data_right .menu .item").hover(
		function() {
			if($(this).find(".submenu").size() != 0) {
				$(this).find(".submenu").show();
			}
			$(this).addClass("active");
		}, function() {
			if($(this).find(".submenu").size() != 0) {
				$(this).find(".submenu").hide();
			}
			$(this).removeClass("active");
		}
	);
	
	$(".data_right .menu .item .submenu .subitem").hover(
		function() {
			$(this).addClass("active");
		}, function() {
			$(this).removeClass("active");
		}
	);
	
	$(".data_right .menu .item").click(function() {
		if(!$(this).hasClass("empty")) window.location = $(this).find("a:first").attr("href");
	});
	
	$(".data_right .menu .item .submenu .subitem").click(function() {
		window.location = $(this).find("a").attr("href");
	});
	
	if($(".article_small .trunk .item").size() != 0) {
		$(".article_small .art_left").html($(".article_small .trunk .item:first").html());
		$(".article_small .trunk .item:first").addClass("active");
		if($(".article_small .trunk .item").size() != 1) $(".article_small .art_left").append('<div class="pager">' + $(".article_small .trunk .pager").html() + '</div>');
	}
	
	$(".article_small .pager .prev").live('click', function() {
		var size = $(".article_small .trunk .item").size();
		var act = 0;
		$(".article_small .trunk .item").each(function(i) {
			if($(this).hasClass("active")) act = i;
		});
		$(".article_small .trunk .item.active").removeClass("active");
		if(act == 0) {
			$(".article_small .art_left").html($(".article_small .trunk .item:last").html());
			$(".article_small .trunk .item:last").addClass("active");
		} else {
			$(".article_small .art_left").html($(".article_small .trunk .item:eq(" + parseInt(act-1) + ")").html());
			$(".article_small .trunk .item:eq(" + parseInt(act-1) + ")").addClass("active");
		}
		$(".article_small .art_left").append('<div class="pager">' + $(".article_small .trunk .pager").html() + '</div>');
	});
	
	$(".article_small .pager .next").live('click', function() {
		var size = $(".article_small .trunk .item").size();
		var act = 0;
		$(".article_small .trunk .item").each(function(i) {
			if($(this).hasClass("active")) act = i;
		});
		$(".article_small .trunk .item.active").removeClass("active");
		if(act+1 == size) {
			$(".article_small .art_left").html($(".article_small .trunk .item:first").html());
			$(".article_small .trunk .item:first").addClass("active");
		} else {
			$(".article_small .art_left").html($(".article_small .trunk .item:eq(" + parseInt(act+1) + ")").html());
			$(".article_small .trunk .item:eq(" + parseInt(act+1) + ")").addClass("active");
		}
		$(".article_small .art_left").append('<div class="pager">' + $(".article_small .trunk .pager").html() + '</div>');
	});
	
	if($(".video_gallery .items .item").size() != 0) {
		$(".page_title").height(36);
		$(".video_gallery .items .item").css("opacity", 0);

		var main = 0;
		
		$(".video_gallery .items .item").each(function(i) {
		    if($(this).hasClass("main")) {
			main = i;
		    }
		});
		
		$(".video_gallery .items .item:eq(" + (main-2) + ")").animate({
		    marginLeft: 30,
		    opacity: 0.3
		}, 500, "swing", function() {
		    $(this).addClass("prevback");
		});
		
		$(".video_gallery .items .item:eq(" + (main-1) + ")").css("z-index", 5).animate({
		    marginLeft: -85,
		    marginTop: 40,
		    opacity: 0.8
		}, 500, "swing", function() {
		    $(this).addClass("prev");
		});
		
		$(".video_gallery .items .item:eq(" + main + ") img").animate({
		    height: 145
		}, 500, "swing", function() {
		    $(".video_gallery .items .item:eq(" + main + ")").addClass("active");
//		    $(".page_title").html($(".video_gallery .items .active .title").html()).height('auto');
		    $(".short_text").html($(".video_gallery .items .active .short").html());
		});
		
		$(".video_gallery .items .item:eq(" + main + ")").animate({
		    opacity: 1
		}, 500, "swing");
		
		$(".video_gallery .items .item:eq(" + (main+1) + ")").css("z-index", 5).animate({
		    marginRight: -85,
		    marginTop: 40,
		    opacity: 0.8
		}, 500, "swing", function() {
		    $(this).addClass("next");
		});
		
		$(".video_gallery .items .item:eq(" + (main+2) + ")").animate({
		    marginRight: 30,
		    opacity: 0.3
		}, 500, "swing", function() {
		    $(this).addClass("nextback");
		});
		
		if(main != 2) {
		    $(".video_gallery .items .item:lt(" + (main-2) + ")").animate({
			opacity: 0
		    }, 500, "swing");
		}		
		$(".video_gallery .items .item:gt(" + (main+2) + ")").animate({
		    opacity: 0
		}, 500, "swing");

		var pos = ((main-2)*142)*-1;
		$(".video_gallery .items").animate({
		    marginLeft: pos
		}, 500, "swing", function() {
		    if(!$(".video_gallery .items .prev").hasClass("blank")) $(".video_gallery .controls .left").show();
		    if($(".video_gallery .items .next").size() != 0) $(".video_gallery .controls .right").show();
		});
	}
	
	var gal_move = 0;	
	$(".video_gallery .items .item").click(function() {
		$(this).blur();
		if($(this).hasClass("blank")) {
		    return false;
		}
		
		if(!$(this).hasClass("active")) {
		    var pos = 0;
		    if($(this).hasClass("prev")) {
			gal_move = 1;
			pos = parseInt($(".video_gallery .items").css("margin-left"))+117+25;
			$(".video_gallery .nextback").animate({
			    marginRight: 25,
			    opacity: 0
			}, 500, "swing", function() {
			    $(this).removeClass("nextback");
			});

			$(".video_gallery .next").css("z-index", 4).animate({
			     marginTop: 0,
			     marginRight: 30,
			     opacity: 0.3
			}, 500, "swing", function() {
			    $(this).removeClass("next").addClass("nextback");
			});

			$(".video_gallery .active").css("z-index", 5).animate({
			    marginRight: -30,
			    marginTop: 60,
			    opacity: 0.9
			}, 250, "swing", function() {
			    $(".video_gallery .active").animate({
				marginRight: -85,
				marginTop: 40,
				opacity: 0.8
			    }, 250, "swing", function() {
				$(this).removeClass("active").addClass("next");
				gal_move = 0;
			    });
			});

			$(".video_gallery .active img").animate({
			    height: 70
			}, 500, "swing", function() {
			});
			
			$(".video_gallery .prev").animate({
			    marginTop: 60,
			    marginLeft: -30,
			    opacity: 0.9
			}, 250, "swing", function() {
			    $(".video_gallery .prev").animate({
				marginTop: 0,
				marginLeft: 0,
				opacity: 1
			    }, 250, "swing", function() {
			        $(this).css("z-index", 4);
			        $(this).removeClass("prev").addClass("active");
//			        $(".page_title").html($(this).find(".title").html());
			        $(".short_text").html($(this).find(".short").html());
				if(!$(".video_gallery .items .prev").hasClass("blank")) $(".video_gallery .controls .left").show();
				else  $(".video_gallery .controls .left").hide();
				if($(".video_gallery .items .next").size() != 0) $(".video_gallery .controls .right").show();
				else $(".video_gallery .controls .right").hide();
			    });
			});
			
			$(".video_gallery .prev img").animate({
			    height: 145
			}, 500, "swing");
			
			$(".video_gallery .prevback").css("z-index", 5).animate({
			    marginLeft: -85,
			    marginTop: 40,
			    opacity: 0.8
			}, 500, "swing", function() {
			    $(this).removeClass("prevback").addClass("prev");
			});
			
			$(".video_gallery .prevback").prev().animate({
			    opacity: 0.3,
			    marginLeft: 30
			}, 500, "swing", function() {
			    $(this).addClass("prevback");
			});
			

			$(".video_gallery .items").animate({
			    marginLeft: pos
			}, 500, "swing");
		    }

		    if($(this).hasClass("next")) {
			gal_move = 1;
			pos = parseInt($(".video_gallery .items").css("margin-left"))-117-25;
			$(".video_gallery .nextback").animate({
			    marginRight: -85,
			    marginTop: 40,
			    opacity: 0.8
			}, 500, "swing", function() {
			    $(this).removeClass("nextback").addClass("next").css("z-index", 5);
			});

			$(".video_gallery .next").animate({
			     marginTop: 60,
			     marginRight: -30,
			     opacity: 0.9
			}, 250, "swing", function() {
			    $(".video_gallery .next").animate({
				marginTop: 0,
				marginRight: 25,
				opacity: 1
			    }, 250, "swing", function() {
				$(this).removeClass("next").addClass("active").css("z-index", 4);
//			        $(".page_title").html($(this).find(".title").html());
			        $(".short_text").html($(this).find(".short").html());
				if(!$(".video_gallery .items .prev").hasClass("blank")) $(".video_gallery .controls .left").show();
				else  $(".video_gallery .controls .left").hide();
				if($(".video_gallery .items .next").size() != 0) $(".video_gallery .controls .right").show();
				else $(".video_gallery .controls .right").hide();
			    });
			});
			
			$(".video_gallery .next img").animate({
			    height: 145,
			    marginRight: 0
			}, 500, "swing", function() {
			});

			$(".video_gallery .active").css("z-index", 5).animate({
			    marginLeft: -30,
			    marginTop: 60,
			    opacity: 0.9
			}, 250, "swing", function() {
			    $(".video_gallery .active").animate({
				marginLeft: -85,
				marginTop: 40,
				marginRight: 25,
				opacity: 1
			    }, 250, "swing", function() {
				$(this).removeClass("active").addClass("prev");
				gal_move = 0;
			    });
			});

			$(".video_gallery .active img").animate({
			    height: 70
			}, 500, "swing", function() {
			});
			
			$(".video_gallery .prev").animate({
			    marginTop: 0,
			    marginLeft: 30,
			    marginRight: 25,
			    opacity: 0.3
			}, 500, "swing", function() {
			    $(this).removeClass("prev").addClass("prevback").css("z-index", 4);
			});
			
			$(".video_gallery .prevback").animate({
			    opacity: 0,
			    marginLeft: 0
			}, 500, "swing", function() {
			    $(this).removeClass("prevback");
			});
			
			$(".video_gallery .nextback").next().animate({
			    marginRight: 30,
			    opacity: 0.3
			}, 500, "swing", function() {
			    $(this).addClass("nextback");
			});

			$(".video_gallery .items").animate({
			    marginLeft: pos
			}, 500, "swing");
		    }

		} else {
		    $(".video_gallery").append('<div class="overlay"></div>').find(".overlay").css("opacity", 0).show();
		    
		    if($(".video_gallery .active .embed").html().search("youtube.com") == -1) {
		    
			$(".video_gallery .overlay").animate({
			    opacity: 0.75,
			    height: 300
			}, 500, "swing");
		    
			$(".video_gallery").animate({
			    height: 300
			}, 500, "swing", function() {
			    $(".video_gallery").append('<div class="player">' + $(".video_gallery .active .embed").html() + '</div>').append('<div class="close"></div>');
			});
		    } else {
			$(".video_gallery .overlay").animate({
			    opacity: 0.75,
			    height: 370
			}, 500, "swing");
		    
			$(".video_gallery").animate({
			    height: 370
			}, 500, "swing", function() {
			    $(".video_gallery").append('<div class="player youtube">' + $(".video_gallery .active .embed").html() + '</div>').append('<div class="close youtube"></div>');
			});		    
		    }
		}
	});
	
	$(".video_gallery .close").live('click', function() {
	    $(this).remove();
	    $(".video_gallery .player").remove();
	    $(".video_gallery").animate({
		height: 200
	    }, 500, "swing", function() {
		$(".video_gallery .overlay").remove();
	    });
	    
	    $(".video_gallery .overlay").animate({
		opacity: 0,
		height: 200
	    }, 500, "swing");
	});
	
	$(".video_gallery .controls .left").click(function() {
	    if(gal_move == 0) $(".video_gallery .items .prev").click();
	});
	
	$(".video_gallery .controls .right").click(function() {
	    if(gal_move == 0) $(".video_gallery .items .next").click();
	});

	$(".logo_rotate").click(function() {
		if(
			( $("input[name='q1']:checked").val() == undefined) ||
			( $("input[name='q2']:checked").val() == undefined) ||
			( $("input[name='q3']:checked").val() == undefined) ||
			( $("input[name='q4']:checked").val() == undefined) ||
			( $("input[name='q5']:checked").val() == undefined)
		) {
			alert('Kérem az összes kérdésre válaszoljon!');
		} else {
			var number = 0;
			number = parseInt($("input[name='q1']:checked").val())+parseInt($("input[name='q2']:checked").val())+parseInt($("input[name='q3']:checked").val())+parseInt($("input[name='q4']:checked").val())+parseInt($("input[name='q5']:checked").val());

			var text = 'Az Ön MZ értéke: <span>' + number + '</span>, amely alapján Önnél <span>a súlyos</span> merevedési zavar valószínűsíthető. A jó hír az, hogy ezen – nagy valószínűséggel – lehet segíteni! Ha Önnek is fontos a kérdés, forduljon a szakorvoshoz!';
			var angle = 45;
			
			if(number > 7) {
				text = 'Az Ön MZ értéke: <span>' + number + '</span>, amely alapján Önnél <span>a közepes mértékű</span> merevedési zavar valószínűsíthető. A jó hír az, hogy ezen – nagy valószínűséggel – lehet segíteni! Ha Önnek is fontos a kérdés, forduljon a szakorvoshoz!';
				angle = 90;
			}
			
			if(number > 16) {
				text = 'Az Ön MZ értéke: <span>' + number + '</span>, amely alapján Önnél <span>az enyhe</span> merevedési zavar valószínűsíthető. A jó hír az, hogy ezen – nagy valószínűséggel – lehet segíteni! Ha Önnek is fontos a kérdés, forduljon a szakorvoshoz!';
				angle = 135;
			}

			if(number > 21) {
				text = 'Jó hír! Önnek nincs merevedési zavara. Ha ez az állapot az idő múlásával vagy élethelyzete alakulásával változna, ne felejtse el, hogy van megoldás! Konzultáljon orvosával';
				angle = 180;
			}
			
			$(".sur_end").html(text).slideDown('slow');

			$(".rotate").rotate({
				animateTo: angle*-1,
				duration: 1500
			});
		}
	});
	
	$(".bottom_index .items_left .article .overlay").css("opacity", 0.5);
	$(".bottom_index .items_left .video .play").css("opacity", 0.7);
	$(".bottom_index .items_left .video .overlay, .bottom_index .items_left .video .title").css("opacity", 0).show();
	$(".bottom_index .items_left .article .title, .bottom_index .items_left .video .title").click(function() {
	    window.location = $(this).parent().find(".pic a").attr("href");
	});
	
	$(".bottom_index .items_left .video .title").hover(
	    function() {
		$(this).parent().find(".overlay").stop().animate({
		    opacity: 0.5
		}, 250, "swing");
		$(this).parent().find(".title").stop().animate({
		    opacity: 1
		}, 250, "swing");
	    }, function() {
		$(this).parent().find(".overlay, .title").stop().animate({
		    opacity: 0
		}, 500, "swing");
	    }
	);
	
	if($(".roller .item").size() != 0) {
	    roll_pic();
	}

	$(".roller .item.active").live('click', function() {
	    $(this).find(".good").animate({
		opacity: 1
	    }, 1000, "swing");
	    $(this).find(".bad").animate({
		opacity: 0
	    }, 1000, "swing", function() {
		setTimeout('roll_pic();', 2000);
/*		$(".roller .item.active .good").animate({
		    opacity: 0
		}, 1000, "swing", function() {
		    $(".roller .item.active").hide().removeClass("active");
		    setTimeout('roll_pic();', 1000);
		});*/
	    });
	});
	
	if($(".over18").size() != 0) {
	    $(".over18, .over18 .overlay").width($(document).width()).height($(document).height());
	    $(".over18 .overlay").css("opacity", 0.75);
	    
	    $(".over18 .yes").click(function() {
		var date = new Date();
		date.setTime(date.getTime()+(365*24*60*60*1000));
		var expires = date.toGMTString();
					
		document.cookie = 'over18=1; expires=' + expires + '; path=/';
		  
		$(".over18").remove();
	    });
	    
	    $(".over18 .no").click(function() {
		window.back();
	    });
	}
	
});
