$(document).ready(function()
{
/* add autocomplete off for more security
----------------------------------*/	
	$('.password-password').hide();
	$('.password-text').show();

	$('.password-text').focus(function() {
		$(this).hide();
		$('.password-password').show();
		$('.password-password').focus();
	});
	
	$('.password-password').blur(function() {
		if($(this).val() == '' || $inputs[$(this).attr('name')] == $(this).val()) {
			$(this).hide();
			$('.password-text').show();
		}
	});
	
	$(":input").attr('autocomplete','off');
	
/* inputs clearing 
----------------------------------*/	
	var $inputs = [];
	
	$(":input").each(function(){
		$inputs[$(this).attr('name')] = $(this).val();
	});

	$(':input').live('focusin', function(){  
		if($(this).val() == $inputs[$(this).attr('name')]){
			$(this).val('');
		}
		else
		{
			//$(this).select();
		}
	});
	
	$(':input').live('focusout', function(){  
		if($(this).val() == ''){
			$(this).val($inputs[$(this).attr('name')]);
		}
	});
	
/* rend les lien externt 
----------------------------------*/
	$("a[rel~='external']").click( function(){
		window.open($(this).attr('href'));
		return false;
	});
	
/* anti spam mailto
----------------------------------*/	
	$("img[rel^=modal]").click(function(e)
	{ 
		e.preventDefault();
		var select = $(this).attr("src");
		
		$.nyroModalManual({
			debug: false, // Show the debug in the background
			windowResize: true,
			url : select,
			modal: false,
			type: 'image',
			forceType: 'image', 
			defaultImgAlt: 'Image', // Default alt attribute for the images
			setWidthImgTitle: true, // Set the width to the image title
			gallery: 'gal',
			width: null, // default Width If null, will be calculate automatically
			height: null, // default Height If null, will be calculate automatically
			resizable: true,
			autoSizable: true
		});
		
		return false;
	});
	
/* anti spam mailto
----------------------------------*/
	if($(".nospam").length){
		// variables, which will be replaced
		var at = / AT /;
		var dot = / DOT /g;

		// function, which replaces pre-made class
		$('.nospam').each(function () {
			var addr = $(this).text().replace(at, '@').replace(dot, '.');
			$(this).after('<a href="mailto:' + addr + '">' + addr + '</a>');
			$(this).remove();
		});
	}

/* sidebar

----------------------------------*/	
	
	var $postShare = $('#sidebar .scroller');
	
	if($postShare.length > 0)
	{
		var descripY = parseInt($postShare.offset().top);
		var footerY = parseInt($('#footer').offset().top);
		var scrollH = $postShare.height();
		var scrollMax = (parseInt(footerY-scrollH)-(16*2));
		
		$(window).scroll(function(){ 
			var scrollY = $(window).scrollTop();
		
			if(scrollY < descripY) {
				$postShare.stop().animate({"top": (descripY) }, 500).css({position: 'absolute', "margin-top": "0"});
			}else if( (scrollY > descripY) && (scrollY < scrollMax) ) {
				$postShare.stop().animate({"top": (scrollY) }, 500).css({position: 'absolute', "margin-top": "16px"});
			}else if(scrollY > scrollMax){
				$postShare.stop().animate({"top": (scrollMax) }, 500).css({position: 'absolute'});
			}
		});
	}
});
