jQuery.fn.slideshow = function(options){
	var ths = $(this);
	var w = 715;
	var h = 473;

	ths.width(w).height(h).css('overflow','hidden')
	var imgs = ths.children('img').css('visibility','visible').fadeOut(0);
	$(imgs[0]).fadeIn(0)

	var iface = $('<div class="iface"></div>')
	ths.append(iface);
	var prev = $('<a href="#" class="button prev disabled" rel="-1"></a>').css('opacity',0.8);
	iface.append(prev)
	var next = $('<a href="#" class="button next disabled" rel="1"></a>').css('opacity',0.8);
	iface.append(next)
	var desc = $('<div class="img-description"></div>').width(w-prev.width()*2).css('opacity',0.8);
	iface.append(desc)
	
	var current_img = 0;
	if(imgs.size()>0) next.removeClass('disabled');
	
	function switch_image(offset)
	{
		var cur_img = $(imgs[current_img]);
		current_img += parseInt(offset);
		//alert(current_img)
		var next_img = $(imgs[current_img]);
		cur_img.fadeOut()
		
		next_img.fadeIn()
		if(current_img == 0)
		{
			prev.addClass('disabled').css('opacity',0.8);
		} 
		else
		{
			prev.removeClass('disabled')
		}
		if(current_img == imgs.size()-1)
		{
			next.addClass('disabled').css('opacity',0.8);
		} 
		else
		{
			next.removeClass('disabled')
		}
		
	}
	$('.iface .button').mouseenter(
		function()
		{
			if($(this).hasClass('disabled')) return false;
			$(this).fadeTo(300,.9)
		}).mouseleave(
		function()
		{
			if($(this).hasClass('disabled')) return false;
			$(this).fadeTo(300,.8)
		}
	).click(function(e){
		e.preventDefault()
		if($(this).hasClass('disabled')) return false;
		switch_image($(this).attr('rel'))
	});
	
	
	// ths.mouseenter(function(e){
	// 		iface.show('slide',{'direction':'down'},500);
	// 		e.preventDefault();
	// 	})
	// 	ths.mouseleave(function(e){
	// 		iface.hide('slide',{'direction':'down'},500);
	// 		e.preventDefault();
	// 	})
	
	//iface.hide('slide',{'direction':'down'},500);
	// var inner = $('<div class="slideshow-container"></div>').css('width',imgs.size()*w).height(h);
	// 	imgs.wrap('<div class="img-canvas"></div>');
	// 	var canvas = $('.img-canvas').css('float','left').wrapAll(inner);
	// 	canvas.each(function(i){
	// 		var img = canvas.children('img');
	// 		$(this).append('<div class="img-description"></div>');
	// 		$(this).children('.img-description').text('hols')
	// 	})
	// 	var thumbs = $('<div class="thumbs"></div>').css('opacity',0.7);
	// 	this.append(thumbs);

	//imgs.css('display','none');
	
	
    return this;
}

jQuery(function(){
	//$('a.brown').fadeTo(0,0.5)
	$('a.brown').hover(
			function(){
				$(this).animate({'backgroundColor':'#111111'},400)
				$(this).fadeIn('400')
			},
			function()
			{
				$(this).animate({'backgroundColor':'#000000'},600)
			}
		)
	
	$('a.menu-item:not(.selected),.contact a').hover(
		function(){
			$(this).animate({'color':'#FF0000'},400)
		},
		function()
		{
			$(this).animate({'color':'#646464'},600)
		}
	)
	
	$('a.orange').hover(
		function(){
			$(this).animate({'backgroundColor':'#FF0000'},400)
		},
		function()
		{
			$(this).animate({'backgroundColor':'#FF6600'},600)
		}
	)
	
	$('a.back').click(function(e){
		e.preventDefault();
		history.go(-1);
		
	})
	
	$('.slideshow').slideshow();
})