var InvestmentChanceViewer = function(investment, lin)
{
    $imgcon=investment;
    $investments = {};
    $lastIndex = -1;
    $images=[];
    init = function()
    {
        $.getJSON("/Estates/GetInvestmentChances.aspx?f="+getRandom(), function(data){$investments=data.estates;if($investments!=null && $investments!=undefined)showImage();})
    }
    
    function showImage()
    {
        $(investment).fadeOut("slow", function(){
        $(investment).unbind("click",InvestmentClick);
        var largeImage = new Image();
        var statement = $("<span/>");
        var seperator = $("<div class=\"investsep\">&nbsp;</div>");
        var src = '';
        var i=getNextIndex();
        if ($investments[i].DisplayPicture != null)
        {
            src ="/image/i.aspx?img=/emlakresimleri/"+ $investments[i].EstateId+"/"+$investments[i].DisplayPicture.PictureName + "&size=190x140&g="+getRandom();
        }
        else 
            src = "";
        statement.text($investments[i].InvestmentStatements);
        $(largeImage).attr("src", src).css("display","block")
             .load(function()
             	{
                    $(investment).empty();
                    $(investment).bind("click",InvestmentClick);
                    $(investment).append(largeImage).append(seperator).append(statement);
                    $(investment).fadeIn("slow", function(){window.setTimeout(showImage,4000);});                  
                });     
        }  
        );                                                            
    }
       
    getNextIndex =function()
    {
        $lastIndex = ($lastIndex + 1) % $investments.length;
        return $lastIndex;
    }
    InvestmentClick = function()
    {
        if(lin)
            window.location.href="/yonetim/EstateEdit.aspx?ei="+$investments[$lastIndex].EstateId;
        else 
            window.location.href="/ayrinti.aspx?ei="+$investments[$lastIndex].EstateId;
    }
   init();
}