$(document).ready(function(){
			
	var matchedWidth;
	
	$.fn.resizeForBack = function() {
	
		imgWidth = $(this).width();
		winWidth = $(window).width();
		imgRatio =  imgWidth / imgHeight;
		winRatio =  winWidth / winHeight;
		
		if(winWidth > imgWidth){
			matchedWidth = winWidth;
			$(this).css({width: '100%'});
		}
		
	};
	
	
	//resize visible image on window resize
	$(window).resize(function(event) {
		$('img.current-slide').resizeForBack();
	});

	$("#header_image").cycle({
		fx		: 'custom',
	    speed	: 3000,
	    timeout	: 1000,
	    slideExpr: '.img_rot',
		cssBefore: {
			left: 0,
			top:  0,
			width: '100%',//matchedWidth,
			opacity: 0,
			zIndex: 1
		},
		animOut: {
			opacity: 0
		},
		animIn: {
			opacity: 1,
			width: '100%'//matchedWidth+1 //animIn seems to require a value differing from cssBefore
		},
		cssAfter: {
			zIndex: 0
		}
	});

	$("#image_caption").cycle({
		fx		: 'fade',
		cleartypeNoBg: true,
	    speed	: 3000,
	    timeout	: 1000
	});
	
	$(".subbrands .med_img").hover(function(){
		$(".border", this).animate({
			"border-width" : "5px",
			"width" : "290px",
			"height" : "150px"
		}, 100)
	}, function() {
		$(".border", this).animate({
			"border-width" : "0px",
			"width" : "300px",
			"height" : "160px"
		}, 200)
	});
	
	$(".small_img").hover(function(){
		$(".border", this).animate({
			"border-width" : "5px",
			"width" : "290px",
			"height" : "110px"
		}, 100)
	}, function() {
		$(".border", this).animate({
			"border-width" : "0px",
			"width" : "300px",
			"height" : "120px"
		}, 200)
	});
	
	$(".bg").hide();
	
		
	/* SET COLOURS */
	
	var currentColour;
	var url = location.pathname;
	var qparts = url.split("/");
	var col = qparts[1];
	
	switch(col) {
		
		case "recordings" :
		currentColour = "#0090E1";
		break;
		
		case "rehearsals" :
		currentColour = "#E10055";
		break;
		
		case "music" :
		currentColour = "#A9D600";
		break;
	
		default :
		currentColour = "#FFF";
	};
	
	$("#menu ul li a.active .title").css("background-color", currentColour);
	
	$(".small_img .border").css("border-color", currentColour);
	
	
	/* SET MENU ROLLOVERS */
	
	$("#menu ul li a:not(.active)").hover(function() {
		$(".title", this).animate({
			"color" : "#222",
			"padding-right" : "6px",
			"padding-left" : "6px"
		}, 100);
		$(".title", this).css({
			"background-color" : currentColour
		}, 600);
	}, function() {
		$(".title", this).animate({
			"color" : "#999",
			"padding-right" : "0px",
			"padding-left" : "0px"
		});
		$(".title", this).css({
			"background-color" : "transparent"
		}, 600);
	});
	
	$(document).ready(function(){
		$("#mainImage").cycle('fade');			
	});
	
	$(".calendar").fancybox({
		'width'				: 600,
		'height'			: 500,
		'hideOnOverlayClick': true,
		'overlayShow'		: true,
		'overlayOpacity'	: 0.3,
		'overlayColor'		: '#000',
		'type'				: 'iframe'
	});
	
	
	/* SET PNG FIX */
	
	$('body').supersleight({shim: '/images/x.gif'});
	
});
