// defines the breadcrumbs for the site
var breadcrumbs = [{Name:'Jane\'s DS Forecast', URL:'index.jsp'},
				   {Name:'Products', URL:'products/index.jsp'},
				   {Name:'Analysis & Articles', URL:'articles-analysis/index.jsp'},
				   {Name:'Markets', URL:'products/markets/index.jsp'},
				   {Name:'Budgets', URL:'products/budgets/index.jsp'}];

function displayFlashMovie(url, width, height, count) {
	// check for a count
	if (count != undefined) {
		// get a random number
		var random=Math.floor(Math.random()*count);
		
		// increment the number to make 1 based
		random = random + 1;
		
		// replace the # place holder with the random number
		url = url.replace('#',random);
	}
	
    // create the html for embedding the specified flash movie
    var obHTML = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="' + width + '" height="' + height + '">' +
                 '<param name="movie" value="' + url + '">' +
                 '<param name="quality" value="high">' +
                 '<embed src="' + url + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' + width + '" height="' + height + '"><\/embed>' +
                 '<\/object>'
    
    // write the html
    document.write(obHTML);
}

function displayFlashMovieInNewWindow(url, width, height, count) {
	// check for a count
	if (count != undefined) {
		// get a random number
		var random=Math.floor(Math.random()*count);
		
		// increment the number to make 1 based
		random = random + 1;
		
		// replace the # place holder with the random number
		url = url.replace('#',random);
	}
	
	// open the chart in a new window
	popupWindow(url,'514','770');
}

//--------------------------------------------------------------------------
// Function: doMain
//
// Description: This function takes the place of the real doMain function 
// that exists in DS Forecast. It allows the same charts to be displayed on 
// the website with out a javascript error occurring.
//--------------------------------------------------------------------------
function doMain(formElement, newValue) {
    // do nothing
}

//--------------------------------------------------------------------------
//Function: loadBreadcrumbs
//
//Parameters:
//		id - The id of the html tah that will contain the breadcrumbs.
//		crumbs - An array of breadcrumb indices in the order to display them.
//		page_title - The title for the current page.
//
//Description: Create a list of clickable breadcrumbs based on the supplied.
// parameters.
//--------------------------------------------------------------------------
function loadBreadcrumbs(id, crumbs, page_title) {
	// init vars
	var breadcrumb;
	
	// create buffer
	var buffer = new Array();
	
	// loop through crumbs
	for (var i=0;i<crumbs.length;i++) {
		// get the breabcrumb
		breadcrumb = breadcrumbs[crumbs[i]];
		
		// add the breadcrumb to the buffer
		buffer.push('<a title="' + breadcrumb.Name + '" href="' + breadcrumb.URL + '">' + breadcrumb.Name + '</a> &gt; ');	
	}
	
	// add the current page title
	buffer.push(page_title);
	
	// get the element and set the html
	document.getElementById(id).innerHTML = buffer.join('');
}

//--------------------------------------------------------------------------
// Function: loadDSForecast
//
// Parameters:
//		instance - The name of the instance to load.
// 
// Description: Opens the specified instance of DS Forecast.
//--------------------------------------------------------------------------
function loadDSForecast(instance) {
  	// make sure an instance was supplied
  	if (instance != '') {
     	// redirect the user to the specified instance -- added 9/28/07
     	document.location = 'https://dsforecast.janes.com/' + instance + '/';
  	}
}

function loadSectionHeader(section) {
	// get the img element
	var img = document.getElementById('header_img');
	
	// set the image
	img.src = 'images/header/sections/' + section + '.jpg';
}

//---------------------------------------------------------------------------------
//Function: loadWidgets
//
//Parameters:
//		context - A context path to the current web application. The context is
//				  to resolve file and image paths.
//		section - Indicates the current section. Determines which tba is selected.
//
//Description:

//The loadWidgets function binds the html objects to javascript objects.
//---------------------------------------------------------------------------------
function loadWidgets(context, section) 
{
	// init vars
	var tab;
	
	// set the image path
	var path = context + "images/header/tabs/";
	
	// get a new widgets object
	var widgets = new Widgets();
	
	// load tabs
	tab = new ImageTab("home", document.getElementById("tabs.home"));
	tab.setOver(path + "home-tab-over.gif");
	tab.setOn(path + "home-tab-on.gif"); 
	widgets.addTab(tab);
	
	tab = new ImageTab("products", document.getElementById("tabs.products"));
	tab.setOver(path + "products-tab-over.gif");
	tab.setOn(path + "products-tab-on.gif"); 
	widgets.addTab(tab);
	
	tab = new ImageTab("analysis-articles", document.getElementById("tabs.analysis-articles"));
	tab.setOver(path + "analysis-articles-tab-over.gif");
	tab.setOn(path + "analysis-articles-tab-on.gif"); 
	widgets.addTab(tab);
	
	tab = new ImageTab("events", document.getElementById("tabs.events"));
	tab.setOver(path + "events-tab-over.gif");
	tab.setOn(path + "events-tab-on.gif"); 
	widgets.addTab(tab);
	
	tab = new ImageTab("inside-ds", document.getElementById("tabs.inside"));
	tab.setOver(path + "inside-tab-over.gif");
	tab.setOn(path + "inside-tab-on.gif"); 
	widgets.addTab(tab);
	
	// get tabs
	var tabs = widgets.getTabs();
	
	// activate the appropriate tab based on the section name
	for (var i=0; i<tabs.length; i++) {
		// compare the name to the page
		if (tabs[i].getName() == section) {
			// activate the tab
			tabs[i].activate();
		}
	}
}

function popupWindow(url,height,width) {
	// open a popup window
	window.open(url,'_blank','location=no,height=' + height + ',left=20,menubar=no,resizeable=no,screenX=20,screenY=20,scrollbars=no,toolbar=no,top=20,width=' + width);
}