// banner
$(document).ready(function(){
	//обнуляем кнопки-превью (чтобы работал js click)
	$('.sm_thumbs a').each(function(index){
		$(this).attr('link',$(this).attr('href')).attr('href','javascript:;');
		if(index==0){
			$('.h-banner-frame-bg .h-banner-preview a').attr('href',$(this).attr('link'));			
			//ChangeBannIm($(this).attr('prev'),'0');
		}
	});
	
	//вешаем клик на наши превью
	$('.sm_thumbs a').click(function(){
		if(!$(this).hasClass('active')){
			$('.sm_thumbs a').removeClass('active');
			$(this).addClass('active');
			prev = $(this).attr('prev');//большой баннер
			link = $(this).attr('link');
			//$('.h-banner-frame-bg .h-banner-preview a').attr('href',$(this).attr('link'));
			//$('.h-banner-frame-bg .h-banner-preview a').attr('href',prev);

			data={str: prev, find: '.flv', index: 1};
			if(strpos(data)>0)							
				{ShowVideo(prev,link);ShowVideo(prev,link);}
			else
				ChangeBannIm(prev,'500',link);//меняет баннер
		}
	});
});


function ChangeBannIm(prev,del,link){
	
	//чтобы убрать object
	$('.h-banner-frame-bg .h-banner-preview a').html('<img src="/images/spacer.gif" />');

	if ($.browser.version =='6.0'){
		$('.h-banner-preview a').html('<img src="images/spacer.gif" width="200" height="230" style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+$(this).attr("prev")+'\', sizingMethod=\'crop\');"  alt="" />');
	}
	else {
		$('.h-banner-preview img').stop(true,true).fadeOut(del,function(){
		
			$('.h-banner-preview img').fadeIn(del).attr('src',prev);//указываем источник картинки
			$('.h-banner-frame').attr('href',link);
		});
	}
}
function ShowVideo(prev,link)
{
	//чтобы пропислась ссылка на flv
	$('.h-banner-frame-bg .h-banner-preview a').attr('href',prev);
	$('.h-banner-frame').attr('href',link);
	flowplayer("player", {src: "/js/player/flowplayer-3.2.7.swf", wmode: 'opaque'},
		{
			clip: {		
				// these two configuration variables does the trick
				autoPlay: true, 
				autoBuffering: true // <- do not place a comma here 
			},
			plugins:  {
				controls: {
					backgroundColor: "rgba(0, 0, 0, 0.8)",
					bufferColor: "#242224",                            
					sliderColor: "#000000",
				}                
			}
		}
	); 
}

function strpos(data) {
// Created by Mark Tali [webcodes.ru]
// Example. Return 8, but if index > 2, then return null
// strpos({str: 'Bla-bla-bla...', find: 'bla', index: 2});
	var haystack = data.str, needle = data.find, offset = 0;
	for (var i = 0; i < haystack.split(needle).length; i++) {
	var index = haystack.indexOf(needle, offset + (data.index != 1 ? 1 : 0));
	if (i == data.index - 1) return (index != -1 ? index : null); else offset = index;
	}
}
