function biggieSlider(rememberPosition) {
	if (rememberPosition == "dontRememberPosition") {
		deleteCookie('sliderIndex');
		deleteCookie('sliderTabPosition');
	}
	//biggieSliderCreateHolders();
	biggieSliderLoadTabNames();
	//biggieSliderSetInitialCookies();
	//alert("slider started");
}

function biggieSliderAddTabCounts() {
	//alert("running add counts");
	// add tab counts to existing slides array
	
	var tmpName1 = "";
	var tmpName2 = slides[0][3];
	var tabIndex = 0;
	var insideTabIndex = 0;
	var tabItemsCount = new Array();
	var tmpTabItemsCount = 1;
	var previousTabIndex = 0;
	for ( i = 0; i < slides.length; i++ ) {
		tmpName1 = slides[i][3];
		if ( tmpName1 == tmpName2 ) {
			slides[i][10] = tabIndex;
			slides[i][11] = insideTabIndex;
			insideTabIndex++;
		} else {
			tabIndex++;
			slides[i][10] = tabIndex;
			insideTabIndex = 0;
			slides[i][11] = insideTabIndex;
			insideTabIndex++;
			
		}
		tmpName2 = tmpName1;
				
		if ( slides[i][10] == previousTabIndex ) {
			tabItemsCount[tabIndex] = tmpTabItemsCount;
			tmpTabItemsCount++;
		} else {
			tmpTabItemsCount = 1;
			tabItemsCount[tabIndex] = tmpTabItemsCount;
			tmpTabItemsCount++;
			previousTabIndex = tabIndex;
		}
		//alert(slides[i][3] + " tab index = " + slides[i][10] + " inside tab index = " + slides[i][11] + " total items in tab = " + tabItemsCount[tabIndex]);
	}
//	for ( i = 0; i < tabItemsCount.length; i++ ) {
//		alert(tabItemsCount[i]);
//	}
	for ( i = 0; i < slides.length; i++ ) {
		slides[i][12] = tabItemsCount[slides[i][10]];
		//alert(slides[i][3] + " tab index = " + slides[i][10] + " inside tab index = " + slides[i][11] + " total items in tab = " + slides[i][12]);
	}
	
	// array structure
	// slides[i][10] = tab index
	// slides[i][11] = index in current tab
	// slides[i][12] = length of items in current tab
	
	//biggieSliderCreateProgressBoxes();
	// now that elements 10, 11, & 12 are added to the array run biggieSliderSetInitialCookies()
	biggieSliderSetInitialCookies();
}

window.sliderAdvanceCheck = 0;

function biggieSliderAdvanceCheck() {
	//alert("running advance check");
	window.sliderAdvanceCheck++;
	if ( window.sliderAdvanceCheck == 2 ) {
		//reset advance check
		window.sliderAdvanceCheck = 0;
		
		// increase rotation counter
		if ( window.sliderRotationCounter == 0 ) {
			window.previousTabIndex = slides[slides.length-1][10];
		} else {
			window.previousTabIndex = slides[window.sliderRotationCounter-1][10];
		}
		//alert(window.previousTabIndex);
		window.sliderRotationCounter++;
		
		// reset rotation counter if needed
		if ( window.sliderRotationCounter == slides.length ) {
			window.sliderRotationCounter = 0;
			//alert("reset slideCounter to 0");
		}
		
		// start progress bar now that new image is in place
		biggieSliderProgressBar();
	}
}

function biggieSliderCreateHolders() {
	for ( i=4; i<slides.length; i++ ) {
		//alert(i);
		$('.sliderSmallSlidesContainer').append('<div class="sliderLoadingBoxBackground sliderLoadingBoxSmall"><img src="/images/loading-circle-5-20fps.gif" class="loadingAnimation"></div>');
	}
	biggieSliderThumbClick();
	biggieSliderLoadBig();
}

window.runCount = 0;
window.boxesReadyForClick = "no";

function biggieSliderCreateProgressBoxes(fromTab) {
	//alert("creating progress boxes");
	if ($.cookie('sliderIndex')) {
		var currentIndex = $.cookie('sliderIndex');
		//alert("cookie present");
	} else {
		var currentIndex = 0;
		//alert("no cookie");
	}
	//alert(currentIndex);
	var boxesNeeded = slides[currentIndex][12];
	//alert(boxesNeeded);
	
	if ( window.runCount == 0 ) {
		for ( i = 0; i < boxesNeeded; i++ ) {
			$('.sliderProgressContainer').append('<div class="sliderProgressBox"><div class="sliderProgressBoxFilled sliderProgressBoxEmpty"></div></div>');
		}
		//alert(slides[currentIndex][11]);
		for ( i = 0; i < slides[currentIndex][11]; i++ ) {
			$('.sliderProgressBoxEmpty').eq(0).removeClass('sliderProgressBoxEmpty').css('display', 'block');
		}
		//window.boxesReadyForClick = "yes";
		biggieSliderCreateProgressBoxesOnClick();
		window.runCount++;
	} else {
		if ( window.previousTabIndex == slides[currentIndex][10] && fromTab != 'fromTab' ) {
			// stop current progress box animation
			$('.sliderProgressBoxAnimating').stop().removeClass('sliderProgressBoxAnimating').animate({opacity: 1}, 300, function() {
				// fadeIn comlete
				//$(this).removeClass('sliderProgressBoxAnimating');
			});
			//alert("no new boxes needed. just fill current ones.");
			for ( i = 0; i < slides[currentIndex][11]; i++ ) {
				$('.sliderProgressBoxFilled').eq(i).removeClass('sliderProgressBoxEmpty').fadeIn(300);
			}
		} else {
		// fade out and then remove old boxes then create new ones
			$('.sliderProgressBox').unbind();
			$('.sliderProgressContainer').fadeOut(300, function() {
				$(this).empty();
				for ( i = 0; i < boxesNeeded; i++ ) {
					$('.sliderProgressContainer').append('<div class="sliderProgressBox"><div class="sliderProgressBoxFilled sliderProgressBoxEmpty"></div></div>');
				}
				for ( i = 0; i < slides[currentIndex][11]; i++ ) {
					$('.sliderProgressBoxFilled').eq(i).removeClass('sliderProgressBoxEmpty').css('display', 'block');
				}
				$(this).fadeIn(300, function(){
					biggieSliderCreateProgressBoxesOnClick();
				});
				//window.boxesReadyForClick = "yes";
			});
		}
	}
}

function biggieSliderCreateProgressBoxesOnClick() {
	$('.sliderProgressBox').each(function() {
		var currentBox = $(this);
		var currentBoxIndex = currentBox.index();
		currentBox.click(function() {
			if (currentBox.children().hasClass('sliderProgressBoxAnimating')) {
				//alert('box is animating');
			} else {
				//alert(window.sliderRotationCounter);
				if ( window.sliderRotationCounter == 0 ) {
					window.sliderRotationCounter = slides.length;
					//alert(window.sliderRotationCounter);
					biggieSliderThumbsCheckPosition('reverse');
				}
				var sliderRotationIndex = window.sliderRotationCounter - 1;
				//alert(sliderRotationIndex);
				var boxDifference = currentBoxIndex - slides[sliderRotationIndex][11];
				//var boxDifference = currentBoxIndex - slides[window.sliderRotationCounter][11];
				//alert("slideRotaionCounter = "+slides[window.sliderRotationCounter][11]+" currentBoxIndex = "+currentBoxIndex+" boxDifference = "+boxDifference);
				var newSliderRotaionCounter = window.sliderRotationCounter + boxDifference -1;
				//alert("window.sliderRotationCounter = "+window.sliderRotationCounter+" boxDifference = "+boxDifference+" newSliderRotaionCounter = "+newSliderRotaionCounter);
				//alert("slides[sliderRotationIndex][11] = "+slides[sliderRotationIndex][11]+" currentBoxIndex = "+currentBoxIndex+" boxDifference = "+boxDifference);
				
				//update sliderIndex cookie and window.sliderRotationCounter
				$.cookie('sliderIndex', newSliderRotaionCounter);
				window.sliderRotationCounter = newSliderRotaionCounter;
				
				// fill boxes
				// first stop animation
				$('.sliderProgressBoxAnimating').stop().removeClass('sliderProgressBoxAnimating');
				for ( i = 0; i < slides[window.sliderRotationCounter][12]; i++ ) {
					//alert(i);
					var progressBoxFilled = $('.sliderProgressBoxFilled');
					progressBoxFilled.eq(i).removeAttr('style').removeClass('sliderProgressBoxEmpty');
					if ( i < slides[window.sliderRotationCounter][11] ) {
						progressBoxFilled.eq(i).css('display', 'block');
					} else {
						progressBoxFilled.eq(i).addClass('sliderProgressBoxEmpty');
					}
					//$('.sliderProgressBoxFilled').eq(i).removeClass('sliderProgressBoxEmpty').fadeIn(300);
				}
				biggieSliderMoveToNewPosition('boxes');
			}
		});
	});
}

window.slideCounter = 0;

function biggieSliderLoadBig() {
	
	// start rotaion if the first 5 have loaded
	if ( window.slideCounter == 5 ) {
		biggieSliderAdvanceCheck();
	}
	
	var img = new Image();
	$(img).load(function () {
      // set the image hidden by default    
      $(this).hide();
	  
	  //if ( window.slideCounter == 0 ) {
//	  
//		  //remove loading animation
//		  $('.sliderLoadingBoxBig img.loadingAnimation').remove();
//		
//		  $('.sliderLoadingBoxBig')
//			// insert the image
//			.append(this);
//		
//		  // fade image in
//		  $(this).addClass('sliderRemove').fadeIn();
//		  
//	  }
	  
	  // load the small image
	  biggieSliderLoadSm();
	  
    })
    
    // if there was an error loading the image, react accordingly
    .error(function () {
      // notify the user that the image could not be loaded
	  //alert(slides[window.slideCounter][2]+" failed to load");
    })
    
    // *finally*, set the src attribute of the new image to our image
    .attr('src', slides[window.slideCounter][2]);
}

function biggieSliderLoadFirstBig() {
	
	var img = new Image();
	$(img).load(function () {
      // set the image hidden by default    
      $(this).hide();
	  
		  //remove loading animation
		  $('.sliderLoadingBoxBig img.loadingAnimation').remove();
		
		  $('.sliderLoadingBoxBig')
			// insert the image
			.append(this);
		
		  // fade image in
		  //$(this).addClass('sliderRemove').fadeIn();
		  $(this).wrap("<a href='"+slides[window.sliderRotationCounter][4]+"' class='sliderRemove' ></a>").fadeIn();
	  
    })
    
    // if there was an error loading the image, react accordingly
    .error(function () {
      // notify the user that the image could not be loaded
	  //alert(slides[window.sliderRotationCounter][2]+" failed to load");
    })
    
    // *finally*, set the src attribute of the new image to our image
    .attr('src', slides[window.sliderRotationCounter][2]);
}

function biggieSliderLoadSm() {
	var img = new Image();
	$(img).load(function () {
      // set the image hidden by default    
      $(this).hide();
	  
	  //remove loading animation
      $('.sliderLoadingBoxSmall').eq(window.slideCounter+3).empty()

	  // insert the image
	  .append(this);
	  
	  // load bottom repeating slides
	  if ( window.slideCounter < 3 ) {
		  var clonedImg = $(this).clone();
		  var bottomTargetBox = slides.length + 3 + window.slideCounter;
		  
		  // remove loading animation
		  $('.sliderLoadingBoxSmall').eq(bottomTargetBox).empty()
		  
		  // insert the image
	  	  .append(clonedImg);
		  
		  // fade image in
      	  clonedImg.fadeIn();
	  }
	  
	  // load top repeating slides
	  if ( (slides.length - window.slideCounter) < 4 ) {
		  //alert(window.slideCounter);
		  var clonedImg = $(this).clone();
		  var bottomTargetBox = 3 - (slides.length - window.slideCounter);
		  //alert(bottomTargetBox);
		  $('.sliderLoadingBoxSmall').eq(bottomTargetBox).empty()
		  
		  // insert the image
	  	  .append(clonedImg);
		  
		  // fade image in
      	  clonedImg.fadeIn();
	  }
	  
	  // fade image in
      $(this).fadeIn();
    
	  //load the next big image
	  window.slideCounter++;
	  if ( window.slideCounter < slides.length ) {
	  	biggieSliderLoadBig();
	  }
	  
    })
    
    // if there was an error loading the image, react accordingly
    .error(function () {
      // notify the user that the image could not be loaded
	  //alert(slides[window.slideCounter][1]+" failed to load");
    })
    
    // *finally*, set the src attribute of the new image to our image
    .attr('src', slides[window.slideCounter][1]);
}

function biggieSliderLoadTabNames() {
	var tmpName1 = "";
	var tmpName2 = "";
	var tabNames = new Array ();
	for ( i = 0; i < slides.length; i++ ) {
		tmpName1 = slides[i][3];
		if ( tmpName1 != tmpName2 ) {
			tabNames[tabNames.length] = tmpName1;
			tmpName2 = tmpName1;
		}
	}
	for ( i=0; i < tabNames.length; i++ ) {
		$('.sliderTabsLinksContainer').append('<a href="#">'+tabNames[i]+'</a>');
	}

	$('.sliderTabsLinksContainer').animate({top: '1px'}, 1000, function() {
		// animation complete
		biggieSliderAddTabCounts();
		sliderSetInitialTab();
		$('.sliderProgressContainer').animate({top: '412px'}, 300, function() {
			// animation complete
		});
	});
	sliderTabClick();
}

function biggieSliderProgressBar() {
	// fill progress box
	
	// fade in effect
	$('.sliderProgressBoxEmpty').eq(0).removeClass('sliderProgressBoxEmpty').addClass('sliderProgressBoxAnimating').fadeIn(5750, 'linear', function() {
		$(this).removeClass('sliderProgressBoxAnimating');
	});
	
	//biggieSliderCreateProgressBoxesOnClick();
	
//	if ( window.boxesReadyForClick == "yes" ) {
//		window.boxesReadyForClick = "no";
//		biggieSliderCreateProgressBoxesOnClick();
//	}
	
	// grow effect
//	$('.sliderProgressBoxEmpty').eq(0).removeClass('sliderProgressBoxEmpty').addClass('sliderProgressBoxAnimating').animate({width: '8px'}, 5000, 'linear', function() {
//		$(this).removeClass('sliderProgressBoxAnimating');
//	});
	
	// animate progress bar
	$('.sliderProgressBar').stop().css('width', '0px').animate({ width: '730px'}, 5750, 'linear', function() {
		//$('.sliderProgressBox').unbind();
		biggieSliderSmallToBig();
		biggieSliderSetCookies();
	});
	window.clickReady = "yes";
}

function biggieSliderProgressBarStop() {
	// animate progress bar
	$('.sliderProgressBar').stop().css('width','0px');
}

function biggieSliderMoveTab(always) {
	if ($('.sliderTabsLinksContainer').length) {
	
		function moveResizeTab() {
			var tabToSetPosition = tabToSet.position();
			var tabToSetWidth = tabToSet.outerWidth();
			var textWidthOnly = tabToSet.width();
			var tabToSetPadding = [tabToSetWidth-textWidthOnly]/2;
			//alert(tabToSetPosition.left);
			var tabBackNewPosition = tabToSetPosition.left+tabToSetPadding-$('.sliderTabsBackLeft').width()+19;
			// resize sliderTabsBackMiddle to size of text
			//$('.sliderTabsBackMiddle').css('width',textWidthOnly);
			$('.sliderTabsBackMiddle').animate({width: textWidthOnly}, 300);
			// move tab background to new position
			//$('.sliderTabsBackContainer').css('left', tabBackNewPosition);
			$('.sliderTabsBackContainer').animate({left: tabBackNewPosition}, 300, function(){
				tabToSet.addClass('sliderTabOn').animate({color: '#ffffff'}, 150);
			});
			// animate from color back to black
			//alert(tabToSet);
			//alert($('.sliderTabOn'));
			var sliderTabOnIndex = $('.sliderTabsLinksContainer > a').index($('.sliderTabOn'));
			var cookieTabIndex = $.cookie('sliderTabPosition');
			//alert(cookieTabIndex);
			if ( sliderTabOnIndex != cookieTabIndex ) {
				$('.sliderTabOn').removeClass('sliderTabOn').stop().animate({color:'#333333'}, 150);
			}
			
		}
		
		// build in a check to see what page the cookie was initially set on so the slider can be reused on other pages without conflict
		
		if ($.cookie('sliderTabPosition') || always == 'always') {
			//alert($.cookie('sliderTabPosition'));
			// cookie present
			var tabToSet = $('.sliderTabsLinksContainer > a').eq($.cookie('sliderTabPosition'));
			moveResizeTab();	
		}
		
	}
}

function biggieSliderMoveToNewPosition(triggeredFrom) {
	biggieSliderProgressBarStop();
	biggieSliderAdvanceCheck();
	if ( triggeredFrom == 'fromTab' ) {
		biggieSliderSetThumbsStartingPosition('animate', 'noMovePast', 'fromTab');
		biggieSliderCreateProgressBoxes('fromTab');
	} else if ( triggeredFrom == 'boxes' ) {
		//alert('triggered from boxes');
		biggieSliderSetThumbsStartingPosition('animate', 'noMovePast', 'fromTab');
		//biggieSliderFillProgressBoxes();
	} else {
		biggieSliderSetThumbsStartingPosition('animate');
		biggieSliderCreateProgressBoxes();
	}
	//biggieSliderCreateProgressBoxes();
}

function biggieSliderSetCookies() {
	// set cookie for new tab position
	//slides[window.sliderRotationCounter][2]
	//window.sliderRotationCounter
	
	var newTabIndex = $(".sliderTabsLinksContainer > a:contains('" + slides[window.sliderRotationCounter][3] + "')").index();
	//alert(newTabIndex);
	
	// set sliderTabPosition cookie
	$.cookie('sliderTabPosition', newTabIndex);
	
	// set sliderIndex cookie
	$.cookie('sliderIndex', window.sliderRotationCounter);
	//alert("sliderIndex cookie = " + window.sliderRotationCounter);
	
	if ( slides[window.sliderRotationCounter][11] == 0 ) {
		biggieSliderCreateProgressBoxes();
	}
	
	biggieSliderAdvanceCheck();
	
	// move tab to new position if needed
	biggieSliderMoveTab();
}

function biggieSliderSetInitialCookies() {
	// sliderTabPosition cookie
	if ($.cookie('sliderTabPosition')) {
		// cookie exists
		//alert("sliderTabPosition cookie exists and = "+$.cookie('sliderTabPosition'));
	} else {
		// cookie does not exist
		$.cookie('sliderTabPosition', 0);
		//alert("sliderTabPosition cookie does not exists and was set to = "+$.cookie('sliderTabPosition'));
	}
	
	// sliderIndex cookie
	if ($.cookie('sliderIndex')) {
		// cookie exists
		//alert("sliderIndex cookie exists and = "+$.cookie('sliderIndex'));
		window.sliderRotationCounter = $.cookie('sliderIndex');
		//biggieSliderSetThumbsStartingPosition();
	} else {
		// cookie does not exist
		$.cookie('sliderIndex', 0);
		//alert("sliderIndex cookie does not exists and was set to = "+$.cookie('sliderIndex'));
	}
	//alert(slides[0]);
	//alert(slides[0][10]);
	if ( slides[$.cookie('sliderIndex')] && slides[$.cookie('sliderIndex')][10] == $.cookie('sliderTabPosition') ) {
		//alert("array element exists and tabs match");
	} else {
		//alert("array element does not exist or tabs do not match");
		//alert(slides[$.cookie('sliderIndex')]);
		//alert($.cookie('sliderTabPosition'));
		//alert(slides[$.cookie('sliderIndex')][10]);
		//alert("resetting cookies");
		$.cookie('sliderTabPosition', 0);
		$.cookie('sliderIndex', 0);
		window.sliderRotationCounter = 0;
		
	}
	biggieSliderCreateProgressBoxes();
	biggieSliderSetThumbsStartingPosition();
	biggieSliderCreateHolders();
	biggieSliderLoadFirstBig();
}

function biggieSliderSetThumbsStartingPosition(animate, movePast, fromTab) {
	$('.sliderSmallSlidesContainer').stop();
	//alert("starting position");
//	var thumbsStartingPosition = ((window.sliderRotationCounter + 1) * 137) * -1;
	var currentPosition = window.sliderRotationCounter * 1;
	//alert(currentPosition);
	var thumbsStartingPosition = ((currentPosition + 4) * 137) * -1;
	//alert(window.sliderRotationCounter);
	//alert(currentPosition);
	//alert(window.sliderRotationCounter+" + 1 * 137 * -1 = "+thumbsStartingPosition);
	if ( animate == 'animate' ) {
		if ( movePast == 'movePast' ) {
			numberToSkip = 4;
		} else {
			numberToSkip = 3;
		}
		var animateToPosition = ((currentPosition + numberToSkip) * 137) * -1;
		$('.sliderSmallSlidesContainer').animate({top: animateToPosition}, 500, function() {
			// animation complete
			biggieSliderThumbsCheckPosition();
			if ( fromTab == 'fromTab' ) {
				biggieSliderSmallToBig();
			}
		});
		if ( fromTab != 'fromTab' ) {
			biggieSliderSmallToBig('clickFromThumb');
		}
	} else {
		$('.sliderSmallSlidesContainer').css('top',thumbsStartingPosition);
		biggieSliderThumbsCheckPosition();
	}
}

function biggieSliderShadowboxPause() {
	//$('.sliderProgressBar').stop().css('width','0px');
//	$('.sliderProgressBoxAnimating').stop().css('display', 'none').removeClass('sliderProgressBoxAnimating').addClass('sliderProgressBoxEmpty');
	$('.sliderProgressBar').stop();
	$('.sliderProgressBoxAnimating').stop();
}

function biggieSliderShadowboxResume() {
	//alert("resume slider");
	//biggieSliderProgressBar();
	biggieSliderSmallToBig();
	biggieSliderSetCookies();
}

window.sliderRotationCounter = 0;

function biggieSliderSmallToBig(clickFromThumb) {
	//alert("running SmallToBig");
	var img = new Image();
	$(img).load(function () {
	  
	  if ( clickFromThumb == 'clickFromThumb' ) {
	  	//alert(window.sliderPreviousIndex);
		var thumbClicked = window.thumbRotationCounter - window.sliderPreviousIndex;
		//alert("window.thumbRotationCounter = "+window.thumbRotationCounter);
		//alert("window.sliderPreviousIndex = "+window.sliderPreviousIndex);
		//alert("thum clicked = "+thumbClicked);
		var topPosition = thumbClicked * 137;
		//alert("top position = "+topPosition);
	  } else {
		  var topPosition = 0;
	  }
	  
	  // set size and position
	  $(this).css({'width':'244px', 'height':'137px', 'left':'730px', 'top':topPosition, 'z-index':'1'});
    	  
	  $('.sliderLoadingBoxBig')
        // insert the image
        .append(this);
		
	  $(this).animate({
	  	left: "0",
		top: "0",
		width: "730px",
		height: "411px"
	  }, 750, function() {
		$('.sliderRemove').remove();
		//$('.sliderActiveLink').addClass('sliderRemove');
		//$(img).css('z-index', '').addClass('sliderRemove');
		$(img).css('z-index', '').wrap("<a href='"+slides[window.sliderRotationCounter][4]+"' class='sliderRemove' ></a>");
		// tell shadowbox to rescan page for new shadowbox links
		Shadowbox.setup();
		//$('.sliderLoadingBoxBig').click(function() {
//			//alert("pausing");
//			biggieSliderShadowboxPause();
//		});
		
	  	//biggieSliderProgressBar();
		biggieSliderAdvanceCheck();
	  });
	  if ( clickFromThumb != 'clickFromThumb' ) {
	  	biggieSliderThumbsForward();
	  }
	  
	  // load the small image
	  //biggieSliderLoadSm();
	  
    })
    
    // if there was an error loading the image, react accordingly
    .error(function () {
      // notify the user that the image could not be loaded
	  //alert(slides[window.sliderRotationCounter][2]+" failed to load");
    })
    
    // *finally*, set the src attribute of the new image to our image
    .attr('src', slides[window.sliderRotationCounter][2]);
	//window.sliderRotationCounter++;
//	if ( window.sliderRotationCounter == slides.length ) {
//		window.sliderRotationCounter = 0;
//		//alert("reset slideCounter to 0");
//	}
}

function biggieSliderThumbsCheckPosition(direction) {
	var totalHeight = (slides.length + 6) * 137;
	var repeatHeight = (totalHeight - (137 * 3)) * -1;
	var thumbsPosition = $('.sliderSmallSlidesContainer').position().top;
	var topRepeatPosition = (137 * 3) * -1;
	if ( thumbsPosition == repeatHeight ) {
		// repeating point reached
		$('.sliderSmallSlidesContainer').css('top',topRepeatPosition);
	}
	if ( direction == "reverse" ) {
		$('.sliderSmallSlidesContainer').css('top',repeatHeight);
		//alert("reverse");
	}
}

function biggieSliderThumbClick() {
	//alert("running thumbClick");
	$('.sliderLoadingBoxSmall').click(function () {
		//alert("thumbnail clicked");
		window.sliderPreviousIndex = window.sliderRotationCounter;
		var currentIndex = $(this).index() - 3;
		window.thumbRotationCounter = currentIndex;
		if ( window.sliderRotationCounter == 0 ) {
			window.previousTabIndex = slides[slides.length-1][10];
		} else {
			window.previousTabIndex = slides[window.sliderRotationCounter-1][10];
		}
		//alert("window.previousTabIndex = "+window.previousTabIndex);
		if ( currentIndex >= slides.length ) {
			currentIndex = currentIndex - slides.length;
			//alert(currentIndex);
			var clickedFrom = $(this).index() - 3 - window.sliderRotationCounter;
			//alert(clickedFrom);
			var newTopPosition = ((3 * 137) + ((currentIndex - clickedFrom) * 137)) * -1;
			$('.sliderSmallSlidesContainer').css('top',newTopPosition);
		}
		var currentTabIndex = slides[currentIndex][10];
		//alert(currentTabIndex);
		//alert(slides.length);
		$.cookie('sliderIndex', currentIndex);
		$.cookie('sliderTabPosition', currentTabIndex);
		window.sliderRotationCounter = currentIndex;
		biggieSliderThumbClickMove();
	});
}

function biggieSliderThumbClickMove() {
	biggieSliderProgressBarStop();
	biggieSliderAdvanceCheck();
	biggieSliderSetThumbsStartingPosition('animate', 'movePast');
	biggieSliderCreateProgressBoxes();
	biggieSliderMoveTab('always');
}

function biggieSliderThumbsForward() {
	//var thumbPosition = $('.sliderSmallSlidesContainer').position();
	//var newThumbPosition = thumbPosition.top-137;
	//alert(newThumbPosition);
	$('.sliderSmallSlidesContainer').animate({
		top: "-=137px"
	}, 750, function() {
		// animation complete
		biggieSliderThumbsCheckPosition();
	});
}

function clearText(theText) {
     if (theText.value == theText.defaultValue) {
         theText.value = ""
     }
}

function deleteCookie(name) {
    document.cookie = name + '=; expires=Thu, 01-Jan-70 00:00:01 GMT;';
}

function formatNavDropDownHighlightedTitle() {
	$('.navDropDownListTitle > br').each(function () {
		$(this).remove();
	});
}

function getHoverHeights() {
	//alert("running getHoverHeights");
	var navCounter = 0;
	window.dropDownMaxHeights = new Array();
	$('.navDropDown').each(function() {
		var currentDropDown = $(this);
		window.dropDownMaxHeights[navCounter] = 0;
		$('.navDropDownFeatured', currentDropDown).each(function() {
			if (window.dropDownMaxHeights[navCounter] < $(this).outerHeight()) {
				window.dropDownMaxHeights[navCounter] = $(this).outerHeight();
			}
			
		}).css('display', 'none');
		$('.navDropDownRightCol', currentDropDown).each(function() {
			if (window.dropDownMaxHeights[navCounter] < $(this).outerHeight()) {
				window.dropDownMaxHeights[navCounter] = $(this).outerHeight();
			}
		});
		
		//alert("nav item"+navCounter);
		navCounter++;
	}).css('display', 'none');
	var len=window.dropDownMaxHeights.length;
	for(var i=0; i<len; i++) {
		//alert(len);
		//alert(window.dropDownMaxHeights[i]+" "+i);
		window.dropDownMaxHeights[i] = window.dropDownMaxHeights[i] + 100;
	}
}

function featuredOnIndex() {
	$('.navDropDownFeatured').each(function() {
		var featuredIndex = $(this).index('.navDropDownFeatured');
		$(this).append("index is: "+featuredIndex);
	});
}

function hoverNavDropDownFeatured() {
	//featuredOnIndex();
	$('a.navDropDownListItem').each(function () {
		var hoveredLink = $(this);
		var linkIndex = hoveredLink.index('a.navDropDownListItem');
		//hoveredLink.append("index is: "+linkIndex);
		hoveredLink.hover(
			function () {
				//hover on
				//alert('running');
				if ( $('.navDropDownFeaturedOn').index('.navDropDownFeatured') != linkIndex ) {
					$('.navDropDownFeaturedOn').stop().fadeOut(150, function () {
						$(this).removeClass('navDropDownFeaturedOn').css('display', 'none').css('opacity', '0');
						$('.navDropDownLeftCol > .navDropDownFeatured').eq(linkIndex).addClass('navDropDownFeaturedOn').stop().fadeTo(300, 1);
					});
				}
			}, function () {
				//hover off
			}
		);
	});
}

function hoverNav() {
	$('.nav > a').each(function () {
		//alert($(this).width());
		var aTag = $(this);
		aTag.hover(
			  function () {
				// on nav hover
				//$('.navDropDownContainer').stop();
				$('.navBackContainer').stop();
				var currentItemPosition = aTag.position();
				var currentNavBackPosition = $('.navBackContainer').position();
				var currentItemWidth = aTag.outerWidth();
				var textWidthOnly = aTag.width();
				var currentItemPadding = [currentItemWidth-textWidthOnly]/2;
				var navBackNewPosition = currentItemPosition.left+currentItemPadding-$('.navBackLeft').width();
				if (currentItemPosition.left-currentNavBackPosition.left != 81) {
					$('.navHovering').removeClass('navHovering').stop().animate({color:'#333333'}, 150);
					$('.navOn').stop().animate({color:'#333333'}, 150);
				}
				if (aTag.hasClass('navHovering')) {
				} else {
					//alert("check here?");
					$('.navBackMiddle').stop().animate({ width: textWidthOnly-28 }, 300, 'easeOutQuint', function() {
						// Animation complete.
					});
					// move nav background to new position
					$('.navBackContainer').stop().animate({ left: navBackNewPosition+14 }, 300, 'easeOutQuint', function() {
						// Animation complete.
						// change color of text to white
						aTag.stop().addClass('navHovering').animate({color:'#ffffff'}, 150, function() {
							// Animation complete.
							// remove any previous navDropDownOn classes and fade out before fading in new content
							if ($('.navDropDownOn').length) {
								$('.navDropDownOn').fadeOut(150, 0, function() {
									// finished
									// remove previous navDropDownFeaturedOn classes and hide
									$('.navDropDownFeaturedOn').removeClass('navDropDownFeaturedOn').css('display', 'none').css('opacity', '0');
									// animate navDropDownContainer down
									$('.navDropDownContainer').stop().animate({ height: window.dropDownMaxHeights[aTag.index()]}, 150, function() {
										// animation complete
										// select coresponding drop down content
										$('.navDropDown').eq(aTag.index()).each(function() {
											// set first item to visible
											$('.navDropDownFeatured', this).first().addClass('navDropDownFeaturedOn').css('display', 'block').css('opacity', '1');
										// fade in coresponding drop down content block
										}).addClass('navDropDownOn').stop().fadeTo(150, 1);
										
									});
								}).removeClass('navDropDownOn');
							} else {
								$('.navDropDownContainer').stop().animate({ height: window.dropDownMaxHeights[aTag.index()]}, 300, function() {
									// animation complete
									//alert(window.dropDownMaxHeights[aTag.index()]);
									// select coresponding drop down content
									$('.navDropDown').eq(aTag.index()).each(function() {
										// set first item to visible
										$('.navDropDownFeatured', this).first().addClass('navDropDownFeaturedOn').css('display', 'block').css('opacity', '1');
									// fade in coresponding drop down content block
									}).addClass('navDropDownOn').stop().fadeTo(150, 1);
									
								});
							}
						});
					});
				}
			  }, function () {
				// hover off
			  }
			);
		});
}

function lastHomeWidget() {
	$('.homeWidget').each(function () {
		$(this).css('width', '243px');
	});
	$('.homeWidget').last().addClass('homeWidgetLast').css('width', '242px');
}

window.testCounter=0;

function navOnDo() {
	var navOn = $('.navOn');
	var navOnPosition = navOn.position();
	var currentNavBackPosition = $('.navBackContainer').position();
	//check if navOn class exists
	if ($('.navOn').length) {
		var navOnPosition = navOn.position();
		var navOnWidth = navOn.outerWidth();
		var textWidthOnly = navOn.width();
		var navOnPadding = [navOnWidth-textWidthOnly]/2;
		var navBackNewPosition = navOnPosition.left+navOnPadding-$('.navBackLeft').width();
		var animateMethod = 'easeOutQuint';
		//returnNav();
	} else {
		var textWidthOnly = 100;
		var navBackNewPosition = -1000;
		var animateMethod = 'easeInQuint';
	}
	
	function returnNav(first) {
		//alert("running return nav");
		$('.navHovering').stop();
		// remove previous navDropDownFeaturedOn classes and hide
		$('.navDropDownFeaturedOn').removeClass('navDropDownFeaturedOn').css('display', 'none').css('opacity', '0');
		$('.navDropDownContainer').stop().animate({ height: '0px'}, 300, function() {
			if ( $('.navOn').hasClass('navHovering') ) {
			} else {
				//window.testCounter++;
				//alert(window.testCounter);
				$('.navHovering').removeClass('navHovering').stop().animate({color:'#333333'}, 150);
			}
			$('.navBackMiddle').stop().animate({ width: textWidthOnly-28 }, 300, animateMethod, function() {
				// Animation complete.
			});
			$('.navBackContainer').stop().animate({ left: navBackNewPosition+14 }, 300, animateMethod, function() {
				// Animation complete.
				navOn.addClass('navHovering');
				$('.navHovering').stop().animate({color:'#ffffff'}, 150);
				if (first = 1) {
					$('.navHovering').removeClass('navHovering');
				}
			});
		});		
	}
	
	$('.nav').hover(
			  function () {
				  //alert("hover on")
			  }, function () {
				  //alert("hover off")
				  if ($('.navDropDownOn').length) {
						$('.navDropDownOn').stop().removeClass('navDropDownOn').fadeOut(150, 0, function() {
							returnNav();
						});
				  } else {
					returnNav();
				  }
	});
	returnNav(1);
}

function showHideHorScroll() {
	var browserWidth = document.body.offsetWidth;
	if (browserWidth < 1004) {
		$("body").css("overflow-x", "visible");
	} else {
		$("body").css("overflow-x", "hidden");
	}
}

window.siteMapPosition = "up";

function showHideSiteMap() {
	$('.siteMapTab').click( function(e){
			  e.preventDefault(); // cancel default behavior
			  var siteMapHeight = document.getElementById('siteMapBackground').offsetHeight;	 
			  if (window.siteMapPosition == "up") {
			  	  window.siteMapPosition = "down";
				  $(".sitemMapArrow").rotate({
					angle: 0, 
					animateTo:180,
					duration:500,
					callback: function(){
						$('#siteMapContainer').animate({top: siteMapHeight+30}, 500);
					}
				  })
			  } else {
				  window.siteMapPosition = "up";
				  $('.sitemMapArrow').rotate({
					angle: 180, 
					animateTo:0,
					duration:500,
					callback: function(){
						$('#siteMapContainer').animate({top: '33px'}, 500);
					}
				  })
	  		  }
	});
}

function sliderSetInitialTab() {
	
	if ($('.sliderTabsLinksContainer').length) {
	
		function moveResizeTab() {
			var tabToSetPosition = tabToSet.position();
			var tabToSetWidth = tabToSet.outerWidth();
			var textWidthOnly = tabToSet.width();
			var tabToSetPadding = [tabToSetWidth-textWidthOnly]/2;
			var tabBackNewPosition = tabToSetPosition.left+tabToSetPadding-$('.sliderTabsBackLeft').width()+19;
			// resize sliderTabsBackMiddle to size of text
			$('.sliderTabsBackMiddle').css('width',textWidthOnly);
			// move tab background to new position
			$('.sliderTabsBackContainer').css('left', tabBackNewPosition);
			$('.sliderTabsBackContainer').animate({top: '0px'}, 300, function(){
				//tabToSet.addClass('sliderTabOn').css('color', '#ffffff');
				tabToSet.addClass('sliderTabOn').animate({color: '#ffffff'}, 150);
				biggieSliderAdvanceCheck();
			});
			
		}
		
		// build in a check to see what page the cookie was initially set on so the slider can be reused on other pages without conflict
		
		if ($.cookie('sliderTabPosition')) {
			// cookie present
			var tabToSet = $('.sliderTabsLinksContainer > a').eq($.cookie('sliderTabPosition'));
			moveResizeTab();	
		} else {
			// no cookie found
			var tabToSet = $('.sliderTabsLinksContainer > a').first();
			moveResizeTab();
		}
		
	}
}

window.clickReady = "yes";

function sliderTabClick() {
	$('.sliderTabsLinksContainer > a').each(function () {
		var tabLink = $(this);
		tabLink.click(function(e) {
			e.preventDefault(); // cancel default behavior
			//$('.sliderTabsBackContainer').stop();
			//alert(window.clickReady);
			var currentItemPosition = tabLink.position();
			var currentTabBackPosition = $('.sliderTabsBackContainer').position();
			var currentItemWidth = tabLink.outerWidth();
			var textWidthOnly = tabLink.width();
			var currentItemPadding = [currentItemWidth-textWidthOnly]/2;
			var tabBackNewPosition = currentItemPosition.left+currentItemPadding-$('.sliderTabsBackLeft').width()+19;
			if (tabLink.hasClass('sliderTabOn') || window.clickReady == 'no') {
			} else {
				window.clickReady = "no";
				var newTabIndex = tabLink.index();
				$.cookie('sliderTabPosition', newTabIndex);
				for ( i = 0; i < slides.length; i++ ) {
					if ( slides[i][10] == newTabIndex ) {
						$.cookie('sliderIndex', i);
						window.sliderRotationCounter = i;
//						biggieSliderProgressBarStop();
//						biggieSliderAdvanceCheck();
//						biggieSliderSetThumbsStartingPosition('animate');
//						biggieSliderCreateProgressBoxes();

						i = slides.length;
					}
				}
				biggieSliderMoveToNewPosition('fromTab');
				$('.sliderTabOn').removeClass('sliderTabOn').stop().animate({color:'#333333'}, 150);
				// resize sliderTabsBackMiddle to size of text
				$('.sliderTabsBackMiddle').stop().animate({ width: textWidthOnly }, 300, 'easeOutQuint', function() {
					// Animation complete.
				});
				// move tab background to new position
				$('.sliderTabsBackContainer').stop().animate({ left: tabBackNewPosition }, 300, 'easeOutQuint', function() {
					// Animation complete.
					tabLink.stop().addClass('sliderTabOn').animate({color:'#ffffff'}, 150, function() {
						//color animation complete
						//window.clickReady = "yes";
					});
				});
			}
		});
	});
}

function tempProgressBar() {
	var boxCount = $('.sliderProgressBox').length-1;
	var currentCount = 0;
	function animateBox() {
		$('.sliderProgressBar').css('width', '0px');
		$('.sliderProgressBox').eq(currentCount).append('<div class="sliderProgressBoxFilled"></div>');
		$('.sliderProgressBar').animate({ width: '730px'}, 5000, 'linear');
		$('.sliderProgressBox').eq(currentCount).find('.sliderProgressBoxFilled').css('display', 'none').css('width', '8px').fadeIn(5000, function() {
		//$('.sliderProgressBox').eq(currentCount).find('.sliderProgressBoxFilled').animate({ width: '8px'}, 5000, 'linear', function() {
			if (currentCount<boxCount) {
				currentCount++;
				animateBox();
			} else {
				currentCount = 0;
				$('.sliderProgressBox').each(function() {
					$(this).empty();
				});
				animateBox();
			}
		});
	}
	animateBox();
//	$('.sliderProgressBox').each(function() {
//		$(this).click(function() {
//			$(this).append('<div class="sliderProgressBoxFilled"></div>');
//			//$('.sliderProgressBoxFilled', this).animate({ width: '8px'}, 5000, 'linear');
//			$('.sliderProgressBoxFilled', this).css('display', 'none').css('width', '8px').fadeIn(5000);
//		});
//	});
}
