function commentViolation( obj ){
	var rel = $(obj).attr('rel');
	var post = { idc:rel };
	$(obj).unbind("click");
	$(obj).html("<img src='/ajax/captcha.php?t="+ new Date().getTime()+"' /><br />przepisz kod:<br /><input class='violation' type='text' /><br />powód naruszenia:<br /><textarea class='violation'></textarea><br /><span class='submitViolation'>zgłoś</span>");
	$(obj).children("span:last").click( function(){
		post.text = $(obj).children('textarea:first').val();
		post.captcha = $(obj).children('input:first').val();
		$.post( '/ajax/commentViolation.php?timestamp='+ new Date().getTime(), post, function(data){ alert(data); });
		$(obj).html("");
	});
}

function uploadViolation( obj ){
	var rel = $(obj).attr('rel');
	var post = { idu:rel };
	$(obj).unbind("click");
	$(obj).html("<img src='/ajax/captcha.php?t="+ new Date().getTime()+"' /><br />przepisz kod:<br /><input class='violation' type='text' />powód naruszenia:<br /><textarea class='violation'></textarea><br /><span class='submitViolation'>zgłoś</span>");
	$(obj).children("span:last").click( function(){
		post.text = $(obj).children('textarea:first').val();
		post.captcha = $(obj).children('input:first').val();
		$.post( '/ajax/uploadViolation.php?timestamp='+ new Date().getTime(), post, function(data){ alert(data); });
		$(obj).html("");
	});
}

$(document).ready( function (){

	$('.noteUp').click( function(){

		var parent = $(this);
		var idu = $(this).attr('rel');

		var post = { idu:idu, note:'yes' };
		
		 
		$.post( '/ajax/note.php', post, function( data ){

			var note = $('.note[rel='+idu+']');	

			note.next().remove();
		
			if( data == 'voted'){ 
				alert('nie mozna oddac dwoch glosow na to samo zdjecie');
			}else{
			var inote = parseInt( note.html() );
			inote++;
			note.fadeOut( 600, function(){
				if( inote > 0 ){ $(this).removeClass('no'); $(this).addClass('yes') };  
				$(this).html(inote);
				$(this).fadeIn(600);
			});
			}
			parent.children('img:first').fadeOut(1000);
		});
		
		var note = $('.note[rel='+idu+']');
		note.after('&nbsp;&nbsp;<img style="display:none;" src="/img/ajaxyes.gif"/>');
		note.next().fadeIn(200);
		
	
	});

	$('.noteDown').click( function(){

		var parent = $(this).parent();
		var idu = $(this).attr('rel');


		var post = { idu:idu, note:'no' }; 

		$.post( '/ajax/note.php', post, function( data ){

		var note = $('.note[rel='+idu+']');
		note.next().remove();

			if( data == 'voted'){ 
				alert('nie mozna oddac dwoch glosow na to samo zdjecie');
			}else{

			
			var inote = parseInt( note.html() );
			inote--;
			note.fadeOut( 600, function(){
				if( inote < 0 ){ $(this).removeClass('yes'); $(this).addClass('no') };  
				$(this).html(inote);
				$(this).fadeIn(600);
			});
			
			}
			
			parent.children('img:first').fadeOut(1000);
			
		});

		var note = $('.note[rel='+idu+']');
		note.after('&nbsp;&nbsp;<img style="display:none;" src="/img/ajaxno.gif"/>');
		note.next().fadeIn(200);
	
	});
	
});	



$(document).ready( function (){

	function browserClientSize(){
		var theWidth, theHeight;
		// Window dimensions: 
		if (window.innerWidth) {
			theWidth=window.innerWidth;
		}
		else if (document.documentElement && document.documentElement.clientWidth) {
			theWidth=document.documentElement.clientWidth;
		}
		else if (document.body) {
			theWidth=document.body.clientWidth;
		}
		if (window.innerHeight) {
			theHeight=window.innerHeight;
		}
		else if (document.documentElement && document.documentElement.clientHeight) {
			theHeight=document.documentElement.clientHeight;
		}
		else if (document.body) {
			theHeight=document.body.clientHeight;
		}
		
		var size = { width:theWidth, height:theHeight }
		
		return size;
	}

	var clientSize = browserClientSize();
	
	function closeFullscreen(){
		$("#closeFullscreen").remove();
		$("#fullscreen").remove();
		$("#bgFullscreen").remove(); 
	}
	
	function fullscreenImg( obj ){
		var src = $(obj).attr('src');
		var width = 800;
		var left = clientSize.width / 2 - ( width / 2 );
		
		var scrollTop = $(document).scrollTop();
		
		$(obj).before(
			"<div id='bgFullscreen' style=' width:"+ clientSize.width +"px; height:"+100+"px; position:absolute; text-align:center; background:#000; left:0px; top:0px;'></div>"+
			"<img id='closeFullscreen' src='/img/close.gif' style='position:absolute; cursor:pointer; z-index:4;'/>"+
			"<div id='fullscreen' style='top:"+scrollTop+"px; width:"+width+"px; left:"+left+"px; position:absolute;'>"+
			"<img width='"+width+"' src='"+src+"' />"+
			"</div>"
		);
		$("#bgFullscreen").css('height', $(document).height() );
		$("#bgFullscreen").css('opacity', '0.5' );
		
		$("#closeFullscreen").css('top', $(document).scrollTop()+"px" );

		$("#closeFullscreen").click( function(){ closeFullscreen(); } );
		$("#bgFullscreen").click( function(){ closeFullscreen(); } );
		
		$(window).scroll( function(){
			$("#closeFullscreen").css('top', $(document).scrollTop()+"px" );
		});
	
	}
	
	$(".uploadThumb").click( function(){
		fullscreenImg( this );
	});
	
	$("#mainMenu a[rel]").each( function( key, obj ){
		var rel = $(obj).attr('rel');
		$(obj).prepend("<img src='/css/layout/btn-over/btn"+rel+".png' class='menuButtonOver' />" ); 
	});
	
	$("#mainMenu a[rel]").hover(
		function(){	
			var rel = $(this).attr('rel');
			if( rel != 2 ){ $('#viewMenu').fadeOut(100); }
			
			$(this).children('img:first').fadeIn("100");	},
		function(){	$(this).children('img:first').fadeOut("200");}
	);

	$("#mainMenu a[rel=2]").hover(
		function(){	$('#viewMenu').fadeIn("100");	},
		function(){	}
	);

	$("#viewMenu").hover(
		function(){		},
		function(){	$('#viewMenu').fadeOut("100"); }
	);
	
	$(".commentViolation").click( function(){ commentViolation(this); });	
	$(".uploadViolation").click( function(){ uploadViolation(this); });	

		
});	
