
function MobliFeedSlider(selector, varName, slider_class, itemSize, itemsPerSlide, itemsRows)
{
	this.buildNav = function()
	{
		if(this.totalSlides>1)
		{
			var slides_ctrls_html = '';
			for(var i=1; i<=this.totalSlides; i++)
			{
				ctrl_class = (i==1) ? ' class="current pg_' + (i-1) + '"' : ' class="pg_' + (i-1) + '"';
				slides_ctrls_html += '<span' + ctrl_class + ' onclick="' + this.varName + '.moveTo(' + (i-1) + ');">' + i + '</span>';
			}
			slides_ctrls_html += '<a href="#" class="ar_l" onclick="' + this.varName + '.movePrev();return false;">Previous</a>';
			slides_ctrls_html += '<a href="#" class="ar_r" onclick="' + this.varName + '.moveNext();return false;">Next</a>';
			
			
			$(this.nav).prepend(slides_ctrls_html);
		}
	};

	this.moveTo = function(slide_num)
	{
		var newPosition = 0 - slide_num * this.itemSize * this.itemsPerRow;
		$(this.nav).find('span.pg_'+this.current_slide).removeClass('current');
		this.current_slide = slide_num;
		$(this.nav).find('span.pg_'+this.current_slide).addClass('current');
		
		$(this.scroller).animate( {"margin-left": newPosition}, this.speed );
	};

	this.movePrev = function()
	{
		if(this.current_slide)
		{
			this.moveTo(this.current_slide-1);
		}
	};

	this.moveNext = function()
	{
		if(this.current_slide < this.lastSlide)
		{
			this.moveTo(this.current_slide+1);
		}
	};
	
	this.varName        = varName;
	this.container      = $(selector);
	this.nav            = $(selector).find('p.sml_paging');
	this.scroller       = $(selector).find('div.scroller div.' + slider_class);
	
	this.itemSize       = typeof(itemSize)!='undefined' ? itemSize : 158;
	this.itemsPerSlide  = typeof(itemsPerSlide)!='undefined' ? itemsPerSlide : 4;
	this.itemsRows      = typeof(itemsRows)!='undefined' ? itemsRows : 1;
	
	this.current_slide  = 0;
	this.itemsPerRow    = Math.ceil(this.itemsPerSlide / this.itemsRows);
	this.totalItems     = $(selector+' div.' + slider_class + ' .atom_item').size();
	this.totalCalcItems = Math.ceil(this.totalItems / this.itemsRows);
	this.totalSlides    = Math.ceil(this.totalItems / this.itemsPerSlide);
	this.lastSlide      = this.totalSlides - 1;
	this.speed          = 800;
	
	//$(this.scroller).css({width: this.totalCalcItems * this.itemSize});
	this.buildNav();
}

///////////////////////////////////
var speed = 500;

function hp_video_on()
{
	swfobject.embedSWF("http://www.mobli.com/player/video_player.swf", "vid", "980", "551", "9.0.0", "expressInstall.swf", flashvars, params, attributes);
	setTimeout("$('div#vid').html('<video src=\"http://cdn.mobli.com/pr_media/m720p_2k.mp4\" poster=\"\" width=\"980\" height=\"551\" controls />')", speed);
}

$(document).ready(function()
{
	$('#hm_cont_sel a.featured_menu').click(function(){
		
		var cur = $('#hm_cont_sel a.featured_menu.current');
		

		$(cur).removeClass('current');
		$('div[id^="region"]').css('display','none');
		
		$(this).addClass('current');
		
		var new_reg = $(this).attr('rel');
		$('#region_'+$(cur).attr('rel')).fadeOut('', function(){
		    
		
			$('#region_'+new_reg).fadeIn('slow');
		
		});
		//$('#region_'+$(cur).attr('rel')).fadeOut('slow', function(){$('#region_'+new_reg).fadeIn('slow');} );  chnged by ReD on 14.11.11
		
	
		
		return false;
	});
	for (i in av_sliders)
	{
		var reg = av_sliders[i]; 
		//r1003_slider = new MobliFeedSlider('#region_1003', 'r1003_slider', 'atoms', 158, 5, 1)
		eval("r" + reg + "_slider = new MobliFeedSlider('#region_" + reg + "', 'r" + reg + "_slider', 'atoms', 158, 5, 1);");
	}
	
	$('#see_vid').click(function(){
		
			$("#home_scroller").animate({left: -980}, speed, function(){$("#welc_vid").animate({height: 551}, speed);});
			setTimeout('hp_video_on()', speed*2);
			return false;
		});
	
	$('#cls_vid').click(function(){
		
			$('#vid').remove();
			$('#welc_vid').append('<div id="vid"></div>');
			$("#home_scroller").animate({left: 0}, speed);
			$("#welc_vid").animate({height: 396}, speed);
			return false;
		});
});

