// JavaScript Document
document.documentElement.id='js';
$(function(){
	
	
		function jcarousel(){
			var $jc = $('#jcarousel');
			var $prev = $('a.prev',$jc);
			var $next = $('a.next',$jc);
			var $t = $('table.main',$jc);
			var $td = $('td.item',$jc);
			var $a = $('ul.navi',$jc).find('a');
			var l = $td.length-1;
			var i = 0;
			
			
			$a.each(function(index){
				$(this).click(function(){
					if(index>i){
						i=index;
						$t.stop().animate({'marginLeft':'+='+200},200,function(){
							$(this).animate({'marginLeft':'-'+i*1000},500);					
						});
					} else {
						i=index;
						$t.stop().animate({'marginLeft':'-='+200},200,function(){
							$(this).animate({'marginLeft':'-'+i*1000},500);					
						});
					}
					$jc.attr('class','jcarousel slide'+i);
					$a.removeClass('act').eq(i).addClass('act');
					$('#contacts').animate({'top':-1000},500);
					setTimeout(function(){ 
						$('ul.navi',$jc).css({'top':225,'left':48});
						$('#fav').css({'top':204,'left':32});
					},200)
					
					$t.parent().css('visibility','').animate({'opacity':1},200)
					$('#phone').parent().removeClass('hide');
					return false;
				});			
			});
			
			$prev.click(function(){
				if(i>0){
					i--;					
					$t.stop().animate({'marginLeft':'-='+200},200,function(){
						$(this).animate({'marginLeft':'-'+i*1000},500);					
					});
					
				} else {
					i=l;					
					$t.stop().animate({'marginLeft':'+='+200},200,function(){
						$(this).animate({'marginLeft':'-'+i*1000},500);					
					});

				
				}
				$jc.attr('class','jcarousel slide'+i);
				$a.removeClass('act').eq(i).addClass('act');
				return false;
			});
			
			$next.click(function(){
				if(i<l){
					i++;					
					$t.stop().animate({'marginLeft':'+='+200},200,function(){
						$(this).animate({'marginLeft':'-'+i*1000},500);					
					});
					
				} else {
					i=0;					
					$t.stop().animate({'marginLeft':'-='+200},200,function(){
						$(this).animate({'marginLeft':'-'+i*1000},500);					
					});

				
				}
				$jc.attr('class','jcarousel slide'+i);
				$a.removeClass('act').eq(i).addClass('act');
				return false;
			});
			
			$('div.desc').each(function(){
				var $obj = $(this);
				var $aBar = $('ul.bar',$obj).find('a');
				var $box = $('div.box',$obj)
				$aBar.each(function(index){
				$(this).click(function(){					
					$box.stop().animate({'opacity':0},200,function(){$(this).addClass('hide'); $box.eq(index).removeClass('hide').animate({'opacity':1},200); })
					$aBar.removeClass('act');
					$(this).addClass('act')
					return false;
				});
			})
			
			})
			
		
		}
		jcarousel()
		
		
	function contacts(){
		var $cont = $('#contacts');
		var $a = $('ul.navi',$cont).find('a');
		var $box = $('div.box',$cont);
		$a.each(function(index){
			$(this).click(function(){
				$a.removeClass('act').eq(index).addClass('act');
				$box.animate({'opacity':0},200,function(){$(this).addClass('hide'); $box.eq(index).removeClass('hide').animate({'opacity':1},200)})
				return false;
			});
		})
	}
	contacts();
	
	$('#phone').click(function(){
		setTimeout(function(){ 
			$('#phone').parent().addClass('hide'); 
			$('#jcarousel').find('ul.navi').css({'top':176,'left':-15}).find('a').removeClass('act');
			$('#fav').css({'top':152,'left':-32});
		}, 200 ); 
		$('#contacts').stop().animate({'top':252},500)
		$('#jcarousel').find('table.main').parent().animate({'opacity':0},200,function(){$(this).css('visibility','hidden');});
		
		
		
		return false;
	})
	
})
