/*window_resize - begin*/
var d = document;
var winIE = (navigator.userAgent.indexOf("Opera")==-1 && (d.getElementById &&  d.documentElement.behaviorUrns))  ? true : false;

function bodySize(){
	if(winIE && d.documentElement.clientWidth) {
		sObj = d.getElementsByTagName("body")[0].style;
		sObj.width = (d.documentElement.clientWidth<1000) ? "1000px" : "100%";
	}
}

function init(){
	if(winIE) { bodySize(); }
}
 
onload = init;

if(winIE) { onresize = bodySize; }
/*window_resize - end*/

function update_items()
{
	var iCenter = $('div.items_roll div.center_item');
	var iLeft   = $('div.items_roll div.left_item');
	var iRight  = $('div.items_roll div.right_item');

	if (cur_item < 0)
		cur_item = max_item - 1;
	else if (cur_item == max_item)
		cur_item = 0;

	iCenter
		.find('a')
			.attr('href', products[cur_item].fullLink)
	;
	iCenter
		.find('img')
			.attr('src', products[cur_item].PhotoMedium)
			.attr('alt', products[cur_item].Title)
	;

	iCenter.find('p')
		.empty()
		.text(products[cur_item].Title)
	;

	iCenter.find('div.price').hide();
	
	if (products[cur_item].Price)
	{
		iCenter.find('div.price')
			.show()
			.find('span').text(products[cur_item].Price)
		;
	}
	
	// prev
	var prev_item = cur_item - 1;
	if (prev_item < 0) prev_item = max_item - 1;

	iLeft.find('a').attr('title', products[prev_item].Title);
	iLeft.find('a:not(class) img').attr('src', products[prev_item].PhotoSmall);
	
	// next
	var next_item = cur_item + 1;
	if (next_item == max_item) next_item = 0;

	iRight.find('a').attr('title', products[next_item].Title);
	iRight.find('a:not(class) img').attr('src', products[next_item].PhotoSmall);
}

$.tools.flashembed.conf.onFail = function(){
	var $container = $(this.getContainer());
	
	var cur_version = this.getVersion();
	
	var html = '<div class="flash-fail" title="">' +
		'<h3 class="req-version">Требуется флэш-плеер версии <strong>' + this.getConf()['version'].join(".") + '</strong> или новее.</h3>' + 
		(cur_version[0] == 0
			? '<h4 class="cur-version">У Вас флеш-плеер <strong>не установлен</strong>!</h4>'
			: '<h4 class="cur-version">Ваша версия <strong>' + cur_version.join(".") + '</strong>.</h4>'
		
		) + 
		'<p class="adobe-link">' + 
			'Загрузить последнюю версию плеера можно ' + 
			'<a href="http://www.adobe.com/go/getflashplayer" target="_blank" title="Загрузить флэш-плеер">здесь</a>.' +
		'</p>' +
		'</div>';
	
	if ($container[0].tagName.toLowerCase() === "a")
	{
		$container.html("");
		$('body').append(
			$(html).addClass("a-flash-fail").css($container.offset()).find("p.close a").click(site.close_flash_fail).end()
		);
	}
	else
	{
		$container.html(html);
	}
};

var cur_item;
var max_item;
var products;
$(document).ready(function() {
	$(".fancybox").fancybox();
	
	// products in home page
	max_item = $(products).size();
	if (max_item)
	{
		$("div.items_roll div.left_item a").click(function(){

			cur_item -= 1;
			update_items();
			return false;
		});
		$("div.items_roll div.right_item a").click(function(){
		
			cur_item += 1;
			update_items();
			return false;
		});
	}
	
	// videoplayer
	var vp = $('#vplayer');
	vp.empty();
	if (vp.size())
	{
		var source = '/images/edhardy/flv/';
		var conf = {
			src: '/images/edhardy/swf/vplayer.swf',
			version: [8,0],
			bgcolor: '#000000',
			width: 345,
			height: 304,
			wmode: 'opaque'
		};
		var fvars = {
			clip1: source + 'clip1.flv',
			clip2: source + 'clip2.flv',
			pic1:  source + 'clip1.jpg',
			pic2:  source + 'clip2.jpg',
			clip1title: 'Видеоклип 1',
			clip2title: 'Видеоклип 2'
		};
		
		vp.flashembed(conf, fvars);
	}
});