 /* 
 * Helpers
 */
function nextText (currSlideElement, nextSlideElement, options, forwardFlag) {      
  $('#banner-nav-text').cycle(options.nextSlide);  
}

function toggleScrollNav() {
  var y = $('div.banner-text-wrapper:visible');
  if (y.height() - (y.scrollTop() + 10) < 284) {
    $('#scroll-nav').hide();
  }
  else {
    $('#scroll-nav').show();
  } 
}

function initSecondaryActiveLink (i){
  $('#subCreative li a').removeClass('activeSlide');
  $('#subExhibits li a').removeClass('activeSlide');
  
  switch (i){
    case 0:
    case 1: //Vision
        $('#banner-text').scrollTo(0, {axis: 'y'});            
        $('#subCreative li:eq(0) a').addClass('activeSlide');
        break;
    case 2: //strategy
      $('#banner-text').scrollTo(314, {axis: 'y'});
      $('#subCreative li:eq(1) a').addClass('activeSlide');
      break;
    case 3: //design
      $('#banner-text').scrollTo(575 , {axis: 'y'});
      $('#subCreative li:eq(2) a').addClass('activeSlide');
      break;
    case 4: //Tradeshow Programs
      $('#banner-text').scrollTo(0, {axis: 'y'});
      $('#subExhibits li:eq(0) a').addClass('activeSlide');
      break;
    case 5: //mobile marketing
      $('#banner-text').stop(false, true).scrollTo(289, {axis: 'y'});
      $('#subExhibits li:eq(1) a').addClass('activeSlide');
      break;
  }
}

function toggleSecondary (i) {  
  if (!i || i == 0) {
    $('#nice-menu-custom1 ul:eq(0)').css('visibility','visible');
    $('#nice-menu-custom1 ul:eq(1)').css('visibility','hidden');    
  }
  else if (i == 1) {
    $('#nice-menu-custom1 ul:eq(0)').css('visibility','hidden');
    $('#nice-menu-custom1 ul:eq(1)').css('visibility','visible');    
  }  
  else {
    $('#nice-menu-custom1 ul').css('visibility','hidden');        
  }
    
}

function hasHash () {
  return document.location.hash == "";
}

function hasMultiLevelMenu () {
  var path = document.location.hash;
  return path.indexOf(",") != -1; 
}

function getUrlArg(i) {
  //test if the arg is proper
  //:TODO
  
  var hash = document.location.hash;
  var index = -1;
  
  if (hasMultiLevelMenu()) {    
    //url like <site/page#0,1
    //remove # from hash
    hash = hash.replace('#', '');
    //return the desired part of the hash (by i)
    index = hash.split(',')[i];
  }
  else {
    //url like <site>/page#1
    index = hash.split('#').pop();
  }
  return index;
}

$(document).ready(function() {
  
//  $(".bimage").corner("round top 10px");   
  $("#banner-right-inner").corner("round top 10px");
  $("#banner-caption").corner("round bottom 10px"); 
$("#foxboro_top").corner("round 10px");  
$("#banner").corner("round 10px");
$("#banner-inner").corner("round 10px");
$("#banner-left").corner("round 10px");

  /* Slideshows */
  
  //Front page
  $('#banner-images').cycle({ 
    fx:    'fade', 
    speed:  1000,
    timeout: 10000,
    prev: '#banner-nav-previous',
    next: '#banner-nav-next',
    before: nextText, //banner-image cycles text divs
    startingSlide: parseInt(getUrlArg(1)) // Get the value after the # in the url
  });
  
  $('#banner-nav-text').cycle({ 
    fx:    'fade', 
    speed:  1000,
    timeout: 0, //ensures it doesn't cycle automatically
    fit: 1,
    containerResize: 0,
    cleartypeNoBg: true,
    startingSlide: parseInt(getUrlArg(1)) // Get the value after the # in the url
  });
  
  
  

  

  
});

