var f;
var menuabout = null;
var menuproduct = null;
var menucooperation = null;
var menucareer = null;


$().ready( function() {
$('.imgleft').each( function() {
var bImg =  $(this).attr('src');
$(this).wrap('<div class="img-left" style="background: url(' + bImg + ')"></div>');
});
$('.imgright').each( function() {
var bImg =  $(this).attr('src');
$(this).wrap('<div class="img-right" style="background: url(' + bImg + ')"></div>');
});
$('.imgcenter').each( function() {
var bImg =  $(this).attr('src');
$(this).wrap('<div class="center-float"><div class="img" style="background: url(' + bImg + ')"></div></div>');
});
	if ( $('.file-clear').length > 0 ) {
		$('.file-clear').click( function(event) {
			//$('.inputfile:first').attr('value', '');
			//$('.inputfile:first').html( $('.inputfile:first').html() );
			$('.file-field:first').html( $('.file-field:first').html() );
			$('.file .input input:first').val('');
			$('.file').each( function() {
				var filediv = $(this);
				filediv.find('.file-field input:first').change( function() {
					filediv.find('.input input:first').val($(this).val());
				});
			});
			event.preventDefault();
		});
	}
	$('#arts h3 a').each( function(i) {
		$(this).click( function(event) {
			$('.arts-group').slideUp();
			$($('.arts-group')[i]).slideDown();
			event.preventDefault()
		});
	});
	/*if ( $('.tablebodytext').length>0 ) {
		$('.tablebodytext').remove();
	}*/
	Cufon.replace('.head .slogan', { fontFamily: 'PFBeauSansProLight' });
	Cufon.replace('.col23 .letters a', { fontFamily: 'PFBeauSansProLight' });
	Cufon.replace('.prod-info a', { fontFamily: 'PFBeauSansProLight' });
	Cufon.replace('.years li a', { fontFamily: 'PFBeauSansProLight' });
	Cufon.replace('.years li span', { fontFamily: 'PFBeauSansProLight' });
	Cufon.replace('h1', { fontFamily: 'PFBeauSansProLight' });
	$('.sub li').each( function() {
		$(this).find('a:first').before(
			'<div class="top"><div></div></div>'
		);
		$(this).find('a:first').after(
			'<div class="bottom"><div></div></div>'
		);
		$(this).find('a:first').wrap(
			'<div class="middle"></div>'
		);
	});
	$('.select').each( function() {
		var target = $(this);
		target.find('img:first').click( function() {
			if (target.hasClass('opened'))
				target.removeClass('opened');
			else {
				$('.select').removeClass('opened');
				target.addClass('opened');
			}
		});
		target.find('ul').each( function() {
			$(this).find('li').each( function() {
				$(this).click( function() {
					target.removeClass('opened');
					target.find('input:first').val($(this).html());
				});
			});
		});
	});
	$('.tab-label li').each( function(i) {
		var target = $(this);
		$(this).find('a:first').click( function(event) {
			if ( target.hasClass('conf') ) {
				$("#conf").dialog({
					modal: true
				});
				$("#confyes").click( function() {
					$("#conf").dialog( "close" );
					$('.tab-label li').removeClass('active');
					target.addClass('active');
					$('.tab-content .tab').removeClass('active');
					$($('.tab-content .tab')[i]).addClass('active');
				});
				$("#confno").click( function() {
					$("#conf").dialog( "close" );
				});
				event.preventDefault();
			} else {
				$('.tab-label li').removeClass('active');
				target.addClass('active');
				$('.tab-content .tab').removeClass('active');
				$($('.tab-content .tab')[i]).addClass('active');
				event.preventDefault();
			}
		})
	});
	$('.default-value').each( function() {
		var defaultValue = $(this).val();
		$(this).focus( function() {
			if ($(this).val() == defaultValue) {
				$(this).val('');
			}
		});
		$(this).blur( function() {
			if ($(this).val() == '') {
				$(this).val(defaultValue);
			}
		});
	});
	$('.validation').each( function() {
		var validation = $(this);
		validation.find('.default-value').each( function() {
			this.defaultValue = $(this).val();
		});
		validation.submit( function(event) {
			if ( validation.hasClass('one-of') ) {
				f = validation.find('.not-empty').length;
			}
			else {
				f = 1;
			}
			validation.find('.default-value').each( function() {
				if ( $(this).val() == this.defaultValue ) $(this).val("");
			})
			validation.find('.not-empty').each( function() {
				if ( $(this).val() == "" ) {
					f--;
					if (f==0) {
						validation.find('.default-value').each( function() {
							$(this).val(this.defaultValue);
						});
						event.preventDefault();
					}
				}
			})
		});
	});
	if ( $('#searchbygroup').length == 1 ) {
		$('#searchbygroup').autocomplete(groupData, {
			//width: 173,
			max: 10,
			highlight: false,
			scroll: true,
			scrollHeight: 300
		});
	}
	if ( $('#searchbyname').length == 1 ) {
		$('#searchbyname').autocomplete(drugNameData, {
			//width: 153,
			max: 10,
			highlight: false,
			scroll: true,
			scrollHeight: 300
		});
	}
	//script for open/close maps in contacts
	$('div.open_map div.img').hide();
	$('div.open_map a').click(function(){
		var this_img = $(this).parent().next();
		if((this_img.is('div.img')) && (this_img.is(':visible'))) {
			this_img.slideUp('normal');
			return false;
		}
		if((this_img.is('div.img')) && (!this_img.is(':visible'))) {
			$('div.open_map div.img:visible').slideUp('normal');
			this_img.slideDown('normal');
			return false;
		}
	});
	$('.vacancy-list li').click( function() {
		$('.vacancy-list li').removeClass('active');
		$(this).addClass('active');
	});
	$('.file').each( function() {
		var filediv = $(this);
		filediv.find('.file-field input:first').change( function() {
			filediv.find('.input input:first').val($(this).val());
		});
	});
	$('.checkbox').each( function() {
		var checkbox = $(this);
		checkbox.find('input:first').change( function() {
			$(":checked").parent().addClass('active-checkbox');
			$(":not(:checked)").parent().removeClass('active-checkbox');
		});
	});
	$('.checks-morph').each( function() {
		$(this).find('br').remove();
		$(this).find('input').wrap('<span class="radio"></span>')
	});
	$('.radio-group').each( function() {
		var radioGroup = $(this);
		radioGroup.find('.radio').each( function() {
			var checkbox = $(this);
			checkbox.find('input:first').change( function() {
				radioGroup.find(":checked").parent().addClass('active-radio');
				radioGroup.find(":not(:checked)").parent().removeClass('active-radio');
			});
		});
	});
	if ( $('#menuabout').length == 1 ) {
		menuabout = $('#menuabout');
		menuabout.flash({
			swf: '/swf/menu/225x100_about.swf',
			id: 'menuaboutflash',
			width: 225,
			height: 100,
			wmode: 'transparent',
			allowScriptAccess: 'sameDomain'/*,
			flashvars: {
					message: true
			}*/
		});
		$('.menu .col1:first').mouseover( function() {
			//aboutMovie().SetVariable("message", true)
			aboutMovie('true');
		});
		$('.menu .col1:first').mouseout( function() {
			//aboutMovie().SetVariable("message", false)
			aboutMovie('false');
		});
	}
	if ( $('#menuproduct').length == 1 ) {
		menuproduct = $('#menuproduct')
		menuproduct.flash({
			swf: '/swf/menu/225x100_prep.swf',
			id: 'menuproductflash',
			width: 225,
			height: 100,
			wmode: 'transparent',
			allowScriptAccess: 'sameDomain'
		});
		$('.menu .col2:first').mouseover( function() {
			//productMovie().SetVariable("message", true)
			productMovie('true')
		});
		$('.menu .col2:first').mouseout( function() {
			//productMovie().SetVariable("message", false)
			productMovie('false')
		});
	}
	if ( $('#menucooperation').length == 1 ) {
		menucooperation = $('#menucooperation')
		menucooperation.flash({
			swf: '/swf/menu/225x100_sotr.swf',
			id: 'menucooperationflash',
			width: 225,
			height: 100,
			wmode: 'transparent',
			allowScriptAccess: 'sameDomain'
		});
		$('.menu .col3:first').mouseover( function() {
			//cooperationMovie().SetVariable("message", true)
			cooperationMovie('true')
		});
		$('.menu .col3:first').mouseout( function() {
			//cooperationMovie().SetVariable("message", false)
			cooperationMovie('false')
		});
	}
	if ( $('#menucareer').length == 1 ) {
		menucareer = $('#menucareer')
		menucareer.flash({
			swf: '/swf/menu/225x100_kar.swf',
			id: 'menucareerflash',
			width: 225,
			height: 100,
			wmode: 'transparent',
			allowScriptAccess: 'sameDomain'
		});
		$('.menu .col4:first').mouseover( function() {
			//careerMovie().SetVariable("message", true)
			careerMovie('true')
		});
		$('.menu .col4:first').mouseout( function() {
			//careerMovie().SetVariable("message", false)
			careerMovie('false')
		});
	}
	function aboutMovie(action) {
		menuabout.flash(
			function() {
				this.SetVariable('/:message', action);
			}
		);
	}
	function productMovie(action) {
		menuproduct.flash(
			function() {
				this.SetVariable('/:message', action);
			}
		);
	}
	function cooperationMovie(action) {
		menucooperation.flash(
			function() {
				this.SetVariable('/:message', action);
			}
		);
	}
	function careerMovie(action) {
		menucareer.flash(
			function() {
				this.SetVariable('/:message', action);
			}
		);
	}
	/*function aboutMovie() {
		var M$ =  navigator.appName.indexOf("Microsoft")!=-1
		return (M$ ? window : document)["menuaboutflash"]
	}*/
	/*function productMovie() {
		var M$ =  navigator.appName.indexOf("Microsoft")!=-1
		return (M$ ? window : document)["menuproductflash"]
	}
	function cooperationMovie() {
		var M$ =  navigator.appName.indexOf("Microsoft")!=-1
		return (M$ ? window : document)["menucooperationflash"]
	}
	function careerMovie() {
		var M$ =  navigator.appName.indexOf("Microsoft")!=-1
		return (M$ ? window : document)["menucareerflash"]
	}*/
	$('#flash75').flash ({
		swf: '/swf/135x70_75_with_lenta.swf',
		width: '135',
		height: '70',
		wmode: 'transparent'
	})
	$('#promoflash').flash ({
		swf: '/swf/470x347_Akrihin_Bitrix.swf',
		width: '100%',
		height: '347',
		wmode: 'transparent'
	})
	$('#smokeflash').flash ({
		swf: '/swf/smoke.swf',
		width: '100%',
		height: '100%',
		wmode: 'transparent'
	})
	$('#bikeflash').flash ({
		swf: '/swf/girl_velo.swf',
		width: '100%',
		height: '100px',
		wmode: 'transparent'
	})
	$('#dogflash').flash ({
		swf: '/swf/girl_man_dog.swf',
		width: '100%',
		height: '100px',
		wmode: 'transparent'
	})
	$('#snakeflash').flash ({
		swf: '/swf/zmey.swf',
		width: '100%',
		height: '100%',
		wmode: 'transparent'
	})
	$('#birdsflash').flash ({
		swf: '/swf/bird.swf',
		width: '100%',
		height: '100%',
		wmode: 'transparent'
	})
	$('#balloonflash').flash ({
		swf: '/swf/shar.swf',
		width: '100%',
		height: '100%',
		wmode: 'transparent'
	})
	$('#planeflash').flash ({
		swf: '/swf/samolet.swf',
		width: '100%',
		height: '100%',
		wmode: 'transparent'
	})
	$('#boatanimflash').flash ({
		swf: '/swf/boat_anim.swf',
		width: '100%',
		height: '100%',
		wmode: 'transparent'
	})
	$('.show-places').click( function(event) {
		$('.hidden-place:first').addClass('form-border');
		$('.hidden-place:first').removeClass('hidden-place');
		if ( $('.hidden-place').length == 0 ) {
			$(this).remove();
		}
		event.preventDefault();
	});
	$('.show-jobs').click( function(event) {
		$('.hidden-job:first').addClass('form-border');
		$('.hidden-job:first').removeClass('hidden-job');
		if ( $('.hidden-job').length == 0 ) {
			$(this).remove();
		}
		event.preventDefault();
	});
	$('.menu .col1').mouseover( function() {
		$('.sub-menu').fadeTo(0, .3);
	})
	$('.menu .col1').mouseout( function(eventObject) {
		//if (eventObject.target.tagName=="A") {
			$('.sub-menu').fadeTo(0, 1);
		//}
	})
});


$(window).load( function() {
	$('.flash-banner').each( function() {
		$(this).flash({
			swf: $(this).find('.flash-swf:first').html(),
			width: '225',
			height: $(this).find('.flash-height:first').html(),
			wmode: 'transparent',
			allowScriptAccess: 'sameDomain'
		});
	});
	/*$('.gradient-box .gradient-image').css({
		display: 'block'
	})*/
});
/*if ($.browser.msie && parseInt($.browser.version) == 6) {
	$(window).load( function() {
		$('.gradient-box .gradient-image').css('_height', $('.gradient-box').height() + "!important");
	});
}*/
if ($.browser.msie && parseInt($.browser.version) < 8) {
	$(window).resize( function() {
		$('.gradient-box .gradient-image').css('width', 'auto');
		$('.gradient-box .gradient-image').css('width', '100%');
		/*$('.gradient-box .gradient-image').css('_height', 'auto!important');
		$('.gradient-box .gradient-image').css('_height', $('.gradient-box').height() + "!important");*/
	});
}

