﻿
    var currentSymbol="";
    var quoteTimeout;
    function ShowQuote(obj, symbol, isTwitPic){
        var par=obj;
        var totalOffsetLeft=obj.offsetLeft;
        var totalOffsetTop=obj.offsetTop;
        //if (document.all){
            for (i=0;i<10;i++){
                if (par.offsetParent){
                    par=(par.offsetParent);
                    totalOffsetLeft += par.offsetLeft;
                    totalOffsetTop += par.offsetTop;
                }
            }
        //}
        
        //---------------------
        var theWindowHeight=0;
        var theWindowWidth=1000;
        
        if(window.innerHeight){
            theWindowHeight = window.innerHeight-0;
            theWindowWidth = window.innerWidth-0;
        }
        if(document.body.clientHeight){
            theWindowHeight = document.body.clientHeight-0;
            theWindowWidth = document.body.clientWidth-0;
        }
        if(document.documentElement.clientHeight){
            theWindowHeight = document.documentElement.clientHeight-0;
            theWindowWidth = document.documentElement.clientWidth-0;
        }
        var theWindowYOffset=0;
        var theWindowXOffset=0;
        
        if (window.pageYOffset){
            theWindowYOffset = window.pageYOffset-0;
            theWindowXOffset = window.pageXOffset-0;
        }
        if(document.documentElement.scrollTop){
            theWindowYOffset=document.documentElement.scrollTop-0;
            theWindowXOffset=document.documentElement.scrollLeft-0;
        }
        
            //alert(theWindowHeight + " " + theWindowYOffset);
            var absoluteBottom = theWindowYOffset+theWindowHeight;
            var absoluteRight = theWindowXOffset+theWindowWidth;
            
            var rLeft = (totalOffsetLeft + obj.offsetWidth)-95;
            var rRight = rLeft + 450;

            var BoxHeight = 265;
            var rTop = totalOffsetTop + 20;
            var rBottom = rTop + BoxHeight;
            
            if (isTwitPic){
                //rLeft = rLeft-100;
                rBottom = rTop + 355;
            }
            
            
            //alert(rBottom + " : " + absoluteBottom);
        
            if (rBottom > absoluteBottom){
                rTop = (rTop - BoxHeight);
                
            }
            if (rRight > absoluteRight){
            ///alert(1)
                rLeft = (rLeft - (rRight-absoluteRight))-170;
            }
        
            var objMini = document.getElementById("divMiniQuote");
            objMini.style.display="";
            objMini.style.left= rLeft + "px";
            objMini.style.top = rTop + "px";
            
            
            
            if (currentSymbol != symbol){
                if (isTwitPic){
                    objMini.innerHTML = "<div style='padding:15px;'>Loading Image...</div>"
                    quoteTimeout=setTimeout("GetTwitImage('"+symbol+"')",750);
                }
                else {
                    objMini.innerHTML = "<div style='padding:15px;'>Loading Chart...</div>"
                    quoteTimeout=setTimeout("GetChart('"+symbol.toUpperCase()+"')",750);
                }
            }
            else{
                clearTimeout(quoteTimeout);
                //quoteTimeout=setTimeout("",500);
            }
    }
    function GetChart(symbol){
        currentSymbol=symbol;
        clearTimeout(quoteTimeout);
        var objMini = document.getElementById("divMiniQuote");
        objMini.innerHTML = GetChartHTML(currentSymbol);
    }
    function GetTwitImage(symbol){
        currentSymbol=symbol;
        clearTimeout(quoteTimeout);
        var objMini = document.getElementById("divMiniQuote");
        objMini.innerHTML = GetTwitPicHTML(currentSymbol);
    }
    
    function HideQuote(){
        clearTimeout(quoteTimeout);
        var objMini = document.getElementById("divMiniQuote");
        objMini.style.display="none";
    }
    
    function GetChartHTML(symbol){
        var html = '<div style="text-align:center;font-size:11pt;">'
        html += '<b>'+symbol+' Chart</b> '
        //html += '<a style="font-size:10pt;margin-left:15px;" '
        //html += 'href="javascript:void(0);" onclick="HideQuote();">Close Chart [X]</a>'
        html += '</div><iframe scrolling="no" width="265" height="215" '
        html += 'src="http://pennystocksmedia.com/stock-chart-quote.aspx?symbol=' + symbol + '&isForexMini=1" '
        html += 'frameborder="0"></iframe>'
        //html += '<div align="center" style="background-color:#ffffcc;margin:7px;padding:2px;border:1px solid #e8e8e8;">Go to <a href="Stock-Quotes.aspx?stock='+symbol+'">'+symbol+'`s Full Quote</a></div>'
        
        return html;
    }
    
    function GetTwitPicHTML(twitPicID){
    
        
    
        var html = '<div style="text-align:center;font-size:11pt;">'
        html += '<img '
        html += 'src="http://twitpic.com/show/large/' + twitPicID + '.jpg" '
        html += ' />'
        //html += '<div align="center" style="background-color:#ffffcc;margin:7px;padding:2px;border:1px solid #e8e8e8;">Go to <a href="Stock-Quotes.aspx?stock='+symbol+'">'+symbol+'`s Full Quote</a></div>'
        
        return html;
    }