//mail

function createMail(){
    var mailTo = "press@intrade.com";
    var mailSubject = "Register Me For A Webinar";

    var link = "mailto:"+mailTo;
    link += "?subject=" + mailSubject;    
      
    window.location.href = link;
}

//end mail

//tabs

var currentLoadingTabIndex = 1;

function initTabs(){
    loadTab();
}

function loadTab(){
    if(!$('tab' + currentLoadingTabIndex))
        return;

    url = '/jsp/intrade/home/tabLoader.jsp?tabIndex=' + currentLoadingTabIndex;

    url += (url.indexOf("?") == -1 ? "?" : "&") + "z=" + new Date().getTime();

    ajaxReq = new Ajax.Request(url,
        {
            method: 'get',
            onSuccess: tabLoadResponse
        });
}

function tabLoadResponse(response){
    $('tabContent' + currentLoadingTabIndex).innerHTML = response.responseText;
    
    currentLoadingTabIndex++;

    loadTab();
}

var selectedTabIndex = 1;

function changeTab(index){
    
    //get rid of explain div    
    YAHOO.intrade.explainPanel.hide(); 
        
    if(index==selectedTabIndex)
        return;
        
    $('tab' + selectedTabIndex).removeClassName("selected");
    $('tab' + selectedTabIndex).addClassName("unselected");
    $('tabContent' + selectedTabIndex).hide();
    
    $('tab' + index).removeClassName("unselected");
    $('tab' + index).addClassName("selected");
    $('tabContent' + index).show();       

    selectedTabIndex = index;
}

//end tabs

//videos

videoLinkArray = new Array();

videoLinkArray [0] = "http://www.youtube.com/v/GWfOIZP2Nag";
videoLinkArray [1] =  "http://www.youtube.com/v/Fxmxyljo8Ag";
videoLinkArray [2] =  "http://www.youtube.com/v/hxE60z_6vYo";
videoLinkArray [3] = "http://www.youtube.com/v/iT6OHCQR1hs";
videoLinkArray [4] = "http://www.youtube.com/v/8ZmCNrgI1IY";
videoLinkArray [5] = "http://www.youtube.com/v/qJ8t0bF8JOg";
videoLinkArray [6] = "http://www.youtube.com/v/7k4K3lnBN10";
videoLinkArray [7] = "http://www.youtube.com/v/dvlaVrXJn7w";
videoLinkArray [8] = "http://www.youtube.com/v/9Rcw78Cfyyk";
videoLinkArray [9] = "http://www.youtube.com/v/i7kBzDE9Biw";
videoLinkArray [10] = "http://www.youtube.com/v/QW46V4XNxwY";

videoHeaderArray = new Array();

videoHeaderArray [0] = "Intrade CEO Talks To CNBC";
videoHeaderArray [1] = "Erin Burnett Talks About Intrade";
videoHeaderArray [2] = "Intrade US Presidential Futures";
videoHeaderArray [3] = "Welcome To Intrade";
videoHeaderArray [4] = "Trading 101";
videoHeaderArray [5] = "Intrade on Kudlow";
videoHeaderArray [6] = "Intrade on Bloomberg";
videoHeaderArray [7] = "Intrade on Fox";
videoHeaderArray [8] = "Intrade on CNBC";
videoHeaderArray [9] = "Intrade on CNBC #2";
videoHeaderArray [10] = "Intrade on ABC 20/20";

function loadVidWindow(index){
    url = videoLinkArray [index-1];
    header = videoHeaderArray [index-1];

    win = window.open('/jsp/intrade/home/vid_window.jsp?url=' + url + '&header=' + header, 
        'vidWindow', 
        'width=515,height=440,resizable=1');

    if(win)//if popup allowed
        win.focus();
    
}

function loadVid(index){
    vidURL = videoLinkArray [index-1];

    vidHeader = $('vidEmbedText');
    vidHeader.innerHTML = videoHeaderArray [index-1];

    vidEm = document.getElementById('vidEmbed');    
    vidEm.src = vidURL;   
    
    $('vidPlayer').innerHTML = $('vidHolder').innerHTML;
}

//end videos

//explain div

var selectedContractID;
var selectedContractGraphURL;
var selectedContractName;
var lastPrice;
var lastPriceDollars;

function showExplain(contractID){
    
    selectedContractID = contractID;    
    selectedContractGraphURL = $(contractID + "_graphURL").innerHTML;
    selectedContractName = $(contractID + "_contractName").innerHTML;;
    lastPrice = $(contractID + "_lastPrice").innerHTML;;
    
    lastPriceDollars = (lastPrice/10.0).toFixed(2);
    
    div = $('explainDiv');
    
    lastPriceSpans = document.getElementsByName('lastPriceSpan');

    for(i=0; i<lastPriceSpans.length; i++)
        lastPriceSpans [i].innerHTML = lastPrice;  
    
    screenWidth = document.body.offsetWidth;
    
    lastPriceDollarsSpan = $('lastPriceDollars');

    lastPriceDollarsSpan.innerHTML = lastPriceDollars;

    $('contractName').innerHTML = selectedContractName;
    
    YAHOO.intrade.explainPanel.show();      
}

//end explain div