var view2ticker = "";
//SKRIPTA ZA PUNJENJE VEZANIH BOX-eva
function view2clickTicker(table) {
  $(table+" td").not(".mark").click(function(){   
    $("#view2tbl tr").removeClass("active");
    $("#view2_box2 table tr").removeClass("active");
		$(this).parents("tr").addClass("active");
		view2ticker = $(this).parents("tr").attr("rel");
		$("#view2_box3 .inner").html("");
		$("#view2_box4 .inner > div object").remove();
		$("#view2_box4 .inner > div").html("");
		$("#view2_box5 .inner > div").html("");
		view2box3(view2ticker);
    switch ($("#view2_box4 .boxnav .on").attr("id")) {
      case "view2_box4_link1":
          graphBox3(view2ticker);
        break;
      case "view2_box4_link2":
          sentimentInt(view2ticker);
        break;
      case "view2_box4_link3":
          newsBox3(view2ticker);
        break;    
    }
    switch ($("#view2_box5 .boxnav .on").attr("id")) {
      case "view2_box5_link1":
          basicBox4(view2ticker);
        break;
      case "view2_box5_link2":
          fundamentBox4(view2ticker);
        break;
      case "view2_box5_link3":
          tehnicalBox3(view2ticker);
        break;
      case "view2_box5_link4":
          analBox3(view2ticker);
        break;    
    }
    return false;
	});
}

//UBACIVANJE STRELICE ZA LOGIN KOD MANJE REZOLUCIJE
$(document).ready(function() {
    if(scrRes=="small"){
        $("#header").after('<img src="'+urlRoot+'images/logButton.gif" alt="Prijavite se na Investa.hr" title="Prijavite se na Investa.hr" id="logTempButt" />');
        $("#logTempButt").toggle(
            function(){
                $pageDimensions=pageDimensions();
                var scrollAmount = $pageDimensions[1] - $(window).width();
                $("html, body").animate({scrollLeft:scrollAmount}, 200);
                $("#logTempButt").attr("src",""+urlRoot+"images/logButtonBack.gif");
            },
            function(){
                $("html, body").animate({scrollLeft:0}, 200);
                $("#logTempButt").attr("src",""+urlRoot+"images/logButton.gif");
            }
        ); 
    }
});

//RIGHT COLUMN SCROLL
/*
$(document).ready(function() {
    var view2_column_offset = $("#stock_view2_wrapper #content").offset();
    $(window).scroll(function () {
        if ( ($("#stock_view2_wrapper #content").height()-36) > $(window).height() ) { return false; }
        if ( $(window).scrollTop() > (view2_column_offset.top+36) ) { $("#stock_view2_wrapper #content").css("padding-top",$(window).scrollTop()-(view2_column_offset.top+36) );}
		else { $("#stock_view2_wrapper #content").css("padding-top","0"); }
    });
});*/
//BOX 1
function tblSorter(tblName,trigger) {
 	$(tblName).tablesorter({ 
      headers: {
          2: { sorter:'investaNum' },
          3: { sorter:'investaPrecent' },
          4: { sorter:'investaNum' },
          5: { sorter:'investaNum' },
          6: { sorter:'investaNum' },
          7: { sorter:'investaNum' },
          8: { sorter:'investaNum' },
          9: { sorter:'investaNum' }
      } 
  }); 
 	$(tblName).trigger("update");
	var colLength = ( $(tblName+" col").length );
	for (i=0;i<=colLength;i++) {
		$(trigger+i).toggle(
			function () {
				var calicon = $(this).attr("id");
				var sorting = [[calicon.substring(11),0]];
        $(tblName).trigger("sorton",[sorting]);
        return false;
			},
			function () {
				var calicon = $(this).attr("id");
				var sorting = [[calicon.substring(11),1]];
				$(tblName).trigger("sorton",[sorting]);
				return false;
			}
		);
	}
}

function view2box1autoComplete(ticker) {
    $.get(urlRoot+"index.php?page=updateUserApartStocks&action=insert&stock="+ticker, function(data){
        var columns = new Array();
      	for ( i=4; ($("#view2tbl_head th").length-1) > i; i++ ) {
      	  columns[i-4] = $("#view2tbl_head th:eq("+i+")").attr("rel");
      	}
      	columnsStr = "name|last|button|precent|buy|sell|sector|"+columns.join("|");
        $.getJSON(urlRoot+"index.php?page=stocksApartBox&ticker="+ticker,{data: columnsStr}, function(data){
            if( $("#view2tbl tbody tr").length == 0  ){
                $("#view2_box1_stock").show();
                $("#view2_box1_nostock").hide();
            }
            $("#view2tbl tbody").append('<tr rel="'+data.ticker+'"><td class="name">'+data.ticker+'</td><td class="alg_center">'+data.sector+'</td><td class="lastprice">'+data.last+'</td><td class="precent '+data.button+'"><img src="'+urlRoot+'images/ICON'+data.button+'.gif" alt="rast" height="15" width="14">('+data.precent+'%)</td><td class="alg_right" rel="'+columns[0]+'">'+data[columns[0]]+'</td><td class="alg_right" rel="'+columns[1]+'">'+data[columns[1]]+'</td><td class="alg_right" rel="'+columns[2]+'">'+data[columns[2]]+'</td><td class="alg_right" rel="'+columns[3]+'">'+data[columns[3]]+'</td><td class="alg_right '+((scrRes=="small")?"noSmall":"")+'" rel="'+columns[4]+'">'+data[columns[4]]+'</td><td class="alg_right last" rel="'+columns[5]+'">'+data[columns[5]]+'</td><td class="mark"><img src="'+urlRoot+'images/ICONclose.gif" alt="izbriši"></td></tr>');
            over_hover ("#view2_box1 tr");
            view2clickTicker("#view2tbl");
            $("#view2tbl").trigger("update");
            $("#view2tbl2cont1").trigger("update"); 
            $("#view2_box1 .mark img").unbind("click");
            $("#view2_box1 .mark img").click(function(){
                if($(this).is(".inProcess")){ return false; }
                $(this).addClass("inProcess");
                stockGridRemove($(this));
            });
        });
	   });
}


$(document).ready(function() {
  tblSorter("#view2tbl","#box1trigger");
	tbl_dropdown ("#view2_box1 th");
	clearInputs ("#view2_box1 .ex_stock input");
	$("#view2_box1 .ex_stock input").autocomplete(urlRoot+"index.php?page=autocomplete&type=stock&partial=1");
  jQuery("#view2_box1 .ex_stock input").result(function(event, data, formatted) {
    var pattern = new RegExp("<");
    pattern.test(formatted.substring(9,formatted.length));
    view2box1autoComplete(RegExp.leftContext);
  });
});
//BOX 2
function tblSorter2(tblName,trigger) {
 	$(tblName).tablesorter({ 
      headers: {
          2: { sorter:'investaNum' },
          3: { sorter:'investaPrecent' },
          4: { sorter:'investaNum' },
          5: { sorter:'investaNum' },
          6: { sorter:'investaNum' },
          7: { sorter:'investaNum' },
          8: { sorter:'investaNum' },
          9: { sorter:'investaNum' }
      } 
  }); 
 	$(tblName).trigger("update");
	var colLength = ( $(tblName+" col").length );
	for (i=0;i<=colLength;i++) {
		$(trigger+i).toggle(
			function () {
				var calicon = $(this).attr("id");
				var sorting = [[calicon.substring(16),0]];
        $(tblName).trigger("sorton",[sorting]);
        return false;
			},
			function () {
				var calicon = $(this).attr("id");
				var sorting = [[calicon.substring(16),1]];
				$(tblName).trigger("sorton",[sorting]);
				return false;
			}
		);
	}
}

function shoeHideBox2(con) {
  $("#view2_box2_content1").hide();
  $("#view2_box2_content2").hide();
  $("#view2_box2_content3").hide();
  $("#view2_box2_content4").hide();
  $("#view2_box2_content5").hide();
  $("#view2_box2_content"+con).show();
}


$(document).ready(function() {
  over_hover ("#view2_box2_link1 ul li");
  $("#view2_box2_link1 ul li").click(function(){
      var filter = $(this).attr("rel");
      var name = $(this).text();
      if (filter=="active") {
          $.get(urlRoot+"index.php?page=stockView2Box2Content&content=1&type=active", function(data){
              $("#view2_box2_content1").html(data);
              tblSorter2("#view2tbl2cont1","#box2cont1trigger");
              tbl_dropdown ("#view2_box1_stock");
              tbl_dropdown ("#view2_box2_content1");
            	over_hover ("#view2_box2_content1 tr");
            	tbl_dropdown("#view2_box2_content1 th");
            	view2clickTicker("#view2_box2_content1 table");
          });
      }
      if (filter=="all") {
          $.get(urlRoot+"index.php?page=stockView2Box2Content&content=1&type=all", function(data){
              $("#view2_box2_content1").html(data);
              tblSorter2("#view2tbl2cont1","#box2cont1trigger");
              tbl_dropdown ("#view2_box1_stock");
              tbl_dropdown ("#view2_box2_content1");
            	over_hover ("#view2_box2_content1 tr");
            	tbl_dropdown("#view2_box2_content1 th");
            	view2clickTicker("#view2_box2_content1 table");
          });
      }
      $("#view2_box2_link2 span").html($("#view2_box2_link2 ul li:eq(0)").text());
      $("#view2tbl2cont1 tbody tr").show();
      $("#view2_box2_link1 span").html(name);
  });
  over_hover ("#view2_box2_link1 ul li");
  $("#view2_box2_link2 ul li").click(function(){
      var filter = $(this).attr("rel");
      var name = $(this).text();
      if (filter=="all") { $("#view2tbl2cont1 tbody tr").show(); }
      else {
          $("#view2tbl2cont1 tbody tr").hide();
          $("#view2tbl2cont1 tbody tr td[rel='"+filter+"']").parents("tr").show();
      }
      $("#view2_box2_link2 span").html(name);
  });


  tblSorter2("#view2tbl2cont1","#box2cont1trigger");
  tbl_dropdown ("#view2_box1_stock");
  tbl_dropdown ("#view2_box2_content1");
	over_hover ("#view2_box2_content1 tr");
	tbl_dropdown("#view2_box2_content1 th");
	view2clickTicker("#view2_box2_content1 table");
	$("#view2_box2 .nav li").click(function() {
	  
		if ( $(this).is(".on") ) {
		    if($("#view2_box2 .nav li.on ul").is(":visible")){
            $("#view2_box2 .nav li ul").hide();
            return false;
        }
		    $("#view2_box2 .nav li.on ul").show();
				return false;
			} if ( $(this).is("#view2_box2_link1") ) {
			    $("#view2_box2 .nav li ul").hide(); 
			    $("#view2_box2 .nav li").removeClass('on');
			    $(this).addClass('on');
			    shoeHideBox2("1");
			} if ( $(this).is("#view2_box2_link2") ) {
			    $("#view2_box2 .nav li ul").hide();
          $("#view2_box2 .nav li").removeClass('on');
			    $(this).addClass('on');
			    shoeHideBox2("1");
			} if ( $(this).is("#view2_box2_link3") ) {
			    $("#view2_box2 .nav li ul").hide();
          $("#view2_box2 .nav li").removeClass('on');
			    $(this).addClass('on');
			    if($("#view2_box2_content3").html()==""){
              $.get(urlRoot+"index.php?page=stockView2Box2Content&content=3", function(data){
                  $("#view2_box2_content3").html(data);
                  tblSorter2("#view2tbl2cont3","#box2cont3trigger");
                  shoeHideBox2("3");
                  over_hover ("#view2_box2_content3 tr");
                  tbl_dropdown("#view2_box2_content3 th");
                  view2clickTicker("#view2_box2_content3 table");
                  tbl_dropdown ("#view2_box2_content3");
              });
          } else {
              shoeHideBox2("3");
        	}
			} if ( $(this).is("#view2_box2_link4") ) {
			    $("#view2_box2 .nav li ul").hide();
          $("#view2_box2 .nav li").removeClass('on');
			    $(this).addClass('on');
			    if($("#view2_box2_content4").html()==""){
              $.get(urlRoot+"index.php?page=stockView2Box2Content&content=4", function(data){
                  $("#view2_box2_content4").html(data);
                  tblSorter2("#view2tbl2cont4","#box2cont4trigger");
                  shoeHideBox2("4");
        			    over_hover ("#view2_box2_content4 tr");
                	tbl_dropdown("#view2_box2_content4 th");
                	view2clickTicker("#view2_box2_content4 table");
                	tbl_dropdown ("#view2_box2_content4");
              });
          } else {
              shoeHideBox2("4");
        	}
			} if ( $(this).is("#view2_box2_link5") ) {
			    $("#view2_box2 .nav li ul").hide();
          $("#view2_box2 .nav li").removeClass('on');
			    $(this).addClass('on');
			    if($("#view2_box2_content5").html()==""){
              $.get(urlRoot+"index.php?page=stockView2Box2Content&content=5", function(data){
                  $("#view2_box2_content5").html(data);
                  tblSorter2("#view2tbl2cont5","#box2cont5trigger");
                  shoeHideBox2("5");
        			    over_hover ("#view2_box2_content5 tr");
                	tbl_dropdown("#view2_box2_content5 th");
                	view2clickTicker("#view2_box2_content5 table");
                	tbl_dropdown ("#view2_box2_content5");
              });
          } else {
              shoeHideBox2("5");
        	}
			}
	});
});
//BOX 3
function view2box3(ticker){
    $("#view2_box3 .inner").html("<img src='images/preloader.gif' class='ajax_preloader' alt='' />");
    $.get(urlRoot+"index.php?page=stockView2Box3Content&ticker="+ticker, function(data){
        $("#view2_box3 .inner").html(data);
    });
}

//BOX 4
// INSERTING & REMOVING small(GRAPH COMPARE
var overallSmallCompareAmount = 0;
var insertedSmallGraphs = new Array();

function removeSelectedGraphEl(ticker) {
    if ( ticker=="CROBEX"){ 
        $("#popupCompare input[value='"+ticker+"']").parents("li").show();
    }
    if (ticker.substr(0,3)=="IFI"){
        $("#popupCompare input[value='"+ticker+"']").parents("li").show();
    }
    overallSmallCompareAmount = overallSmallCompareAmount-1;
    if( insertedSmallGraphs[0]==ticker) {
        insertedSmallGraphs[0]="";
    } else {
        if( insertedSmallGraphs[1]==ticker) {
            insertedSmallGraphs[1]="";
        } else {
            if( insertedSmallGraphs[2]==ticker) {
                insertedSmallGraphs[2]="";
            } else {
                insertedSmallGraphs[3]="";
            }
        }
    }
}

function checkColor(ticker){
    overallSmallCompareAmount = overallSmallCompareAmount+1;
    var colorOrder;
    var color;
    if( typeof(insertedSmallGraphs[0])=="undefined"||insertedSmallGraphs[0]=="" ) {
        insertedSmallGraphs[0]=ticker;
        colorOrder = "0";
        color = "000000";
    } else {
        if( typeof(insertedSmallGraphs[1])=="undefined"||insertedSmallGraphs[1]=="" ) {
            insertedSmallGraphs[1]=ticker;
            colorOrder = "1";
            color = "a81400";
        } else {
            if( typeof(insertedSmallGraphs[2])=="undefined"||insertedSmallGraphs[2]=="" ) {
                insertedSmallGraphs[2]=ticker;
                colorOrder = "2";
                color = "0008a8";
            } else {
                insertedSmallGraphs[3]=ticker;
                colorOrder = "3";
                color = "51105c";
            }
        }
    }
    return color+"|"+colorOrder;
}

function smallDropCompare(){
    clearInputs("#stockCompare");
    clearInputs("#fundCompare");
    $("#stockCompare").autocomplete(urlRoot+"index.php?page=autocomplete");
    $("#fundCompare").autocomplete(urlRoot+"index.php?page=autocomplete&type=fund");
    $("#stockCompare").result(function(event, data, formatted) {
        $("#stockCompare").attr("readonly","readonly");
    });
    $("#fundCompare").result(function(event, data, formatted) {
        var tickerName = formatted.split("</b>");
        $(this).val(tickerName[1]);
        var pattern = new RegExp("<");
        pattern.test(formatted.substring(9,formatted.length));
        var fundTicker = RegExp.leftContext;
        $("#fundCompare").attr("rel",fundTicker);
        $("#fundCompare").attr("readonly","readonly");
    });     
    $("#popupCompare input[type=checkbox]").checkbox();
    $("#popupCompare .close").click(function(){
        $("#popupCompare").hide();
    });
    $("#popupCompare .insert").click(function(){
        if(overallSmallCompareAmount>3){ return false; }
        var ticker1 = $("#stockCompare").val();
        if (ticker1!="Unesite naziv ili oznaku" && ticker1!=""){
            var color = checkColor(ticker1).split("|");
            document.getElementById("small_graph").compare(ticker1,"0x"+color[0],"stock");
        }
        var ticker2 = $("#fundCompare").attr("rel");
        var ticker2val = $("#fundCompare").val();
        if (ticker2val!="Unesite naziv" && ticker2val!=""){
            var color = checkColor(ticker2).split("|");
            document.getElementById("small_graph").compare(ticker2,"0x"+color[0],"fund");
        }
        
        if ($("#popupCompare input[type=checkbox]:checked").length!=0){
            for (i=0;i<$("#popupCompare input[type=checkbox]:checked").length;i++){
                var color = checkColor($("#popupCompare input[type=checkbox]:checked:eq("+i+")").val()).split("|");
                var indexTicker = $("#popupCompare input[type=checkbox]:checked:eq("+i+")").val();
                var indexType;
                if (indexTicker=="CROBEX") {indexType="market";}
                else {indexType="fund";}
                document.getElementById("small_graph").compare(indexTicker,"0x"+color[0],indexType);
            }
            $("#popupCompare input[type=checkbox]:checked").parents("li").hide();
            $("#popupCompare input[type=checkbox]:checked").parents(".jquery-checkbox-box").removeClass("jquery-checkbox-checked");
            $("#popupCompare input[type=checkbox]:checked").attr("checked", false);
        }
        $("#popupCompare").hide();
        $("#stockCompare").val("Unesite naziv ili oznaku");
        $("#fundCompare").val("Unesite naziv");
    });
}

function graphBox3(ticker) {
  $("#view2_box4_link1").addClass("active");
  $("#view2_box4_content1").show();
  $("#view2_box4_content2").hide();
  $("#view2_box4_content3").hide();
  $("#view2_box4_content1").html("<img src='images/preloader.gif' class='ajax_preloader' alt='' />");
  ;
  $.get(urlRoot+"index.php?page=stockView2Box4Content&content=chart&ticker="+ticker, function(data){
    $("#view2_box4_content1").html(data);   
    var graphValue = $('#box4_flash').attr('rel').split('|');
    var so = new SWFObject(urlRoot+"flash/Graph.swf?siteURL="+urlRoot+"&graphSize=small&graphType=stock&tickerHtml="+graphValue[0]+"&periodStart="+graphValue[1]+"&periodEnd="+graphValue[2], "small_graph", "351", "201", "9");
    so.addParam("allowScriptAccess", "always");
    so.addParam("wmode", "transparent");
    so.write("box4_flash");
    overallSmallCompareAmount = 0;
    for (i=0;i<insertedSmallGraphs.length;i++){
        insertedSmallGraphs[i]="";
    } 
    //FLASH HELP FOR MOUSE ENTER/LEAVE
  	$("#box4_flash").hover(function(){
        document.getElementById("small_graph").mouseEnter();
    }, function(){
        document.getElementById("small_graph").mouseLeave(); 
    });
    
    $(".timespan li").not("#pickDate").click(function(){
  	    if ( $(this).is(".on") ) { return false; }
        $(".timespan li").removeClass("on");
        $(this).addClass("on");
        var ticker = $('#box4_flash').attr('rel').split('|');
        var loc = urlRoot+"index.php?page=xmlStockHistoricDataInfo&ticker="+ticker[0]+"&period="+$(this).attr("rel");
        $.get(loc, function(data){
          flashMethod("small_graph").changePeriod($(data).find('begindate').text(),$(data).find('enddate').text());
				});
  	});
  	dateRestrictor = $("#pickDate").attr("rel").split("|");
    dateRestrictorMin = dateRestrictor[0].split(".");
    dateRestrictorMax = dateRestrictor[1].split(".");
  	$("#pickDate input").datepicker("destroy");
  	$("#pickDate input").datepicker({
        showOn: 'button', 
        buttonImage: urlRoot+'images/button/small2Graph_pickDate.gif',
        buttonImageOnly: true,
        minDate: new Date(dateRestrictorMin[2],(dateRestrictorMin[1]-1),dateRestrictorMin[0]),
        maxDate: new Date(dateRestrictorMax[2],(dateRestrictorMax[1]-1),dateRestrictorMax[0])    
    });
    $("#pickDate input").bind("change", function(){     
        $(".timespan li").removeClass("on");
        document.getElementById("small_graph").changePeriod($("#pickDate input").attr("value"),dateRestrictorMax.join("."));
  	});
  	smallDropCompare();
  });
}

function sentimentInt(ticker) {
  $("#view2_box4_content1").hide();
  $("#view2_box4_content3").hide();
  $("#view2_box4_content2").show();
  $("#view2_box4_content2").html("<img src='images/preloader.gif' class='ajax_preloader' alt='' />");
  $.get(urlRoot+"index.php?page=stockView2Box4Content&content=sentiment&ticker="+ticker, function(data){
    $("#view2_box4_content2").html(data);
    infraSentPopup ("box3_sent_info","view2_box4");
    infraSentPopup ("box3_sent_info2","view2_box4");
    sentAnimation(ticker);
	});
}

function newsBox3(ticker) {
  $("#view2_box4_content1").hide();
  $("#view2_box4_content2").hide();
  $("#view2_box4_content3").show();
  $("#view2_box4_content3").html("<img src='images/preloader.gif' class='ajax_preloader' alt='' />");
  $.get(urlRoot+"index.php?page=stockView2Box4Content&content=news&ticker="+ticker, function(data){
    $("#view2_box4_content3").html(data);
    news1popup("view2_box4_content3");
  });
}

$(document).ready(function() {
	$("#view2_box4 .boxnav li").click(function() {
		if ( $(this).is(".on") ) {
				if($(this).is(".active")){
            $("#popupCompare").show();
        }
				return false;
			} if ( $(this).is("#view2_box4_link1") ) {
			    $("#view2_box4 .boxnav li").removeClass('on');
			    $(this).addClass('on');
			    if ( $("#view2_box4_content1").contents("span").is(".noneSelected") ) { return false; }
          if ( $("#view2_box4_content1").html() == false ) { graphBox3(view2ticker); }
			    else {
            $("#view2_box4_content1").show();
            $("#view2_box4_content2").hide();
            $("#view2_box4_content3").hide();
          }			    
			} if ( $(this).is("#view2_box4_link2") ) {
			    $("#view2_box4 .boxnav li").removeClass('on');
			    $(this).addClass('on');
			    if ( $("#view2_box4_content1").contents("span").is(".noneSelected") ) { return false; }
			    if ( $("#view2_box4_content2").html() == false ) { sentimentInt(view2ticker); }
			    else {
            $("#view2_box4_content1").hide();
            $("#view2_box4_content2").show();
            $("#view2_box4_content3").hide();
          }
			} if ( $(this).is("#view2_box4_link3") ) {
			    $("#view2_box4 .boxnav li").removeClass('on');
			    $(this).addClass('on');
			    if ( $("#view2_box4_content1").contents("span").is(".noneSelected") ) { return false; }
			    if ( $("#view2_box4_content3").html() == false ) { newsBox3(view2ticker); }
			    else {
            $("#view2_box4_content1").hide();
            $("#view2_box4_content2").hide();
            $("#view2_box4_content3").show();
          }		    
			}
	});
});

//BOX 5
function basicBox4(ticker) {
  $("#view2_box5_content1").show();
  $("#view2_box5_content2").hide();
  $("#view2_box5_content3").hide();
  $("#view2_box5_content4").hide();
  $("#view2_box5_content1").html("<img src='images/preloader.gif' class='ajax_preloader' alt='' />");
  $.get(urlRoot+"index.php?page=stockView1Box4Content&content=generalData&ticker="+ticker, function(data){
    $("#view2_box5_content1").html(data);
    $("#view2_box5_content1 dt").click(function() {
      if ( $("#"+$(this).attr("id")+"_popup").is(":visible") ) { $("#"+$(this).attr("id")+"_popup").remove(); }
      else { calcdatabox_popup ( $(this).attr("id") ); }
    });
  });
}

function fundamentBox4(ticker) {
  $("#view2_box5_content1").hide();
  $("#view2_box5_content2").show();
  $("#view2_box5_content3").hide();
  $("#view2_box5_content4").hide();
  $("#view2_box5_content2").html("<img src='images/preloader.gif' class='ajax_preloader' alt='' />");
  $.get(urlRoot+"index.php?page=stockView1Box4Content&content=fundamental&ticker="+ticker, function(data){
    $("#view2_box5_content2").html(data);
    $("#view2_box5_content2 th").click(function() {
      if ( $("#"+$(this).attr("id")+"_popup").is(":visible") ) { $("#"+$(this).attr("id")+"_popup").remove(); }
      else { calcdatabox_popup ( $(this).attr("id") ); }
    });
  });
}

function tehnicalBox3(ticker) {
  $("#view2_box5_content1").hide();
  $("#view2_box5_content2").hide();
  $("#view2_box5_content3").show();
  $("#view2_box5_content4").hide();
  $("#view2_box5_content3").html("<img src='images/preloader.gif' class='ajax_preloader' alt='' />");
  $.get(urlRoot+"index.php?page=stockView1Box4Content&content=technical&ticker="+ticker, function(data){
    $("#view2_box5_content3").html(data);
    calcdatabox_content3("#view2_box5_content3");
  });
}

function analBox3(ticker) {
  $("#view2_box5_content1").hide();
  $("#view2_box5_content2").hide();
  $("#view2_box5_content3").hide();
  $("#view2_box5_content4").show();
  $("#view2_box5_content4").html("<img src='images/preloader.gif' class='ajax_preloader' alt='' />");
  $.get(urlRoot+"index.php?page=stockView1Box4Content&content=investa&ticker="+ticker, function(data){
    $("#view2_box5_content4").html(data);
    $("#analy_bar_wrapper span").click(function() {
      if ( $("#"+$(this).attr("id")+"_popup").is(":visible") ) { $("#"+$(this).attr("id")+"_popup").remove(); }
      else { calcdatabox_popup ( $(this).attr("id") ); }
    });
  });
}

$(document).ready(function() {
	$("#view2_box5 .boxnav li").click(function() {
		if ( $(this).is(".on") ) {
				return false;
		} else {
      $("#view2_box5 .boxnav li").removeClass('on');
      $(this).addClass('on');
      if ( $("#view2_box5_content1").contents("span").is(".noneSelected") ) { return false; }
        if ( $(this).is("#view2_box5_link1") ) {
            $("#view2_box5_content1").show();
            $("#view2_box5_content2").hide();
            $("#view2_box5_content3").hide();
            $("#view2_box5_content4").hide();
            if ( $("#view2_box5_content1").html() == false ) { basicBox4(view2ticker); }
        } if ( $(this).is("#view2_box5_link2") ) {
            $("#view2_box5_content1").hide();
            $("#view2_box5_content2").show();
            $("#view2_box5_content3").hide();
            $("#view2_box5_content4").hide();
            if ( $("#view2_box5_content2").html() == false ) { fundamentBox4(view2ticker); }
        } if ( $(this).is("#view2_box5_link3") ) {
            $("#view2_box5_content1").hide();
            $("#view2_box5_content2").hide();
            $("#view2_box5_content3").show();
            $("#view2_box5_content4").hide();
            if ( $("#view2_box5_content3").html() == false ) { tehnicalBox3(view2ticker); }
        } if ( $(this).is("#view2_box5_link4") ) {
            $("#view2_box5_content1").hide();
            $("#view2_box5_content2").hide();
            $("#view2_box5_content3").hide();
            $("#view2_box5_content4").show();
            if ( $("#view2_box5_content4").html() == false ) { analBox3(view2ticker); }
        }
      }
	});
});

