function init_confirmations() {
	$(".confirmation").dialog({
		bgiframe: true,
		resizable: false,
		height: 350,
		autoOpen: false,
		modal: true,
		overlay: {
			backgroundColor: '#000',
			opacity: 0.5
		},
		buttons: {
			'I agree to terms and conditions': function() {
				$("#" + $(this).attr("rel")).attr('checked','checked');
				$(this).dialog('close');
			},
			Cancel: function() {
				$("#" + $(this).attr("rel")).removeAttr('checked');
				$(this).dialog('close');
			}
		}
	});
	$(".open_confirmation")
		.css({'cursor':'pointer'})
		.click(function() {
			$("#" + $(this).attr("rel")).dialog('open');
			return false;
		});
}

function init_msgbox() {
	$(".msgBox").dialog({
		height: 400,
		width: 690,
		modal: true,
		draggable: false,
		resizable: false,
		autoOpen: false
	});
	$(".open_msgBox")
		.css({'cursor':'pointer'})
		.click(function() {
			$("#" + $(this).attr("rel")).dialog('open');
			return false;
		});
}

function get_parent_div_of_class(element, class_name){
	while ($(element).parent().length){
		element = $(element).parent();
		if ($(element).hasClass(class_name))
			break;
	}
	/*while(pp = $(element).parent().length){
		
	}*/
	return element;
}

function init_sifr() {
	if(UseSiFR) {
		$('.simple .title, .benefit .title, .bright .title, .world .title').sifr({
			font: 'LugaBookC.swf',
			path: '/css/sifr',
			over: 1,
			zoom: 1,
			resizable: false,
			lineHeight: 20,
			width: 220,
			height: 80,
			version: 3
		});
	}
	/*setTimeout(function(){
		$('.simple .title, .benefit .title, .bright .title, .world .title').sifr({
			font: 'LugaBookC.swf',
			path: '/css/sifr',
			over: 1,
			zoom: 1,
			resizable: false,
			lineHeight: 20,
			width: 220,
			height: 80,
			version: 3
		});
	},7000);*/
	if(UseSiFR) {
		$('.vendor_title').sifr({//.product_video_title, 
			font: 'LugaC.swf',
			path: '/css/sifr',
			lineHeight: 20,
			width: 220,
			height: 60,
			version: 3
		});
		$('span.composition').sifr({
			font: 'LugaC.swf',
			path: '/css/sifr',
			lineHeight: 20,
			width: 55,
			height: 20,
			version: 3
		});
		$('.video_index_title').sifr({
			font: 'LugaBookC.swf',
			style: {'text-decoration':'none'},
			path: '/css/sifr',
			selectable: false,
			width: 115,
			zoom: 1,
			overY: 1,
			version: 3
		});
	}
	$('.slogan_top_red').sifr({
		font: 'LugaC.swf',
		width: 237,
		path: '/css/sifr',
		selectable: false,
		zoom: 1,
		overY: 1,
		version: 3
	});
	$('.title:not(.product_short_desc .title)').sifr({
		font: 'LugaBookC.swf',
		width: 250,
		style: {'text-decoration':'none'},
		path: '/css/sifr',
		selectable: false,
		zoom: 1,
		overY: 1,
		version: 3
	});
/*	$('.top_menu .item a:not(.top_menu .idea a)').sifr({
		font: 'LugaBookC.swf',
		style: {'text-decoration':'none'},
		path: '/css/sifr',
		selectable: false,
		width: 85,
		zoom: 1,
		overY: 1,
		version: 3
	});
	$('.top_menu .idea a').sifr({
		font: 'LugaBookC.swf',
		style: {'text-decoration':'none'},
		path: '/css/sifr',
		selectable: false,
		width: 147,
		zoom: 1,
		overY: 1,
		version: 3
	});*/
	/*$('.short_desc_about').sifr({
		font: 'LugaBookC.swf',
		style: {'text-decoration':'none'},
		path: '/css/sifr',
		selectable: false,
		height: 700,
		zoom: 1,
		overY: 1,
		version: 3
	});
	$('div.idea div.short_desc, table.idea td').sifr({
		font: 'LugaBookC.swf',
		style: {'text-decoration':'none'},
		path: '/css/sifr',
		selectable: false,
		width: 210,
		height: 230,
		zoom: 1,
		overY: 1,
		version: 3
	});*/
}


var ScrollingRemained;
var ScrollingItems2Move;
var ScrollingLeftExclude = 1;
var ScrollingRightExclude = 1;
var ScrollingCurrent = ScrollingLeftExclude + 7;
var ScrollingLocked = false;
var ScrollingAxis = 'x';
var ScrollingDuration = 1200;
var ScrollingEasing = "easeOutQuart";
var ScrollingKoef = 151.6;
var ScrollingOffset = ($("div.products_list_scroll").width() - 500) * -0.5;
var ScrollingHideSpeed = 20;
var ScrollingShowSpeed = 1000;
var ScrollingLargePic = 325;
var ScrollingMediumPic = 250;
var ScrollingSmallPic = 150;

function callback(){}
function init_products_index_list() {
	complete = true;
	
	//var Images2Load = new Array;
	alert($("img,object").length);
	/*$.each($("img,object"),function(i,obj){
		Images2Load[i] = obj;
	});

	if (Images2Load.length) {
		alert(Images2Load.length);
		for (var i in Images2Load) {
			var x = $(Images2Load[i]);
			if (!x[0].complete)
				complete = false;
		}
	}
	if (!complete)
		return setTimeout(init_products_index_list,1000);*/
	setTimeout(init_products_index_list_functions,1000);
}


function reinit_title_SIFR(){
	if (!$.browser.msie || !UseSiFR)
		return;
	if ($('.simple .title:visible').hasClass('sifr_processed'))
		return;
	$('.simple .title:visible, .benefit .title:visible, .bright .title:visible, .world .title:visible').sifr({
			font: 'LugaBookC.swf',
			path: '/css/sifr',
			over: 1,
			zoom: 1,
			resizable: false,
			lineHeight: 20,
			width: 220,
			height: 80,
			version: 3
		});
	$('.simple .title:visible').addClass('sifr_processed');
}

function hide_elements($els,dur) {
	if (!dur)
		dur = ScrollingHideSpeed;
	if ($.browser.msie)
		$els.hide();
	else
		$els.fadeOut(dur);
}
function show_elements($els,dur) {
	if (!dur)
		dur = ScrollingShowSpeed;
	if ($.browser.msie)
		$els.show();
	else
		$els.fadeIn(dur);
}
function animate_pic_size($el,pic_height) {
	var width2set = ( pic_height / $el.find("div.product_picture").height() ) * $el.find("div.product_picture").width()
	$el.animate(
		{
			width: width2set
		},
		ScrollingDuration,
		ScrollingEasing,
		callback
	);
	$el.find("div.product_picture").animate(
		{
			width: width2set,
			height: pic_height
		},
		ScrollingDuration,
		ScrollingEasing,
		callback
	);
}
function make_small($el) {
	animate_pic_size($el,ScrollingSmallPic);
}
function make_medium($el) {
	animate_pic_size($el,ScrollingMediumPic);
}
function make_large($el) {
	animate_pic_size($el,ScrollingLargePic);
}
function small2medium($el) {
	hide_elements($el.find("span.small_img"));
	setTimeout(function(){
		$el.addClass("medium");
		show_elements($el.find("span.medium_img"));
	},ScrollingHideSpeed);
}
function medium2small($el) {
	$el.find("span.medium_img").hide();
	$el.removeClass("medium");
	$el.find("span.small_img").show();
}
function large2medium($el) {
	$("div.video_menu ul.product_video_ul li").removeClass("active");
	$("div.product_video_tips span").removeClass("active");
	hide_details_blocks($el);
	hide_elements($el.find("div.product_desc"));
	hide_elements($el.find("span.large_img"));
	hide_elements($el.find("span.small_img"));
	setTimeout(function(){
		$el.removeClass("large");
		$el.addClass("medium");
		show_elements($el.find("span.medium_img"));
	},ScrollingHideSpeed);
}
function large2small($el) {
	$("div.video_menu ul.product_video_ul li").removeClass("active");
	$("div.product_video_tip span").removeClass("active");
	hide_details_blocks($el, 1);
	$el.find("div.product_desc").hide();
	$el.find("span.large_img").hide();
	$el.removeClass("large");
	$el.find("span.small_img").show();
}
function hide_details_blocks($el, dur) {
	if (!dur)
		dur = ScrollingHideSpeed;
	hide_elements($el.find("div.safari_test"),dur);
	hide_elements($el.find("div.close_details"),dur);
	hide_elements($el.find("a.read_more"),dur);
	hide_elements($el.find("div.product_icons"),dur);
	hide_elements($el.find("div.product_short_desc"),dur);
	hide_elements($el.find("div.farmer"),dur);
	hide_elements($el.find("div.video_menu"),dur);
	hide_elements($el.find("div.product_video_tips"),dur);
}
function show_details_blocks($el, dur) {
	if (!dur)
		dur = ScrollingHideSpeed;
	show_elements($el.find("div.safari_test"),dur);
	show_elements($el.find("div.close_details"),dur);
	show_elements($el.find("a.read_more"),dur);
	show_elements($el.find("div.product_icons"),dur);
	show_elements($el.find("div.product_short_desc"),dur);
	show_elements($el.find("div.farmer"),dur);
	show_elements($el.find("div.video_menu"),dur);
	show_elements($el.find("div.product_video_tips"),dur);
}
function scroll2element(el) {
	if (ScrollingLocked)
		return false;
	if (!el)
		el = ScrollingCurrent;
	clearTimeout(WindowScrolling);
	$("div.video_index_box ul.video_index_listing li:not(div.video_index_box ul.video_index_listing li.current)").html('<img src="img/plate.jpg" border="0">');
	fading_video_next();
	var $items = $("div.products_list_scroll li.products_index_scroll-item");
	ScrollingLocked = true;
	hide_elements($('div.products_list_scroll .prev, div.products_list_scroll .next'),200);
	$items.find("div.product_picture").animate({opacity:1},50);
	setTimeout(function(){show_elements($('div.products_list_scroll .next, div.products_list_scroll .prev'),200);}, ScrollingDuration);
	$('.products_list_scroll').scrollTo( ScrollingKoef*el + ScrollingOffset, {duration:ScrollingDuration, axis:ScrollingAxis, easing: ScrollingEasing} );
	setTimeout(function(){ reinit_title_SIFR(); }, ScrollingDuration + 200);
	
	if (ScrollingCurrent < $items.length - ScrollingRightExclude - 1) {
		var p_next = $items.get(ScrollingCurrent + 1);
		if (el != ScrollingCurrent + 1 && el != ScrollingCurrent + 2)
			make_small($(p_next));
	}
	if (ScrollingCurrent > ScrollingLeftExclude) {
		var p_prev = $items.get(ScrollingCurrent - 1);
		if (el != ScrollingCurrent - 1 && el != ScrollingCurrent - 2)
			make_small($(p_prev));
	}
	var p_cur = $items.get(ScrollingCurrent);
	$("div.video_menu ul.product_video_ul li").removeClass("active");
	$("div.product_video_tips span").removeClass("active");
	hide_details_blocks($(p_cur));
	$(p_cur).removeClass("current");
	if (el != ScrollingCurrent - 1 && el != ScrollingCurrent + 1)
		make_small($(p_cur));
	
	if (el <= $items.length - ScrollingRightExclude - 2) {
		var next = $items.get(el + 1);
		make_medium($(next));
		if ($('.products_list_scroll .next').attr("id") != "next_" + $(next).attr("rel"))
			$('.products_list_scroll .next').attr("id", "next_" + $(next).attr("rel"));
	} else {
		var first = $items.get(ScrollingLeftExclude);
		if ($(".products_list_scroll .next").attr("id") != "next_" + $(first).attr("rel"))
			$(".products_list_scroll .next").attr("id", "next_" + $(first).attr("rel"));	
	}
	
	var cur = $items.get(el);
	$(cur).addClass("current");
	make_large($(cur));
	$("div#slogan_top")
		.html($(cur).attr("title"))
		.attr('class','slogan_top_' + $(cur).attr("rel"))
		.sifr({
			font: 'LugaC.swf',
			width: 237,
			path: '/css/sifr',
			selectable: false,
			zoom: 1,
			overY: 1,
			version: 3
		});
	
	if (el > ScrollingLeftExclude) {
		var prev = $items.get(el - 1);
		make_medium($(prev));
		if ($(".products_list_scroll .prev").attr("id") != "prev_" + $(prev).attr("rel"))
			$(".products_list_scroll .prev").attr("id", "prev_" + $(prev).attr("rel"));
	} else {
		var last = $items.get($items.length - ScrollingRightExclude - 1);
		if ($(".products_list_scroll .prev").attr("id") != "prev_" + $(last).attr("rel"))
			$(".products_list_scroll .prev").attr("id", "prev_" + $(last).attr("rel"));
	}
	
	ScrollingCurrent = el;
	setTimeout(function(){current2middle();},ScrollingDuration);
}
function current2middle() {
	var $items = $("div.products_list_scroll li.products_index_scroll-item:not(li.marginal)");
	var current = ScrollingCurrent + 1;
	var length = $items.length;
	ScrollingItems2Move = (current > length/2)?Math.floor((length - current*2)/2):Math.ceil((length - current*2)/2);
	ScrollingRemained = Math.abs(ScrollingItems2Move);
	if (ScrollingItems2Move < 0)
		for (var i = 0; ScrollingRemained > 0; i++){
			var obj = $items.get(i);
			$(obj).insertBefore('#products_index_scroll_end');
			ScrollingRemained--;
			$('.products_list_scroll').scrollTo( ScrollingKoef*(ScrollingCurrent + (Math.abs(ScrollingItems2Move) - ScrollingRemained)*ScrollingItems2Move/Math.abs(ScrollingItems2Move)) + ScrollingOffset, {axis:ScrollingAxis} );
		}
	if (ScrollingItems2Move > 0)
		for (var i = length - 1; ScrollingRemained > 0; i--){
			var obj = $items.get(i);
			$(obj).insertAfter('#products_index_scroll_start');
			ScrollingRemained--;
			$('.products_list_scroll').scrollTo( ScrollingKoef*(ScrollingCurrent + (Math.abs(ScrollingItems2Move) - ScrollingRemained)*ScrollingItems2Move/Math.abs(ScrollingItems2Move)) + ScrollingOffset, {axis:ScrollingAxis} );
		}
	ScrollingCurrent+=ScrollingItems2Move;
	$.each($("div.products_list_scroll li.products_index_scroll-item:not(li.marginal)"),function(i,obj){
		$(obj).attr("href",i+1);
	});
	ScrollingLocked = false;
}
function init_products_index_list_functions() {
	if ($('div.products_list_scroll').length < 1)
		return false;
	jQuery.easing.easeOutQuart = function (x, t, b, c, d) {
		return -c * ((t=t/d-1)*t*t*t - 1) + b;
	};
	//if (!$.browser.msie)
	//	setTimeout(init_image_rotation,5000);
	$(".products_list_scroll .prev").click(function(){
		if( $(this).blur )
			$(this).blur();
		
		var $items = $("div.products_list_scroll li.products_index_scroll-item");
		if (ScrollingCurrent == ScrollingLeftExclude) {
			scroll2element($items.length - ScrollingRightExclude - 1);
			return;
		}
		scroll2element(ScrollingCurrent-1);
	});
	$(".products_list_scroll .next").click(function(){
		if( $(this).blur )
			$(this).blur();
		
		var $items = $("div.products_list_scroll li.products_index_scroll-item");
		if (ScrollingCurrent >= $items.length - ScrollingRightExclude - 1) {
			scroll2element(ScrollingLeftExclude);
			return;
		}
		scroll2element(ScrollingCurrent+1);
	});
	
	$('li.products_index_scroll-item div.product_picture')
		.css({'cursor':'pointer'})
		.click(function(){
			if (ScrollingLocked)
				return false;
			clearTimeout(WindowScrolling);
			var $items = $("div.products_list_scroll li.products_index_scroll-item");
			var parent_li = $(this).parents("li").get(0);
			if ($(parent_li).hasClass("current")) {
				var close_div = $(parent_li).find('div.close_details').get(0);
				if ($(close_div).length && $(close_div).css("display") != 'none') {
					$(close_div).click();
					return false;
				}
				$items.find("div.product_picture:not(#" + $(parent_li).attr("id") + " div.product_picture)").animate({opacity:0.3},50);
				show_details_blocks($(parent_li), 500);
				setTimeout( function(){
					$(parent_li).find("div.video_menu ul.product_video_ul li.featured").click();
				}, ScrollingDuration - 200);
				return true;
			} else {
				scroll2element(ScrollingLeftExclude + Number($(parent_li).attr("href")) - 1);
				location.href = "#" + $(parent_li).attr("hash");
				window.location.hash = $(parent_li).attr("hash");
			}
		});
		
	$("div.video_index_title")
		.css({'cursor':'pointer'})
		.click(function(){
			clearTimeout(WindowScrolling);
			var $items = $("div.products_list_scroll li.products_index_scroll-item");
			var parent_li = $items.get(ScrollingCurrent);
			var close_div = $(parent_li).find('div.close_details').get(0);
			if ($(close_div).length && $(close_div).css("display") == 'none') {
				$items.find("div.product_picture:not(#" + $(parent_li).attr("id") + " div.product_picture)").animate({opacity:0.3},50);
				show_details_blocks($(parent_li), 500);
				setTimeout( function(){
					$(parent_li).find("div.video_menu ul.product_video_ul li.featured").click();
				}, ScrollingDuration - 200);
				return true;
			}
			if ($(parent_li).find("div.video_menu ul.product_video_ul li.active").length > 0) {
				$(parent_li).find("div.video_menu ul.product_video_ul li.active").click();
				return true;
			}
			$(parent_li).find("div.video_menu ul.product_video_ul li:first").click();
		});
		
	$("div.video_menu ul.product_video_ul li")
		.css({'cursor':'pointer'})
		.click(function(){
			if (NowPlaying)
				return false;
			NowPlaying = true;
			//setTimeout(function(){NowPlaying = false;},5000);	
			if (typeof($(this).attr("rel")) != 'undefined') {
				clearTimeout(WindowScrolling);
				$("div.video_menu ul.product_video_ul li").removeClass("active");
				$("div.product_video_tips span").removeClass("active");
				$(this).addClass("active");
				$('#SMALL_VIDEO_TIP_' + $(this).attr("name")).addClass("active");
				var parent_li = $(this).parents("li").get(0);
				var parent_ul = $(this).parents("ul").get(0);
				var $els = $(parent_ul).find("li");
				var preview;
				var prev_li;
				if ($(this).hasClass("featured")) {
					preview = '/cms/img/plate.jpg';
					$("div.video_index_tmp").append('<img src="img/plate.jpg" border="0>"');
				} else {
					var img = new Image();
					img.src = $(this).attr("href");
					$("div.video_index_tmp").append('<img src="' + $(this).attr("href") + '" border="0>"');
					if (prev_li = $els.get(Number($(this).find("span.index:first").text()) - 2))
						preview = $(prev_li).attr("href");
					else
						if ($(parent_ul).find("li.featured").length > 0)
							preview = $(parent_ul).find("li.featured").attr("href");
				}
				set_video_index_box($(parent_li), $(this).attr("rel"), preview, $(this).hasClass("featured"), ($(this).hasClass("featured") || AutoPlay)?1:0);
				AutoPlay = true;
			}
		});
		
	$("div.product_video_tips span")
		.css({'cursor':'pointer'})
		.click(function(){
			$('#VIDEO_TIP_' + $(this).attr("name")).click();
		});
	
	$('div.close_details')
		.css({'cursor':'pointer'})
		.click(function(){
			var $items = $("div.products_list_scroll li.products_index_scroll-item");
			$("div.video_menu ul.product_video_ul li").removeClass("active");
			$("div.product_video_tips span").removeClass("active");
			var parent_li = $(this).parents("li").get(0);
			$items.find("div.product_picture").animate({opacity:1},150);
			hide_details_blocks($(parent_li), 500);
			$("div.video_index_box ul.video_index_listing li:not(div.video_index_box ul.video_index_listing li.current)").html('<img src="img/plate.jpg" border="0">');
			fading_video_next();
		});
	
	//$('div#products_list_loading').fadeOut(700);
	//if ($.browser.msie)
		//setTimeout(init_swf_image_rotation,300);
	//$('#products_index_scroll').animate({opacity: 1}, 700);
	show_elements($('#products_index_scroll, div.products_list_scroll .next, div.products_list_scroll .prev'),700);
	
	var anch = window.location.hash;
	if(anch.length > 1 && $("li.products_index_scroll-item[hash=" + anch.replace('#','') + "]").length > 0) {
		var ScrollingCurrent_tmp = ScrollingLeftExclude + Number($("li.products_index_scroll-item[hash=" + anch.replace('#','') + "]").attr("href")) - 1;
		if(ScrollingCurrent_tmp < 3) {
			scroll2element(ScrollingCurrent - 3);
			setTimeout(function(){scroll2element(ScrollingCurrent_tmp + 4);},ScrollingDuration);
			return;
		}
		if(ScrollingCurrent_tmp > $("div.products_list_scroll li.products_index_scroll-item").length - 1) {
			scroll2element(ScrollingCurrent + 2);
			setTimeout(function(){scroll2element(ScrollingCurrent_tmp - 2);},ScrollingDuration);
			return;
		}
		ScrollingCurrent = ScrollingCurrent_tmp;
		setTimeout(function(){scroll2element(ScrollingCurrent);},100);
		return;
	}
	scroll2element(ScrollingCurrent);
}
var AutoPlay = true;
function on_video_completed(){
	if (!NowPlaying) {
		AutoPlay = false;
		$.each($("div.video_menu ul.product_video_ul li.active"),function(i,obj){
			var parent_ul = $(obj).parents("ul").get(0)
			if ($(obj).hasClass("featured")){
				$(parent_ul).find("li:first").click();
			} else {
				var el = $("div.video_menu ul.product_video_ul li.active + li").get(0);
				if ($(el).hasClass("featured")) {
					$("div.video_index_box ul.video_index_listing li:not(div.video_index_box ul.video_index_listing li.current)").html('<img src="' + $(obj).attr("href") + '" border="0">');
					AutoPlay = true;
					fading_video_next();
					$("div.video_menu ul.product_video_ul li, div.product_video_tips span").removeClass("active");
				} else {
					$(el).click();
				}
			}
		});
	}
}
function on_video_started() {
	NowPlaying = false;
}
var WindowScrolling;
var WindowScrollingBuffer = 0;
var WindowScrollingTimeOut = 10;
var WindowScrollingDuration = 100;
var WindowScrollingOffset;
var WindowScrollingOffsetTop;
var WindowScrollingOffsetTopBuffer;
function scroll2video($el, video_url, img, is_featured, autoplay) {
	if (ScrollingLocked)
		return false;
	WindowScrollingBuffer+=WindowScrollingOffset;
	window.scrollTo(0, WindowScrollingBuffer);
	if (((WindowScrollingOffset > 0 && WindowScrollingBuffer < WindowScrollingOffsetTop) || (WindowScrollingOffset < 0 && WindowScrollingBuffer > WindowScrollingOffsetTop)) && WindowScrollingOffsetTopBuffer != $(window).scrollTop()) {
		WindowScrolling = setTimeout(function(){scroll2video($el, video_url, img, is_featured, autoplay);},WindowScrollingTimeOut);
		WindowScrollingOffsetTopBuffer = $(window).scrollTop();
	} else {
		set_movie2obj($el, video_url, img, is_featured, autoplay);
		fading_video_next();
	}
}
function scroll2bottom($el, video_url, img, is_featured, autoplay){
	WindowScrollingBuffer = $(window).scrollTop();
	WindowScrollingOffsetTop = Number($('#VideoPlayerLink').offset().top);
	WindowScrollingOffset = (WindowScrollingOffsetTop - WindowScrollingBuffer) * WindowScrollingTimeOut / WindowScrollingDuration;
	scroll2video($el, video_url, img, is_featured, autoplay);
}
function scroll2top(){
	if (ScrollingLocked)
		return false;
	WindowScrollingBuffer+=WindowScrollingOffset;
	window.scrollTo(0, WindowScrollingBuffer);
	if (WindowScrollingBuffer > WindowScrollingOffsetTop)
		WindowScrolling = setTimeout(scroll2top,WindowScrollingTimeOut);
}
function sendPlayRequest(id)
{
 thisMovie(id).requestPlayStart();
}

function thisMovie(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
        return window[movieName]
    }
    else {
        return document[movieName]
    }
}
function set_movie2obj($el, video_url, img, is_featured, autoplay) {
	AutoPlayBuffer = is_featured;
	$("div.video_index_box ul.video_index_listing li:not(div.video_index_box ul.video_index_listing li.current)").flash({
		swf: 'js/afplayer.swf',
		width: 1024,
		height: 575,
		id: 'VIDEO_' + $el.attr("id"),
		name: 'VIDEO_' + $el.attr("id"),
		flashvars: {
			mediatype: 'video',
			file: video_url,
			panelShown: 0,
			fadeOutPreview: 0,
			ofset: 0,
			videoId: 'VIDEO_' + $el.attr("id"),
			sh: 575,
			sw: 1024,
			image: img,
			playBanners: 0,
			showCodePanel: 0,
			opens: autoplay,
			mainFileLink: '',
			mainFileLinkTarget: '',
			controllsBarWidth: 0,
			hidePlayButton: 1
		},
		params: {
			movie: 'js/afplayer.swf',
			wmode: 'transparent',
			quality: 'high',
			allowFullScreen: false,
			allowScriptAccess: 'sameDomain'
		}
	});
}
var AutoPlayBuffer;
function set_video_index_box($el, video_url, img, is_featured, autoplay) {
	if (ScrollingLocked)
		return false;
	if (autoplay > 0) {
		scroll2bottom($el, video_url, img, is_featured, autoplay);
		return true;
	}
	if (AutoPlayBuffer) {
		WindowScrollingBuffer = $(window).scrollTop();
		WindowScrollingOffsetTop = 0;
		WindowScrollingOffset = (WindowScrollingOffsetTop - WindowScrollingBuffer) * WindowScrollingTimeOut / WindowScrollingDuration;
		scroll2top();
	}
	$("div.video_index_box ul.video_index_listing li:not(div.video_index_box ul.video_index_listing li.current)").html('<img src="' + img + '" border="0">');
	fading_video_next(prepend_play_button);
	set_movie2obj($el, video_url, img, is_featured, autoplay);
}
function prepend_play_button() {
	$("div.video_index_box ul.video_index_listing li.current:first").prepend('<span id="play_button"></span>');
	NowPlaying = false;
	$("span#play_button")
		.css({'cursor':'pointer'})
		.click(function(){
			//if ($.browser.msie) {
				$("ul#products_index_scroll ul.product_video_ul li.active").click();
			/*} else {
				$(this).hide();
				fading_video_next(start_current_video);
			}*/
		});
}
function start_current_video() {
	var movie = $('div.video_index_box ul.video_index_listing li.current:first').find("embed, object").get(0);
	sendPlayRequest($(movie).attr('name'));
}
var NowPlaying = false;
var GlobalFadingLocked = false;
var GlobalFadingCurrent = 1;
var GlobalFadingLast = 0;
var GlobalFadingSettings = {
		speed: 10,
		timeout: 3000,
		containerheight: '575px',
		animationtype: 'single'
	};
function init_fading_video() {
	if ($('div.video_index_box ul.video_index_listing').length > 0)
		$('div.video_index_box ul.video_index_listing').innerfade(GlobalFadingSettings);
}
function fading_video_next(callback) {
	GlobalFadingLocked = true;
	if (!callback)
		callback = function(){}
	var elements = $("div.video_index_box ul.video_index_listing li");
	var settings = GlobalFadingSettings;
	var current = GlobalFadingCurrent;
	var last = GlobalFadingLast;
	
	$(elements[last]).removeClass("current").fadeOut(settings.speed,function(){
		GlobalFadingLocked = false;
		$("div.video_index_box ul.video_index_listing li:not(div.video_index_box ul.video_index_listing li.current)").html("");
	});
	$(elements[current]).addClass("current").fadeIn(settings.speed,callback);
	
	if ( ( current + 1 ) < elements.length ) {
		current = current + 1;
		last = current - 1;
	} else {
		current = 0;
		last = elements.length - 1;
	};

	GlobalFadingCurrent = current;
	GlobalFadingLast = last;
}

var RotationBuffer = new Array();
var RotationForward = new Array();
var RotationTimeout = new Array();
function init_image_rotation() {
	$.each($(".products_index_scroll-item span.small_img img, .products_index_scroll-item span.medium_img img"),function(i,obj){
		RotationBuffer[i] = $(obj).rotate({maxAngle:30,minAngle:-30});
		RotationForward[i] = Math.random()>0.5?true:false;
		RotationTimeout[i] = Math.floor(Math.random()*300) + 1000;
		setTimeout( function(){ rotate_element(i, Math.floor(Math.random()*11)+10); }, RotationTimeout[i] );
	});
}
function rotate_element(idx, ang) {
	ang*=!RotationForward[idx]?-1:1;
	//alert(ang);
	RotationBuffer[idx][0].rotateAnimation(ang);
	RotationForward[idx]=!RotationForward[idx];
	setTimeout( function(){ rotate_element(idx,ang); }, RotationTimeout[idx] );
}

function init_icons_listing() {
	var anim = 'fade';
	if ($.browser.msie)
		anim = 'none';
	$('ul.product_icons').innerfade({
		speed: 2000,
		timeout: 3000,
		containerheight: '97px',
		animationtype: anim
	}); 
}

function fix_products_list_scroll_width() {
	var $items = $("div.products_list_scroll li.products_index_scroll-item");
	var cur = $items.get(ScrollingCurrent);
	hide_details_blocks($(cur), 200);
	$("div.products_list_scroll").width(document.body.clientWidth<1024?1024:document.body.clientWidth);
	ScrollingOffset = ($("div.products_list_scroll").width() - 500) * -0.5;// * -0.2375;
	$('.products_list_scroll').scrollTo( ScrollingKoef*ScrollingCurrent + ScrollingOffset, {duration:100, axis:ScrollingAxis} );
}

var ArrowsOffset = 0;
function fix_arrows_position() {
	if (document.body && document.body.clientWidth<1024)
		ArrowsOffset = $(window).scrollLeft();
	else 
		ArrowsOffset = 0;
	$(".products_list_index .prev").css({'left':ArrowsOffset});
	$(".products_list_index .next").css({'right':-1*ArrowsOffset});
}

function init_object_links() {
	$('a object, a span, a embed')
		.click(function(){
			var parent_link = $(this).parents("a").get(0);
			alert($(parent_link).attr("href"));
			location.href = $(parent_link).attr("href");
			return false;
		})
		.focus(function(){
			$(this).click();
		});
	$('a')
		.click(function(){
			if ($(parent_link).attr("href")!='' && $(parent_link).attr("href")!='undefined')
				location.href = $(parent_link).attr("href");
		})
		.focus(function(){
			$(this).click();
		});
}

function init_swf_image_rotation() {
	$.each($("span.small_img"),function(i,obj){
		if (UseImageRotation) {
			$(obj).flash({
				swf: 'img/ImageRotator.swf',
				width: '135',
				height: '150',
				flashvars: {
					imageURL: $(obj).text()
				},
				params: {
					wmode: 'opaque',
					play: true,
					loop: true,
					allowFullScreen: false,
					allowScriptAccess: 'sameDomain'
				}
			});
		} else {
			$(obj).html('<img src="' + $(obj).text() + '" alt="" border="0">');
		}
	});
	
	$.each($("span.medium_img"),function(i,obj){
		if (UseImageRotation) {
			$(obj).flash({
				swf: 'img/ImageRotator.swf',
				width: '280',
				height: '300',
				flashvars: {
					imageURL: $(obj).text()
				},
				params: {
					wmode: 'opaque',
					play: true,
					loop: true,
					allowFullScreen: false,
					allowScriptAccess: 'sameDomain'
				}
			});	
		} else {
			$(obj).html('<img src="' + $(obj).text() + '" alt="" border="0">');
		}
	});
	
	
	/*$.each($("span.medium_img img"),function(i,obj){
		var parent = $('#PARENT_'+ $(obj).attr('ID'));
		$(parent).flash({
			swf: 'img/ImageRotator.swf',
			width: '280',
			height: '300',
			flashvars: {
				imageURL: $(obj).attr("src")
			},
			params: {
				wmode: 'opaque',
				play: true,
				loop: true,
				allowFullScreen: false,
				allowScriptAccess: 'sameDomain'
			}
		});
	});*/
	hide_elements($('div#products_list_loading'),700);
	//alert('loaded...');
}

function init_gallery_scroll() {
		jQuery.easing.easeOutQuart = function (x, t, b, c, d) {
			return -c * ((t=t/d-1)*t*t*t - 1) + b;
		};
		jQuery(function( $ ){
			$('div.pictures_list_index').serialScroll({
				//target:'.gallery_full_list',
				items:'li', // Selector to the items ( relative to the matched elements, '#sections' in this case )
				prev:'.pictures_list_index .prev',// Selector to the 'prev' button (absolute!, meaning it's relative to the document)
				next:'.pictures_list_index .next',// Selector to the 'next' button (absolute too)
				axis:'x',// The default is 'y' scroll on both ways
				//navigation:'#greybox_m img.nav_first, #navigation_hidden a, #greybox_m img.nav_last',
				duration:700,// Length of the animation (if you scroll 2 axes and use queue, then each axis take half this time)
				force:true, // Force a scroll to the element specified by 'start' (some browsers don't reset on refreshes)
				cycle:false, //don't pull back once you reach the end
				//queue:false,// We scroll on both axes, scroll both at the same time.
				//event:'click',// On which event to react (click is the default, you probably won't need to specify it)
				//stop:false,// Each click will stop any previous animations of the target. (false by default)
				//lock:true, // Ignore events if already animating (true by default)		
				//start: 0, // On which element (index) to begin ( 0 is the default, redundant in this case )
				exclude:3,//Exclude n elements before end		
				//cycle:true,// Cycle endlessly ( constant velocity, true is the default )
				//step:4, // How many items to scroll each time ( 1 is the default, no need to specify )
				//jump:false, // If true, items become clickable (or w/e 'event' is, and when activated, the pane scrolls to them)
				//lazy:false,// (default) if true, the plugin looks for the items on each event(allows AJAX or JS content, or reordering)
				//interval:1000, // It's the number of milliseconds to automatically go to the next
				//constant:true, // constant speed
				
				onBefore:function( e, elem, $pane, $items, pos ){
					 //those arguments with a $ are jqueryfied, elem isn't.
					e.preventDefault();
					if( this.blur )
						this.blur();
				},
				onAfter:function( elem ){
					//'this' is the element being scrolled ($pane) not jqueryfied
				}
			});
		});
}
function init_add_desc() {
	$.each($("ul#products_index_scroll ul.product_video_ul li span.add_desc"),function(i,obj){
		var parent = $(this).parents("div").get(0);
		$(parent).find("div.add_desc").html($(this).text());
	});
}
function init_products_submenu() {
	$("#salads_submenu_open").hover(
		function(){
			$("#salads_submenu").show();
		},
		function(){
			$("#salads_submenu").hide();
		}
	);
	$("div.current #salads_submenu li a").click(function(){
		$("#" + $(this).attr("rel")).find("div.product_picture").click();
		var parent_ul = $(this).parents("#salads_submenu").get(0);
		$(parent_ul).hide();
	});
}

var UseSiFR;
var UseImageRotation;
if ($.browser.msie) {
	UseSiFR = false;
	UseImageRotation = false;
} else {
	UseSiFR = false;
	UseImageRotation = false;
}
//main jquery hook-up function
$(document).ready(
	function() {
		$('#products_index_scroll').hide();
		$('div.products_list_scroll .prev, div.products_list_scroll .next').hide();
		$.preloadCssImages();
		init_msgbox();
		//init_object_links();
		//fix_products_list_scroll_width();
		init_gallery_scroll();
		init_add_desc();
		
		//---------------------------//
		init_products_index_list_functions();
		init_icons_listing();
		init_products_submenu();
		init_fading_video();
		fix_products_list_scroll_width();
		fix_arrows_position();
		init_sifr();
/*		init_products_index_list();
		init_icons_listing();
		fix_products_list_scroll_width();
		fix_arrows_position();
		init_sifr();*/
		
		
	}
);

$(window).resize(
	function(){
		fix_products_list_scroll_width();
		fix_arrows_position();
	}
);
$(window).scroll(
	function(){
		fix_arrows_position();
	}
);
