// JavaScript Document

// test for Internet Explorer 6
var isIE6 = false;
if (( $.browser.msie ) && (parseInt($.browser.version,10) == 6)) { isIE6 = true; }

// array of background colours
var DarkColours = new Array("#e60e64","#19bcb9","#2d55a5","#8caea2","#40ae49","#495c7a","#ef4035","#c11a2e","#9d6bb2","#506f33","#2d55a5","#7373a9","#ef4035","#b91e54","#00aeef","#9e0039","#1e7138","#19bcb9","#325c5d","#e63e97","#093334","#ce2e03");

var LightColours = new Array("#dbe213","#c5c19d","#fff000","#94a8d6","#ecf1ba","#b6d05b","#f9f162","#a2daea","#b5e853","#f77ea6","#f78f1e","#72d8d9","#efcd12","#a695e7","#d5e14d");

$('.cchome #donate').removeClass('disc');
$('#subnav').removeClass('discs');
$('body.visiting').removeClass('discs');
$('.cchome #artistnav').removeClass('squares');

$(document).ready(function() {
						   
	// set the logo colour
	var i = Math.floor(Math.random()*22) // random integer
	$('#logobarsimple.inverse #logobarnewtatelogo').css({backgroundColor:DarkColours[i]});

	// enable the rollover effect on the sub navigation
	$('#subnav li a').each(function(index){
		$(this).after('<div class="topdisc"></div>');
		$(this).hover(function(){
			$('#subnav li:eq('+index+') .topdisc').stop(true,true).fadeOut(200);
			},function(){
			$('#subnav li:eq('+index+') .topdisc').stop(true,true).fadeIn(300);
			});	
		});
	$('#subnav').removeClass('discs');


	if ($('body').hasClass('visiting')) {
		// enable the rollover effect on the 'book tickets' and 'join members' links
		$('#book').hover(function(){$('#book img').stop(true,true).fadeOut(200);},function(){$('#book img').stop(true,true).fadeIn(300)});	
		$('#members').hover(function(){$('#members img').stop(true,true).fadeOut(200);},function(){$('#members img').stop(true,true).fadeIn(300)});
		$('#book, #members').removeClass('disc');
		$('body').removeClass('discs');
	}
	
	if ($('body').hasClass('cchome')) {
		
		// enable the rollover effect on the home page squares
		$('.cchome #artistnav li a').each(function(index){
			$(this).after('<div class="topname"></div>');
			$(this).hover(function(){
				$('#artistnav li:eq('+index+') .topname').stop(true,true).fadeOut(200);
				},function(){
				$('#artistnav li:eq('+index+') .topname').stop(true,true).fadeIn(300);
				});
			});
		$('#artistnav').removeClass('squares');
		
		$('.cchome #artistnav li .topname').each(function(){
			$(this).click(function(){
				window.location = $(this).parent().attr('href');
			});
		});

		// enable the rollover effect on promos
		$('.cchome #promolist li a').each(function(index){
			$(this).after('<div class="topdisc"></div>');
			$(this).hover(function(){
				if (index == 0) { $('#promo_kids').css('background-image','url("/liverpool/exhibitions/colourchart/images/promo-kids_hover.gif")');}
				$('#promolist li:eq('+index+') .topdisc').stop(true,true).fadeOut(200);
				},function(){
				if (index == 0) { $('#promo_kids').css('background-image','none');}
				$('#promolist li:eq('+index+') .topdisc').stop(true,true).fadeIn(300);
				});	
			});
		$('#promolist').removeClass('discs');
		
		// fix transparency of PNG for IE6
		$('.cchome #donate').removeClass('disc');
		if (isIE6) { $('#donate').show().ifixpng(); }
		// enable the rollover effect on the donate button
		$('#donate').hover(function(){
			$('#donate .topdisc').stop(true,true).fadeIn(200);
			},function(){
			$('#donate .topdisc').stop(true,true).fadeOut(300);
			});	
		setTimeout("moveDisc();",1000);
		setTimeout("moveDisc();",2000); // second attempt in case shop feature was slow to load
	} 
		/*
	else { // insert the survey link on every other page of the microsite
		$('#content').after('<div id="survey"><a href="http://www.tate.org.uk/go/colour-chart-survey" class="external" target="_blank"><span>Win &pound;100. Complete our online survey</span></a><div class="topbox"></div></div>');
		var k = 1 + Math.floor(Math.random()*3) // random integer
		var j = Math.floor(Math.random()*15) // random integer
		$('#survey').css({backgroundImage:'url("/liverpool/exhibitions/colourchart/images/surveybanner'+k+'.png")',backgroundColor:LightColours[j]});
		$('#survey .topbox').css({backgroundImage:'url("/liverpool/exhibitions/colourchart/images/surveybanner'+k+'_hover.gif")',backgroundColor:LightColours[j]});
		// fix transparency of PNG for IE6
		if (isIE6) { $('#survey').show().ifixpng(); }
		// enable the rollover effect on the survey button
		$('#survey a').hover(function(){
			$('#survey .topbox').stop(true,true).fadeIn(200);
			},function(){
			$('#survey .topbox').stop(true,true).fadeOut(300);
			});	
	} */
	var i = Math.floor(Math.random()*22) // random integer
	$('#logobarsimple.inverse #logobarnewtatelogo, #donate').stop(true,false).animate({backgroundColor:DarkColours[i]},300,function(){
		if (!isIE6) {setTimeout("setBg();",500);}
	});	

});

function setBg() {
	var i = Math.floor(Math.random()*22) // random integer
	var j = Math.floor(Math.random()*15) // random integer
	// $('#survey').stop(true,false).animate({backgroundColor:LightColours[j]},1500);
	$('#logobarsimple.inverse #logobarnewtatelogo, #donate').stop(true,false).animate({backgroundColor:DarkColours[i]},1500,function(){
		setTimeout("setBg();",500);
	});
}

function moveDisc() {
	// position the "donate" buttom when the shop box has finished loading.
	$('#donate').css({'top':($('.rhsbox').innerHeight() + 95)+'px','display':'block'});
} // end of moveDisc function