function showInstructions(browser) {
	var browsers = {firefox: 'Firefox 3', firefox2: 'Firefox 2', safari: 'Safari', opera: 'Opera', ie7: 'Internet Explorer', ie8: 'Internet Explorer'};
	$('#firefox').slideUp();
	$('#safari').slideUp();
	$('#opera').slideUp();
	$('#firefox2').slideUp();
	$('#ie7').slideUp();
	$('#ie8').slideUp();
	$('#'+browser).slideDown();
	$('#browser-name').html(browsers[browser]);
}

function ajaxFileUpload(elem)
{
	$("#loading"+elem).ajaxStart(function(){
		$(this).show();
	}).ajaxComplete(function(){
		$(this).hide();
	});
	
	var _url = '/user/import'+elem;
	
	$.ajaxFileUpload({
			url:_url, 
			secureuri:false,
			fileElementId:elem,
			dataType: 'json',
			success: function (data, status) {
				if(typeof(data.error) != 'undefined') {
					if(data.error != '') {
						alert(data.error);
					} else {
						alert(data.msg);
						window.location = (""+window.location).replace('#','');		            
					}
				}				
			},
			error: function (data, status, e) {
				alert("All links from the file were imported to your account.\n Click \"OK\" and then proceed to the next step.");
                                window.location = (""+window.location).replace('#','');
			}
		}
	);
	return false;
}
function ajaxAvatarUpload()
{	
	var fileName = $('#avatar').val();
	var ext = fileName.substring(fileName.lastIndexOf('.') + 1);
	if (ext == "gif" || ext == "GIF" || ext == "JPEG" || ext == "jpeg" || ext == "jpg" || ext == "JPG" || ext == "png" || ext == 'PNG') {	
	
		$("#loading").ajaxStart(function(){	
			$(this).show();
		}).ajaxComplete(function(){
			$(this).hide();
		});
		
		$.ajaxFileUpload({
				url:'/user/upload', 
				secureuri:false,
				fileElementId:'avatar',
				dataType: 'json',
				success: function (data, status) {
					if(typeof(data.error) != 'undefined') {
						if(data.error != '') {
							alert(data.error);
					} else {
            			srcSeed = '?'+(new Date()).getTime();
            			srcM = $('#imageProfileMedium').attr('src') + srcSeed;
            			srcL = srcM.replace(/m/,'l');

            			$('#avatar-image-p .toggle-cp img').remove();
            			$('#avatar-image-p .toggle-cp').prepend('<img src="'+srcL+'"/>');

            			$('#cp-pic .toggle-cp img').remove();
            			$('#cp-pic .toggle-cp').prepend('<img src="'+srcL+'"/>');

            			profileParent = $('#imageProfileMedium').parent();
            			$('#imageProfileMedium').remove();
            			profileParent.prepend('<img id="imageProfileMedium" src="'+srcM+'"/> ');
					}
				}
			},
			error: function (data, status, e) {
				alert("Oops.. something happened. Please try yo use another image.");
			}
		});
	} else {
		alert('Please select JPEG or GIF image');
	}
	return false;
}

$(function() {
	

	$('.remove').bind('click',function(){
		if($(this).hasClass('administrator')){
		$.post('/user/collaborate/?remove=administrator&useremail='+$(this).attr('href'),function(req){});
		}
		else if($(this).hasClass('collaborator')) {
		$.post('/user/collaborate/?remove=collaborator&useremail='+$(this).attr('href'),function(req){});
		}
		$(this).parent().parent().hide();
		return false;
	});
	
	$('#or_importbrowser').click(function() {
		$('#or_importdelicious').removeClass('_current');
		$('#or_importbrowser').addClass('_current');
		$('#tab-delicious').hide();
		$('#tab-browser').show();
		return false;
	});
	
	$('#or_importdelicious').click(function() {
		$('#or_importbrowser').removeClass('_current');
		$('#or_importdelicious').addClass('_current');
		$('#tab-browser').hide();
		$('#tab-delicious').show();
		return false;
	});
	
	$('.toggle-cp').click( function() {
			$('#change-photo').toggle();
	});
	
	$('a#toggle-open-id').click(function() {
		$('#use-email').hide();
		$('#use-openid').show();
		$('#login-openid').show();
		return false;							 
	});
	
	$('a#toggle-username').click(function() {
		$('#use-openid').hide();
		$('#login-openid').hide();
		$('#use-email').show();
		return false;							 
	});
	
	
	$('#login-username').blur(function() {
	   if($(this).attr('value') == undefined || $(this).attr('value').length == 0) {
	      $(this).attr('value','Username');
	   }
	});
	
	$('#login-username').focus(function() {
		if( $(this).attr('value') == 'Username') {
			$(this).attr('value','');
		}
	});

	$('#login-openid').focus(function() {
		if( $(this).attr('value') == 'OpenID URL') {
			$(this).attr('value','');
		}
	});
	$('#login-openid').blur(function() {
		if( $(this).attr('value') == undefined || $(this).attr('value').length == 0) {
			$(this).attr('value','OpenID URL');
		}
	});

	$('#login-password-mask').focus(function() {
	   $(this).hide();
	   $('#login-password').show();
	   $('#login-password').focus();
	});


	$('#login-password').blur(function() {
	   if( $(this).attr('value') == undefined || $(this).attr('value').length == 0) {
	      $(this).hide();
	      $('#login-password-mask').show();
	   }
	});

	
	
	var default_squery_value = $('#squery').attr('value');
	
	$('#squery').focus(function() {
		if( $(this).attr('value') == default_squery_value) {
			$(this).attr('value','');
		}
	});
	$('#squery').blur(function() {
		if( $(this).attr('value') == '') {
			$(this).attr('value',default_squery_value);
		}
	});

	$('#use-email-signup').click(function() {
		$('#signup-w-openid').hide();
		$('#signup-w-email').show();
		return false;
	});

	$('#use-openid-signup').click(function() {
		$('#signup-w-email').hide();
		$('#signup-w-openid').show();
		return false;
	});
	
	$('#use-email-login').click(function() {
		$('#login-w-openid').hide();
		$('#login-w-email').show();
		return false;
	});

	$('#use-openid-login').click(function() {
		$('#login-w-email').hide();
		$('#login-w-openid').show();
		return false;
	});
	
});
