var o = null;
$(function(){
	o = setInterval(function() {
		$(".khungslide1 a.nextslide").click();
		}, 5000);
		setTimeout(function() {
			setInterval(function() {
				$(".khungslide2 a.nextslide").click();
			}, 5000);
	}, 2500);
  			        
    $.fn.extend({
        simpleSlider: function(options)
        {
            var options = $.extend({}, options);

            return this.each(function()
            {
                var li = $('ul.boxRegion_inside li', this);
                var count = li.length;

                if (count <= 2)
                {
                    $('a.nextslide, a.prevslide', this).remove();
                    return;
                }

                var nextBtn = $('a.nextslide', this);

                nextBtn.parent().attr('rel', 0);

                $('a.nextslide, a.prevslide', this).click(function()
                {
                    li.hide();
                    var parent = $(this).parent();
                    var index = parseInt($(this).parent().attr('rel'));

                    if ($(this).hasClass('nextslide')){

                        if (index + 2 >= count)
                        {
                            index = -2;
                        }

                        for (var i=0;i<2;i++)
                        {
                            li.eq(index + 2 + i).fadeIn();
                        }
                        var next = index + 2;
                        if (next >= count)
                        {
                            next = 0;
                        }

                        parent.attr('rel', next);
                    }
                    else
                    {
                        var mod;
                        if (index <= 0)
                        {
                            mod = (count % 2);
                            if (mod == 0)
                            {
                                index = count + 1;
                            }
                            else
                            {
                                index = count + 1;
                            }
                        }
                        for (var i=0;i<2;i++)
                        {
                            li.eq(index - 2 + i).fadeIn();
                        }
                        var prev = index - 2;
                        if (prev < 0)
                        {
                            mod = (count % 2);
                            if (mod != 0)
                            {
                                count += 1;
                            }
                            prev = count - 2;
                            //prev = Math.max(0, prev);
                        }

                        parent.attr('rel', prev);
                    }
                    return false;
                });
            });
        }
    });
    $(".boxtrongchuaitemcon").simpleSlider();
});

