slideshow = {
    context: true,
    tabs: true,
    timeout: 10000,      // time before next slide appears (in ms)
    slideSpeed: 1000,   // time it takes to slide in each slide (in ms)
    tabSpeed: 100,      // time it takes to slide in each slide (in ms) when clicking through tabs
    fx: 'fade',   // the slide effect to use

    init: function() {
        // set the context to help speed up selectors/improve performance
        this.context = $('#slideshow');

        // set tabs to current hard coded navigation items
        this.tabs = $('ul.slides-nav li', this.context);

        // remove hard coded navigation items from DOM
        // because they aren't hooked up to jQuery cycle
        this.tabs.remove();

        // prepare slideshow and jQuery cycle tabs
        this.prepareSlideshow();
    },

    prepareSlideshow: function() {
        // initialise the jquery cycle plugin -
        // for information on the options set below go to:
        // http://malsup.com/jquery/cycle/options.html
        $('div.slides > ul', slideshow.context).cycle({
            fx: slideshow.fx,
            timeout: slideshow.timeout,
            speed: slideshow.slideSpeed,
            fastOnEvent: slideshow.tabSpeed,
            pager: $('ul.slides-nav', slideshow.context),
            pagerAnchorBuilder: slideshow.prepareTabs,
            before: slideshow.activateTab,
            pauseOnPagerHover: true,
            pause: true
        });
    },

    prepareTabs: function(i, slide) {
        // return markup from hardcoded tabs for use as jQuery cycle tabs
        // (attaches necessary jQuery cycle events to tabs)
        return slideshow.tabs.eq(i);
    },

    activateTab: function(currentSlide, nextSlide) {
        // get the active tab
        var activeTab = $('a[href="#' + nextSlide.id + '"]', slideshow.context);

        // if there is an active tab
        if(activeTab.length) {
            // remove active styling from all other tabs
            slideshow.tabs.removeClass('on');

            // add active styling to active button
            activeTab.parent().addClass('on');
        }
    }
};


$(function() {
    // add a 'js' class to the body
    $('body').addClass('js');

    // initialise the slideshow when the DOM is ready
    slideshow.init();
    $('div.platforms_banner').show();
});















	$(document).ready(function(){
		var i = 0;
   		$('#s1').cycle({
		fx: 'fade',
		timeout:	10000,
		speed:      100,
		pager:  '#nav_tabs_vertical',
		 pagerAnchorBuilder: function(idx, slide) {

        return '<li class="nav_tabs_vertical"><a href="#1"><div>' + titles[i++] + '</div></a>';
    } 
		
	});
	$('.slideshow').mouseover(function() { 
    $('#s1').cycle('pause'); 
  	});
	$('.nav_tabs_vertical').click(function() { 
    $('#s1').cycle('pause'); 
	});
		
		// popup
		var l_l = $(this).find('.l_l');
		var r_r = $(this).find('.r_r');
		var t_t = $(this).find('.t_t');
 		$(l_l).mouseover(function() {$(this).children().show();});
 		$(l_l).mouseout(function() {$(this).children().fadeOut('fast');});
 		$(r_r).mouseover(function() {$(this).children().show();});
 		$(r_r).mouseout(function() {$(this).children().fadeOut('fast');});
 		$(t_t).mouseover(function() {$(this).children().show();});
 		$(t_t).mouseout(function() {$(this).children().fadeOut('fast');});
 	});

(function($) {
$(function() {

  $('ul.tabs_m').each(function() {
    $(this).find('li').each(function(i) {
      $(this).click(function(){
        $(this).addClass('current_m').siblings().removeClass('current_m')
          .parents('div#section_m').find('div.box_m').hide().end().find('div.box_m:eq('+i+')').fadeIn(150);
      });
    });
  });

})
})(jQuery)
	
$(function(){
    var curquotes_height = $('#curquotes').height();

    var quote_graphic_draw = function(instrument){
        var d = new Date();
	    var tz = d.getTimezoneOffset();
        //alert(tz);
		$.getJSON(
			'/en/quote/graph'
          //'/front_dev_sample.php/ru/quote/graph'
        , {'instrument': instrument}
		    ,	function(data, status){
                if (status == 'success') {
                    $.each(data, function(i,v){
                        data[i][0] = (data[i][0] * 1000) - (tz * 60 * 1000);
                    });
                    $('#curquotes').hide();
                    $('#curquotes_block').append($('<div>').attr('id', 'quote_graphic').css({
                        'height': curquotes_height
                    }));
                    $.plot($('#quote_graphic'), [data], {
                      xaxis: { mode: "time", timeformat: "%H:%M", tickSize: [1, 'hour']}
                    ,	y2axis: {min: 0, tickDecimals: 4}
                    ,	shadowSize: 0
                    ,	grid: { hoverable: false }
                    ,	points: { radius: 1	 }
                    });
                    $('#curquotes_block')
                    .after($('<span>').text('[X]').addClass('button_close').click(function(){
                        $('#quote_graphic').remove();
                        $('#instrument_shower').remove();
                        $('#curquotes').show();
                        $(this).remove();
                    }))
                    .after($('<span id="instrument_shower">').text(instrument));
                    $("#curquotes_block").click(function() {
                        $('#quote_graphic').remove();
                        $('#instrument_shower').remove();
                        $('span.button_close').remove();
                        $('#curquotes').show();
                        
                    });
                }
			}
		);
	};

/*
    $('#curquotes thead').children().each(function(){
        $(this).append($('<th class="graph_title">').text('Chart'));
    });
    $('#curquotes tbody').children().each(function(){
        var row = $(this);
        $(this).append($('<td class="graph">').click(function(){
            var re = /row(.*)/;
            var matches = re.exec($(row).attr('id'));
            quote_graphic_draw(matches[1]);
        }));
    });
*/

     window.onmousemove = displayQ;

     function getCurTime()
     {
         date = new Date();
         return Math.ceil(date.getTime()/1000)
     }

     stop_time = getCurTime() +60; //init

     var stop_time;

      function displayQ() {
          stop_time = getCurTime() +60;
       }


    setInterval(function(){
        if (getCurTime() < stop_time) {
            $.getJSON(
            '/quotes.php',
                function(data, status) {
                    if (status == 'success') {
                        var date = new Date(data['time'] * 1000);
                        $('#curquotes_time').text(date.toLocaleTimeString());
                        $.each(data['quotes'], function(index, value){
                            $('#row'+index).attr('class', 'curquotes'+value['cur']);

                            var min = value['bid'] < value['min'] ? value['bid'] : value['min'];
                            var max = value['bid'] > value['max'] ? value['bid'] : value['max'];

                            $('#bid'+index).html("<span>" + value['bid'] + "</span>");
                            $('#ask'+index).html("<span>" + value['ask'] + "</span>");
                            $('#min'+index).text(min);
                            $('#max'+index).text(max);
                        });
                    }
                }
            );
    } else {}
    }, 5000);

});

