﻿
    var currentSymbol="";
    var currentType="stock";
    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;
            
            var thisType = "stock";
            if (isTwitPic){
                //rLeft = rLeft-100;
                rTop -= 120
                rBottom = rTop + 650;
                thisType = "img";
            }
            
            
            //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 || currentType!=thisType || (objMini.innerHTML).indexOf("Loading") != -1){
                if (isTwitPic){
                    objMini.innerHTML = "<div style='padding:15px;'>Loading Image...</div>"
                    quoteTimeout=setTimeout("GetTwitImage('"+symbol+"')",750);
                    currentType="img";
                }
                else {
                    objMini.innerHTML = "<div style='padding:15px;'>Loading Chart...</div>"
                    quoteTimeout=setTimeout("GetChart('"+symbol.toUpperCase()+"')",750);
                    currentType="stock";
                }
            }
            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 = ''
        //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>'
//        html += '<iframe scrolling="no" width="265" height="225" '
//        html += 'src="QM-Stock-Chart.aspx?scale=5d&symbol=' + symbol + '&w=262&h=197&simple=1" '
//        html += 'frameborder="0"></iframe>'
        html += '</div><iframe scrolling="no" width="265" height="219" '
        html += 'src="http://pennystocksmedia.com/stock-chart-quote.aspx?scale=1y&symbol=' + symbol + '&w=262&h=197&simple=1" '
        html += 'frameborder="0"></iframe>'
        //html += '<script type="text/javascript" src="http://app.quotemedia.com/quotetools/miniQuotes.go?toolWidth=224&chscale=1m&chtype=FinancialCandleStick&chhig=198&symbols=<%=ViewState("rStock")%>&webmasterId=90699&section=mini_quote&theme=theme1"></script>'
        //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 = ''
        html += '<img '
        //html += 'src="http://twitpic.com/show/large/' + twitPicID + '.jpg" '
        html += 'src="' + twitPicID + '" width="350" height="350" '
        html += ' />'
//        html += '<iframe scrolling="no" width="450" height="250" '
//        html += 'src="' + twitPicID + '" '
//        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;
    }