$(document).ready(function() {
	$.preloadCssImages();
	
	$('#menu').setCursor();
	$('#autokris').swapImg(750);
	$('#hella').swapImg(490);
	$('#krisway').swapImg(245);
	$('#motokris').swapImg(-5);
	/*
	$(window).resize(function() {
		window.location.href=window.location.href;
		//var cursor = $('#menu').css('backgroundPosition');
		//var pos = (cursor.slice(1, (cursor.length - 6)));
		//var position = ($(window).width() / 2) - 370;
		//alert(pos);
  		//$('#menu').animate({backgroundPosition: (position) + 'px 0px'}, 300, 'swing');
	});
	*/
	$('#menu_bottom a').clickMenuBottom();
 				
 	var lbSettings = {
 		imageLoading 	: 'img/lightbox/loading.gif',
		imageBtnClose 	: 'img/lightbox/close.gif',
		imageBtnPrev 	: 'img/lightbox/prev.gif',
		imageBtnNext 	: 'img/lightbox/next.gif'//,
		//txtImage 		: 'Снимка',
		//txtOf 			: 'от'
	};
	
	$('.about_autokris').lightBox(lbSettings);
	$('.about_hella').lightBox(lbSettings);
	$('.autokris_bs').lightBox(lbSettings);
	$('.autokris_bs2').lightBox(lbSettings);
	$('.autokris_sl').lightBox(lbSettings);
	$('.hella_bs').lightBox(lbSettings);
	$('.motokris_pl').lightBox(lbSettings);
	$('.krisgroup_vn').lightBox(lbSettings);
	$('.service_bs').lightBox(lbSettings);
	
	
				
});

(function($) {

	var position = ($(window).width() / 2);
	
	$.fn.setCursor = function() {
		$(this).animate({backgroundPosition: (position - 750) + 'px 0px'}, 300, 'swing');
	}
	
	$.fn.swapImg = function(pos) {	
		var bgImg = $(this).attr('id');
		//var cont = $(this);
		
		$(this).mouseover(function() {
			var selClass = $(this).attr('class');
			if(!selClass.match('selected') && $('#content_info').is(':hidden')) {
				// set cursor
				$('#menu').animate({backgroundPosition: (position - pos) + 'px 0px'}, 300, 'swing', function() {
					$('#content').fadeOut('fast', function() {
						$(this).fadeIn('fast').css({'background':'url(en/img/' + bgImg +'_bg.jpg)'});
					});
				});
				// remove class
				$('#menu ul li a').each(function() { $(this).removeClass('selected'); });
				// set bg img
				
			}	
		});
		$(this).mouseout(function() {
			if ($('#content_info').is(':hidden')) $(this).addClass('selected');
		});
		
	}
	
	$.fn.clickMenuBottom = function() {
		var infoId = new Array('about', 'contacts');
		var selId;
		$(this).click(function() {
			var className = $(this).attr('class');
			$('#menu a').each(function() { 
				if ($(this).hasClass('selected')) {
					selId = $(this).attr('id');
					$(this).removeClass('selected');
				} 
			});
			$.each(infoId, function(key, value) {
				if (className != value)  $('#' + value).hide(); 
			});
			$('#content_info').fadeIn('normal', function() {
				$('#' + className).fadeIn('normal');
				$('#content_info div#scrPanel').jScrollPane({showArrows:true});
			});
			$('#close a').click(function() {
				$('#content_info').fadeOut('fast');
				$('#menu a#' + selId).addClass('selected');
			});	
		});
		
	}
	
	
})(jQuery);	
