$(document).ready(function(){
    // rotator
    function rotator(index) {
        $("div#slider ul").animate({ left: -index*760 }, {duration: animTime});
        next++;
        if (next > max-1) {
            next = 0;
        }
    }
    var index = 0, next = index+1, changeTime = 7000, animTime = 550, max = $("div#slider ul li").length;
    var indit = setInterval(function() { rotator(next); }, changeTime);	
    
    // partner rotator
    /*var sections = Math.ceil($('#partners img').height()/200), sectionIndex = 0, nextSection = sectionIndex+1;
    console.log(sections);
    function partner(sectionIndex) {
        $('#partners img').animate({top:-sectionIndex*200},{duration:1000});
        nextSection++;
    }
    var partnerStart = setInterval(function() { partner(nextSection); }, 3000);*/
    var iHeight = $('#partners img').height();
    
    function pRotate() {
        $('#partners img').css('top',265);
        $('#partners img').animate({top:-iHeight},55000,function(){pRotate()});
    }    
//    $('#partners img').animate({top:-iHeight},{duration:550},'linear',function(){console.log('ka');});
    $('#partners img').animate({top:-iHeight},55000,function(){pRotate()});
    
    $('h1.menutoggle').click(function(){
        $(this).parent().parent().find('ul').hide();
        $(this).parent().find('ul').toggle();
    });
    
    $('#partners').hover(function(){
        $(this).find('img').css("left","-155px");
    },function(){
        $(this).find('img').css("left","0");    
    });
    
    $('#voteform').submit(function(){
    	$.ajax({
       		type: "POST",
       		dataType: "json",
       		url: "/do/vote",
       		data: $("#voteform").serialize(),
       		success: function(json) {
       			if (json.response == 'invalidmail') {
       				$('#error > p').html('Kérjük érvényes e-mail címet adjon meg!');
       				$('#error').show();
       			} else if (json.response == 'alreadyvoted') {
       				$('#error > p').html('Ezzel az e-mail címmel már szavazott!');
       				$('#error').show();
       			} else if (json.response == 'nominee') {
       				$('#error > p').html('Kérjük válasszon a jelöltek közül!');
       				$('#error').show();
       			} else if (json.response == 'ok') {
       				$('#error').hide();
       				$('#voteform').hide();
       				$('#vintro').hide();
       				$('#vok').show();
       			}
       		}       		
       });
    	return false;    
    });
    
});

function fireFancy() {
	$("a.group_fancy").fancybox({
		'zoomSpeedIn': 300, 
		'zoomSpeedOut': 300, 
		'overlayShow': true,
		'imageScale': false,
		'overlayColor': '#000000',
		'padding': 0
	});
}
