var colors=['#33ff00','#33ffff','#ff6600','#ff3399','#ff33ff','#ff3333','#33ffff','#9933ff','#ffff00'],
	tmpHeight;
window.onload=function(){
	if ($('#main_content').size()) $('#main_content').css({marginTop: '-'+$('#main_content').height()/2+'px'});
	if ($('#random_container').size()) $('#random_container').css({top: ($(window).height()/2-$('#random_container').height()/3)+'px'});
}
$(function(){

	if ($.browser.msie && $.browser.version<8) setInterval(function(){
		ieH=tmpHeight?tmpHeight:'100%';
		$('body').height('10px').height(ieH);
	},500);

    if ($('.login').size()) {
		$('input[type=text],input[type=password],textarea').each(function(){
			$(this).attr('default',$.trim($(this).val()));
		});
		$('input[type=text],input[type=password],textarea').focus(function(){
			$(this).addClass('focused');
			if ($.trim($(this).val())==$(this).attr('default')) $(this).val('');
		}).blur(function(){
			$(this).removeClass('focused');
			if ($.trim($(this).val())=='') $(this).val($(this).attr('default'));
		}).hover(
			function(){$(this).addClass('field_hover')},
			function(){$(this).removeClass('field_hover')}
		);
		$('.login .button').hover(
			function(){$(this).addClass('hover')},
			function(){$(this).removeClass('hover')}
		).mousedown(function(){
			$(this).addClass('active')
		}).mouseup(function(){
			$(this).removeClass('active')
		});
		$('.login label').append('<span class="checkbox"></span>')
			/*.click(function(){
				if ($.browser.msie && $.browser.version<7) {
					$('.login input[type=checkbox]').click();
					checkCkechbox();
				}
			})*/
			.find('input[type=checkbox]')
				.change(function(){checkCkechbox();})
				.click(function(){checkCkechbox();});
		checkCkechbox();
		function checkCkechbox() {
			if ($('.login input[type=checkbox]').attr('checked'))
				$('.login input[type=checkbox]').parent().find('.checkbox').addClass('checked');
			else
				$('.login input[type=checkbox]').parent().find('.checkbox').removeClass('checked');
		}
	}

	$('.close')
		.live('mouseover',function(){
			$(this).css('backgroundPosition','left bottom');
		})
		.live('mouseout',function(){
			$(this).css('backgroundPosition','left top');
		});

	if ($('.rubric').size() || $('.list').size() || $('#makes_content').size() || $('.random').size() || $('.vis').size() || $('.theory').size()) {
		var hash=location.hash.substring(0,location.hash.length-1);
		if (hash.length) {
			var targetLi=$('li'+hash).size()?$('li'+hash):$('a'+hash);
			if (targetLi.size()) {
				targetLi.addClass('work_open');
			}
		}
		$('.rubric li, .list li, #makes_content a, .random li, .theory li, .vis li').click(function(){
			location.href='#'+this.id+'/';
		});
	}
});
