var $j = jQuery.noConflict();

function clearText(theField)
{
if (theField.defaultValue == theField.value)
theField.value = '';
$j(theField).css('color','#fff');
}

function addText(theField)
{
if (theField.value == '')
theField.value = theField .defaultValue;
$j(theField).css('color','#333');
}

$j(function() {
	$j('#slides li a').attr('href','/work');
	$j('.work_image a img').animate({opacity:.4},0);
	$j('.work_image a img').hover(function() {
		$j(this).parent().parent().children('.work_image_over_container').children('.work_image_over').stop().animate({bottom: 0}, 'fast');
		$j(this).stop().animate({opacity:1},500);
	});
	$j('.work_image a img').mouseout(function() {
		$j(this).parent().parent().children('.work_image_over_container').children('.work_image_over').stop().animate({bottom: -45}, 'fast');
		$j(this).stop().animate({opacity:.4},500);
	});
	$j('#tags a').removeAttr('style');
	
	var numSlides = $j('#slides li').length;
	var currentSlide = numSlides;
	var nextSlide = 1;
	var prevSlide = numSlides - 1;
	var s = 0;
	
	if(numSlides > 1) {
		s = setInterval(next, 10000);
		$('#buttonContainer').append('<div id="prevBtn" class="left" style="margin: 0 10px 20px 0"></div><div id="nextBtn" class="left"></div>');
	}
	
	
	$j('#slides li').css({'position':'absolute','display':'none'});
	$j('#nextBtn').click(next);
	$j('#nextBtn').click(function() {clearInterval(s);});
	$j('#prevBtn').click(prev);
	$j('#prevBtn').click(function() {clearInterval(s);});
	$j('#slides img').load(function() {
	$j('#slides li:nth-child('+currentSlide+')').fadeIn(1000);
		var height = $j('#slides li:nth-child('+currentSlide+')').height();
		$j('#slideshowsmall').animate({'height':height},500);
	});
	
	function prev() {
		var newHeight = $j('#slides li:nth-child('+prevSlide+')').height();
		$j('#slideshowsmall').animate({'height':newHeight}, 500);
		
		$j('#slides li:nth-child('+currentSlide+')').fadeOut();
		$j('#slides li:nth-child('+prevSlide+')').fadeIn();
		currentSlide -= 1;nextSlide -= 1;prevSlide -= 1;
		if(currentSlide < 1) {currentSlide = numSlides;}
		if(nextSlide < 1) {nextSlide = numSlides;}
		if(prevSlide < 1) {prevSlide = numSlides;}
	}
	
	function next() {
		var newHeight = $j('#slides li:nth-child('+nextSlide+')').height();
		$j('#slideshowsmall').animate({'height':newHeight});
		$j('#slides li:nth-child('+currentSlide+')').fadeOut();
		$j('#slides li:nth-child('+nextSlide+')').fadeIn();
		currentSlide += 1;nextSlide += 1;prevSlide += 1;
		if(currentSlide > numSlides) {currentSlide = 1;}
		if(nextSlide > numSlides) {nextSlide = 1;}
		if(prevSlide > numSlides) {prevSlide = 1;}
	}
	
	
});

function filterWork() {
	var tags = $j('#tags a');
	for(var i = 0; i < tags.length; i++){
		$j(tags[i]).attr({href: "#" + $j(tags[i]).text()});
	}
	$j('#tags a').click(function(){
		$j("#tags a.active").removeClass("active");
		$j(this).addClass("active");
		var tag = $j(this).attr('href').replace(/#/,"");
		$j(".work_item").hide();
		$j(".work_item:has(.tag_list a:contains('" + tag + "'))").show();
		$j(".work_item:has(.tag_list a:contains('" + tag + "'))").show();
	});
}
