$(document).ready(function(){
	//	home page animation start
	$('#mainSlider').each(function(){
		var $t=$(this);
		$t.left=$t.find('div.leftSlide');
		$t.left.button=$('#sliderType_1 a');
		$t.left.pos={'left':'0px','center':'-996px'};
		$t.left.ret=$t.left.find('a.txtSlideRetour');
		$t.right=$t.find('div.rightSlide');
		$t.right.button=$('#sliderType_2 a');
		$t.right.pos={'right':'0','center':'996px'};
		$t.right.ret=$t.right.find('a.txtSlideRetour');
		$t.center=$t.find('div.centerSlide div.box');
		$t.center.links=$t.find('div.centerSlide ul a');
		$t.center.pos={'left':'-81px','center':'-401px','right':'-671px'};
		
		//	animate click on green button
		$t.left.button.click(function(e){
			e.preventDefault();
			$t.center.links.fadeOut(500);
			$t.center.animate({left:$t.center.pos['left']}, 500);
			$t.left.animate({left:$t.left.pos['left'], opacity:'1'}, 500);
		});
		
		//	animate click on pink button
		$t.right.button.click(function(e){
			e.preventDefault();
			$t.center.links.fadeOut(500);
			$t.center.animate({left:$t.center.pos['right']}, 500);
			$t.right.animate({left:$t.right.pos['right'], opacity:'1'}, 500);
		});
		
		//	animate click return from green page
		$t.left.ret.click(function(e){
			e.preventDefault();
			$t.center.animate({left:$t.center.pos['center']}, 500);
			$t.left.animate({left:$t.left.pos['center'], opacity:'0'}, 500);
			$t.center.links.fadeIn(500);
		});
		
		//	animate click return from pink page
		$t.right.ret.click(function(e){
			e.preventDefault();
			$t.center.animate({left:$t.center.pos['center']}, 500);
			$t.right.animate({left:$t.right.pos['center'], opacity:'0'}, 500);
			$t.center.links.fadeIn(500);
		});
	});
	//	home page animation end

	// skinning drop-down lists
	$('form li.skinSelect').each(function(){
		var $t=$(this);
		$t.input=$t.find('select');
		
		//	adding HTML for skinned select
		$t.list=$('<ul class="dropDownList"></ul>');
		$t.input.find('option').each(function(){
			$t.list.append('<li value="'+$(this).val()+'">'+$(this).text()+'</li>');
		});
		$t.list.find('li:first').remove();
		$t.list.insertBefore($t.input).hide();
		$t.input.hide();
		var $firstOption=$t.input.find('option:first');
		$t.current=$('<div class="currentSel" value="'+$firstOption.val()+'"><a href="#">'+$firstOption.text()+'</a></div>');
		$t.current.insertBefore($t.list);
		
		//	binding events for dropdown list items
		$t.list.find('li').hover(function(){
			$(this).addClass('hover');
		},function(){
			$(this).removeClass('hover');
		}).click(function(){
			$t.current.attr('value',$(this).attr('value')).find('a').text($(this).text());
			$t.list.find('li.current').removeClass('current');
			$(this).addClass('current');
			$t.input.val($(this).attr('value'));
			$t.current.click();
		});
		
		//	bending events for dropdown list (showing/hiding dropdown list)
		$t.current.toggle(
			function(){
				$t.list.slideDown(200);
			},
			function(){
				$t.list.slideUp(200)
			}
		).find('a').click(function(e){
			e.preventDefault();
		});
	});
	
	//	hiding labels on cloick
	$('form li.skinInput').each(function(){
		var $t=$(this);
		$t.label=$t.find('label');
		$t.input=$t.find('input');
		if($t.input.val()!='') $t.label.hide();
		$t.input.focus(function(){
			 $t.label.hide();
		});
		$t.input.blur(function(){
			if($t.input.val()=='') $t.label.show();
		});
	});
	
	//	submit forms by click on link-button
	$('form a.submitLink').click(function(e){
		e.preventDefault();
		$(this).parents('form').submit();
	}); 
	
	//	animation for experts page
	var $experts=$('#expertsList');
	//$experts.find('div.expertContent:not(.active)').show().slideUp(1);
	
	$experts.find('div.expertItem').each(function(){
		var $t=$(this).find('div.inBlock');
		$t.a=$t.find('a');
		$t.id=$t.a.attr('href').slice(1);
		$t.block=$experts.find('div.'+$t.id);
		$t.block.h=$t.block.show().height();
		$t.block.height(0).hide();
		
		// hover on experts blocks
		$t.a.hover(function(){
			$t.addClass('hover');
		},function(){
			$t.removeClass('hover');
		});
		
		if(window.location.hash){
			if($t.id==window.location.hash.slice(1)){
				$t.addClass('active');
				$t.block.height($t.block.h).css('opacity','1').show();
				$t.block.find('div.flashAnimation').html('').each(function(){
					var so = new SWFObject($(this).attr('title'), "", $(this).width(), $(this).height(), "8", "#fff");
					so.addParam('wmode','transparent');
					so.addParam('allowFullScreen','true');
					so.write($(this).attr('id'));
				});
			}
		}
		
		//	click on expert block
		$t.a.click(function(e){
			e.preventDefault();
			$t.a.blur()
			window.location.hash=$t.id;
			var tmp=false;
			if($t.hasClass('active')) tmp=true;
			//	closing another active block
			$experts.find('div.active').each(function(){
				var $this=$(this);
				if($this.hasClass('inBlock')){
					$experts.find('div.'+$this.find('a').attr('href').slice(1)).animate({height:'1px', opacity:'0'}, 400);
					return $this.removeClass('active');
				}
			});
			if (tmp){
				window.location.hash='closed';
				return $(this);
			}
			
			// opening expert block
			$t.addClass('active');
			$t.block.animate({height:$t.block.h, opacity:'1'}, 500);
			$t.block.find('div.flashAnimation').html('').each(function(){
				var so = new SWFObject($(this).attr('title'), "", $(this).width(), $(this).height(), "8", "transparent");
				so.addParam('wmode','transparent');
				so.addParam('allowFullScreen','true');
				so.write($(this).attr('id'));
			});
		}).focus(function(){
			$t.a.blur()
		});
	});
	
	//	inserting flash
	$('#content div.flashAnimation').html('').each(function(){
		var so = new SWFObject($(this).attr('title'), "", $(this).width(), $(this).height(), "8", "transparent");
		so.addParam('wmode','transparent');
		so.addParam('allowFullScreen','true');
		so.write($(this).attr('id'));
	});
	
	$('#header ul.mainMenu li:has(ul)').each(function(){
		var $t=$(this);
		$t.lnk=$t.find('a:first'); $t.submenu=$t.find('ul:first');
		$t.submenu.find('li.active a:first').addClass('hover');
		$t.lnk.bind('mouseenter', function(){
			$t.submenu.show();
		});
		$t.parent().bind('mouseleave',function(){
			$t.submenu.hide();
		});
		$t.parent().children().not($t).bind('mouseenter', function(){
			$t.submenu.hide();
		});
	});
	
});

Cufon.replace('.cufon', { fontFamily: 'Arista 2.0 Light', hover: true });













