
document.write("<link rel='stylesheet' href='files/javascript.css' media='screen' type='text/css' />");

// Tabbed editorial stories
NewTab = new Array ();
var ids;
var TabNum = 0;
var TabLength = NewTab.length - 1;
var delay = 4000;
var lock = false;
var run;

function assignTabs(ids) {
	myNewTab = ids.split('/');
	NewTab = myNewTab;
	TabLength = NewTab.length - 1;
}

// Auto news panel rotating
function autoTab(myids, newdelay) {
	ids = myids;
	if (newdelay) {
		delay = newdelay;
	}
	if (lock == true) {
		lock = false;
		window.clearInterval(run);
	} else if (lock == false) {
		lock = true;
		run = setInterval("chgTab(ids, 1)", delay);
	}
}

function chgTab(myids, direction) {
	if (myids) {
		assignTabs(myids);
	}
	var currpanel = document.getElementById(NewTab[TabNum]);
	TabNum = TabNum + direction;
		if (TabNum > TabLength) {
			TabNum = 0;
		}
		if (TabNum < 0) {
			TabNum = TabLength;
		}
	var nextpanel = document.getElementById(NewTab[TabNum]);
	nextpanel.style.zIndex = 2;
	currpanel.style.zIndex = 1;
}

// Show or hide id
function swap(show, hide) {
	var showpanel = document.getElementById(show);
	var hidepanel = document.getElementById(hide);
	showpanel.className = 'hide';
	hidepanel.className = 'show';
}

/* Display tabbed panel's contents (using .tabpanel, .tab, .tabactive, tabpanelcontents) */
function selectTab(n, numDiv, panelID) {
	// iterate all tab-panels
	for (var i = 0; i < numDiv; i++) {
		var panel = window.document.getElementById(panelID + "panel" + i);
		var tab = document.getElementById(panelID + "tab" + i);
		z = panel.style.zIndex
		// if clicked and not front, move to front
		if (i == n && z != ((numDiv * 2) - 1)) {
			z = numDiv + 98;
			t = numDiv + 99;
			c = 'tabactive';
		} else {
			z = (numDiv - i);
			t = z;
			c = 'tab';
		}
		panel.style.zIndex = z;
		tab.style.zIndex = t;
		tab.className = c;
	}
}

/* Show particular tab -and panel replaces selectTab above */
function showPanel(panel,size,Id) {
	for (var i = 0; i <= size; i++) {
		panelId = panel + i;
		element = document.getElementById(panelId);
		elementP = document.getElementById(panelId+"body");
		if (i == Id) {
			element.className = "tabsactive";
			elementP.style.display = "";
		} else {
			element.className = "";
			elementP.style.display = "none";
		}
	}
}

// Create a popup window 
// href defines the target url
// size (optional) defines the popup window size. e.q. 350x250
function popuphelp(href,size) {
  var dim = 'width=350,height=250';
  if (size) {
    var dims = size.split('x');
    dim = 'width='+ dims[0] +',height='+ dims[1];
  }
  if (href.indexOf("knowledgebase.iii") != -1){
    href += "__popup";
  }
  var popup = window.open(href, "popup", dim + ",scrollbars,resizable");
  popup.focus();
  return false;
}



var delay = 10000;
$(function() {
  // hide flash ticker when lightbox
  $('.thickbox').click(function(){
    $('#stockticker').hide();
  });
  
  var headline_count = $(".multistory").size();
  var headline_wait = 3000
  var headline_interval = setInterval(headline_rotate, headline_wait);
  var current_headline = 0;
  var old_headline = 0;
  var direction = +1;
  var headline_pause = 0;
  
  // set up page:
  $('.multistory').css({left: -800, opacity:1.0});
  $('span#headline-counter').html(current_headline + 1 +' of ' + headline_count);
  $(".multistory:eq(" + current_headline + ")").css({left: 0, zIndex: 0});
  $('#panelnav').show();
  $(".login").load('/login_box', {a: 'generic'});


  $('#carousel').hover(function() {
    if (headline_pause == 0) {
      clearInterval(headline_interval);
    }
  }, function() {
    if (headline_pause == 0) {
      clearInterval(headline_interval);
      headline_interval = setInterval(headline_rotate, headline_wait);
    }
  });

  $('#headline-next').click(function(){
    clearInterval(headline_interval);
    headline_interval = setInterval(headline_rotate, headline_wait);
    headline_rotate();
  })

  $('#headline-pause').toggle(function() {
    clearInterval(headline_interval);
    headline_pause = 1;
  }, function() {
    headline_pause = 0;
    clearInterval(headline_interval);
    headline_interval = setInterval(headline_rotate, headline_wait);
    headline_rotate();
  });

  function headline_rotate() {
    $(".multistory:eq(" + old_headline + ")").animate({left: -800,opacity:0.0},1250).css({zIndex: 1});
    current_headline = (old_headline + 1) % headline_count;
    $(".multistory:eq(" + current_headline + ")").css({left: 0, zIndex: 0,opacity:1.0});
    old_headline = current_headline;
    $('span#headline-counter').html(current_headline + 1 +' of ' + headline_count);
  }

  $('#next_headline').click(function(){
    clearInterval(headline_interval);
    headline_interval = setInterval(headline_rotate, headline_wait);
    headline_rotate();
    return false;
  })

  // iBall dropdown
  $(function() {
    $('#awsomarchiveformcustom select').change(function(){
      window.parent.location = $('#awsomarchiveformcustom select').val();
      return false;
    });
  });
  
  

});