﻿var contentPairs = {
	"home-nav":"home_content",
	"equity-research":"equity_research_content",
	"factor-analysis":"factor-analysis-content",
	"multi-factor-models":"multi-factor-models-content",
	"portfolio-alerts":"portfolio-alerts-content",
	"trading-analytics":"trading-analytics-content",
	"sign-in": "signin-content"
};

var bottomContentPairs = {
	"contact":"contact-container",
	"press-kit":"press-kit-container",
	"careers":"careers-container",
    "leadership":"leadership-container",
    "recentlinks":"recent-links-container"
};

var subBottomCareersContentPairs = {
	"it-tech-analyst-data":"it-tech-analyst-data-content",
	"it-tech-analyst":"it-tech-analyst-content",
	"research-analyst":"research-analyst-content",
	"trading-analyst":"trading-analyst-content"
};

var subBottomLeadershipContentPairs = {
	"TIM_SARGENT" : "TIM_SARGENT-content",
	"JOHN_JOSEPH" : "JOHN_JOSEPH-content",
	"DAN_BUKOWSKI" : "DAN_BUKOWSKI-content",
	"GEORGE_BODINE" : "GEORGE_BODINE-content",
	"MINGBO_QIN" : "MINGBO_QIN-content",
	"MIKE_STRITCH" : "MIKE_STRITCH-content",
	"STUART_TOLANDER" : "STUART_TOLANDER-content",
	"ALEX_HAGMEYER" : "ALEX_HAGMEYER-content"
};

// We need a pointer to the default item that's displayed.
// When a new nav item gets selected, it'll set itself to this variable
// so that the next item clicked knows which one to turn off.
// The $ means we're loading the actual HTML element, 
// not just a string that happens to match the ID, like we're doing above
var currentNav = $("home-nav");

var bottomCurrentNav = $("contact");

var subBottomCareersCurrentNav = $("it-tech-analyst-data");
var subLeadershipCurrentNav = $("TIM_SARGENT");

function ShowTopNav(navid)
{
    var thisnav = $(navid);
    if(currentNav != thisnav)
    { //we need this so that we don't fade out the content completely if the user clicks the selected item
		var thisContentID = contentPairs[thisnav.get("id")]; 			// grab the nav item's ID and pass it to our assignment object to get the content ID
		var thisContentEl = $(thisContentID); 						// using that content ID, grab that element from the html so we can do stuff with it

		var currentContentID = contentPairs[currentNav.get("id")]; // grab the current item's ID and pass it to our assignment object to get the content ID
		var currentContentEl = $(currentContentID); 				// using the content ID, grab the content element from the html so we can do stuff with it			
						
		// set up a FADE IN effect object
		var inFx = new Fx.Morph(thisContentEl,{"transition":Fx.Transitions.Quart.easeOut,"duration":300});
		
		// set up a FADE OUT effect object
		var outFx = new Fx.Morph(currentContentEl,{"transition":Fx.Transitions.Quart.easeOut,"duration":300});
		// set the display style on the content object to block
		// we still can't see it because of the opacity but when we fade, we'll see it
		thisContentEl.setStyle("display","block");

								// run the fade in, opacity from 0 to 1
		outFx.start({"opacity":[1,0]}).chain(function(){
				inFx.start({"opacity":[0,1]}); 	 			// run the fade out, opacity from 1, to 0
			currentContentEl.setStyle("display","none"); 			// and chain a function on the fade out so we can set the display to none when it's done fading
		});

		currentNav.removeClass("selected") 							// remove the "selected" class from the current nav item

		currentNav = thisnav; 											// set the currently selected item to the clicked item
		thisnav.addClass("selected"); 									// add the "selected" class to the clicked item
	}
	
	//Remember current top nave
	var topnav = document.getElementById('hdnTopNav');
	topnav.value = navid;
}

function ShowPic(id)
{
    var rowTab = $('rowTab');
    var i;
    var rowid;
    for(i = 0; i <= 4; i++)
    {
        rowid = 'row' + i;
        var thisnav = $(rowid);
        if(i == id)
        {
            thisnav.setStyle("display", "block");        
            rowTab.cells[i].className = 'SelectedTab';
        }
        else
        {
            thisnav.setStyle("display", "none");
            if(i == 4)
            {
                rowTab.cells[i].className = 'RightTab';
            }
            else if(i == 0)
            {
                rowTab.cells[i].className = 'LeftTab';
            }
            else
            {
                rowTab.cells[i].className = 'DefaultTab';
            }
        }
    }
}

function ShowBottomNav(navid)
{
    var thisnav = $(navid);
    if(bottomCurrentNav != thisnav)
    { 
        //we need this so that we don't fade out the content completely if the user clicks the selected item
    	var thisContentID = bottomContentPairs[thisnav.get("id")]; 			// grab the nav item's ID and pass it to our assignment object to get the content ID
		var thisContentEl = $(thisContentID);

		var bottomCurrentContentID = bottomContentPairs[bottomCurrentNav.get("id")]; // grab the current item's ID and pass it to our assignment object to get the content ID
		var bottomCurrentContentEl = $(bottomCurrentContentID); 				// using the content ID, grab the content element from the html so we can do stuff with it			

		// set up a FADE IN effect object
		var inFx = new Fx.Morph(thisContentEl,{"transition":Fx.Transitions.Quart.easeOut,"duration":400});

		// set up a FADE OUT effect object
		var outFx = new Fx.Morph(bottomCurrentContentEl,{"transition":Fx.Transitions.Quart.easeOut,"duration":400});

		// set the display style on the content object to block
		// we still can't see it because of the opacity but when we fade, we'll see it
		thisContentEl.setStyle("display","block");
	
		inFx.start({"opacity":[0,1]}); 								// run the fade in, opacity from 0 to 1
		outFx.start({"opacity":[1,0]}).chain(function(){ 			// run the fade out, opacity from 1, to 0
			bottomCurrentContentEl.setStyle("display","none"); 			// and chain a function on the fade out so we can set the display to none when it's done fading
		});

		bottomCurrentNav.removeClass("selected") 							// remove the "selected" class from the current nav item

		bottomCurrentNav = thisnav; 											// set the currently selected item to the clicked item
		thisnav.addClass("selected"); 									// add the "selected" class to the clicked item
	}
	
	var myFx = new Fx.Scroll(window, {"transition":Fx.Transitions.Quart.easeOut,"duration":400}).toBottom();
}
	
function ShowCareerNav(navid)
{
    var thisnav = $(navid);
    if(subBottomCareersCurrentNav != thisnav)
    { //we need this so that we don't fade out the content completely if the user clicks the selected item
		var thisContentID = subBottomCareersContentPairs[thisnav.get("id")]; 			// grab the nav item's ID and pass it to our assignment object to get the content ID
		var thisContentEl = $(thisContentID);

		var subBottomCurrentContentID = subBottomCareersContentPairs[subBottomCareersCurrentNav.get("id")]; // grab the current item's ID and pass it to our assignment object to get the content ID
		var subBottomCurrentContentEl = $(subBottomCurrentContentID); 				// using the content ID, grab the content element from the html so we can do stuff with it			

		// set up a FADE IN effect object
		var inFx = new Fx.Morph(thisContentEl,{"transition":Fx.Transitions.Quart.easeOut,"duration":400});

		// set up a FADE OUT effect object
		var outFx = new Fx.Morph(subBottomCurrentContentEl,{"transition":Fx.Transitions.Quart.easeOut,"duration":400});

		// set the display style on the content object to block
		// we still can't see it because of the opacity but when we fade, we'll see it
		thisContentEl.setStyle("display","block");

		inFx.start({"opacity":[0,1]}); 								// run the fade in, opacity from 0 to 1
		outFx.start({"opacity":[1,0]}).chain(function(){ 			// run the fade out, opacity from 1, to 0
			subBottomCurrentContentEl.setStyle("display","none"); 			// and chain a function on the fade out so we can set the display to none when it's done fading
		});

		subBottomCareersCurrentNav.removeClass("selected") 							// remove the "selected" class from the current nav item

		subBottomCareersCurrentNav = thisnav; 											// set the currently selected item to the clicked item
		thisnav.addClass("selected"); 									// add the "selected" class to the clicked item
	}
}


function ShowLeadershipNav(navid)
{
    var thisnav = $(navid);
    if(subBottomLeadershipCurrentNav != thisnav)
    { //we need this so that we don't fade out the content completely if the user clicks the selected item
		var thisContentID = subBottomLeadershipContentPairs[thisnav.get("id")]; 			// grab the nav item's ID and pass it to our assignment object to get the content ID
		var thisContentEl = $(thisContentID);

		var subBottomCurrentContentID = subBottomLeadershipContentPairs[subBottomLeadershipCurrentNav.get("id")]; // grab the current item's ID and pass it to our assignment object to get the content ID
		var subBottomCurrentContentEl = $(subBottomCurrentContentID); 				// using the content ID, grab the content element from the html so we can do stuff with it			

		// set up a FADE IN effect object
		var inFx = new Fx.Morph(thisContentEl,{"transition":Fx.Transitions.Quart.easeOut,"duration":400});

		// set up a FADE OUT effect object
		var outFx = new Fx.Morph(subBottomCurrentContentEl,{"transition":Fx.Transitions.Quart.easeOut,"duration":400});

		// set the display style on the content object to block
		// we still can't see it because of the opacity but when we fade, we'll see it
		subBottomCurrentContentEl.setStyle("display","none");
		thisContentEl.setStyle("display","block");

		inFx.start({"opacity":[0,1]}); 								// run the fade in, opacity from 0 to 1
		outFx.start({"opacity":[1,0]}).chain(function(){ 			// run the fade out, opacity from 1, to 0
			subBottomCurrentContentEl.setStyle("display","none"); 			// and chain a function on the fade out so we can set the display to none when it's done fading
		});

		subBottomLeadershipCurrentNav.removeClass("selected") 							// remove the "selected" class from the current nav item

		subBottomLeadershipCurrentNav = thisnav; 											// set the currently selected item to the clicked item
		thisnav.addClass("selected"); 									// add the "selected" class to the clicked item
	}
}


function ShowHomeNav()
{
    var thisnav = $("home-nav");
    if(true){ 
		var currentContentID = contentPairs[currentNav.get("id")]; // grab the current item's ID and pass it to our assignment object to get the content ID
		var currentContentEl = $(currentContentID);
	
	    if (currentNav != $("home-nav"))
	    {	
		    var outFx = new Fx.Morph(currentContentEl,{"transition":Fx.Transitions.Quart.easeOut,"duration":400});
		    outFx.start({"opacity":[1,0]}).chain(function(){ 			// run the fade out, opacity from 1, to 0
			    currentContentEl.setStyle("display","none"); 			// and chain a function on the fade out so we can set the display to none when it's done fading
		    });
		}
		
	    var inFx = new Fx.Morph("home_content",{"transition":Fx.Transitions.Quart.easeOut,"duration":400});
	    $("home_content").setStyle("display","block");

	    inFx.start({"opacity":[0,1]}); 								// run the fade in, opacity from 0 to 1
		
	    currentNav.removeClass("selected") 							// remove the "selected" class from the current nav item
	    currentNav = thisnav; 	
	}	
	
	var topnav = document.getElementById('hdnTopNav');
	topnav.value = '';
}

function RequestResearch(reportName)
{
    fillForm(reportName);
}

function RequestButtonClicked()
{
    populateForm();
}

populateForm = function(){
    var checkedTitles = "";
    var idx = 1;
	var checkedItems = $$("input[type=checkbox]");
	checkedItems.each(function(check){
		if(check.getProperty("checked")==true)
		{
			var parent = check.getParent("td").getParent("tr");
			var tds = parent.getChildren("td");
			checkedTitles += idx + ". " + tds[2].get("text") + "\n";
			idx += 1;
		}
	});
	if (checkedTitles != "")
	{
	    checkedTitles = "I'm interested in requesting:\n" + checkedTitles;
	}

	var commentFill = $("txtComments");
	commentFill.set("text", checkedTitles);
	
	ShowBottomNav("contact");
}

fillForm = function(reportName) {
    if (reportName != "")
	{
	    reportName = "I'm interested in requesting:\n" + reportName;
	}

	var commentFill = $("txtComments");
	commentFill.set("text", reportName);
	
	ShowBottomNav("contact");
}
