$(document).ready(function(){
	var timer;
	var hide;
	var hidenTime=10000;
	$('#sub'+activeSub).css({display:'block'});
	$('#topUl li:first').find('a').hover(
		function(){
			hide=false;
			$('#topMenu span').css({backgroundPosition:'50% 43px'});
			$('.subTop').css({display:'none'});
			if($('#topUl li:last').attr('class')!='active')
			{
				$('.tmRight').css({backgroundPosition:'left 43px'});
			}
			$('.tmLeft').css({backgroundPosition:'50% -26px'});
			$(this).parent().css({backgroundPosition:'50% -26px'});
			$('#sub'+$(this).attr('id').replace('main','')).css({display:'block'});
		},
		function(){
			hide=true;
			timer=setTimeout('hideSubMenu()', hidenTime);
		}
	);
	$('#topUl li:last').find('a').hover(
		function(){
			hide=false;
			$('#topMenu span').css({backgroundPosition:'50% 43px'});
			if($('#topUl li:first').attr('class')!='active')
			{
				$('.tmLeft').css({backgroundPosition:'50% 43px'});
			}
			$('.subTop').css({display:'none'});
			$(this).parent().css({backgroundPosition:'50% -26px'});
			$('.tmRight').css({backgroundPosition:'left -26px'});
			$('#sub'+$(this).attr('id').replace('main','')).css({display:'block'});
		},
		function(){
			hide=true;
			timer=setTimeout('hideSubMenu()', hidenTime);
		}
	);
	$('#topUl li:not(:first):not(:last)').find('a').hover(
		function(){
			hide=false;
			if($('#topUl li:first').attr('class')!='active')
			{
				$('.tmLeft').css({backgroundPosition:'50% 43px'});
			}
			if($('#topUl li:last').attr('class')!='active')
			{
				$('.tmRight').css({backgroundPosition:'left 43px'});
			}
			$('#topMenu span').css({backgroundPosition:'50% 43px'});
			$('.subTop').css({display:'none'});
			$(this).parent().css({backgroundPosition:'50% -26px'});
			$('#sub'+$(this).attr('id').replace('main','')).css({display:'block'});
		},
		function(){
			hide=true;
			timer=setTimeout('hideSubMenu()', hidenTime);
		}
	);
	hideSubMenu=function(){
		if(hide){
			if($('#topUl li:first').attr('class')!='active')
			{
				$('.tmLeft').css({backgroundPosition:'50% 43px'});
			}
			if($('#topUl li:last').attr('class')!='active')
			{
				$('.tmRight').css({backgroundPosition:'left 43px'});
			}
			$('#topMenu span').css({backgroundPosition:'50% 43px'});
			$('.subTop').css({display:'none'});
			if(activeSub!='')
			{
				$('#sub'+activeSub).css({display:'block'});
			}
		}
	}
	$('.subTop a').hover(
		function(){
			hide=false;
			clearTimeout(timer);
		},
		function(){
			hide=true;
			timer=setTimeout('hideSubMenu()', hidenTime);
		}
	);
	$('.message_title').click(function(){
		$('.message textarea').focus();
	});
	$('.thumbs img').bind('mouseenter',function(){
		var imgsrc=$(this).attr('src').replace('thumbals','front');
		if(imgsrc!=$('#image img').attr('src')){
			//$('#image img').stop().css({opacity:'1'});
			$('#image img').fadeOut('slow',function(){
				$('#image img').stop().attr({src:imgsrc}).load(function(){$(this).fadeIn('slow');});	
			});
		}
	});
	$('.panel img').bind('mouseenter',function(){
		var imgsrc=$(this).attr('src').replace('thumbals','front');
		if(imgsrc!=$('#image img').attr('src')){
			//$('#image img').stop().css({opacity:'1'});
			$('#image img').fadeOut('slow',function(){
				$(this).attr({src:imgsrc}).fadeIn('slow');	
			});
			//$('#image img').attr({src:imgsrc}).fadeIn('slow');
		}
	});
	$('.panel_2 img').bind('mouseenter',function(){
		var imgsrc=$(this).attr('src').replace('thumbals','front');
		if(imgsrc!=$('#image img').attr('src')){
			//$('#image img').stop().css({opacity:'1'});
			$('#image img').fadeOut('slow',function(){
				$('#image img').attr({src:imgsrc}).fadeIn('slow');	
			});
		}
	});
	
	$('#search_btn').click(function(){
		if($('#search').css('display')=='none')
		{
			//$(this).find('a').css({backgroundImage:'../images/button_90.png'});
			$('#search').slideDown(1000);
		} else {
			//$(this).find('a').css({backgroundImage:'../images/button.png'});
			$('#search').slideUp(1000);
		}
		return false;	
	});
	$('#search_clo a').click(function(){
		if($('#search').css('display')=='none')
		{
			$(this).find('a').css({backgroundImage:'../images/button_90.png'});
			$('#search').slideDown(1000);
		} else {
			$(this).find('a').css({backgroundImage:'../images/button.png'});
			$('#search').slideUp(1000);
		}
		return false;	
	});
});