/**
* General scripts
**/



$(document).ready(function(){

	// IMAGE PRELOAD func:
	var cache = [];
	// Arguments are image paths relative to the current page.
	$.preLoadImages = function() {
		var args_len = arguments.length;
		for (var i = args_len; i--;) {
			var cacheImage = document.createElement('img');
			cacheImage.src = arguments[i];
			cache.push(cacheImage);
		}
	}
	
	// preload individual images as function arguments
	$.preLoadImages(
		"/uploads/bios/donna-luke-colour.jpg",
		"/uploads/bios/jamie-brown-colour.jpg",
		"/uploads/bios/jeff-peeler-colour.jpg",
		"/uploads/bios/lynne-skromeda-colour.jpg",
		"/uploads/bios/rachel-low-colour.jpg",
		"/uploads/bios/Shawn-Watson-colour.jpg"
	);



	
	
	// AWARDS Animation
	$("#awards").ready(function() {
		$("#awards .year, #awards .award").hide();
		var latest_year = false;
		latest_year = $("#awards-index a:first").attr("href");
		if(latest_year) {
			latest_year = latest_year.substr(6);
		}
		$("#awards .award.year_"+latest_year).show();
		$("#awards .year_"+latest_year).show();
		
		$("#awards-index a").click(function(){
			var id = $(this).attr("href");
			
			id = id.substr(6);
			$("#awards .year, #awards .award").css('display', 'none');
			$("#awards .award.year_"+id).fadeIn('slow');
			$("#awards .year_"+id).fadeIn('slow');
			return false;
		});
	});
	
	
	
	
	// News Animation
	$("#news-display-0").show();
	
	$("#news-index a").click(function(){
		var id = $(this).attr("id");
		
		id = id.substr(5);
		
		$("#news-display .news-article").hide();
		$("#news-display-"+id).fadeIn('slow');
		return false;
	});
	
	// Castings Animation
	$("#castings-display-0").show();
	
	$("#castings-index a").click(function(){
		var id = $(this).attr("id");
		
		id = id.substr(9);
		
		$("#castings-display .castings-article").hide();
		$("#castings-display-"+id).fadeIn('slow');
		return false;
	});
	
	
	// Lightbox
	//$(function() {
	//	$("a.lightbox").lightBox(); // Select all links with lightbox class
	//});
	
	//PrettyPhoto
	$(".product-display a[rel^='prettyPhoto']").prettyPhoto({theme:'dark_rounded'});
	
	// BIOs Animation
	function bioShowColour($element) {
		var src = $element.find("img").attr("src");
		src = src.replace(/-bw/, "-colour");
		$element.find("img").attr("src", src);
	}
	
	function bioShowBlack($element) {
		var src = $element.find("img").attr("src");
		src = src.replace(/-colour/, "-bw");
		$element.find("img").attr("src", src);
	}
	
	$("#bios-display-1").css('display', 'block');
	$("#bio-1").addClass("active");
	var default_bio = $("#bio-1").length;
	if( default_bio) {
		bioShowColour( $("#bio-1") );
	}
	
	
	$("#bios-index a").hover(function(){
			bioShowColour( $(this) );
		}, function(){
			if( !$(this).hasClass("active") ){
				bioShowBlack( $(this) );
			}
	});
	
	$("#bios-index a").click(function(){
		$("#bios-index a").removeClass("active");
		$("#bios-index a").each(function(i){
			bioShowBlack( $(this) );
		});
		
		$(this).addClass("active");
		bioShowColour( $(this) );
			
		var id = $(this).attr("id");
		id = id.substr(4);
		
		$("#bios-display .bios-bio").css('display', 'none');
		$("#bios-display-"+id).fadeIn('slow');
		return false;
	});
	
	

	// Home slides
	
	// var anim_speed = 2000;
	// var pause_time = 2000;
	// var control_nav = false;
	// var anim_effect = 'random';

	// Left clips:
	$('#clip_left_0').jcarousel({
		auto: 10,
		wrap: 'last',
		animation: 'slow',
		scroll: 1,
		initCallback: mycarousel_initCallback
	});
	
	$('#clip_left_1').jcarousel({
		auto: 20,
		wrap: 'last',
		animation: 'slow',
		scroll: 1,
		initCallback: mycarousel_initCallback
	});
	
	$('#clip_left_2').jcarousel({
		auto: 15,
		wrap: 'last',
		animation: 'slow',
		scroll: 1,
		initCallback: mycarousel_initCallback
	});
	
	$('#clip_left_3').jcarousel({
		auto: 23,
		wrap: 'last',
		animation: 'slow',
		scroll: 1,
		initCallback: mycarousel_initCallback
	});
	
	// Right clips: =============================
	$('#clip_right_0').jcarousel({
		auto: 13,
		wrap: 'last',
		animation: 'slow',
		scroll: 1,
		initCallback: mycarousel_initCallback
	});
	
	$('#clip_right_1').jcarousel({
		auto: 24,
		wrap: 'last',
		animation: 'slow',
		scroll: 1,
		initCallback: mycarousel_initCallback
	});
	
	$('#clip_right_2').jcarousel({
		auto: 17,
		wrap: 'last',
		animation: 'slow',
		scroll: 1,
		initCallback: mycarousel_initCallback
	});
	
	$('#clip_right_3').jcarousel({
		auto: 16,
		wrap: 'last',
		animation: 'slow',
		scroll: 1,
		initCallback: mycarousel_initCallback
	});


});

