$(function() {
	$("#flashMessage").click(function() {
		$(this).hide('slow');	
	});
	$("#sessionFlash").click(function() {
		$(this).hide('slow');
	});
	
	$('.focused').bind('focus', function() {
		var text = $(this).val();
		$(this).val('');
		$(this).bind('blur', function() {
			if ($(this).val() == '') {
				$(this).val(text);
			}
		});
	});
		
	$('#indicator').ajaxStart(function() {
		$(this).show();
	});
	
	$('#indicator').ajaxComplete(function() {
		$(this).hide();
	});
	
	// быстры переход
	$("#quick-go").bind('change', function() {
		var url = $(this).val();
		if (url != '') {
			window.location.href = url;
		}
	});
});

// обрабатываем банера
$(function() {
	$('.header-baner').media({autoplay: true, width: 750, height: 50, bgColor: '#edeff1', attrs: {wmode:  'opaque'}, params: {wmode:  'opaque'}});
	
	$('.left-top-baner').media({autoplay: true, width: 250, height: 350, bgColor: '#edeff1', attrs: { wmode:  'opaque'}, params: {wmode:  'opaque'}});
	
	$('.left-bottom-baner').media({autoplay: true, width: 250, height: 350, bgColor: '#edeff1', attrs: { wmode:  'opaque'}, params: {wmode:  'opaque'}});
	$('.content-top-baner').media({autoplay: true, width: 700, height: 70, bgColor: '#edeff1', attrs: { wmode:  'opaque'}, params: {wmode:  'opaque'}});
	$('.content-bottom-baner').media({autoplay: true, width: 700, height: 70, bgColor: '#edeff1', attrs: { wmode:  'opaque'}, params: {wmode:  'opaque'}});
	$('.content-small-baner').media({autoplay: true, width: 410, height: 70, bgColor: '#edeff1', attrs: { wmode:  'opaque'}, params: {wmode:  'opaque'}});
	$('.top-baner').media({autoplay: true, width: 700, height: 90, bgColor: '#edeff1', attrs: { wmode:  'opaque'}, params: {wmode:  'opaque'}});
	$('.footer-baner').media({autoplay: true, width: 1000, height: 90, bgColor: '#edeff1', attrs: { wmode:  'opaque'}, params: {wmode:  'opaque'}});
	$('.flash-hover').css('cursor', 'pointer').bind('click', function() {
		var link = $(this).parents('.ads:first').find('.baner-link:first');
		if (link) {
			window.open(link.attr('href'));
			return false;
		}
		
		return true;
	});
	
});

// менюшка
$(function() {
	var div = $('div#top-menu');
	var ul = $('ul#menu');
	var ulPadding = 15;
	var divWidth = div.width();
	div.css({overflow: 'hidden'});
	var lastLi = ul.find('li:last-child');
	
	div.mousemove(function(e) {
		var ulWidth = lastLi[0].offsetLeft + lastLi.outerWidth() + ulPadding;
		var left = (e.pageX - div.offset().left) * (ulWidth - divWidth) / divWidth;
		div.scrollLeft(left);
	});
});
