$(document).ready(function(){
	$('#oSideMenu>ul>li>ul>li>a.closed').each(function() {
		$(this).parent().children('ul').each(function() {
			$(this).hide();
			if (!$(this).parent().children('a').hasClass('haspage')) {
				$(this).parent().bind('click', function() {
					$(this).blur();
					$(this).children('ul').slideToggle('slow', function() {
						var parent = $(this).parent().children('a');
						if ($(parent).attr('class')=='closed') {
							$(parent).attr('class','open');
						} else {
							$(parent).attr('class','closed');	
						}
					});
				});
			}
		});
	});

	$(".accordion .oFaqQuestionHolder:first ").addClass("active");
	$(".accordion .oFaqAnswerHolder:not(:first)").hide();
	$(".accordion .oFaqQuestionHolder, .accordion .oFaqQuestionHolderAlt").click(function(){

	  $(this).next(".oFaqAnswerHolder").slideToggle("slow")
	   .siblings(".oFaqAnswerHolder:visible").slideUp("slow");
	  $(this).toggleClass("active");
	  $(this).siblings(".oFaqQuestionHolder").removeClass("active");
	  

	});
	
	
	
	$(".accordion .oRewardsOptionHolder:first").addClass("active");
	$(".accordion .oFaqAnswerHolder:not(:first)").hide();
	$(".accordion .oRewardsOptionHolder").click(function(){

	  $(this).next(".oFaqAnswerHolder").slideToggle("slow")
	   .siblings(".oFaqAnswerHolder:visible").slideUp("slow");
	  $(this).toggleClass("active");
	  $(this).siblings(".oRewardsOptionHolder").removeClass("active");
	  

	});

	//delayed facebook connect loading due to fw.
	$.getScript('http://static.ak.fbcdn.net/connect.php/js/FB.Share', function() {
		$('div.oBottomLinksFacebook').show();
	});
	
	$("#hiddenemail").css("display","none");
	$("#hiddentelephone").css("display","none");
	
	$(".contactmethod").click(function(){
	if ($('input[name=contactmethod]:checked').val() == "Email" ) {
		$("#hiddenemail").slideDown("fast"); 
		$("#hiddentelephone").slideUp("fast"); 	
	} else if ($('input[name=contactmethod]:checked').val() == "Telephone" ) {
		$("#hiddentelephone").slideDown("fast"); //Slide Down Effect
		$("#hiddenemail").slideUp("fast"); 	
	} else  {
		$("#hiddentelephone").slideUp("fast");	//Slide Up Effect
		$("#hiddenemail").slideUp("fast");
	}
    });

	
	
	


});


var ContentHeight = 110; //120
var TimeToSlide = 250.0;

var openAccordion = '';

function runAccordion(index)
{
  var nID = "Accordion" + index + "Content";
  if(openAccordion == nID)
    nID = '';
    
  setTimeout("animate(" + new Date().getTime() + "," + TimeToSlide + ",'" 
      + openAccordion + "','" + nID + "')", 33);
  
  openAccordion = nID;
}

function animate(lastTick, timeLeft, closingId, openingId)
{  
  var curTick = new Date().getTime();
  var elapsedTicks = curTick - lastTick;
  
  var opening = (openingId == '') ? null : document.getElementById(openingId);
  var closing = (closingId == '') ? null : document.getElementById(closingId);
 
  if(timeLeft <= elapsedTicks)
  {
    if(opening != null)
      opening.style.height = ContentHeight + 'px';
    
    if(closing != null)
    {
      closing.style.display = 'none';
      closing.style.height = '0px';
    }
    return;
  }
 
  timeLeft -= elapsedTicks;
  var newClosedHeight = Math.round((timeLeft/TimeToSlide) * ContentHeight);

  if(opening != null)
  {
    if(opening.style.display != 'block')
      opening.style.display = 'block';
    opening.style.height = (ContentHeight - newClosedHeight) + 'px';
  }
  
  if(closing != null)
    closing.style.height = newClosedHeight + 'px';

  setTimeout("animate(" + curTick + "," + timeLeft + ",'" 
      + closingId + "','" + openingId + "')", 33);
}


function situational() {
	window.open("http://bootssituational.nextlevelinteractive.co.uk/index.htm","situational","menubar=no,scrollbars=no,status=no,titlebar=no,toolbar=no,resizable=yes,directories=no,width=596,height=460");
	return false;
} 

function accessibility() {
	window.open("accessibility.php","accessibility","menubar=no,scrollbars=yes,status=no,titlebar=no,toolbar=no,resizable=no,directories=no,width=596,height=460");
	return false;
}

function sitemap() {
	window.open("sitemap.php","accessibility","menubar=no,scrollbars=yes,status=no,titlebar=no,toolbar=no,resizable=no,directories=no,width=596,height=460");
	return false;
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_nbGroup(event, grpName) { //v6.0
  var i,img,nbArr,args=MM_nbGroup.arguments;
  if (event == "init" && args.length > 2) {
    if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
      img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
      if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
      nbArr[nbArr.length] = img;
      for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
        if (!img.MM_up) img.MM_up = img.src;
        img.src = img.MM_dn = args[i+1];
        nbArr[nbArr.length] = img;
    } }
  } else if (event == "over") {
    document.MM_nbOver = nbArr = new Array();
    for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = (img.MM_dn && args[i+2]) ? args[i+2] : ((args[i+1])? args[i+1] : img.MM_up);
      nbArr[nbArr.length] = img;
    }
  } else if (event == "out" ) {
    for (i=0; i < document.MM_nbOver.length; i++) {
      img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
  } else if (event == "down") {
    nbArr = document[grpName];
    if (nbArr)
      for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
    document[grpName] = nbArr = new Array();
    for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = img.MM_dn = (args[i+1])? args[i+1] : img.MM_up;
      nbArr[nbArr.length] = img;
  } }
}

var addthis_config = { ui_click: true }

/* Slide Our Stories Functions */


$(document).ready(function(){
  var currentPosition = 0;
  var slideWidth = 636;
  var slides = $('.slide');
  var numberOfSlides = 2;
  $('#leftControl').hide();

  // Remove scrollbar in JS
  $('#slidesContainer').css('overflow', 'hidden');

  // Wrap all .slides with #slideInner div
  slides
  .wrapAll('<div id="slideInner"></div>')
  // Float left to display horizontally, readjust .slides width
  .css({
    'float' : 'left',
    'width' : slideWidth
  });

  // Set #slideInner width equal to total width of all slides
  $('#slideInner').css('width', slideWidth * numberOfSlides);

  // Insert left and right arrow controls in the DOM
  /*$('#slideshow')
    .prepend('<span class="control" id="leftControl">Move left</span>')
    .append('<span class="control" id="rightControl">Move right</span>');*/

  // Hide left arrow control on first load
 /* manageControls(currentPosition);*/

  // Create event listeners for .controls clicks
  $('.control')
    .bind('click', function(){
    // Determine new position
      currentPosition = ($(this).attr('id')=='rightControl')
    ? currentPosition+1 : currentPosition-1;

      // Hide / show controls
      manageControls(currentPosition);
      // Move slideInner using margin-left
      $('#slideInner').animate({
        'marginLeft' : slideWidth*(-currentPosition)
      });
    });

  // manageControls: Hides and shows controls depending on currentPosition
	function  manageControls(position){
	  // position==0 is first slide
	  if(position==0)  { $('#leftControl').hide(); }
	  else { $('#leftControl').show(); }
		// numberOfSlides-1 is last slides
	  if(position==numberOfSlides-1) {  $('#rightControl').hide(); }
	  else { $('#rightControl').show(); }
	}      
});
