$(function() {
	
	
	var currentslide = 0;
	setInterval(function() {
	if($('#homeslideshow').hasClass('rotate')) {
		currentslide++;
		if(currentslide == $('#homeslideshow .images li').size()) { currentslide = 0; }
		$('#homeslideshow .images li').fadeOut(1000);
		$('#homeslideshow .images li').eq(currentslide).fadeIn(1000);
	}
	}, 3000);
	
	
	$('#overlay, a.closejoinasafriend').click(function() {
		$('#overlay').fadeOut();
		$('#window').fadeOut();
		$('#joinasafriend').fadeOut();
		return false;
	});
	
	
	$('a.joinasfriendlink').click(function() {
		$('#overlay').height($(document).height());
		$('#overlay').fadeIn();
		$('#joinasafriend').fadeIn();
		return false;
	});
	
	$('.sidebar ul.openinwindowlinks li a').hide();
	$('.sidebar ul.openinwindowlinks ul li a').show();
	$('.sidebar ul.openinwindowlinks ul ul li a').hide();
	
	$('#overlay').height($(document).height());
	
	var locationtoload;
	$('.sidebar ul.openinwindowlinks li a, a.openwindow, a.wp-caption').click(function() {
		locationtoload = $(this).attr('href');
		$('#window .inner').html("&nbsp;");
		$('#overlay').show();
		$('#window').show();
		$('#window img.loading').show();
		$('#window .inner').load(locationtoload, function() {
			$('#window img.loading').hide();
			$('.scrollpane').jScrollPane();
		});
		return false;
	});
	
	
	$('a.openwindowinwindow').live("click", function() {
		locationtoload = $(this).attr('href');
		$('#window .inner').html("&nbsp;");
		$('#window .inner').load(locationtoload, function() {
			$('#window img.loading').hide();
			$('.scrollpane').jScrollPane();
		});
		return false;
	});
	
	$('a.openjoininwindow').live("click", function() {
		$('#window').fadeOut();
		$('#overlay').height($(document).height());
		$('#overlay').fadeIn();
		$('#joinasafriend').fadeIn();
		return false;
	});
	
	
	$('.menu_link').live("click", function() {
		locationtoload = $(this).attr('href');
		$('#window .inner').html("&nbsp;");
		$('#window img.loading').show();
		$('#window .inner').load(locationtoload, function() {
			$('#window img.loading').hide();
		});
		return false;
	});
	
	$('a.closewindow').click(function() {
		$('#overlay').fadeOut();
		$('#window').fadeOut();
		return false;
	});
	
	$('.theimages').hover(function() {
		$('#gallery .arrowleft').fadeIn();
		$('#gallery .arrowright').fadeIn();
		$('#gallery p').animate({"bottom":"0px"});
	}, function() {
		$('#gallery .arrowleft').fadeOut();
		$('#gallery .arrowright').fadeOut();
		$('#gallery p').animate({"bottom":"-50px"});
	});
	
	
	
	var imagetoshow = 0;
	var newpointerlocation = 0;
	var newimagelocation = 0;
	$('#gallery ul.thumbs li a').click(function() {
		imagetoshow = $('#gallery ul.thumbs li').index($(this).parent('li'));
		newimagelocation = imagetoshow*780;
		newimagelocation = newimagelocation - newimagelocation - newimagelocation;
		$('#gallery ul.images').animate({"left":newimagelocation},1000);
		newpointerlocation = imagetoshow*64;
		$('#gallery .pointer').animate({"left":newpointerlocation},500);
		return false;
	});
	
	
	$('#gallery .arrowright').click(function() {
		imagetoshow++;
		if(imagetoshow == $('#gallery ul.thumbs li').size()) { imagetoshow = 0; }
		newimagelocation = imagetoshow*780;
		newimagelocation = newimagelocation - newimagelocation - newimagelocation;
		$('#gallery ul.images').animate({"left":newimagelocation},1000);
		newpointerlocation = imagetoshow*64;
		$('#gallery .pointer').animate({"left":newpointerlocation},500);
		return false;
	});
	
	$('#gallery .arrowleft').click(function() {
		imagetoshow--;
		if(imagetoshow == -1) { imagetoshow = 11; }
		newimagelocation = imagetoshow*780;
		newimagelocation = newimagelocation - newimagelocation - newimagelocation;
		$('#gallery ul.images').animate({"left":newimagelocation},1000);
		newpointerlocation = imagetoshow*64;
		$('#gallery .pointer').animate({"left":newpointerlocation},500);
		return false;
	});
	
	
	$('#gallery ul.thumbs li a').hover(function() {
		$(this).animate({"opacity":"0.7"});
	}, function() {
		$(this).animate({"opacity":"1"});	
	});
	
	
	$('#gallery a.arrowleft, #gallery a.arrowright').css({"opacity":"0.5"});	
	$('#gallery a.arrowleft, #gallery a.arrowright').hover(function() {
		$(this).animate({"opacity":"1"});
	}, function() {
		$(this).animate({"opacity":"0.5"});	
	});
	
});
