(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  };
})(jQuery);

function theRotator(imgBox, interval, speed) {
	// Устанавливаем прозрачность всех картинок в 0
	$('div'+imgBox+' ul li').css({opacity: 0.0});
 
	// Берем первую картинку и показываем ее (по пути включаем полную видимость)
	$('div'+imgBox+' ul li:first').css({opacity: 1.0});
 
	// Вызываем функцию rotate для запуска слайдшоу, 5000 = смена картинок происходит раз в 5 секунд
	setInterval('rotate("'+imgBox+'", '+speed+')',interval);
}
 
function rotate(imgBox, speed) {	
	// Берем первую картинку
	var current = ($('div'+imgBox+' ul li.show')?  $('div'+imgBox+' ul li.show') : $('div'+imgBox+' ul li:first'));
 
	// Берем следующую картинку, когда дойдем до последней начинаем с начала
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div'+imgBox+' ul li:first') :current.next()) : $('div'+imgBox+' ul li:first'));	
 
	// Расскомментируйте, чтобы показвать картинки в случайном порядке
	// var sibs = current.siblings();
	// var rndNum = Math.floor(Math.random() * sibs.length );
	// var next = $( sibs[ rndNum ] );
 
	// Подключаем эффект растворения/затухания для показа картинок, css-класс show имеет больший z-index
	next.css({opacity: 0.0}).addClass('show').animate({opacity: 1.0}, speed);
 
	// Прячем текущую картинку
	current.animate({opacity: 0.0}, speed).removeClass('show');
};


$(document).ready(function() {


			$("a.zoom").fancybox();

			$("a.zoom1").fancybox({
				'overlayOpacity'	:	0.7,
				'overlayColor'		:	'#FFF'
			});

			$("a.zoom2").fancybox({
				'zoomSpeedIn'		:	500,
				'zoomSpeedOut'		:	500,
				'overlayShow'		:	false,
				'showNavArrows'		: 	true
			});
	if( !($.browser.webkit))
	{
		//$('div.cornerContainer').height($("#main").height()+'px');
		/* высота блока mainMenu*/
		mainMenuH = 0;
		$('.mainMenuBlock').each( function(){
			if( $(this).height() > mainMenuH )
				mainMenuH = $(this).height();
		});
		if(mainMenuH >0)
			$('#mainMenu').height(mainMenuH+'px');
	
	}

	if( ($.browser.webkit))
	{
		//$('div.cornerContainer').height($("#main").height()+'px');
		//$('div.cornerContainer').height($("#main").height()+'px');
		//$('table#main').css('height','100%');
		
	}


	contH = $('.mainBox').height();
	headH = $('#header').height();
	mainMenuH = $('#mainMenu').height();
	centerTblH = contH-headH-mainMenuH;
	//alert( $('#tblLeftColumn').height());
	//$('#centerTbl').height(centerTblH+'px');
	//$('#tblRightColumn').height(centerTblH+'px');
	//смена изображений в меню
	var images	= new Array();
	var kolvoImages = 4;
	var interval = 4000;
	var speed = 1000;
	//var medInterval = Math.round( (interval+(speed/2))/kolvoImages  );
	
	for( var i=0; i < kolvoImages; i++)
	{
		theRotator('#img_'+i, interval, speed);
		
	}

	/*
	 * Меню услуг - ниспадающе
	 */
	$('div.mainMenuBlock:last').css('margin-right','0px');
	
	
	
	$('div.mainMenuBlock').hover( function(){
		$(this).children("div.mainMenuBlockH1").addClass('activeMenu');
		$(this).children("div.popupMenu").animate({'opacity':'show'},'fast');
	}, function(){

		$(this).children("div.mainMenuBlockH1").removeClass('activeMenu');
		$(this).children("div.popupMenu").animate({'opacity':'hide'},'fast');
	});

});
;
