$(document).ready(function(){

	// highlight fields on focus
	$(function(){$("fieldset input").focus(function(){$(this).parent('div.input').addClass("focus");});});
	$(function(){$("fieldset input").blur(function(){$(this).parent('div.input').removeClass("focus");});});
	$(function(){$("fieldset select").focus(function(){$(this).parent('div.input').addClass("focus");});});
	$(function(){$("fieldset select").blur(function(){$(this).parent('div.input').removeClass("focus");});});
	$(function(){$("fieldset textarea").focus(function(){$(this).parent('div.input').addClass("focus");});});
	$(function(){$("fieldset textarea").blur(function(){$(this).parent('div.input').removeClass("focus");});});

	// change product images when new colour selected
	$("form#ProductViewBasketForm select#ProductColourId").change(function(){
		// check to see if there are any product images for this colour selection
		$('div.product-colour-images').css('display', 'none');
		$('div.product-colour-images-' + $(this).val()).css('display', 'block');		
	});

	// change product images when new size selected
	$("form#ProductViewBasketForm select#ProductSizeId").change(function(){
		// check to see if there are any product images for this colour selection
		$('div.product-colour-images').css('display', 'none');
		$('div.product-colour-images-' + $(this).val()).css('display', 'block');		
	});

	$("div.colour-swatch ul li a").hover(function(){
		// show the relevant colour image from the colour swatch
		$('div.' + $(this).attr('class')).css('display', 'none');
		$('div.' + $(this).attr('class') + '-' + $(this).attr('rel')).css('display', 'block');		
	});

	/*
	$("ul.colour-swatch li a").mouseout(function(){
		// reset the colour swatch
		$('div.product-colour-image').css('display', 'none');
		$('div.' + $(this).attr('class')).css('display', 'block');		
	});
	*/

	$('div.lightbox a').lightBox();

	// add hover state to product lists
	$("div.product").mouseover(function(){
		$(this).addClass("hover");
	});
	$("div.product").mouseout(function(){
		$(this).removeClass("hover");
	});
	// make the whole box clickable
	$("div.product").click(function(){
		window.location = $(this).children('div.info').children('p.details').children('a').attr('href');		
	});

	// add hover state to promo boxes
	$("div.promo").mouseover(function(){
		$(this).addClass("hover");
	});
	$("div.promo").mouseout(function(){
		$(this).removeClass("hover");
	});
	// make the whole box clickable
	$("div.promo").click(function(){
		window.location = $(this).children('div.info').children('a').attr('href');		
	});

	// add hover state to product lists
	$("div.case-study-clickable").mouseover(function(){
		$(this).addClass("hover");
	});
	$("div.case-study-clickable").mouseout(function(){
		$(this).removeClass("hover");
	});
	// make the whole case-study div clickable
	$("div.case-study-clickable").click(function(){
		var location = $(this).children('div.image').children('a').attr('href');
		if (location != undefined) window.location = location;		
	});

	// add hover state to product lists
	$("div#category-thumbs div.category").mouseover(function(){
		$(this).addClass("hover");
	});
	$("div#category-thumbs div.category").mouseout(function(){
		$(this).removeClass("hover");
	});

	$("div.tab-nav a").click(function() {
		// subnav has been clicked on - hide all .content-section divs and show the correct one
		$('div.content-section').hide();
		var link = $(this).attr('href');
		$('div#section-' + link.replace(/\//g, '-')).fadeIn();
		return false;
	});

	$("body#body-our-people div#subnav a").click(function() {
		// subnav has been clicked on - hide all .content-section divs and show the correct one and start the new video
		$('div.content-section').hide();
		$('div#subnav > ul > li').removeClass('on');
		var link = $(this).attr('href');
		$('div#section-' + link.replace(/\//g, '-')).fadeIn();
		$(this).parent().addClass('on');
		// show the video player
		$('div#video-player').show();
		// hide thumbnails
		$('div#thumbnails').hide();
		// also change the video file to the person's intro	
		api.playClip({url: '/videos/' + link + 'intro.flv'});
		current_profile = link;
		return false;
	});

	$("div#thumbnails div.thumbnail").click(function() {
		// thumbnail has been clicked on - hide all .content-section divs and show the correct one and start the new video
		$('div.content-section').hide();
		$('div#content-area').slideDown("normal");	
		var link = $(this).children('div.name').children('a').attr('href');
		$('div#section-' + link.replace(/\//g, '-')).fadeIn();
		// hide thumbnails
		$('div#thumbnails').hide();
		// show the video player
		$('div#video-player').css('visibility', 'visible');
		// also change the video file to
		api.playClip({url: '/videos/' + link + 'intro.flv'});
		current_profile = link;
		$('div#toggler > a').toggleClass("open");
		return false;
	});

	$("div#subnav a").click(function() {
		// subnav has been clicked on - hide all .content-section divs and show the correct one
		$('div.content-section').hide();
		$('div#subnav > ul > li').removeClass('on');
		var link = $(this).attr('href');
		$('div#section-' + link.replace(/\//g, '-')).fadeIn();
		$(this).parent().addClass('on');
		return false;
	});

	$("a.contentlink").click(function() {
		// subnav has been clicked on - hide all .content-section divs and show the correct one
		$('div.content-section').hide();
		$('div#subnav > ul > li').removeClass('on');
		var link = $(this).attr('href');
		$('div#section-' + link.replace(/\//g, '-')).fadeIn();
		return false;
	});

	$("div.video-profile a").click(function() {
		$('div.video-profile a').removeClass('selected');
		// show the correct question video
		api.playClip({url: '/videos/' + current_profile + $(this).attr('class') + '.flv'});
		$(this).addClass('selected');
		return false;
	});
	
	$("div#locations a").mouseover(function() {
		// subnav has been clicked on - hide all .content-section divs and show the correct one
		$('div.location-details').hide();
		var link = $(this).attr('href');
		$('div#location-' + link.replace(/\//g, '-')).fadeIn();
	});
	
	$("div#locations a").click(function() {
		return false;
	});
		
	$("div.show-transcription").click(function() {
		if ($("div.transcript").css('display') == 'block') {
			$("div.transcript").slideUp('normal');
			$(this).text('Show transcription');
		} else {
			$("div.transcript").slideDown('normal');			
			$(this).text('Hide transcription');
		}
		$(this).toggleClass("hide-transcription");
	});

});


sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

