
$(document).ready(function(){

	function repaint(jElement) {
		if (!$.browser.msie) return;
		for (var i = 0; i < jElement.length; i++) {
			jElement[i].className = jElement[i].className;
		}
	}

	$(function() {
		var zIndexNumber = 1000;
		$('.popup').each(function() {
			$(this).css('zIndex', zIndexNumber);
			zIndexNumber -= 10;
		});
	});
	
	var timer;
	var timer1;
	var pheight;
	$(window).resize(function(){
		var pheight = $(window).height() - 172;
		if (pheight <577){pheight=577;}
		var pwidth = pheight*2.4390;
		
		$('.mainsizable').attr('style','max-width : '+pwidth+'px');
		$('.menu1').attr('style','max-width : '+ pwidth +'px');
		$('#menudark').attr('style','max-width : '+ pwidth +'px');
		$('.maintransparent').attr('style','max-width : '+ pwidth +'px');
		$('.mainfooter').attr('style','max-width : '+ pwidth +'px');
		
		$('#mainimage img').css('width',pwidth);
		$('#mainimage img').css('height',pheight);
		$('.search').attr('style','max-width : '+ pwidth +'px');
		
		if ($(window).width()<pwidth){
			var margin = -(pwidth - $('#mainimage').width())/2;
			$('#mainimage img').css('marginLeft',margin);
		} else {
			var margin = ($('#mainimage').width() - pwidth)/2;
			$('#mainimage img').css('marginLeft', margin);
			$('.menu1').css('marginLeft', margin);
			$('#menudark').css('marginLeft', margin);
			$('.maintransparent').css('marginLeft', margin);
		}

		pheight = pheight - 100;
		$('#layoutMainContent').attr('style','height : '+pheight +'px; max-width : ' + pwidth + 'px;');
		var bheight = $(window).height() - 447; 
		margin = (bheight - $('.mainsizable').height())/2;
		if (margin>=50){
			$('.mainsizable').css('top',margin);
		} else {
			margin=50;
			$('.mainsizable').css('top',margin);
		}
		pheight = pheight + 101;
		
	});
	$(window).resize();
	
	
	
	
	
	$('#searchform .input input').focus(function(){
		if ($(this).attr('value')=='Введите название продукта или ключевое слово'){
			$(this).attr('value','');
		} 
	});
	$('#searchform .input input').blur(function(){
		if ($(this).attr('value')==''){
			$(this).attr('value','Введите название продукта или ключевое слово');
		} 
	});
	
	$('.menuLink').hover(function(){
		$('.menutransparent').stop(true);
		$('.col').hide();
		clearTimeout(timer);
		var str = $(this).index();
		str = str+1;
		str = '.c' + str;
		if ($(str).length){
			if ($('#hiddenMenuMain').length){
				var pheight = $(window).height() - 172;
				if (pheight < 577){pheight=577;}
				$('.menutransparent').animate({height: "250px"},200, function(){$(str).show();});
			} else {
				$('.menutransparent').animate({height: "250px"},200, function(){$(str).show();});
			}
		} else {
			$('.menutransparent').animate({height: "100px"},200, function(){});
		}
	}, function(){
		$('.menutransparent').stop(true);
		clearTimeout(timer);
		timer = setTimeout(function(){
			$('.col').hide();
			$('.menutransparent').animate({height: "100px"},200, function(){});
		},400);
	});
	
	$('.col').hover(function(){
		clearTimeout(timer);
	},function(){
		$('.menutransparent').stop(true);
		clearTimeout(timer);
		timer = setTimeout(function(){
			$('.col').hide();
			$('.menutransparent').animate({height: "100px"},200, function(){
		});},400);
	});
	
	
	if ($('#timeline').length) {
		$('#timeline .popup').each(function(){
			var top = ($(this).parent().height() - $(this).height())/2;
			top = top-10;
			$(this).css('top',top);
		});
	}
	
	
	if ($('#slideshow').length){
	
		$('#slideshow').cycle({ 
			fx:     'scrollVert', 
			speed:  'slow', 
			timeout: 0, 
			pager:  '#nav',
			pagerAnchorBuilder: function(idx, slide) { 
				return '#nav a:eq(' + idx + ')'; 
			}     
		});
	
		$('#hslides1').cycle({ 
			fx:     'scrollHorz', 
			speed:  'slow', 
			timeout: 0, 
			prev:   '#prev1', 
			next:   '#next1', 
			after:   onAfter1,
			pager:  '#top1',
			pagerAnchorBuilder: function(idx, slide) { 
				return '#top1 a:eq(' + idx + ')'; 
			}	     
		});
		
		$('#hslides2').cycle({ 
			fx:     'scrollHorz', 
			speed:  'slow', 
			timeout: 0, 
			prev:   '#prev2', 
			next:   '#next2',
			after:   onAfter2,
			pager:  '#top2',
			pagerAnchorBuilder: function(idx, slide) { 
				return '#top2 a:eq(' + idx + ')'; 
			}	     
		});
		
		$('#hslides3').cycle({ 
			fx:     'scrollHorz', 
			speed:  'slow', 
			timeout: 0, 
			prev:   '#prev3', 
			next:   '#next3',
			after:   onAfter3,
			pager:  '#top3',
			pagerAnchorBuilder: function(idx, slide) { 
				return '#top3 a:eq(' + idx + ')'; 
			}	     
		});
		
		$('#hslides4').cycle({ 
			fx:     'scrollHorz', 
			speed:  'slow',			
			timeout: 0, 
			prev:   '#prev4', 
			next:   '#next4',
			after:   onAfter4,
			pager:  '#top4',
			pagerAnchorBuilder: function(idx, slide) { 
				return '#top4 a:eq(' + idx + ')'; 
			}	     
		});
	
	}

	
	function onAfter1(curr, next, opts) {
		var index = opts.currSlide;
		if (index == 0){
			$('#prev1').hide();
		} else {
			$('#prev1').show();
		}
		
		if (index == opts.slideCount - 1){
			$('#next1').hide();
		} else {
			$('#next1').show();
		}
	}
	function onAfter2(curr, next, opts) {
		var index = opts.currSlide;
		if (index == 0){
			$('#prev2').hide();
		} else {
			$('#prev2').show();
		}
		
		if (index == opts.slideCount - 1){
			$('#next2').hide();
		} else {
			$('#next2').show();
		}
	}
	function onAfter3(curr, next, opts) {
		var index = opts.currSlide;
		if (index == 0){
			$('#prev3').hide();
		} else {
			$('#prev3').show();
		}
		
		if (index == opts.slideCount - 1){
			$('#next3').hide();
		} else {
			$('#next3').show();
		}
	}
	function onAfter4(curr, next, opts) {
		var index = opts.currSlide;
		if (index == 0){
			$('#prev4' ).hide();
		} else {
			$('#prev4' ).show();
		}
		
		if (index == opts.slideCount - 1){
			$('#next4').hide();
		} else {
			$('#next4').show();
		}
	}
	
	
	
	$('#schemea1').click(function(e,keepScroll){
		$('.schemePopup').hide(); 
		$('#scheme1').show();
		$('#schemea2').attr('style','text-decoration : none;');
		$('#schemea1').attr('style','text-decoration : underline;');
		e.preventDefault();
	});
	$('#schemea2').click(function(e,keepScroll){
		$('.schemePopup').hide(); 
		$('#scheme2').show();
		$('#schemea1').attr('style','text-decoration : none;');
		$('#schemea2').attr('style','text-decoration : underline;');
		e.preventDefault();
	});
	$('.schemePopup .close').click(function(e,keepScroll){
		$('.schemePopup').hide();
		$('#schemea1').attr('style','text-decoration : none;');
		$('#schemea2').attr('style','text-decoration : none;');
		e.preventDefault();
	});
	
	$("a[href^='http://']:not(a[href*='jnj.ru']):not(a.plink):not(a.nodsc)").mousedown(function() {
		if (confirm("Вы покидаете сайт ООО «Джонсон & Джонсон». Эта ссылка ведёт Вас на вебсайт, где политика конфиденциальности нашей компании не действует. Мы рекомендуем Вам ознакомиться с Политикой Конфиденциальности каждого сайта, который Вы посещаете.")) { 
			window.open($(this).attr('href'));
		} else {
			return true;
		}	
	});
	
	
	
	/*$("a[href^='http://']:not(a[href*='pichesky.ru'])").hover(function() {
		$('#outerpopup').hide();
		$('#outerpopup').css('top', $(this).offset().top - 20);
		$('#outerpopup').css('left', $(this).offset().left - 255);
		$('#outerpopup .plink').attr('href', $(this).attr('href'));
		$('#outerpopup .plink').html($(this).attr('href'));
		$('#outerpopup').show();
	}, function(){
		clearTimeout(timer1);
		timer1 = setTimeout(function(){
			$('#outerpopup').hide();
		},400);
	});
	
	$('#outerpopup').hover(function(){
		clearTimeout(timer1);
	}, function(){
		$('#outerpopup').hide();
	});
	
	$('#outerpopup').click(function(){
		window.open($(this).find('.plink').attr('href'));
	});*/
	
});
