function closeFlash(){
	
}

$(document).ready(function() {
	
	$("a[rel='blank']").click(function(){
		window.open($(this).attr('href'));
		return false
	});
	$('.flash div').html('<object type="application/x-shockwave-flash" data="/hcs4.swf?v" wmode="transparent" width="600" height="600"><param name="movie" value="/hcs4.swf?v" /><param name="wmode" value="transparent" /></object>')
	
	//$('.flash div.standart').html('<object type="application/x-shockwave-flash" data="/hcs.swf" wmode="transparent" width="600" height="600"><param name="movie" value="/hcs.swf" /><param name="wmode" value="transparent" /></object>')
	//$('.flash div.holy').html('<object type="application/x-shockwave-flash" data="/hcs1.swf" wmode="transparent" width="750" height="750"><param name="movie" value="/hcs.swf" /><param name="wmode" value="transparent" /></object>')

	$('.flash a').click(function(){
			$('.flash .holy object').remove();
			$('.flash a').hide(); 
			$('.flash div').html('<object type="application/x-shockwave-flash" data="/hcs.swf" wmode="transparent" width="600" height="600"><param name="movie" value="/hcs.swf" /><param name="wmode" value="transparent" /></object>');
		return false
	});

	maxheight = 0;
	$('.all .tw .bl').each(function(){
		 if ($(this).height() > maxheight) {maxheight = $(this).height();}
	});
	$('.all .tw .bl').each(function(){
		$(this).height(maxheight+"px");
	});

	$('.all:last-child .on:last-child').addClass('lastt');

	
	$('.auto .header a').click(function(){
		if ($('.auto .header').hasClass('active')){
			$('.auto .header').removeClass('active')
			$('.auto form').slideUp();
		} else {
			$('.auto .header').addClass('active')
			$('.auto form').slideDown();
		}		
		return false
	});
	$('.auto .header span').click(function(){
		$('.auto .header a').click();
	});
	layers();
	$(window).resize(function(){
		layers();
		fixed();
	});
	
	
	$('.path div span').click(function(){
		divlink = $(this).parent('div').children('a').attr('href');
		window.location.href = divlink
	});
	
	$('.btn a').click(function(){
		$('.popup').show();
		$('.hidden').hide();
		$('.visible').show();
		$("input[name='company']").focus();
		return false
	});
	$('.popup .close').click(function(){
		$('.popup').hide();
		return false
	});
	
	$('.header strong.check-events').click(function(){
		if($(this).hasClass('active')){
			if ($('.check-news').hasClass('active')){
				
			$(this).removeClass('active');
			$.ajax({
				url: '/news/events/events_news.js',
				cache: false,
				success: function(msg){
			     $('.tbl').html('');
			     $('.tbl').append(msg);
				 
			   }
			});
			} else {
				all();
			}			
		} else {
			all();
		}
	});
	$('.header strong.check-news').click(function(){
		if($(this).hasClass('active')){
			if ($('.check-events').hasClass('active')){
			$(this).removeClass('active');
			$.ajax({
				url: '/news/events/events_events.js',
				cache: false,
				success: function(msg){
			     $('.tbl').html('');
			     $('.tbl').append(msg);
			   }
			});
			} else {
				all();
			}
		} else {
			all();
		}
	});
	
	if ($.browser.msie && $.browser.version == 6) {
		$('.path td').not('.first').children('div').each(function(){
			divwidth = $(this).width();
			if(divwidth>155){
				$(this).width('155');
			}
		});
	}
	
	
	
	
	menuheight = $('.left .menu').height() + 200;
	$('.legenda .wr').css('top',menuheight);
	$(window).scroll(function(){	

		fixed();
	});

	$('.legenda li a').click(function(){
		$('.legenda li').removeClass('active');
		$(this).parent().addClass('active');
		qu = $(this).parent().prevAll().size() + 1;
		$.scrollTo( $('.line .one:eq('+ qu +')'), {speed:1000} );
		return false
	});
	
	form();
	$('.sign a').click(function(){
		$('#semFrm').submit()
		return false
	})
});

function all(){
	$('.header strong').addClass('active');
		$.ajax({
			url: '/news/events/events_all.js',
			cache: false,
			success: function(msg){
		     $('.tbl').html('');
		     $('.tbl').append(msg);		 
	   		}
	});
}

function fixed(){
	
	if($.browser.msie && $.browser.version == 6) {
		browsfixed = $('html').get(0).scrollTop;
		if (browsfixed > menuheight-50) 
		{
			$('.legenda .wr').css('position','absolute').css('left','22px').stop().animate({top:browsfixed+50},500);		
		} else {
			$('.legenda .wr').css('position','absolute').css('left','22px').stop().animate({top:menuheight},500);
		}	
	} else {	
	if ($.browser.safari) {
		browsfixed = $('body').get(0).scrollTop;
		ddd = $('#wrapper').get(0).offsetLeft +22;
	} else {
		browsfixed = $('html').get(0).scrollTop;
		ddd = $('#wrapper').get(0).offsetLeft +22;
	}	
		if (browsfixed+50 > menuheight) 
		{
			$('.legenda .wr').css('position','fixed').css('top','50px').css('left',ddd);
			
		} else {
			$('.legenda .wr').css('position','absolute').css('top',menuheight).css('left','22px');
		}	
		
	}
}

function form(){
	$('#semFrm').validate({
		rules: {
		    company: {
		      required: true
		    },
		    fio: {
		      required: true
		    },
		    people: {
		      required: true
		    },
		    tel: {
		      required: true
		    }			
		  },
	   submitHandler: function() {
	   $('#semFrm').ajaxSubmit(function(){
			
			success: {
				$('.hidden').show();
				$('.visible').hide();
				$('#semFrm').resetForm();
			}
			return false
		});
	   }
	});
}


function getscroll(){
	if (self.pageYOffset){
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body){
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;	
	}
};

function layers(){	
	getscroll();
	winheight = $(window).height();
	if (winheight < 700) {
		$('.popup').css('top','350px');
	} else {
		$('.popup').css('top',yScroll+winheight-winheight/2-20);
	}
}





function validateLogin(f) {



    if (f.login.value.length == 0) {

        alert("Введите логин!");

        f.login.focus();

        return false;

    }



    if (f.pass.value.length == 0) {

        alert("Введите пароль!");

        f.pass.focus();

        return false;

    }

    return true;

}
