$(document).ready(function(){
 $('.lightbox').lightbox();
$('.karavaninvite').facebox();

var movie_src='http://4i.hu/mmm/';

	if ($('.login_error_1').size() > 0) {
		$('.login_error_1').click(function() {
		$('.login_error_1').hide();
		$('.login_error_2').hide();
		});
		$('.login_error_2').click(function() {
		$('.login_error_1').hide();
		$('.login_error_2').hide();
		});
	}
	
	if ($('.answer_that').size() > 0) {
		$('.answer_that').click(function () {
			var thiscomment=$(this).attr('rel');
			$('#commenttextarea').html($('#user_'+thiscomment).html()+' írta: ' + $('#'+thiscomment).html());
		});
	}
	
	
	if ($('#player').size() > 0) {
		flash_source = $('#player').attr('rel');
	flowplayer("player", "http://4i.hu/flow/flowplayer.commercial-3.2.4.swf",  {
		key: '#$8ebf5470f7f51cf9480',

        play: { replayLabel: '' },
		
    	// here is our playlist with two clips
		playlist: [
		
			// this first PNG clip works as a splash image
			{
				url: movie_src + flash_source + '.jpg',
				scaling: 'orig'
			},
			
			// second clip is a video. when autoPlay is set to false the splash screen will be shown
			{
				scaling: 'orig',
				provider: 'lighttpd',
				url: movie_src + flash_source+'.flv',
                bufferTime: 1,
                forceStop: false,
				autoPlay: false, 
				onFinish: function(clip){ 
						window.setTimeout(function(){$f('player').play(0);}, 1500);
				},  
				// video will be buffered when splash screen is visible
				autoBuffering: false 
			}
		],
		plugins: {
			lighttpd: {
				url: 'http://4i.hu/flow/flowplayer.pseudostreaming-3.2.4.swf'
			}
		}
	});
	}

	if ($('#player2').size() > 0) {
	flash_source = $('#player2').attr('rel');
	flowplayer("player2", "http://4i.hu/flow/flowplayer.commercial-3.2.4.swf",  {
		key: '#$8ebf5470f7f51cf9480',
		
        play: { replayLabel: '' },
    	// here is our playlist with two clips
		playlist: [
		
			// this first PNG clip works as a splash image
			{
				url: movie_src + flash_source+'.jpg', 
				scaling: 'orig'
			},
			
			// second clip is a video. when autoPlay is set to false the splash screen will be shown
			{
				scaling: 'orig',
				provider: 'lighttpd',
				url: movie_src + flash_source+'.flv', 
				autoPlay: false, 
                bufferTime: 1,
                forceStop: false,
				onFinish: function(clip){ 
						window.setTimeout(function(){$f('player2').play(0);}, 1500);
				},  
				// video will be buffered when splash screen is visible
				autoBuffering: false 
			}
		],
		plugins: {
			lighttpd: {
				url: 'http://4i.hu/flow/flowplayer.pseudostreaming-3.2.4.swf'
			}
		}
	});
	}

	if ($('#player3').size() > 0) {
	flash_source = $('#player3').attr('rel');
	flowplayer("player3", "http://4i.hu/flow/flowplayer.commercial-3.2.4.swf",  {
		key: '#$8ebf5470f7f51cf9480',
		
        play: { replayLabel: '' },
    	// here is our playlist with two clips
		playlist: [
		
			// this first PNG clip works as a splash image
			{
				url: movie_src + flash_source+'.jpg', 
				scaling: 'orig'
			},
			
			// second clip is a video. when autoPlay is set to false the splash screen will be shown
			{
				scaling: 'orig',
				provider: 'lighttpd',
				url: movie_src + flash_source+'.flv', 
				autoPlay: false, 
                bufferTime: 1,
                forceStop: false,
				onFinish: function(clip){ 
						window.setTimeout(function(){$f('player3').play(0);}, 1500);
                },
				// video will be buffered when splash screen is visible
				autoBuffering: false 
			}
		],
		plugins: {
			lighttpd: {
				url: 'http://4i.hu/flow/flowplayer.pseudostreaming-3.2.4.swf'
			}
		}
	});
	}

	if ($('#player4').size() > 0) {
	flash_source = $('#player4').attr('rel');
	flowplayer("player4", "http://4i.hu/flow/flowplayer.commercial-3.2.4.swf",  {
		key: '#$8ebf5470f7f51cf9480',
		
        play: { replayLabel: '' },
    	// here is our playlist with two clips
		playlist: [
		
			// this first PNG clip works as a splash image
			{
				url: movie_src + flash_source+'.jpg', 
				scaling: 'orig'
			},
			
			// second clip is a video. when autoPlay is set to false the splash screen will be shown
			{
				scaling: 'orig',
				provider: 'lighttpd',
				url: movie_src + flash_source+'.flv', 
                bufferTime: 1,
                forceStop: false,
				autoPlay: false, 
				onFinish: function(clip){ 
						window.setTimeout(function(){$f('player4').play(0);}, 1500);
				},  
				// video will be buffered when splash screen is visible
				autoBuffering: false 
			}
		],
		plugins: {
			lighttpd: {
				url: 'http://4i.hu/flow/flowplayer.pseudostreaming-3.2.4.swf'
			}
		}
	});
	}

	if ($('#player5').size() > 0) {
	flash_source = $('#player5').attr('rel');
	flowplayer("player5", "http://4i.hu/flow/flowplayer.commercial-3.2.4.swf",  {
		key: '#$8ebf5470f7f51cf9480',
		
        play: { replayLabel: '' },
    	// here is our playlist with two clips
		playlist: [
		
			// this first PNG clip works as a splash image
			{
				url: movie_src + flash_source+'.jpg', 
				scaling: 'orig'
			},
			
			// second clip is a video. when autoPlay is set to false the splash screen will be shown
			{
				scaling: 'orig',
				provider: 'lighttpd',
				url: movie_src + flash_source+'.flv', 
                bufferTime: 1,
                forceStop: false,
				autoPlay: false, 
				onFinish: function(clip){ 
						window.setTimeout(function(){$f('player4').play(0);}, 1500);
				},  
				// video will be buffered when splash screen is visible
				autoBuffering: false 
			}
		],
		plugins: {
			lighttpd: {
				url: 'http://4i.hu/flow/flowplayer.pseudostreaming-3.2.4.swf'
			}
		}
	});
	}
	
	$('.monthdisplay').click( function () {
		$('.month_content').hide();
		$(this).next('.month_content').toggle("slow");
	});

	$('.yeardisplay').click( function () {
		$('.month_content').hide();
		$('.monthdisplay_li').toggle("slow");
	});	
	
	if ($('.preselected_avatar')) {
	    var oldsrc=new Array();
	    for (i=0; i<12;i++) {
		oldsrc[i]=$('.preselected_avatar').eq(i).attr('src');
	    }
	}

        $('.preselected_avatar').click(function () {
	    for (i=0; i<12;i++) {
		$('.preselected_avatar').eq(i).attr('src',oldsrc[i]);
	    }
            $(this).attr('src','static/css/images/avatars/inverz_avatar'+$(this).attr("rel")+'.png');
            $('.avatarpic').val($(this).attr("rel"));
        });

	if (typeof(avatarpicture) != 'undefined') {
	    $('.preselected_avatar').eq(avatarpicture-1).attr('src','static/css/images/avatars/inverz_avatar'+avatarpicture+'.png');
	}

   // attach handler to form's submit event
    $('#prizegameupload').submit(function() {
	// submit the form
	$(this).ajaxSubmit({
		     beforeSubmit: prizegamevalidate,
		     success: function () {
			 $('#availablepics').append($('#uploadedpics').html());
			 $('#uploadedpics').html('');
  
		    },
		     target: '#uploadedpics'});

	// return false to prevent normal browser submit and page navigation
	return false;
    });

	 $('.addvote').click(function() {
		$.get('nyeremenyjatek/szavazas/'+$(this).attr('id'), function(data) {
			alert(data);
		});
	 });

	 var oldcontent=new Array();
	$('.updatepic').live('click',function() {
		var tempval=$('#pic'+$(this).attr('id')).html();
		var tempid=$(this).attr('id');
		oldcontent[tempid]=$('#pic'+$(this).attr('id')).parent().html();
		$(this).remove();
		$('#pic'+$(this).attr('id')).html('<input type="text" name="newtitle" id="newcontent'+$(this).attr('id')+'" value="'+tempval+'"/><span style="cursor:pointer" class="picsend" id="'+$(this).attr('id')+'">Mentés</span>');
	 });


	 $('.picsend').live('click',function() {
		 var tempid=$(this).attr('id');
		if ($('#newcontent'+$(this).attr('id')).val()=="") {
			alert('Nem lehet üres a mező!');
		} else {
			var tempid = $(this).attr('id');
			var send_data=$('#newcontent'+$(this).attr('id')).val();
		$.post('nyeremenyjatek/modositas/'+tempid, {newname:send_data}, function(data) {
			 $('#pictitle_'+tempid).html(oldcontent[tempid]);
			 $('#pic'+tempid).html(send_data);
		});
		}
	 });
	 
	 $('.picvote').live('click',function() {
		 me = $(this);
		 $.post('fotopalyazat/szavazas',
		 {picname: me.attr('rel')},
		 function(msg) {
			 me.html(msg);
		 }
		);
	 });	 
});


function prizegamevalidate(formData, jqForm, options) {
    for (var i=0; i < formData.length; i++) {
        if (!formData[i].value) {
            alert('Egyik mező tartalma se lehet üres!');
            return false;
        }
    }
}

