// JavaScript Document


$(document).ready(
	function() {
		
		
		if (0 == $('.nav .selected').length) {
			$('.nav li:first').addClass('selected');
		}

		var _timer = null;
	
		$(".side").hover(function(){
			var _this = this;
			_timer = setTimeout(function(){
				$(_this)
					.stop(true)
					.animate({width: "339"}, "slow");
			}, 400);

		},function(){
			clearTimeout(_timer);
			$(this)
				.animate({width: "70"}, "slow");

		});
		
		$(".side li").hover(function(){
		$(this).addClass("hover");
		},function(){
		$(this).removeClass("hover");
		});
		
		
		$('.scroll-pane').jScrollPane({showArrows:false, scrollbarWidth:12});
		
		
		{	// Перемотка скрлолла на выделенный пункт
		
			if ($('.scroll-pane LI.current').length) {
				if ($('.scroll-pane').get(0).scrollTo) {
					$('.scroll-pane').get(0).scrollTo($('.scroll-pane LI.current').position().top);
				}
			}
			
		}
		
		$(".gallery > ul").tabs({
			click: function (object) {
				
				var _content = $('.hidden', object).html();
				
				if (_content) {
					$('.ui-tabs-panel DIV').html('<p>' + _content + '</p>');
				}
				
				$('#preloader')
					.css('opacity', .8)
					.show();
				
				var link = $(object).attr('rel');
				
				if ($('#hidden_image').length == 0) {
					$('body').append('<img id="hidden_image"/>');
					$('#hidden_image')
						.hide()
						.load(function () {
							$('.presentation IMG').attr('src', $(this).attr('src'));
							$('#preloader').hide();
						});

				}
				
				$('#hidden_image').attr('src', link);
			}

		});

		$('#carousel').jcarousel();
		
		if ($('.jcarousel-clip-horizontal li').length < 2) {
			$('.jcarousel-clip-horizontal').hide();
		}
		
		/*
		jQuery(document).ready(function() {
			jQuery('#carousel').jcarousel();
		});
		*/
		
		$(".close").click( function() { 
			$(".outer").animate({ opacity: 'hide' }, "slow");
		} );
		
		
		$(".type .item").hover(function(){
			$(this).children("span").show();
			},function(){
			$(this).children("span").hide();
		});
		
		/*
		{	
			
				var originalWidth = $('.presentation IMG').get(0).getAttribute('width');
				var originalHeight = $('.presentation IMG').get(0).getAttribute('height');

				$(window).resize(function () {
					var width = $('body').width();
					if (width > 80000) {
						$('.presentation IMG').width(800);
					}
					else {
						$('.presentation IMG').width('100%');
					}
					
					var width = $('.presentation IMG').width();
					var height = originalHeight * width / originalWidth;
					$('.presentation IMG').height(height);
				});

				$(window).resize();
			//}
			
		}
		*/
		$('.calculator form, .content form').jqTransform();
		
		$('.navigation > ul > li').hover(function(){
			$(this).find('ul').stop(true, true);
			$(this).children('ul').fadeIn();
			$(this).addClass("hover");
		},function(){
			$(this).children('ul').fadeOut();
			$(this).removeClass("hover");
		});
		
		
		
		{	// кнопочки назад вперёд на главное у больших картинок
			function ToggleStrMain(flag) {

				if ($('.ui-tabs-selected').prev().length) {
					$('.pres-prev').show();
				}
				else {
					$('.pres-prev').hide();
				}
				
				if ($('.ui-tabs-selected').next().length) {
					$('.pres-next').show();
				}
				else {
					$('.pres-next').hide();
				}
				
				var index = $('.jcarousel-item').index($('.ui-tabs-selected'));

				if (flag) {
					if (flag == 'next') {
						$('.jcarousel-next').click();
					}
					else {
						$('.jcarousel-prev').click();
					}
				}
			
			}

			$('.pres-next').click(function () {

				
				$('a', $('.ui-tabs-selected').next()).click();
				ToggleStrMain('next');
				
				return false;
				
			});
			
			$('.pres-prev').click(function () {
				
				$('a', $('.ui-tabs-selected').prev()).click();
				ToggleStrMain('prev');
				
				return false;
				
			});
			
			$('a', $('.jcarousel-item')).click(function () {
				ToggleStrMain();
			});
			
			ToggleStrMain();
			
		}
				
	});
