// Awards Section Featured Stories

//var slideTotal    = 5;
var slideCurrent  = 0;

function slideShow() {

  if(slideTotal<=0) return;
	
  slidePrevious   = slideCurrent == 0 ? 1 : slideCurrent;
  slideCurrent    = (slideCurrent + 1) > slideTotal ? 1: (slideCurrent + 1);

  slideObjectOld  = document.getElementById("award_stories_" + slidePrevious);
  slideObject     = document.getElementById("award_stories_" + slideCurrent);
  if(slideObjectOld!=null)
	slideObjectOld.style.visibility="hidden";
  
  if(slideObject!=null)
	slideObject.style.visibility="visible";
	
  timer = setTimeout ("slideShow()", 7000);
} // ! slideShow()

// Next Slide Button
function nextSlide() {
	if(slideShowPaused == true) {
		slidePrevious   = slideCurrent == 0 ? 1 : slideCurrent;
  		slideCurrent    = (slideCurrent + 1) > slideTotal ? 1: (slideCurrent + 1);
  		slideObjectOld  = document.getElementById("award_stories_" + slidePrevious);
  		slideObject     = document.getElementById("award_stories_" + slideCurrent);
  		slideObjectOld.style.visibility="hidden";
  		slideObject.style.visibility="visible";
		clearTimeout (timer);
	} else {
	slideCurrent - 1;
	clearTimeout (timer);
	slideShow();
	}
}

// Previous Slide Button
function prevSlide() {

	if(slideCurrent == 1) {
		slidePrevious   = slideCurrent;
  		slideCurrent    = slideTotal;
		slideObjectOld  = document.getElementById("award_stories_" + slidePrevious);
  		slideObject     = document.getElementById("award_stories_" + slideCurrent);
  		slideObjectOld.style.visibility="hidden";
		slideObject.style.visibility="visible";
		if(slideShowPaused == true) {
			clearTimeout (timer);
		} else {
			clearTimeout (timer);
			timer = setTimeout ("slideShow()", 7000); 
		}
	} else {
		slidePrevious   = slideCurrent == 0 ? slideCurrent - 1 : slideCurrent;
  		slideCurrent    = slideCurrent == 0 ? slideTotal : slideCurrent - 1;
		slideObjectOld  = document.getElementById("award_stories_" + slidePrevious);
  		slideObject     = document.getElementById("award_stories_" + slideCurrent);
  		slideObjectOld.style.visibility="hidden";
		slideObject.style.visibility="visible";
		if(slideShowPaused == true) {
			clearTimeout (timer);
		} else {
			clearTimeout (timer);
			timer = setTimeout ("slideShow()", 7000); 
		}
	}
}

var slideShowPaused = false;

// Pause Button 
function pauseSlide() {
	if(slideShowPaused == true) {
		document.getElementById('pause_off').style.zIndex = "99";
		document.getElementById('pause_on').style.zIndex = "1";
		slideShowPaused = false;
		timer = setTimeout ("slideShow()", 7000);
	} else if (slideShowPaused == false) {
		document.getElementById('pause_on').style.zIndex = "99";
		document.getElementById('pause_off').style.zIndex = "1";
		slideShowPaused = true;
		clearTimeout (timer);
	}
}
// End Awards Featured Stories

// Nominee Category Scroll

var catCurrent  = 1;
var catPrevious = 0;

function catNext() {
	catPrevious   = catCurrent == 1 ? 1 : catCurrent;
  	catCurrent    = (catCurrent + 1) > catTotal ? 1: (catCurrent + 1);
	shiftSet('nominees_title', "nominees_title_" + catCurrent);
	shiftSet('nominee_category', "nominee_category_" + catCurrent);
	shiftSet('featured_nominees', "nominee_content_wrap_" + catCurrent);
}

function catPrev() {
	if(catCurrent == 1) {
	catPrevious   = catCurrent;
  	catCurrent    = catTotal;
	shiftSet('nominees_title', "nominees_title_" + catCurrent);
	shiftSet('nominee_category', "nominee_category_" + catCurrent);
	shiftSet('featured_nominees', "nominee_content_wrap_" + catCurrent);
} else {
	catPrevious   = catCurrent == 0 ? catCurrent - 1 : catCurrent;
  	catCurrent    = catCurrent == 0 ? catTotal : catCurrent - 1;
	shiftSet('nominees_title', "nominees_title_" + catCurrent);
	shiftSet('nominee_category', "nominee_category_" + catCurrent);
	shiftSet('featured_nominees', "nominee_content_wrap_" + catCurrent);
	}
}
// End Nominee Category Scroll


// Category Div Scroll

var shiftTotalWidth   = new Array();
var shiftTotalObjects = new Array();
var catCurrent = 1;
var shiftArray        = new Array();


function shiftPrepare(checkID) {

  var checkObject   = document.getElementById(checkID);

  if( checkObject ) {

    // Get all the child-nodes under the parent ID
    checkChildren   = checkObject.childNodes;

    shiftWidth          = 0;
    shiftArray[checkID] = new Array();
    shiftTotalObjects[checkID] = 0;

    /*
      Would do for(var thisChild in checkChildren) if it wasn't for
      certain browsers. And by certain browsers I mean Safari.
    */
    for(thisChild = 0; thisChild <= checkChildren.length; thisChild++) {
      thisObject    = checkChildren[thisChild];

      if( typeof(thisObject)=='object' && thisObject.id != undefined && shiftArray[checkID][thisObject.id] == undefined ) {

        thisWidth   = thisObject.clientWidth != 0 ? thisObject.clientWidth : thisObject.offsetWidth;
        thisObject.style.left = shiftWidth + 'px';
        shiftWidth += thisWidth;

        shiftArray[checkID][thisObject.id] = thisObject;
        shiftTotalObjects[checkID]++;
      }
    }

    shiftTotalWidth[checkID] = shiftWidth;
    formatNomineeNumber();

  } // ! object exists?

} // ! shiftPrepare()



function shiftObjects(shiftID, shiftTo) {

  shiftCount    = 1;
  shiftWidth    = 0;

  orderArray    = new Array(); // will replace shiftArray with a new list
  orderList     = new Array();

  // Cycle through each of the elements discovered in the target
  for(var thisID in shiftArray[shiftID]) {
    thisObject  = shiftArray[shiftID][thisID];
    thisWidth   = thisObject.clientWidth != 0 ? thisObject.clientWidth : thisObject.offsetWidth;
    thisLeft    = thisObject.style.left.replace('px', '') * 1;

    shiftWidth  = shiftTo == '<' && shiftWidth == 0 ? thisWidth : shiftWidth;
    shiftToX    = thisLeft + (shiftTo == '>' ? -(shiftWidth) : shiftWidth);
    shiftToPos  = shiftTo == '>' ? shiftCount - 1 : shiftCount + 1;


    if( shiftToPos == 0 ) {
      thisObject.style.left = (shiftTotalWidth[shiftID] - thisWidth) + 'px';
      orderList[shiftTotalObjects[shiftID]] = thisObject.id;

    } else if( shiftToPos > shiftTotalObjects[shiftID] ) {
      thisObject.style.left = 0 + 'px';
      orderList[1] = thisObject.id;

    } else {
      thisObject.style.left = shiftToX + 'px';
      orderList[shiftToPos] = thisObject.id;

    }

    shiftWidth = thisWidth;

  shiftCount++;
  } // ! loop through objects


  // Re-order the list according to how it was shifted
  for(listCount = 1; listCount <= shiftTotalObjects[shiftID]; listCount++) {
    listIndex   = orderList[listCount];
    orderArray[listIndex] = shiftArray[shiftID][listIndex];
  }

  shiftArray[shiftID] = orderArray;

	if(document.selection && document.selection.empty ) {
	document.selection.empty();
	} else if(window.getSelection) {
	window.getSelection().removeAllRanges();
	}

} // ! shiftObjects()


function shiftSet(shiftInID, shiftToID) {

  var shiftObject   = document.getElementById(shiftInID);
  var loadObjects   = document.getElementById(shiftToID);

  if( shiftObject && loadObjects ) {

    shiftObject.innerHTML   = loadObjects.innerHTML;

    shiftPrepare(shiftInID);
	
	if(useArrows == 1) {
		if(shiftTotalObjects[shiftInID] <= 5) {
			document.getElementById('featured_nominees_left').style.backgroundImage="none";
			document.getElementById('featured_nominees_right').style.backgroundImage="none";
			document.getElementById('featured_nominees_left').style.cursor="default";
			document.getElementById('featured_nominees_right').style.cursor="default";
		} else {
			document.getElementById('featured_nominees_left').style.backgroundImage="url(../images/awards/featured_left_arrow.gif)";
			document.getElementById('featured_nominees_right').style.backgroundImage="url(../images/awards/featured_right_arrow.gif)";
			document.getElementById('featured_nominees_left').style.cursor="pointer";
			document.getElementById('featured_nominees_right').style.cursor="pointer";
		}
	}

  } // ! valid objects?

} // ! shiftSet()

function prepareCats() {
	var catPrepare = new Array();
	for(i = 1; i <= catTotal; i++) {
		shiftPrepare('nominee_content_wrap_' + i);	
	}
}

// Load Functions
function loadWindow() {
	shiftPrepare();
	prepareCats();
	slideShow();
	if(useArrows == 0) {
	shiftSet('featured_winners', 'nominee_content_wrap_1');
	} else {
	shiftSet('nominees_title', 'nominees_title_1');
	shiftSet('nominee_category', 'nominee_category_1');
	shiftSet('featured_nominees', 'nominee_content_wrap_1');
	}
}

function formatNomineeNumber()
{
	var nominee_number = document.getElementById ( "nominee_number" );
	if ( nominee_number )
	{	nominee_number.style.left = "520px"; }	
}