jQuery(document).ready(function() {
    jQuery('.date').css({'-moz-border-radius':'4px','-webkit-border-radius':'4px'});
    jQuery('.btn').css({'-moz-border-radius':'4px','-webkit-border-radius':'4px'});
    jQuery('.slider-box').bulletsSlider();
	jQuery('#article-rightpic .slider-image').click(function(e) {
		if($(this).hasClass('open'))
		{
			var a = $(this).attr('src');
			$(this).attr('src', $(this).attr('rel'));
			$(this).attr('rel', a);
			$(this).width('300px');
			$(this).removeClass('open');
			$(this).parent().parent().css({'float': 'right', 'width': '300px'});
		} else {
			var a = $(this).attr('src');
			$(this).attr('src', $(this).attr('rel'));
			$(this).attr('rel', a);
			$(this).width('570px');
			$(this).addClass('open');
			$(this).parent().parent().css({'float': 'none', 'width':'auto'});
		}
	});
});

function toggleElements(id1,id2) {
    if (document.getElementById(id1).style.display == 'none') {
        document.getElementById(id2).style.display = 'none';
        document.getElementById(id1).style.display = '';
    }
    else {
        document.getElementById(id1).style.display = 'none';
        document.getElementById(id2).style.display = '';
    }
}
jQuery.fn.bulletsSlider = function(options) {
    settings = jQuery.extend({
        duration: 200,
        easing: 'linear'
    }, options);
    
    
    return this.each(function(){
        

        var slider_objects_width = 0;
        var current_object_id = 0;
        var scrolling = 0;
        var slider_objects = jQuery(this).find('.slider-object');
        var slider_object_width = jQuery(slider_objects[0]).width();
        var slider_object_margin = parseInt(jQuery(slider_objects[0]).css('margin-right')) || 0;
        var slider_bullets = jQuery(this).find('.slider-bullet');
        
        slider_objects.each(function() {
            slider_objects_width += (slider_object_margin + slider_object_width);
        });
        var slider_objects_container = jQuery(this).find('.slider-objects')[0];
        jQuery(slider_objects_container).width(slider_objects_width);
        
        if((slider_objects_width-slider_object_margin) > slider_object_width) {
            
            jQuery(this).find('.arrow-left').click(function() {
               if(current_object_id > 0 && scrolling == 0) {
                   scrolling = 1;
                   jQuery(slider_bullets[current_object_id]).removeClass('filled').addClass('empty');
                   jQuery(slider_bullets[current_object_id-1]).removeClass('empty').addClass('filled');
                   jQuery(slider_objects_container).animate({
                       marginLeft: '+='+(slider_object_width + slider_object_margin)+'px'
                   },settings.duration,settings.easing, function() {
                       current_object_id--;
                       scrolling = 0;
                   });
               }
            });
            jQuery(this).find('.arrow-right').click(function() {
               if(current_object_id < (slider_objects.length-1) && scrolling == 0) {
                   scrolling = 1;
                   jQuery(slider_bullets[current_object_id]).removeClass('filled').addClass('empty');
                   jQuery(slider_bullets[current_object_id+1]).removeClass('empty').addClass('filled');
                   jQuery(slider_objects_container).animate({
                       marginLeft: '-='+(slider_object_width + slider_object_margin)+'px'
                   },settings.duration,settings.easing, function() {
                       current_object_id++;
                       scrolling = 0;
                   });
               }
            });
        }
        
        slider_bullets.click(function() {
            if(jQuery(this).hasClass('empty')) {
                //console.log(slider_bullets.index(this));
                //console.log(current_object_id);
                
                var index, step_count;
                if(current_object_id < slider_bullets.index(this)) {
                    
                    scrolling = 1;
                    
                    index = slider_bullets.index(this);
                    step_count = index - current_object_id;
                    
                    jQuery(slider_bullets[current_object_id]).removeClass('filled').addClass('empty');
                    jQuery(this).removeClass('empty').addClass('filled');
                    current_object_id = index;
                    
                    
                    
                    jQuery(slider_objects_container).animate({
                           marginLeft: '-='+(step_count * (slider_object_width + slider_object_margin))+'px'
                       },settings.duration,settings.easing, function() {
                           scrolling = 0;
                       });

                }
                else {
                    
                    scrolling = 1;
                    
                    index = slider_bullets.index(this);
                    step_count = index - current_object_id;
                    
                    jQuery(slider_bullets[current_object_id]).removeClass('filled').addClass('empty');
                    jQuery(this).removeClass('empty').addClass('filled');
                    current_object_id = index;
                    
                    jQuery(slider_objects_container).animate({
                           marginLeft: '+='+(Math.abs(step_count) * (slider_object_width + slider_object_margin))+'px'
                       },settings.duration,settings.easing, function() {
                           scrolling = 0;
                       });
                }
            }
        });
    });
};

