
/*-------------------------------------------------------
---- BEHAVIOUR (Primary Javascript file) ----------------
--------------------------------------------------------*/


$(document).ready( function() { 																	//When the document is ready


//Open external links in new windows
	
		var external = $('a[rel="external"]');														//Get all links with rel="external" and place them into the 'external'
	
		external.attr("title", external.attr("title") + " - Link opens in a new window..");	//Take the links current title and append it with the external link message
			
		external.click( function() {																//When an external link is clicked
			
		window.open($(this).attr('href'));															//Open its href in a new window
        
		return false;																				//Cancel the links default behaviour
		
		});																							//End function
		

//Focus form function ------------------------------------------

	var position;

	//$(".focus .frmRowRadio input").attr('checked', false);
	
//	$(".focus").prepend("<div id='focusPane'><p></p></div>");

//	$(".focus .frmRow,.focus .frmRowMultiSelect").click( function(){
		
//		$("#focusPane").fadeIn('fast');	
		
//		$("#focusPane p").text($(this).children('.tip').text());
			

//		 position = $(this).position();
				
//		$("#focusPane").animate({"top":position.top - 10});

//    });	
	

//	$(".focus .frmRow input, .focus .frmRow select, .focus .frmRow textarea,.focus .frmRowMultiSelect select").focus( function(){
	
		
//		$("#focusPane").fadeIn('fast');	
		
//		var text = $(this).siblings('.tip').text();
		
//		$("#focusPane p").text(text);
			
//			var position = $(this).position();			
		
//		if (position.top == 0) {
			
//			position.top = 88;
		
//		}		
//			$("#focusPane").animate({"top": position.top - 10});
			
//   });


//Your Body Image map ------------------------------------------

	$('#mapPoints li').hide();
	
	$('#mapPoints').addClass('jsActive');
	
	$('map area').mouseover( function(){
		
		//$('li.' + $(this).attr('id')).fadeIn('slow');
		$('li.' + $(this).attr('id')).show();	
		
	});
	
	$('map area').mouseout( function(){
		
		$('li.' + $(this).attr('id')).hide();	
		
	});
	
	$('map area').click( function(){
		
		return false;
		
	});
	
	
	
	
//Conditional fields in the sign up form ------------------------------------------	

	$('.conditional, .conditional2').hide();

	$('.freeFootball input,.winParty input').click( function(){
		
		var label = $(this).siblings('label').text();
		var labelParent = $(this).parent('div').parent('div').attr('class');

			if (labelParent == "frmRowRadio freeFootball" && label == "Yes") {
			
				$('.conditional').show();
				
			}
			else 
			
				if (labelParent == "frmRowRadio winParty" && label == "Yes") {
				
					$('.conditional').show();
					$('.conditional2').show();
					
				}
				
			else 
			
				if (labelParent == "frmRowRadio freeFootball" && label == "No") {
				
					if($('.conditional2').is(":hidden")){
						
						$('.conditional').hide();
						$("#focusPane").hide();	
						$("#focusPane").css('top','10px');						
						
					}
					
				}
		
			else 
			
				if (labelParent == "frmRowRadio winParty" && label == "No") {
				
				if($('#yesFootball').is(":checked")){
					
					$('.conditional2').hide();
					$("#focusPane").hide();	
					$("#focusPane").css('top','10px');				
					
					
					} else {
						
					$('.conditional').hide();
					$('.conditional2').hide();
					$("#focusPane").hide();	
					$("#focusPane").css('top','10px');						
						
					}
					
				}


		
	})
	
	
	
	/*
	
	if($('.conditional').is(":hidden")){
			
			} else {
				
				$('.conditional').hide();
				$("#focusPane").hide();	
				$("#focusPane").css('top','10px');	
				
			}
	
	*/


	
	$('#features .featureWrapper').click( function(){
		
		var location = $(this).find('a').attr('href');
		
		window.location = location;
		
	});	
		



//Smokefree League table ----------------------------------


	$('.tableBoxInner table').hide();
	$('.tableBoxInner table:first').show();
	
	$('.tableBoxInner').prepend("<ul class='leagueTableTabs'></ul>");				
					
	$('.leagueTableContainer h2').each( function(){
		
		$(this).addClass("offSet");
	
		$('.leagueTableTabs').append("<li><span><a href='#'>" + $(this).text() + "</a></span></li>");
	
	});
			
	$('.leagueTableTabs li:first').addClass("on");
	
	
	
	$('.leagueTableTabs li a').click( function(){
	
		$('.leagueTableTabs li').removeClass("on");
		$(this).parent('span').parent('li').addClass("on");

		$('.tableBoxInner table').hide();
		$("h2:contains('" + $(this).text() + "')").siblings('table').show();

		
		return false;
	
	});





//The bench table ----------------------------------


	$('.theBenchWrapper table').hide();
	$('.theBenchInner table:first').show();
	
	$('.theBenchInner').prepend("<ul class='leagueTableTabs'></ul>");				
					
	$('.theBenchTableContainer h3').each( function(){
		
		$(this).addClass("offSet");
	
		$('.leagueTableTabs').append("<li><span><a href='#'>" + $(this).text() + "</a></span></li>");
	
	});
			
	$('.leagueTableTabs li:first').addClass("on");
	
	
	
	$('.leagueTableTabs li a').click( function(){
	
		$('.leagueTableTabs li').removeClass("on");
		$(this).parent('span').parent('li').addClass("on");

		$('.theBenchInner table').hide();
		$("h3:contains('" + $(this).text() + "')").siblings('table').show();

		
		return false;
	
	});


// LSSS Search panels 
	

		$('a.services-callback').click( function(){
			window.open($(this).attr("href"), "newwindow", "location=0,status=0,width=450,height=660");	
			return false;
		});
		
		$('.contentBox').addClass('JsActive');
		$('.area').hide();	
		
		$('.areaList').show();
		$('.areaList li:first').addClass("active");
		$('.content').hide();
		
		$('#LSSSSearchResults h3').click( function(){
			
			$('.content').hide();
			$(this).siblings('.contentBoxInner').children('.content').show();
			$(this).siblings('.contentBoxInner').children('.content').children('.contactContent').show();

			$('.areaList li').removeClass("active");			
			$('.contactTab').parent('span').parent('li').addClass("active");
			
		});
	

		$('.areaList li a').click( function(){

			$('.areaList li').removeClass("active");
			
			$(this).parent('span').parent('li').addClass("active");
			
			var tab = $(this).attr('class');
			
			var content = tab.substring(0,tab.length - 3);
			
			//alert(content);
			
			$('.area').hide();
			$(this).parent('span').parent('li').parent('ul').siblings('.' + content + 'Content').show();
			
			return false;
			
		});
		
		
		$('h3:first').click();


// ----- Prizes on sign up page --------------

		$('.panel').hide();
		$('.panel:first').show();

		$('.panel:first').before('<ul id="tabList"></ul>');
		
		$('#panels h3').each( function(i){
			
			$('#tabList').append('<li><a href="#" class="' +  i + '">' + $(this).text() + '</a></li>');
			
			$(this).remove();
			
		});
		
		$('#tabList li:first').addClass('active');
		
		
		$('#tabList li a').click( function(){
			
			$('#tabList li').removeClass('active')
			$(this).parent('li').addClass('active');
			
			$('.panel').hide();
			
			var theID = $(this).attr('class');
			
			$('#panel' + theID).show();
			
			return false;
			
		});
		
		
		
		// ----- News. --------------

		$('.newsPanel').hide();
		$('.newsPanel:first').show();		
		
		$('#newsTabList li:first').addClass('active');
		
		
		$('#newsTabList li a').click( function(){
			
			$('#newsTabList li').removeClass('active')
			$(this).parent('li').addClass('active');
			
			$('.newsPanel').hide();
			
			var theID = $(this).attr('class');
			
			$('#panel' + theID).show();
			
			return false;
			
		});

/* ----------------------------------------- */

        // Audio message player
        $("a[href$=.mp3]").click(function() {
            $.sound.play(this.href,{track: "track1"});
            return false;
        });
		
		
/* ------------------- Sign up form */


		$('.articleListing .articleBody').hide().append('<a href="#" class="back"><img src="/united/images/site/buttons/back_white.png" alt="Back" /></a>').before('<a href="#" class="more"><img src="/united/images/site/buttons/read_more.png" alt="Read more" /></a>');
		$('.articleListing .more').click(function(){
			$(this).next('.articleBody').show();
			$(this).parents('li').siblings('li').hide();
			$(this).hide();
			
		});
		$('.articleListing .back').click(function(){
			$(this).parents('.articleBody').hide();
			$('.articleListing li, .articleListing .more').show();
			return false;
		});			

		
		$('.blue').css({'cursor':'pointer'})
		
		$('.blue').click( function(){
			
			var link = $(this).find('a').attr('href');
			
			//alert(link);
			
			window.location = link;
			
		});		
		

}); 			//End document.ready

