// FCE vyuzivajici JQuery
$(document).ready(function(){
  // ***************** Externi okna E-broker *************** //
  $('a.external').click( function() {
    window.open( $(this).attr('href'), "e-Broker", "toolbar=n,height=400,width=700,resizable=1,scrollbars=1" );
    return false;
  });  
  
  // ***************** GRAFY *************** //
  // ***************** MINI
	$("#grafy-href a").click( function(event) {
        event.preventDefault();
        $("#grafy-href a").removeClass("active");
        $(this).addClass("active");
        $("#grafy-indexy").html("<div class='loader' style='padding:55px 0'><img src='gfx/loader.gif' alt='loader' /><\/div> ");
        
        jQuery.url.setUrl($(this).attr('href'));
        var graf = parseInt(jQuery.url.param("graf"));   		
        $("#grafy-indexy").load("ajax_graf.php", {typ:"vpravo", graf:graf});
        $.cookie("grafy-indexy", graf);
	});
	
	// *************** NORMAL
    $("#graf-detail a").click( function(event) {
        event.preventDefault();
        $("#graf-detail a").removeClass("active");
        $(this).addClass("active");
        $("#graf").html("<div class='loader' style='padding:217px 0'><img src='gfx/loader.gif' alt='loader' /><\/div> ");
        
        jQuery.url.setUrl($(this).attr('href'));
        var trh = jQuery.url.param("trh");    
        $("#graf").load("ajax_graf.php", {typ:"detail", trh:trh, TICKER:ticker, ID_CENINA:id_cenina});
    });
  
    // ***************** OBRAZKOVEJ
	$("#grafy-obdobi a").click( function(event) {
        event.preventDefault();
        $("#graf-obr").html("<div class='loader' style='padding:56px 0'><img src='gfx/loader.gif' alt='loader' /><\/div> ");
        
        jQuery.url.setUrl($(this).attr('href'));
        var fromMaly = jQuery.url.param("fromMaly");
        var toMaly = jQuery.url.param("toMaly");
        $("#graf-obr").load("ajax_graf_obr.php", {cenina:cenina, fromMaly:fromMaly, toMaly:toMaly});
	});
    
	$("#grafy-obr-href a").click( function(event) {
        event.preventDefault();
        $("#grafy-obr-href a").removeClass("active");
        $(this).addClass("active");
        $("#graf-obr").html("<div class='loader' style='padding:56px 0'><img src='gfx/loader.gif' alt='loader' /><\/div> ");
        
		jQuery.url.setUrl($(this).attr('href'));
        var graf =  parseInt(jQuery.url.param("graf"));
        $("#graf-obr").load("ajax_graf_obr.php", {cenina:graf});
        $.cookie("grafy-indexy", graf);
	});         	
	
  // ***************** HOMEPAGE *************** //
  // ***************** PAPIRY
	$("#stocks li a").click( function(event) 
		{
			event.preventDefault();
			//menu
			$("#stocks li").removeClass("active");
			$(this).parent().addClass("active");
			//data
			var which = parseInt($(this).attr('href').split("?Z=stocks_")[1]);
			if ( !which || (which < 1) || (which>6) ) { which = 1; }
			$("#stocks-content div.cols2-exact").hide();
			$("#stocks-content div.cols2-exact:eq("+(which-1)+")").show();
			$.cookie("hp-papiry", which);
		} );
	                  
  // ***************** NOVINKY 
	$("#news li a").click( function(event) 
		{
			event.preventDefault();
			//menu
			$("#news li").removeClass("active");
			$(this).parent().addClass("active");
			//data
			var which = parseInt($(this).attr('href').split("?Z=news_")[1]);
			if ( !which || (which < 1) || (which>3) ) { which = 1; }
			$("#news-content div.content").hide();
			$("#news-content div.content:eq("+(which-1)+")").show();
			$.cookie("hp-zpravy", which);			
		} );  

  // ***************** KURZY *************** //
  // ***************** KOBOS
  
	$('#table-sort-kobos').dataTable( {
    "aoColumns": [
      { "sType": "html" },
      { "bSortable": false },
      { "sType": 'date-euro' },
      { "sType": 'num-html' },
      { "sType": 'num-html' },
      { "sType": 'num-html' },
      { "sType": 'float-num' }
    ],
          
    "bJQueryUI": true,
    "aaSorting": [[0,'asc']],
    "bAutoWidth": false,
    "bPaginate": false,
    "bInfo": false,
    "bProcessing": true
	} );  
  
  
  // ***************** SPAD
  $('#table-sort-spad-aktual').dataTable( {
    "aoColumns": [
      { "sType": "html" },
      { "sType": 'float-num' },
      { "sType": 'float-num' },
      { "sType": 'num-html' }, // Koupe
      { "sType": "num-html" },
      { "sType": 'float-num' },
      { "sType": 'float-num' },
      { "sType": 'float-num' },
      { "sType": 'float-num' },
      { "bSortable": false },
      { "sType": 'float-num' }
    ],
          
    "bJQueryUI": true,
    "aaSorting": [[0,'asc']],
    "bAutoWidth": false,
    "bPaginate": false,
    "bInfo": false,
    "bProcessing": true
	} );
	       
	$('#table-sort-spad-vyvoj').dataTable( {
    "aoColumns": [
      { "sType": "html" },
      { "sType": 'date-euro' },
      { "sType": 'float-num' },
      { "sType": 'float-num' },
      { "sType": 'float-num' },
      { "sType": 'float-num' },
      { "sType": 'float-num' },
      { "sType": 'float-num' },
      { "bSortable": false },
      { "bSortable": false },
      { "bSortable": false }
    ],
          
    "bJQueryUI": true,
    "aaSorting": [[1,'asc']],
    "bAutoWidth": false,
    "bPaginate": false,
    "bInfo": false,
    "bProcessing": true
	} );

	$('#table-sort-spad-zaver').dataTable( {
    "aoColumns": [
      { "sType": "html" },
      { "sType": 'float-num' },
      { "sType": 'float-num' },
      { "sType": 'float-num' },
      { "sType": 'float-num' },
      { "sType": 'float-num' },
      { "sType": 'float-num' },
      { "sType": 'float-num' },
      { "sType": 'float-num' },
      { "sType": 'num-html' },
      { "sType": 'float-num' },      			
      { "sType": 'float-num' }
    ],
          
    "bJQueryUI": true,
    "aaSorting": [[0,'asc']],
    "bAutoWidth": false,
    "bPaginate": false,
    "bInfo": false,
    "bProcessing": true
	} );	       
  
  // ***************** spad zaver
  $('#table-sort-spad-zaver-cenina').dataTable( {
    "aoColumns": [
      { "sType": 'only-date' },
      { "sType": 'float-num' },
      { "sType": 'float-num' },
      { "sType": 'float-num' },
      { "sType": 'float-num' },
      { "sType": 'float-num' },
      { "sType": 'float-num' },
      { "sType": 'float-num' },
      { "sType": 'num-html' },
      { "sType": 'num-html' },
      { "sType": 'float-num' },
      { "sType": 'num-html' },
      { "sType": 'num-html' }
 		],
          
    "bJQueryUI": true,
    "aaSorting": [[0,'desc']],
    "bAutoWidth": false,
    "bPaginate": false,
    "bInfo": false,
    "bProcessing": true
	} );
	
	// ***************** easy click
	$('#table-sort-easyclick').dataTable( {
    "aoColumns": [
      { "sType": "html" },
      { "sType": 'date-euro' },
      { "sType": 'num-html' },
      { "sType": 'num-html' },
      { "sType": 'float-num' },
      { "sType": 'float-num' },
      { "sType": 'num-html' },
      { "sType": 'float-num' },
      { "sType": 'num-html' },
      { "sType": 'float-num' },
      { "sType": 'float-num' },
      { "sType": 'num-html' }
    ],
          
    "bJQueryUI": true,
    "aaSorting": [[0,'asc']],
    "bAutoWidth": false,
    "bPaginate": false,
    "bInfo": false,
    "bProcessing": true
	} );
  
  // ***************** RMS
	$('#table-sort-rms').dataTable( {
    "aoColumns": [
      { "sType": "html" },
      { "sType": 'date-euro' },
      { "sType": 'num-html' },
      { "sType": 'num-html' },
      { "sType": 'float-num' },
      { "sType": 'float-num' },
      { "sType": 'num-html' },
      { "sType": 'float-num' },
      { "sType": 'num-html' },
      { "sType": 'float-num' },
      { "sType": 'float-num' },
      { "sType": 'num-html' }
    ],
          
    "bJQueryUI": true,
    "aaSorting": [[0,'asc']],
    "bAutoWidth": false,
    "bPaginate": false,
    "bInfo": false,
    "bProcessing": true
	} );  	
	
	// ***************** fixing
	$('#table-sort-fixing').dataTable( {
    "aoColumns": [
      { "sType": "html" },
      { "sType": 'float-num' },
      { "sType": 'float-num' },
      { "sType": 'float-num' },
      { "sType": 'num-html' },
      { "sType": 'float-num' },      			
      { "sType": 'num-html' },
      { "sType": 'date-euro' }
    ],
          
    "bJQueryUI": true,
    "aaSorting": [[0,'asc']],
    "bAutoWidth": false,
    "bPaginate": false,
    "bInfo": false,
    "bProcessing": true
	} );
	
	// *********************** detail historie - zalozka Kurzy
  $('#table-sort-kurzy-historie').dataTable( {
    "aoColumns": [
      { "sType": "only-date" },
      { "sType": 'float-num' },
      { "sType": 'float-num' },
      { "sType": 'float-num' },
      { "sType": 'num-html' },
      { "sType": 'float-num' },
      { "sType": 'float-num' },
      { "sType": 'float-num' },
      { "sType": 'float-num' },
      { "sType": 'float-num' },
      { "sType": 'num-html' },
      { "sType": 'float-num' },
      { "sType": 'float-num' }
    ],
          
    "bJQueryUI": true,
    "aaSorting": [[0,'desc']],
    "bAutoWidth": false,
    "bPaginate": false,
    "bInfo": false,
    "bProcessing": true
	} );	
  
  // ************************ detail zaver rms
  $('#table-sort-zaver-rms').dataTable( {
    "aoColumns": [
      { "sType": "only-date" },
      { "sType": 'float-num' },
      { "sType": 'float-num' },
      { "sType": 'float-num' },
      { "sType": 'num-html' },
      { "sType": 'float-num' },
      { "sType": 'float-num' },
      { "sType": 'float-num' },
      { "sType": 'float-num' },
      { "sType": 'float-num' },
      { "sType": 'num-html' },
      { "sType": 'float-num' },
      { "sType": 'float-num' }
    ],
          
    "bJQueryUI": true,
    "aaSorting": [[0,'desc']],
    "bAutoWidth": false,
    "bPaginate": false,
    "bInfo": false,
    "bProcessing": true
	} );
           
  // ************************ historie
  $('#table-sort-srovnani').dataTable( {
    "aoColumns": [
      { "sType": "html" },
      { "sType": 'float-num' },
      { "sType": 'float-num' },
      { "sType": 'num-html' },
      { "sType": 'num-html' },
      { "sType": 'float-num' },
      { "sType": 'float-num' },
      { "sType": 'num-html' },
      { "sType": 'num-html' }      			
    ],
          
    "bJQueryUI": true,
    "aaSorting": [[0,'asc']],
    "bAutoWidth": false,
    "bPaginate": false,
    "bInfo": false,
    "bProcessing": true
  } );
	
  // ***************** prazska burza listek
	$('#table-sort-listek-burza').dataTable( {
    "aoColumns": [
      { "sType": "html" },
      { "sType": "html" },
      { "sType": "html" },
      { "sType": 'float-num' },
      { "sType": 'float-num' },
      { "sType": 'float-num' },
      { "sType": 'float-num' },
      { "sType": 'float-num' },
      { "sType": 'num-html' },
      { "sType": 'num-html' },
      { "sType": 'only-date' }
    ],
          
      "bJQueryUI": true,
      "aaSorting": [[0,'asc']],
      "bAutoWidth": false,
      "bPaginate": false,
      "bInfo": false,
      "bProcessing": true
	  } );


  // ***************** clenove burzy
  $('#table-sort-clenove').dataTable( {
    "oLanguage": {
      "sSearch": "Člen"
    },
    "bJQueryUI": true,
    "aaSorting": [[2,'asc']],
    "bAutoWidth": false,
    "bPaginate": false,
    "bInfo": false,
    "bProcessing": true
	} );
	
  // ***************** pismenka
	$('#table-sort-pismena').dataTable( {
    "aoColumns": [
      { "sType": "html" },
      { "sType": "html" },
      { "sType": "html" },
      { "sType": 'float-num' },
      { "sType": 'float-num' }
    ],
          
    "bJQueryUI": true,
    "aaSorting": [[0,'asc']],
    "bAutoWidth": false,
    "bPaginate": false,
    "bInfo": false,
    "bProcessing": true
	} );
	
	// *********************** listek meny
	
	$('#table-sort-listek-meny').dataTable( {
    "aoColumns": [
      { "sType": "html" },
      { "sType": "html" },
      { "sType": "html" },
      { "sType": 'float-num' },
      { "sType": 'float-num' },
      { "bSortable": false },
      { "bSortable": false }
    ],
      "oLanguage": {
      	"sSearch": "Výběr měny"
    	},     
      "bJQueryUI": true,
      "aaSorting": [[0,'asc']],
      "bAutoWidth": false,
      "bPaginate": false,
      "bInfo": false,
      "bProcessing": true
	} );	
	
	
	// *********************** listek rms
	
	$('#table-sort-listek-rms').dataTable( {
    "aoColumns": [
      { "sType": "html" },
      { "sType": "html" },
      { "sType": "html" },
      { "sType": 'float-num' },
      { "sType": 'float-num' },
      { "sType": 'float-num' },
      { "sType": 'float-num' },
      { "sType": 'float-num' },
      { "sType": 'num-html' },
      { "sType": 'num-html' },
      { "sType": 'float-num' },
      { "sType": 'float-num' }
    ],
          
      "bJQueryUI": true,
      "aaSorting": [[0,'asc']],
      "bAutoWidth": false,
      "bPaginate": false,
      "bInfo": false,
      "bProcessing": true
	  } );
	  
	// ***************** KURZY ZAHRANICI *************** //

	$('#table-sort-cp-zahranici').dataTable( {
    "aoColumns": [
      { "sType": "html" },
      { "sType": "html" },
      { "sType": 'float-num' },
      { "sType": 'float-num' },
      { "sType": 'float-num' },
      { "sType": 'float-num' },
      { "sType": 'float-num' },
      { "sType": 'float-num' },
      { "sType": 'date-euro' }
    ],
          
    "bJQueryUI": true,
    "aaSorting": [[0,'asc']],
    "bAutoWidth": false,
    "bPaginate": false,
    "bInfo": false,
    "bProcessing": true
	} );
	
	$('#table-sort-cp-komodity').dataTable( {
    "aoColumns": [
      { "sType": "html" },
      { "sType": "html" },
      { "sType": "html" },
      { "sType": 'float-num' },
      { "sType": 'float-num' },
      { "sType": 'float-num' },
      { "sType": 'float-num' },
      { "sType": 'float-num' },
      { "sType": 'float-num' },
      { "sType": 'date-euro' }
    ],
          
    "bJQueryUI": true,
    "aaSorting": [[0,'asc']],
    "bAutoWidth": false,
    "bPaginate": false,
    "bInfo": false,
    "bProcessing": true
	} );	
	
	
                        
                                                
  // ***************** VYHLEDAVANI *************** //                  
	$('#table-sort-hledani').dataTable( {
    "aoColumns": [
      { "sType": "html" },
      { "sType": "html" },
      { "sType": "html" },
      { "sType": 'float-num' },
      { "sType": 'float-num' },
      { "bSortable": false }
    ],
          
    "bJQueryUI": true,
    "aaSorting": [[0,'asc']],
    "bAutoWidth": false,
    "bPaginate": false,
    "bInfo": false,
    "bProcessing": true
	} );
	
	
	// ***************** PORTFOLIO *************** //
	$('#table-sort-portfolio').dataTable( {
    "aoColumns": [
      { "sType": "html" },
      { "sType": 'num-html' },
      { "sType": 'float-num' },
      { "sType": "html" },
      { "sType": 'float-num' },
      { "sType": 'float-num' },
      { "bSortable": false }
    ],
          
    "bJQueryUI": true,
    "aaSorting": [[0,'asc']],
    "bAutoWidth": false,
    "bPaginate": false,
    "bInfo": false,
    "bProcessing": true
	} );	
	
  // ***************** SOUTEZ - VITEZNE TIPY *************** //
  $('#table-sort-vitezne-tipy').dataTable( {
    "aoColumns": [
      { "sType": "html" },
      { "sType": "html" },
      { "sType": "html" },
      { "sType": 'float-num' },
      { "sType": 'float-num' },
      { "sType": 'date-euro' }
    ],
      
      "oLanguage": {
      	"sSearch": "Výběr tipujícího"
    	},
          
      "bJQueryUI": true,
      "aaSorting": [[0,'asc']],
      "bAutoWidth": false,
      "bPaginate": false,
      "bInfo": false,
      "bProcessing": false
	} );
  
  // ***************** SOUTEZ - MESICNI PREHLEDY *************** //
	$('#table-sort-mesicni-prehled').dataTable( {
    "aoColumns": [
      { "bSortable": false },
      { "sType": "html" },
      { "sType": 'num-html' },
      { "sType": 'num-html' },
      { "sType": 'num-html' },
      { "sType": 'num-html' },
      { "sType": 'num-html' }
    ],
      
      "oLanguage": {
      	"sSearch": "Výběr tipujícího"
    	},    
          
      "bJQueryUI": true,
      "aaSorting": [[0,'asc']],
      "bAutoWidth": false,
      "bPaginate": false,
      "bInfo": false,
      "bProcessing": false
	  } );    
    
	
                          
  // ***************** DISKUSE - VSE *************** //
  $("div.vic-temat").show();
  
  $(".vic-temat a").click(function (event) 
		{
    	event.preventDefault();
    	var tmp = $(this).parent().parent().attr("id");
    	var n = tmp.substr(tmp.length-1);
    	var kolik = 0;

			if (n=="1") { kolik = 8; }
			else if (n=="2") { kolik = 5; }

			var cookie = ($.cookie("diskuze_show"));
			if (cookie)
			{
				cookie = cookie.split(':')
			}
			else 
			{
				cookie = {};
			}
			var new_cookie = '';

			var x;
			if ($("#temata"+n+" .tbl1 tr:gt("+kolik+")").is(":hidden")) 
			{
				$(this).text("Zpět na krátký přehled");

				for (x in cookie)
				{
					if (cookie[x] != n)
					{
						if (new_cookie) { new_cookie += ':'; }
						new_cookie += cookie[x];
					}
				}
				if (new_cookie) { new_cookie += ':'; }
				new_cookie += n;
			} 
			else 
			{
				$(this).text("Všechna témata");
				
				for (x in cookie)
				{
					if (cookie[x] != n)
					{
						if (new_cookie) { new_cookie += ':'; }
						new_cookie += cookie[x];
					}
				}				
			}
			$.cookie("diskuze_show", new_cookie);
			$("#temata"+n+" .tbl1 tr:gt("+kolik+")").toggle();
  	});


  // ***************** ANKETA - AJAX *************** //
  var hlasuj = function () { 
    //ID odpovedi
    var id = this.href.split("anketa?o=")[1];
    var id = id.split("&P=")[0];
  
    // Odesli na zpracovani
    $.post("anketa", {o: id, typ:"ajax"},
      function(data){
        // Vypis
        $("#ankOznameni").show();
                  
        $("#ankOznameni").html(data.getElementsByTagName("zapocitano")[0].firstChild.nodeValue);
        $("#ankAktivniOdpovedi").html(data.getElementsByTagName("odpovedi")[0].firstChild.nodeValue);
                  
        $("#ankOznameni").fadeOut(5000);
      }
    ); 
    return false;
  };                           
  $("div#ankAktivniOdpovedi a").live("click",(hlasuj));

	//print cudlitka
	$(".print_it").click( function(event) 
		{
			event.preventDefault();
			window.print();
		} );
  
}); // ***************** KONEC FCE                           

