/* SECTION 1: SITE STAT CODE FRAGMENT */
function sitestat(ns_l,ns_0){
  ns_l+='&amp;ns__t='+(new Date()).getTime();ns_pixelUrl=ns_l; 
  $('#refererDebug').append('<p>JAVASCRIPT referer is '+ns_0+'</p>');
  ns_0=(ns_0.lastIndexOf('/')==ns_0.length-1)?ns_0.substring(ns_0.lastIndexOf('/'),0):ns_0; 
  if(ns_0.length>0)ns_l+='&amp;ns_referrer='+escape(ns_0); 
  if(document.images){ns_1=new Image();ns_1.src=ns_l;}else 
  document.write('<img src=\"'+ns_l+'\" width=\"1\" height=\"1\" alt=\"\">');
}

/* SECTION 2: TENPIN BESPOKE JS CODE */
curHeadline=-1; headlines=[]; headlines[0]={headline1:'Welcome!',headline2:'Welcome to Tenpin online...'}; headlines[1]={headline1:'New student discount nights',headline2:'check out your local Tenpin for details'}; curQuote=-1; allQuotes=[]; allQuotes[0]={phrase:'TENPIN CHESHIRE OAKS RULES ! ! ! ! !',name:'Benjamin Thomas Swash',date:''}; allQuotes[1]={phrase:'TENPIN SUNDERLAND BABY!!!!!',name:'Adam Hudson',date:''}; allQuotes[2]={phrase:'I LUV TENPIN!! where excitment strikes... EVERYTIME!!!!!',name:'April McCarthy',date:''}; allQuotes[3]={phrase:'I\'m goin tonight in wrexham, well ace',name:'Hannah Rosemary Gater',date:''}; allQuotes[4]={phrase:'TENPIN C.OAKS IS THE WAY 4WARD',name:'Dionne Maxwell',date:''}; allQuotes[5]={phrase:'WOOOO!!! GO TENPIN WREXHAM!!!',name:'Jimmy Adams',date:''}; allQuotes[6]={phrase:'Lovin the new tenpin in wrexham',name:'Rebecca Riding',date:''}; allQuotes[7]={phrase:'Whoop whoop love bowling! X',name:'Jazz Torrence',date:''}; allQuotes[8]={phrase:'Love Tenpin at Star City. Will be heading there next week with a few friends. I\'m rubbish at it, but I love bowling!',name:'Elizabeth Fleming',date:''}; allQuotes[9]={phrase:'Me and my girl off to have a wicked night tomorrow at Sixfields, Northampton. 2 pints and the ball\'s in the gutter. Lol',name:'A.j. Stevenson',date:''}; allQuotes[10]={phrase:'It\'s my boy Harry\'s birthday tomorrow, cant wait to bowl!',name:'Frances Elizabeth Weeks',date:''}; allQuotes[11]={phrase:'My birthday on Monday, me and my mate\'s are going on Sat. can\'t wait, whoop whoop xxx',name:'Adam Beaumont',date:''}; allQuotes[12]={phrase:'I\'ve just looked for 3 games for 2 adults + 6 kids 14 and under with a bite (cheese burger) for everyone and it come to Â£94.50 bargain!!',name:'Gudrun Reynolds',date:''}; allQuotes[13]={phrase:'Had Party at Tenpin for my 6 year old and her friends. Different to the usual soft play thing and worth every penny',name:'Sime Sawyers',date:''}; allQuotes[14]={phrase:'Going today and really looking forward to it!',name:'Jack Palmer',date:''}; allQuotes[15]={phrase:'I have booked it through the website and saved a fortune - cant wait!!',name:'Nichola Brennan',date:''}; allQuotes[16]={phrase:'Taking my 5 year old to Swansea bowling today - only just discovered the joys of bowling and we love it! heh',name:'Anthony Poole',date:''}; allQuotes[17]={phrase:'Wicked!',name:'Hayley Mcneil',date:''}; allQuotes[18]={phrase:'I lovee Tenpin...',name:'Lorna Holly\' Pulsford',date:''}; allQuotes[19]={phrase:'Bowling Today! In 10 Hours! So Excited!',name:'Joe Carswell',date:''}; allQuotes[20]={phrase:'I can\'t wait to go bowling, thanks for making this dream happen!',name:'Eleanor Duncan',date:''};

/* SECTION 3 - jQuery */ 
$(document).ready(function(){
  //Tab box stuff
	$('#tab-box div.content').css("display","none");
	$('#tab-box div.content').eq(0).css("display","block");
	$('#tabs li').click(function(){
		var index = $('#tabs li').index(this);
		var tab = $(this);  
    if (tab.hasClass('on')) {
    } else {
      $('#tabs li').removeClass('on'); 
      tab.addClass('on');
      $('#tab-box div.content').css("display","none");
      $('#tab-box div.content').eq(index).css("display","block");
    } 
	}); 
  //Show location pop-up when town link is clicked (showing on mouseover would obscure some towns...)
	$('#locations #towns div div > a').click(function(){
		$('#locations #towns > div > div').css({"position" : "static", "z-index" : "1000"}); // to fix IE6 z-index bug
		$(this).parent().css({"position" : "relative", "z-index" : "5000"}); // ditto
		$('#locations #towns div div .pop-up').css("display","none");	
		$(this).next().css("display","block");
		return false;		
	}); 
	$('#locations #towns .pop-up').mouseleave(function(){
    $(this).css("display","none");
	});
	// Use PNG fix (http://www.dillerdesign.com/experiment/DD_belatedPNG/) to get PNG transparency working in IE6
	if ($.browser.msie && $.browser.version.substr(0,1)<7) {
		DD_belatedPNG.fix('img, #meta li.facebook, #header, .box-thin-top, .box-thin-bottom, .box-med-top, .box-med-bottom, .box-wide-top, .box-wide-bottom, #find-nearest-1 .content, #find-nearest-2 .content, #find-nearest-2 a.book-online-now, #book-online, #what-next, #locations .content, #locations .content a.icon, form#postcode-search, #tabs li, #tabs li a, #tabs li.on, #tabs li.on a, #tab-box, #tab-box-bottom, #tab-box, #tab-box-bottom');
	}
  $("#tenpinSlides").jKlikFlow({
      width: "638px",  
      height: "223px", 
      easing: "easeOutBack", 
      prev: "#jFlowPrev",
      next: "#jFlowNext",
      duration: 1000,
      pauseBetweenSlides: 2500,
      auto: false
  });
	newHeadline();
	newQuote();
});

// Other Tenpin specific JS routines
newHeadline=function() {
  curHeadline=Math.floor(Math.random()*(headlines.length));
  $('#the-headline').attr("style","margin-left:0px");
  headline="<strong>"+headlines[curHeadline].headline1+" &#124 </strong>"+headlines[curHeadline].headline2;
  $('#news').html("<div id='news-window'><span id='the-headline'>"+headline+"</span></div>");
  if ($('#the-headline').width()<$('#news').width()) {
    setTimeout("newHeadline();",5000);
  } else {
    setTimeout("animateHeadline();",3000);
  }
  /* alert("the-headline.width="+$('#the-headline').width()+" and news.width="+$('#news').width()); */
}

function animateHeadline() {
  // How long is the current headline? (roughly 6px per char)
  pixelsToShift=(6*(headlines[curHeadline].headline1.length+headlines[curHeadline].headline2.length));
	$('#the-headline').animate({marginLeft: "-"+pixelsToShift+"px"},pixelsToShift*15,"linear",newHeadline);
}

newQuote=function() {
  curQuote=Math.floor(Math.random()*(allQuotes.length));
  $('#the-quote').attr("style","margin-left:0px");
  phrase=allQuotes[curQuote].phrase+" <span class='extra'>"+allQuotes[curQuote].name+" "+allQuotes[curQuote].date+"</span>";
  $('#quote-block').html("<div id='quote-window'><span id='the-quote'>"+phrase+"</span></div>");
  if ($('#the-quote').width()<$('#quote-block').width()) {
    setTimeout("newQuote();",6000);
  } else {
    setTimeout("animateQuote();",6000);
  }
}

function animateQuote() {
  // How long is the current phrase? (roughly 10px per char)
  pixelsToShift=(10*(allQuotes[curQuote].phrase.length+allQuotes[curQuote].name.length+allQuotes[curQuote].date.length));
	$('#the-quote').animate({marginLeft: "-"+pixelsToShift+"px"},pixelsToShift*15,"linear",newQuote);
}

var qWindow = '';
function qOpen(url) {
  /* Referrer and SiteRefferer parameters are now part of the url string passed in from PHP */
  if (!qWindow.closed && qWindow.location){
    qWindow.location=url;
  } else {
    qWindow = window.open(url, '_blank', "height=620, width=960, top=30, left=30, status=yes, toolbar=no, menubar=no, location=no, scrollbars=yes, resizable=yes", true);
    if (!qWindow.opener) qWindow.opener = self;
  }
  qWindow.focus();
  return false;
}

function cl(goWhere) {
  document.location.href=goWhere;
}