
function checkPortfolio( obj )
{
	var n = $("input:checked[name='portfolio[]']").length;
	if ( n > 3 ) {
		obj.removeAttr( 'checked' );
	}	
}

$(function() {

	$('.magicInput').each( function() {

		$(this).attr( 'title', $(this).val());

	});

	$('.magicInput').focus( function() {

		if ($(this).val() ==	$(this).attr( 'title') ) {

			$(this).val('');

		}

	});



	$('.magicInput').blur( function() {

		if ( $(this).val() == '' ) {

			$(this).val( $(this).attr( 'title' ) );

		}

	});

		$('.razdel .clk').click(function() {

			if($(this).hasClass('down')){
				
				$(this).parent().parent().find('.razdel_open').slideDown(600);
				$(this).parent().parent().find('.down').removeClass('down').addClass('up');
				

			} else { 
				$(this).parent().parent().find('.razdel_open').slideUp(600);
				$(this).parent().parent().find('.up').removeClass('up').addClass('down');
			}
			

		});


		$('.razdel h2').hover(function(){
			$(this).addClass('over');
		}, function(){
			$(this).removeClass('over');
		});		
		
		$('#addFileButton').click( function() {
			var temp = $('#hiddenFile').clone( );
			temp.show( );
			temp.find( 'input' ).attr( 'name', 'files[]' );
			temp.insertAfter( $('.fileInput:last') );
		});
		
		$('#acceptFilterButton').click( function() {
			var string = '';
			if ( $('#tag_1').attr( 'checked' ) ) {
				string += '1';
			} else {
				string += '0';
			}
			
			if ( $('#tag_2').attr( 'checked' ) ) {
				string += '1';
			} else {
				string += '0';
			}
			
			if ( $('#tag_3').attr( 'checked' ) ) {
				string += '1';
			} else {
				string += '0';
			}
			
			if ( $('#tag_4').attr( 'checked' ) ) {
				string += '1';
			} else {
				string += '0';
			}
			
			window.location.replace( 'http://architector.ru/lance/project/filter/'+string );
			return false;
		});
		
		$('.reportAllButton').click( function() {
			$('.reportDiv').show( );
		});
		
		$('.reportPlusButton').click( function() {
			$('.reportDiv').hide( );
			$('.reportPlus').show( );
		});
		
		$('.reportMinusButton').click( function() {
			$('.reportDiv').hide( );
			$('.reportMinus').show( );
		});
		
		$('.relRadio').change( function( ) {
			var id = $(this).attr( 'rel' );
			var type=  $(this).val( );
			var parent = $(this).parent( ).parent( ).parent( ).parent( );
			$.post( 'http://architector.ru/lance/profile/setRelation/', {
				id : id,
				type : type }, function( data ) {
					console.info( parent );
					parent.removeClass( 'relations1' ).removeClass( 'relations2' ).addClass( 'relations'+type );
					
				} );
		});
		
		$('.relButtonAll' ).click( function( ) {
			$('.relations' ).show( );
		} );
		
		$('.relButtonFav' ).click( function( ) {
			$('.relations' ).hide( );
			$('.relations1' ).show( );
		} );
		
		$('.relButtonIgnore' ).click( function( ) {
			$('.relations' ).hide( );
			$('.relations2' ).show( );
		} );
		
		$('.projectsAll' ).click( function( ) {
			$('.project' ).show( );
		} );
		
		$( '.projectsOpened' ).click( function( ) {
			$( '.project' ).hide( );
			$( '.projectOpened' ).show( );
		} );
		
		$( '.projectsClosed' ).click( function( ) {
			$( '.project' ).hide( );
			$( '.projectClosed' ).show( );
		} );
		
		$( '#addPortfolioButton' ).click( function() {
			$(' #portfolioDiv' ).load( 'http://architector.ru/lance/profile/getMyPortfolio/', {}, function() {
				$( '#portfolioDiv' ).slideToggle( );
			});
			
			$('.myPortfolio').change( function() {
				var n = $("input:checked[name='portfolio[]']").length;
				console.log( 'size: '+n );
				if ( n > 1 ) {
					alert( 'fucckk' );
					$(this).attr( 'checked' , 'false' );
				}
			} );
			
		} );
		
		$('.magicInput').each( function() {

			$(this).attr( 'title', $(this).val());

		});

		$('.magicInput').focus( function() {

			if ($(this).val() ==	$(this).attr( 'title') ) {

				$(this).val('');

			}

		});



		$('.magicInput').blur( function() {

			if ( $(this).val() == '' ) {

				$(this).val( $(this).attr( 'title' ) );

			}					

		});	
});