jQuery.fn.runString = function(options)
{
    var options = jQuery.extend(
	{
	    speed	: 500,
	    classItem	: 'runNew',
	    width	: '902px',
	    delay	: 600,
		json	: ''	    
	}
	,options
    );

    this.jObj = jQuery(this);
    this.speed = options.speed;
    this.classItem = options.classItem;
    this.width = options.width;
    this.count = 0;
    this.delay = options.delay;
	this.json = options.json;
    var runObj = this;

   	var json = jQuery.parseJSON(this.json);
	runObj.container = jQuery('<div style="width:50000px;margin-left:10px"></div>').appendTo(runObj.jObj);
	runObj.container.css('position','relative');
	for (i in json)
	{
		runObj.container.append('<div class="'+runObj.classItem+'">'+json[i]+'</div>');
		runObj.count++;
	}
	setTimeout(function(){runObj.animate(-1);});

    this.animate = function(step)
    {
		step++;
		if (step % runObj.count == 0)
		{
		    runObj.container.css('left',runObj.width);
		}
	
		runObj.container.animate(
			{
			    left	: '-='+runObj.width
			},
			runObj.speed,
			function()
			{
			    setTimeout(function(){runObj.animate(step);}, runObj.delay);
			}
		);
    };

    return this;
};

jQuery(function(){
	jQuery('.hover-border').hover(function(){ jQuery(this).addClass('borders');}, function() { jQuery(this).removeClass('borders'); } );
});

function openVideo(url, width, height) {
	height = height + 24;
	var win = window.open('/flvplayer.php?u=' + url + '&w=' + width + '&h=' + height, 'video', 'width=' + width + ',height=' + height);
	return false;
}

jQuery(document).ready(function()
{
	var spoilers = jQuery('.spoiler-content');
	
	spoilers.css({
		height		: 'auto',
		overflow	: 'visible'
	});
	spoilers.slideUp(0);
	
	jQuery('.spoiler-caption').click(function()
	{
		spoiler = jQuery(this).parent();
		spoilerContent = spoiler.find('.spoiler-content:first');
		
		if (!spoiler.hasClass('expand'))
		{
			spoilerContent.stop(true,true).slideDown();
			spoiler.addClass('expand');
			jQuery(this).find('.spoiler-right-caption').html('Скрыть');
		}
		else
		{
			spoilerContent.stop(true,true).slideUp();
			spoiler.removeClass('expand');
			jQuery(this).find('.spoiler-right-caption').html('Показать');
		}
	});
});

var subaruSlider = new Object();
subaruSlider.speed = 500;//скорость анимации

/**
 * Выбор новости
 * @param int newsID идентификатор новости
 */
subaruSlider.selectNews = function(newsID)
{
	if (newsID >= 0 && newsID < this.newsCount)
	{
		dx = (this.newsID - newsID)*jQuery('.sn-news-item-content').width();
		this.animate({dx:dx});
		this.newsID = newsID;

		jQuery('.sn-news-item').removeClass('selected');
		jQuery('#news'+(newsID+1)).addClass('selected');
		
		id = parseInt((jQuery(jQuery('.sn-news-item.selected')).attr('id')).replace('news','')) - 1;
		var contents = jQuery('.sn-news-item-content');
		jQuery('#sn-slider-content').height(jQuery(contents[id]).height());
		
		window.location.hash = '#'+(newsID+1);
	}
	else
	{
		if (newsID <= 0)
		{
			this.selectNews(this.newsCount-1);
		}
		if (newsID >= this.newsID)
		{
			this.selectNews(0);
		}
	}
};

/**
 * Перемещение к следующей новости
 */
subaruSlider.next = function()
{
	this.selectNews(this.newsID+1);
};

/**
 * Перемещение к предыдущей новости
 */
subaruSlider.prev = function()
{
	this.selectNews(this.newsID-1);
};

/**
 * Анимация
 * @param Object options параметры
 */
subaruSlider.animate = function(options)
{
	var options = jQuery.extend({
		dx	: -jQuery('.sn-news-item-content').width(),
		speed	: this.speed
	},options);
	
	jQuery('#sn-content-news').animate({
		left	: '+='+options.dx
	},options.speed);
};

jQuery(document).ready(function()
{
	jQuery('.sn-news-item').click(function()
	{
		jQuery('.sn-news-item').removeClass('selected');
		jQuery(this).addClass('selected');
		
		id = parseInt((jQuery(this).attr('id')).replace('news','')) - 1;
		subaruSlider.selectNews(id);
	});
	
	subaruSlider.newsID = 0;
	subaruSlider.newsCount = jQuery('.sn-news-item-content').size();
	jQuery('#sn-content-news').width(subaruSlider.newsCount * jQuery('.sn-news-item-content').width());
	
	if (window.location.hash.indexOf('#') >= 0)
	{
		subaruSlider.selectNews(parseInt(window.location.hash.replace('#',''))-1);
	}
});
