function tabElements() {
	this.tabs = [];
	this.tabLinks = [];

	this.interval = null;
    this.current = 0;
	this.next = 0;
	this.speed = 4000;

	this.init = function (tab, link, img) {
		this.tabs = $(tab);
		this.tabLinks = $(link);

		var cls = this;
        this.tabLinks.each(function(i){
            var $this = $(this);
            $this.idx = i;
			$this.cls = cls
            $this.mouseover(function() {
                $this.cls.showTab($this.idx)
				$this.current = i;
            });
        });

        $(img).each(function(i){
            var $this = $(this);
			$this.cls = cls
            $this.mouseover(function() {
				console.log($this)
                $this.cls.stopLoop()
            });
        });

		var $this = this;
		this.interval = setInterval(function()
		{
			$($this.tabLinks[$this.current]).removeClass("selected");
			$($this.tabs[$this.current]).css('display', 'none');
			if ($this.next + 1 == $this.tabLinks.length)
			{
				$this.next = 0;
			} else {
				$this.next++;
			}
			$($this.tabLinks[$this.next]).addClass("selected");
			$($this.tabs[$this.next]).css('display', 'block');
			$this.current = $this.next
		}, this.speed);

	};

	this.stopLoop = function()
	{
		clearTimeout(this.interval);
	};

    this.showTab = function(i)
    {
        this.tabs.each(function(idx){
            if (idx == i) {
                $(this).css('display', 'block');
            } else {
                $(this).css('display', 'none');
            }
        });
        this.tabLinks.each(function(idx){
            if (idx == i) {
                $(this).addClass('selected');
            } else {
                $(this).removeClass('selected');
            }
        });
    };
}

var deeb = {

};
                       
$(document).ready(function() {
	var ptab = new tabElements();
	ptab.init('#foanyagok_box .tp_tab', '#foanyagok_box a.tp_btn', '#foanyagok_box .tp_tab img');
	ptab.showTab(0);

	var vtab = new tabElements();
	vtab.init('#videolista_box .tp_tab', '#videolista_box li.tp_btn', '#videolista_box .tp_tab a');
	vtab.showTab(0);
});

