function populateElement(selector, formsel, defvalue) {
	if($.trim($(selector).val()) == "") {
		$(selector).val(defvalue);
		$(selector).css("color","#666666");
	}
	
	$(selector).focus(function() {
		if($(selector).val() == defvalue) {
			$(selector).val("");
			$(selector).css("color","#000000");
		}
	});
	
	$(selector).blur(function() {
		if($.trim($(selector).val()) == "") {
			$(selector).val(defvalue);
			$(selector).css("color","#666666");
		}
	});

	$(formsel).submit(function() {
		$(selector).each(function() {
			if($(this).val() == defvalue) {
				$(this).val("");
			}
		});
	});
}

function showall() {
	$("dd").slideToggle(200);
}

function showd2d() {
	$(".d2dbanner").html('<br /><center><a href="home_dot_to_dot_festival_2010_.html"><img src="images/d2d_alttix.gif" alt="Dot to Dot 2010" /></a></center>');
}

$(document).ready(function() {
	// Set up FAQs
	$("dd").hide();
	$("dl").before("<span class=\"showhide\">Show/hide all</span>");
	$(".showhide").click(function() {
		showall();
	});
	$("dt").click(function() {
		$(this).next().slideToggle(100);
	});
	
	// Add defaults to search boxes
	populateElement('.search input:eq(0)','.search','Search gigs...');
	populateElement('.bigsearch .input','.bigsearch','Search for tickets now...');
	
	$("#ctl00_header_search_box_qs_btn").attr("value","");
	
	// Custom data protection questions
	var artistname = $(".artist-name").html();
	
	switch (artistname) {
		case "Maximo Park" :
			$(".dpquestion").html("<span>Are you happy to receive exclusive Maximo Park news and deals direct from the band?</span>");
			break;
		case "Kasabian" :
			$(".dpquestion").html("<span>Are you happy to receive exclusive news and deals direct from the band and Sony Music?</span>");
			$("#ctl00_ContentPlaceHolder1_OrderForm1_ctl00_OrderFormDP_rep_questions_ctl00_OrderFormDPAnswer_cbl_answers_0").attr("checked","checked");
			break;
	}
	
	// Display Dot to Dot banner on specific pages
	if ($('#townname').length > 0) {
		var townname = $('#townname').text();
		
		if (townname == 'Nottingham' || townname == 'Bristol') {
			showd2d();
		}
	}
	
	
	/*if ($(".d2dtitle").length > 0) {
		var currArtist = $(".d2dtitle:first").text();
		
		switch(currArtist) {
			case "The Maccabees" :
				showd2d();
				break;
			case "Maximo Park" :
				showd2d();
				break;
			//case "Moriarty" :
			//	$(".d2dbanner").html("<center><a href=\"http://www.musicglue.com/moriarty\" target=\"_blank\"><img src=\"images/moriarty_banner.jpg\" alt=\"Moriarty - Free Download\" /></a></center>");
			//	break;
			//case "The Specials" :
			//	$(".d2dbanner").html("The Specials have sold out, but <strong>MADNESS</strong> are headlining this year's Splendour Festival at Wollaton Park Nottingham, <a href=\"home_splendour.html\">click here for more details</a>.");
			//	break;
			//case "Jamie T" :
			//	$(".d2dbanner").html("<img src=\"http://www.gigantic.com/alttickets/images_home/maccabees.jpg\" style=\"float: left; margin-right: 20px; margin-top: -10px\" /><p style=\"font-weight: bold; margin-top: 30px\">Jamie T sold out?  <a href=\"home_the_maccabees.html\">Why not check out the Maccabees</a>.</p>");
			//	break;
			case "Frank Turner" :
				var isftsoldout = $(".proceedlink:eq(0)").html().length;
				if (isftsoldout < 70) {
					$(".d2dbanner").html("<img src=\"http://www.gigantic.com/assets/gigantic/bellow%20head.jpg\" style=\"float: left; margin-right: 20px; margin-top: -10px\" /><p style=\"font-weight: bold; margin-top: 30px\">Frank Turner sold out?  <a href=\"home_bellowhead.html\">Why not check out Bellowhead</a>.</p>");
				}
				break;
		}
	}*/
});
