var $j = jQuery.noConflict();

$j(document).ready(init);

function init() {
	// hide background text if window is too small
	if($j(window).width()<1120){
		$j('#bglogo').addClass('hidden').animate({opacity: 0}, 0);
	}
	$j(window).resize(function() {
		if($j(this).width()<1120){
			if (!$j('#bglogo').hasClass('hidden')) {
				$j('#bglogo').addClass('hidden').stop().animate({
					opacity: 0
				}, 200);
			}
		} else {
			if ($j('#bglogo').hasClass('hidden')) {
				$j('#bglogo').removeClass('hidden').stop().animate({
					opacity: 1
				}, 200);
			}
		}
	});
	
	
	//nav stuff
	$j('#nav li').each(function() {
		$j(this).append('<div></div>');
		var NC = $j(this).find('div');
		if (!$j(this).hasClass('current')) {
			NC.stop().animate({opacity: 0}, 0, function(){$j(this).hide();});
			$j(this).hover(
				function() {
					NC.stop().show().animate({
						opacity: 1
					}, 340);
				},
				function () {
					NC.stop().animate({
						opacity: 0
					}, 430, function () {$j(this).hide();});
				}
			);
		}
	});
	
	//form stuff
	/*
	$j('input:text:visible, textarea').each(function() {
		if ($j(this).closest('p').find('label').text()=="message") {
			$j(this).closest('p').find('label').text('\n\n\nmessage')
		}
		var defaulttext = $j(this).closest('p').find('label').text();
		$j(this).closest('p').find('label').hide();
		if ($j(this).val()==defaulttext || $j(this).val()=='') {
			$j(this).addClass('default').val(defaulttext);
		}
		$j(this).focus(function() {
			if ($j(this).val()==defaulttext || $j(this).val()=='') {
				$j(this).removeClass('default').val('');
			}
		});
		$j(this).blur(function() {
			if ($j(this).val()==defaulttext || $j(this).val()=='') {
				$j(this).addClass('default').val(defaulttext);
			}
		});
	});
	$j('form').submit(function() {
		$j('input:text:visible, textarea').each(function() {
			if ($j(this).hasClass('default')) {
				$j(this).val('');
			}
		});
	});
	*/
	
	// FOLIO STUFF
	// front page hovers
	$j('#folio .fCol div').each(function() {
		$j(this).find('h3').stop().animate({opacity: 0}, 0, function(){$j(this).hide();});
		$j(this).hover(
			function() {
				$j(this).find('h3').stop().show().animate({
					opacity: 1
				}, 180);
			},
			function () {
				$j(this).find('h3').stop().animate({
					opacity: 0
				}, 430, function () {$j(this).hide();});
			}
		);
	});
	
	// Internal Folio page
	// initialize
	var Current=$j('#fint #thumbs .thumb:first').addClass('current');
	$j('#images img').each(function() { // hide images
		$j(this).animate({opacity:0},0, function(){$j(this).hide();});
	});
	var CurrentIMG=$j('#images img:first').animate({opacity:1},0, function(){$j(this).show();}); // set initial image
	$j('#info').html($j('#fint #thumbs .thumb:first').find('.info').html()); // set initial info
	$j('#images').animate({
		width:$j('#images img:first').width(),
		height:$j('#images img:first').height()
	}, 0);
	// image transition
	$j('#fint #thumbs .thumb').each(function(i) {
		$j(this).click(function() {
			if (!$j(this).hasClass('current')) {
				Current.removeClass('current');
				Current=$j(this);
				$j(this).addClass('current');
				var I=$j(this).find('.info').html();
				CurrentIMG.stop().animate({
					opacity:0
				}, 360, function(){$j(this).hide();});
				CurrentIMG=$j('#images img:eq('+i+')').stop().show().animate({
					opacity:1
				}, 360);
				
				$j('#images').stop().animate({
					width:$j('#images img:eq('+i+')').width(),
					height:$j('#images img:eq('+i+')').height()
				}, 360);
				$j('#info').stop().animate({
					opacity: 0
				}, 160, function(){
					$j(this).html(I);
					$j(this).animate({
						opacity:1
					},200);
				});
			}
		});
	});
	
	//blog stuff
	$j('#filters li').each(function() {
		$j(this).find('ul').animate({opacity: 0}, 0, function(){$j(this).hide();});
		$j(this).hover(
			function() {
				//$j(this).addClass('hover');
				$j(this).find('ul').stop().show().animate({
					opacity: 1
				}, 100);
			},
			function() {
				//$j(this).removeClass('hover');
				$j(this).find('ul').stop().animate({
					opacity: 0
				}, 200, function () {$j(this).hide();});
			}
		);
	});
	
	//a contact thing
	var name='rachel.verhaaren';
	var host='gmail';
	var adr = name+'@'+host+'.com';
	$j('#contactblurb').append('<p>email: <a href="'+adr+'">'+adr+'</a></p>');
}