$(document).ready(function() {
	mac_pc();
	clear_text();
	if ($('.gravatar_wrap').length > 0) gravatar_fade();
	if ($('#dd').length > 0) main_nav();
});
function main_nav() {
	$('#dd').hover(function() {
		$(this).addClass('hover');
	},function() {
		$(this).removeClass('hover');
	});
	
	$('#container').click(function() {
		if (!$('#dd').hasClass('hover')) {
			$('#dd').animate({'margin-top':'-382px'},{duration:300,queue:false,complete:function() {
				$('#dd').removeClass('open');
				$('#main_nav > li').removeClass('active');
			}});
		}
	});
	$('.nav_link').click(function() {
		if ($(this).parent('li').hasClass('active')) {
			$('#dd').animate({'margin-top':'-382px'},{duration:300,queue:false,complete:function() {
				$('#dd').removeClass('open');
			}});
		} else {
			$('.nav_link').each(function() { $(this).parent('li').removeClass('active') });
			$(this).parent('li').addClass('active');
			if (!$('#dd').hasClass('open')) {
				$('#dd').animate({'margin-top':'0px'},{duration:300,queue:false,complete:function() {
					$('#dd').addClass('open');
				}});
			}
		}
		return false;
	});
	
	$('.archive_link').click(function() {
		$('.archive_link,.archive').removeClass('active');
		var i = $('.archive_link').index(this);
		$('.archive_link:eq('+i+'),.archive:eq('+i+')').addClass('active');
	});
	
	
	$('a#b_left').hide();
	$('a#b_right').click(function() {
		$('.wide_slide').animate({'margin-left':'-338px'},{duration:300,queue:false,complete:function() {
			$('a#b_right').hide();
			$('a#b_left').show();
		}});
		return false;
	});
	$('a#b_left').click(function() {
		$('.wide_slide').animate({'margin-left':'0px'},{duration:300,queue:false,complete:function() {
			$('a#b_right').show();
			$('a#b_left').hide();
		}});
		return false;
	});
	
	$('a#archive_left').hide();
	$('a#archive_right').click(function() {
		$('.wide').animate({'margin-left':'-338px'},{duration:300,queue:false,complete:function() {
			$('a#archive_right').hide();
			$('a#archive_left').show();
		}});
		return false;
	});
	$('a#archive_left').click(function() {
		$('.wide').animate({'margin-left':'0px'},{duration:300,queue:false,complete:function() {
			$('a#archive_right').show();
			$('a#archive_left').hide();
		}});
		return false;
	});
}
function gravatar_fade() {
	/*
	$('.gravatar_wrap').each(function() {
		$(this).fadeTo(0,0);
		$(this).parent('div').hover(function() {
			$('.gravatar_wrap',this).fadeTo(200,1);
		},function() {
			$('.gravatar_wrap',this).fadeTo(200,0);
		});
	});
	*/
	$('.gravatar_wrap').fadeTo(0,0);
	$('.comment_div').hover(function() {
		$('.gravatar_wrap:eq(0)',this).animate({'opacity':'1'},{duration:200,queue:false});
		//$('.gravatar_wrap:eq(0)',this).fadeTo(200,1);
	},function() {
		$('.gravatar_wrap:eq(0)',this).animate({'opacity':'0'},{duration:200,queue:false});
		//$('.gravatar_wrap:eq(0)',this).fadeTo(200,0);
	});
}
function clear_text() {
	$('input.text').each(function() {
		var text = $(this).attr('value');
		$(this).click(function() { if ($(this).attr('value') == '') $(this).removeClass('with_background'); });
		$(this).blur(function() { if ($(this).attr('value') == '') $(this).addClass('with_background'); });
	});
	$('textarea').each(function() {
		var text = $(this).html();
		$(this).click(function() { if ($(this).html() == '') $(this).removeClass('with_background'); });
		//$(this).blur(function() { if ($(this).html() == '') $(this).addClass('with_background'); });
	});
}
function mac_pc() {
	if (navigator.appVersion.indexOf("Mac")!=-1) {
		$('body').addClass('mac');
	} else {
		$('body').addClass('pc');
	}
}
