$(document).ready(function() {

	// Placeholders
	
	$('input, textarea').placeholder();
	
	
	// jScrollPane
	
	$('#show-list').each(function() {
		$(this).jScrollPane({
			verticalGutter: 22	
		});
		var api = $(this).data('jsp');
		var throttleTimeout;
		$(window).bind('load', function() {
			var window_height = $(window).height();
			
			var usemefirst = window_height - 20 - 54;
			$('#content').css('min-height',usemefirst);
			
			var useme = window_height - (237+54+54+54+9);
			$('#show-list').height(useme);
			
			if ($.browser.msie) {
				if (!throttleTimeout) {
					throttleTimeout = setTimeout( function() {
						api.reinitialise();
						$('.jspVerticalBar').fadeTo(0, 0.3);
						$('.jspContainer').hover(function(){
							$('.jspVerticalBar').fadeTo(500, 1);
						}, function(){
							$('.jspVerticalBar').fadeTo(500, 0.3);
						});
						throttleTimeout = null;
					}, 50);
				}
			} else {
				api.reinitialise();
				$('.jspVerticalBar').fadeTo(0, 0.3);
				$('.jspContainer').hover(function(){
					$('.jspVerticalBar').fadeTo(500, 1);
				}, function(){
					$('.jspVerticalBar').fadeTo(500, 0.3);
				});
			}
		});
		$(window).bind('resize', function() {
			var window_height = $(window).height();
			
			var usemefirst = window_height - 20 - 54;
			$('#content').css('min-height',usemefirst);
			
			var useme = window_height - (237+54+54+54+9);
			$('#show-list').height(useme);
			
			if ($.browser.msie) {
				if (!throttleTimeout) {
					throttleTimeout = setTimeout( function() {
						api.reinitialise();
						$('.jspVerticalBar').fadeTo(0, 0.3);
						$('.jspContainer').hover(function(){
							$('.jspVerticalBar').fadeTo(500, 1);
						}, function(){
							$('.jspVerticalBar').fadeTo(500, 0.3);
						});
						throttleTimeout = null;
					}, 50);
				}
			} else {
				api.reinitialise();
				$('.jspVerticalBar').fadeTo(0, 0.3);
				$('.jspContainer').hover(function(){
					$('.jspVerticalBar').fadeTo(500, 1);
				}, function(){
					$('.jspVerticalBar').fadeTo(500, 0.3);
				});
			}
		});
	
	
	
	// Tabs
	
	$.address.init(function(event) {
		$('ul.tabs li a').address();
		$(".tab_content").hide();
		$("ul.tabs li").each(function() {
			// here be dragons
			// i'm no regEXPert
			var value1 = event.path;		
			if (value1 === '/') {
				$("ul.tabs li:first").addClass("active").show();
				$(".tab_content:first").show();
			} else {			
				var regex1 = '([A-z]+)';
				var doregx = new RegExp(regex1,["i"]);
				var value2 = doregx.exec(value1);
				var finalvalue = value2[1];
				$("ul.tabs li").removeClass("active");
				$('a[href="'+finalvalue+'"]').parent().addClass("active").show();
				$('#'+finalvalue).show();
			}
		});	
		$("ul.tabs li").click(function() {
			$("ul.tabs li").removeClass("active");
			$(this).addClass("active");
			var activeTab = $(this).find("a").attr("href");
			$.address.value(activeTab);
			$(activeTab).fadeIn();
		});
	}).change(function(event) {
		$(".tab_content").hide();
		var value1 = event.path;
		if (value1 === '/') {
			$("ul.tabs li").removeClass("active");
			$("ul.tabs li:first").addClass("active").show();
			$(".tab_content:first").show();
		} else {		
			var regex1 = '([A-z]+)';
			var doregx = new RegExp(regex1,["i"]);
			var value2 = doregx.exec(value1);
			var finalvalue = value2[1];
			
			$("ul.tabs li").removeClass("active");
			$('a[href="' + finalvalue + '"]').parent().addClass("active").show();
			$('#' + finalvalue).show();
		}
	});
	
});


// Fancy Box

$("a.photo-link").fancybox({
	'overlayColor'	:	'#000'
});

$("a.iframe").fancybox({
	'width'			:	700,
	'height'		:	450,
	'overlayColor'	:	'#000'
});


// Logo background

$('#logo-bg').cycle({
	fx: 	'fade',
	speed:	'10000',
	timeout:'100',
	random:	1
});


// Homepage thumb titles

$('#homepage-thumbs li a').find('div').fadeTo(0, 0);

$('#homepage-thumbs li').not('li#homepage-feature').hover( function() {
	var position = $(this).position();
	$(this).before('<li id="scusemeimnewhere"></li>').css({
		'position'				:	'absolute',
		'left'					:	position.left - 1,
		'top'					:	position.top - 1,
		'height'				:	'auto',
		'width'					:	'auto',
		'z-index'				:	'100',
		'-moz-box-shadow'		:	'0px 1px 8px #000',
		'-webkit-box-shadow'	:	'0px 1px 8px #000',
		'box-shadow'			: 	'0px 1px 8px #000',
		'border'				:	'1px solid #FFF'
	});
}, function() {
	$('li#scusemeimnewhere').remove();
	$(this).css({
		'position'				:	'relative',
		'left'					:	'0',
		'top'					:	'0',
		'height'				:	'122px',
		'width'					:	'122px',
		'z-index'				:	'auto',
		'-moz-box-shadow'		:	'none',
		'-webkit-box-shadow'	:	'none',
		'box-shadow'			:	'none',
		'border'				:	'none'
	});
});

/* $('#homepage-thumbs li a').hover(function(){
	$(this).find('div').fadeTo(250, 1);
}, function(){
	$(this).find('div').fadeTo(250, 0);
}); */


// Gig scroller

$('#gigs ul.gigpress-listing').cycle({
	fx:		'scrollUp',
	speed:	'1000',
	timeout:'10000'
});


});
