$(document).ready(function() {

//startAnimating();

$('#l-navbar').superfish({
	autoArrows: false,
	animation: {opacity:'show',height:'show'}
});

$('.l-promo-text').fadeIn(2000);

if($('#l-newsticker').length > 0) {
    $().newsTicker({
	newsList: "#l-newsticker",
    startDelay: 10,
    placeHolder1: " |"
    });
}

$("input#mce-EMAIL").addClass("placeholder");
$("input#mce-EMAIL").attr("value", "Email address");
$("input#mce-FNAME").addClass("placeholder");
$("input#mce-FNAME").attr("value", "First name");
$("input#mce-LNAME").addClass("placeholder");
$("input#mce-LNAME").attr("value", "Last name");
$("input#mce-MMERGE3").addClass("placeholder");
$("input#mce-MMERGE3").attr("value", "Postcode");
$("input#search-field").addClass("placeholder");
$("input#search-field").attr("value", "event search...");

$("input#mce-EMAIL").focus(function() {
$(this).removeClass("placeholder");$(this).attr("value", "");
});
$("input#mce-FNAME").focus(function() {
$(this).removeClass("placeholder");$(this).attr("value", "");
});
$("input#mce-LNAME").focus(function() {
$(this).removeClass("placeholder");$(this).attr("value", "");
});
$("input#mce-MMERGE3").focus(function() {
$(this).removeClass("placeholder");$(this).attr("value", "");
});
$("input#search-field").focus(function() {
$(this).removeClass("placeholder");$(this).attr("value", "");
});

$("input#mce-EMAIL").blur(function() {
if($(this).attr("value").length<1){
$(this).attr("value", "Email address");
$(this).addClass("placeholder");
}
});
$("input#mce-FNAME").blur(function() {
if($(this).attr("value").length<1){
$(this).attr("value", "First name");
$(this).addClass("placeholder");
}
});
$("input#mce-LNAME").blur(function() {
if($(this).attr("value").length<1){
$(this).attr("value", "Last name");
$(this).addClass("placeholder");
}
});
$("input#search-field").blur(function() {
if($(this).attr("value").length<1){
$(this).attr("value", "event search...");
$(this).addClass("placeholder");
}
});
$("input#mce-MMERGE3").blur(function() {
if($(this).attr("value").length<1){
$(this).attr("value", "Postcode");
$(this).addClass("placeholder");
}
});

$('.l-play-video').click(function() {
	stopAnimating();
	$(this).colorbox();
});

$('.l-play-video-home').click(function() {
	stopAnimating();
	$(this).colorbox();
});

$('#l-cat-picknmix').click(function() {
if(selectedCats.length > 2) {
	$('#picknmixform').submit();
} else {
	$(this).addClass('activated');
	$('.l-cat-but').click(function() {
		return false;
	});
}
});

$('.l-play-event-video').click(function() {
	stopAnimating();
	$(this).colorbox({iframe:true, innerWidth:425, innerHeight:344});
//	return false;
});

$('#panto-relapse').click(function() {
	stopAnimating();
	$(this).colorbox({iframe:true, innerWidth:425, innerHeight:344});
//	return false;
});

$('#l-cat-theatre').click(selectCategory1);
$('#l-cat-comedy').click(selectCategory2);
$('#l-cat-music').click(selectCategory3);
$('#l-cat-dance').click(selectCategory4);
$('#l-cat-family').click(selectCategory5);
$('#l-cat-workshops').click(selectCategory6);
$('#l-cat-talks').click(selectCategory7);
$('#l-cat-special').click(selectCategory8);


function selectCategory1(e) {
		if($('#l-cat-theatre').hasClass('selected')) {
			removeFromArray($('#l-cat-theatre'));	
			$('#l-opt-theatre').attr('checked', false);
		} else {
			insertToArray($('#l-cat-theatre'));
			$('#l-opt-theatre').attr('checked', true);
		}
	$('#l-cat-theatre').toggleClass('selected');
}
function selectCategory2(e) {
		if($('#l-cat-comedy').hasClass('selected')) {
			removeFromArray($('#l-cat-comedy'));
			$('#l-opt-comedy').attr('checked', false);
		} else {
			insertToArray($('#l-cat-comedy'));
			$('#l-opt-comedy').attr('checked', true);
		}
	$('#l-cat-comedy').toggleClass('selected');
}
function selectCategory3(e) {
		if($('#l-cat-music').hasClass('selected')) {
			removeFromArray($('#l-cat-music'));
			$('#l-opt-music').attr('checked', false);
		} else {
			insertToArray($('#l-cat-music'));
			$('#l-opt-music').attr('checked', true);
		}
	$('#l-cat-music').toggleClass('selected');
}
function selectCategory4(e) {
		if($('#l-cat-dance').hasClass('selected')) {
			removeFromArray($('#l-cat-dance'));
			$('#l-opt-dance').attr('checked', false);
		} else {
			insertToArray($('#l-cat-dance'));
			$('#l-opt-dance').attr('checked', true);
		}
	$('#l-cat-dance').toggleClass('selected');
}
function selectCategory5(e) {
		if($('#l-cat-family').hasClass('selected')) {
			removeFromArray($('#l-cat-family'));
			$('#l-opt-family').attr('checked', false);
		} else {
			insertToArray($('#l-cat-family'));
			$('#l-opt-family').attr('checked', true);
		}
	$('#l-cat-family').toggleClass('selected');
}
function selectCategory6(e) {
		if($('#l-cat-workshops').hasClass('selected')) {
			removeFromArray($('#l-cat-workshops'));
			$('#l-opt-workshops').attr('checked', false);
		} else {
			insertToArray($('#l-cat-workshops'));
			$('#l-opt-workshops').attr('checked', true);
		}
	$('#l-cat-workshops').toggleClass('selected');
}
function selectCategory7(e) {
		if($('#l-cat-talks').hasClass('selected')) {
			removeFromArray($('#l-cat-films'));
			$('#l-opt-talks').attr('checked', false);
		} else {
			insertToArray($('#l-cat-talks'));
			$('#l-opt-talks').attr('checked', true);
		}
	$('#l-cat-talks').toggleClass('selected');
}
function selectCategory8(e) {
		if($('#l-cat-special').hasClass('selected')) {
			removeFromArray($('#l-cat-special'));
			$('#l-opt-special').attr('checked', false);
		} else {
			insertToArray($('#l-cat-special'));
			$('#l-opt-special').attr('checked', true);
		}
	$('#l-cat-special').toggleClass('selected');
}

selectedCats = new Array();

function insertToArray(obj) {
	selectedCats.push(obj);
	// pop last one off
	if(selectedCats.length > 3) {selectedCats[0].removeClass('selected');selectedCats.shift();}
	//console.log(selectedCats.length);
}
function removeFromArray(obj) {
	
}


/* Backgrounds */

currentSlide = 0;

function animateFirstSlots() {

/* console.log("currentSlide is " + currentSlide); */

switch(currentSlide) {
	case 0:
		$('#l-slot-1').animate({
		    width: "0",
			opacity: 0,
		    backgroundPosition: "0 0"
		  }, { queue: false, duration: 3000 });
		  	
		$('#l-slot-2').animate({
		    width: "560",
			opacity: 100,
		    backgroundPosition: "0 0"
		  }, { queue: false, duration: 3000 });
		  
		  $("#l-text-1").fadeOut("slow");
		  $("#l-text-2").fadeIn("slow");
		  
		  $("#genericImage4").fadeOut("slow");
		  
		currentSlide = 1;
		break;
	case 1:
		$('#l-slot-2').animate({
		    width: "0",
			opacity: 0,
		    backgroundPosition: "0 0"
		  }, { queue: false, duration: 3000 });

		$('#l-slot-3').animate({
		    width: "560",
			opacity: 100,
		    backgroundPosition: "0 0"
		  }, { queue: false, duration: 3000 });

		  $("#l-text-2").fadeOut("slow");
		  $("#l-text-3").fadeIn("slow");
		  
		  $("#genericImage3").fadeOut("slow");
		  
		currentSlide = 2;
		break;
	case 2:
		$('#l-slot-3').animate({
		    width: "0",
			opacity: 0,
		    backgroundPosition: "0 0"
		  }, { queue: false, duration: 3000 });

		$('#l-slot-4').animate({
		    width: "560",
			opacity: 100,
		    backgroundPosition: "0 0"
		  }, { queue: false, duration: 3000 });

		currentSlide = 3;
		  $("#l-text-3").fadeOut("slow");
		  $("#l-text-4").fadeIn("slow");
		  
		  $("#genericImage2").fadeOut("slow");		  
	
		break;
	case 3:
		$('#l-slot-4').animate({
		    width: "0",
			opacity: 0,
		    backgroundPosition: "0 0"
		  }, { queue: false, duration: 3000 });

		$('#l-slot-1').animate({
		    width: "560",
			opacity: 100,
		    backgroundPosition: "0 0"
		  }, { queue: false, duration: 3000 });

		  $("#l-text-4").fadeOut("slow");
		  $("#l-text-1").fadeIn("slow");

		  $("#genericImage1").fadeIn("slow");
		  $("#genericImage2").fadeIn("slow");
		  $("#genericImage3").fadeIn("slow");
		  $("#genericImage4").fadeIn("slow");

		currentSlide = 0;
	
		break;
}
	
/*
	$('#l-slot-2').animate({
	    width: "0",
		opacity: 0,
	    backgroundPosition: "0 0"
	  }, { queue: false, duration: 3000 });	
*/

}

	var int = window.setInterval(animateFirstSlots, 10000);

$("#l-slot-2").width(0);
$("#l-slot-3").width(0);
$("#l-slot-4").width(0);

$("#l-text-1").fadeIn("slow");

$('#cboxClose').click(function() {
	startAnimating();
});

function stopAnimating() {
	window.clearInterval(int);
	$(':animated').stop();
}

/*
$('#l-slot-1').animate({
    width: "422",
    backgroundPosition: "0 0"
  }, { queue: false, duration: 6000 });
*/

});
