/*log*/
function log(a,a1,a2,a3,a4,a5,a6,a7) {
 if(window.console && window.console.log){
	 if(a7 != undefined){
	 	window.console.log(a,a1,a2,a3,a4,a5,a6,a7);
	 }else if(a6 != undefined){
		 window.console.log(a,a1,a2,a3,a4,a5,a6);
	 }else if(a5 != undefined){
		 window.console.log(a,a1,a2,a3,a4,a5);
	 }else if(a4 != undefined){
		 window.console.log(a,a1,a2,a3,a4);
	 }else if(a3 != undefined){
		 window.console.log(a,a1,a2,a3);
	 }else if(a2 != undefined){
		 window.console.log(a,a1,a2);
	 }else if(a1 != undefined){
		 window.console.log(a,a1);
	 }else{
		 window.console.log(a);
	 }
 }
 //window.console && window.console.log && window.console.log(a,a1,a2,a3,a4,a5,a6,a7);
}
/**/
$(function(){

$('.contacts_sect #content').css({zoom:1})

$('.shadowed .tl,.shadowed .bl').css({zoom:1})
$(window).bind('resize',function(){
	$('.shadowed .tl,.shadowed .bl').css({zoom:0})
	$('.shadowed .tl,.shadowed .bl').css({zoom:1})
})
$('.autosubmit').each(function(){
	$('#bd').css({zoom:'1'})
	$(this).hide().parents('form').find('input,select').bind('change',function(){
		$(this).parents('form').submit()
	})
})
$('.search form').bind('submit',function(){
	if($(this).find('.submited input').val() =='')
	return false
})
/*
$('.s_hd').scroll(function () { 
      console.log(';')
		$("span").css("display", "inline").fadeOut("slow"); 
    });

$('.s_hd').bind('mousemove',function(){
//	$(this).blur()
	$('.s_content').mouseover()
	
})
$('.s_hd').scroll(function(e){
	$('.s_content').scroll()
	console.log(e,'k')
})
*/


$('.map_wr,.map_cmns').addClass('action')

	if($('.map_wr').size() > 0){
		initMapWr($('.map_wr'))	
	}


	function initMapWr(MapWrO){
	
		var mapWrO = MapWrO[0],
		points = $('.point',MapWrO),
		mapCmns = $('.map_cmns:first'),
		crot = $('.crot:first',mapCmns),
		nextMov = $('.next-mov:first').addClass('visible')
		
		mapWrO.active = false
		mapWrO.lock = false
		mapWrO.points = points
		
		
		
		for(ii = 0 ; ii < points.length ; ii++){
			points[ii].sub = 	$('.cm_' + ii + ':first',mapCmns).hide()
			$(points[ii]).attr('title',points[ii].innerHTML)
		}
		
		crot.bind('click',function(){
			if($(this).hasClass('r_left')){
				initDir('left',points,crot)
			}else{
				initDir('right',points,crot)
			}
		})
		
		points.bind('click',function(){
			if(mapWrO.active !=this){
				$(mapWrO.active).removeClass('p_act')
	
				mapWrO.active.activated = false
				checkNext(this)
				mapWrO.active = this
				this.activated = true			
			}
		}).bind('mouseover',function(){
			setPoint(this,points,false)
		}).bind('mouseout',function(){
			delPoint(this,points)
		})
		
		nextMov.find('.c span').bind('click',function(){
			moveNext()
		})
		
		
		initDir('left',points,crot)
		
		function moveNext(){
			var curNum = parseInt(mapWrO.points.index(mapWrO.active),10)
			if(curNum == mapWrO.points.size() - 2){
				nextMov.removeClass('visible')
			}
			setPoint(curNum + 1,mapWrO.points,true)
		}
		function checkNext(o){
			var curNum = parseInt(mapWrO.points.index(o),10)
			//log(curNum == mapWrO.points.size() - 2,curNum , mapWrO.points.size() - 2)
			if(curNum == mapWrO.points.size() - 1){
				nextMov.removeClass('visible')
			}else{
				nextMov.addClass('visible')
			}
		}
		
		
		function initDir(dir,point,crot){
			if(!mapWrO.lock){
				if(dir == 'left'){
					crot.addClass('r_right').removeClass('r_left')
					for(ii = 0 ; ii < points.length ; ii++){
						point[ii] =	points[ii]

						points[ii].sub.find('.num').html(ii + 1);
					}
				}else{
					crot.addClass('r_left').removeClass('r_right')
		
					tPoints = new Array;;
				
					for(ii = 0 ; ii < point.length ; ii++){
						tPoints[point.length - ii -1] =	point[ii]
						point[ii].sub.find('.num').html(point.length - ii);
					}
					point = $(tPoints)
				}
				mapWrO.points = point
				setPoint('0',point,true)			
			}

		}
	
		function setPoint(num,pt,activate){
			
			if(typeof num == 'number' || typeof num == 'string'){
	
				$(pt[num]).addClass('p_act')

				if(mapWrO.active && mapWrO.active != pt[num]){
				
					$(mapWrO.active).removeClass('p_act')
					
					mapWrO.lock = true
				
					$(mapWrO.active.sub).fadeOut('100',function(){
						mapWrO.lock = false
						afterFade(pt[num])
					})
				
				}else if(mapWrO.active && mapWrO.active == pt[num]){
					checkNext($(pt[num]))
				}else{
					pt[num].activated = true
					afterFade(pt[num])
				}
			}else{
				if(num != mapWrO.active){
					$(num).addClass('p_act')
	
					mapWrO.lock = true
					$('.cm_el',mapCmns).not($(mapWrO.active.sub)).hide()
					$(mapWrO.active.sub).fadeOut('100',function(){
						mapWrO.lock = false
						afterFade(num)
					})					
				}
			
			}
			function afterFade(o){
				o.sub.show()

				if(activate){
					
					mapWrO.active.activated = false

					o.activated = true
					mapWrO.active = o
					o.activated = true
				}				
			}
			
		}
	
		function delPoint(num,pt){
				if(!num.activated){
					$(num).removeClass('p_act')
			
					$(mapWrO.active.sub).show()
					num.sub.hide()				
				}

			
		}
	

	}


	
	

});
