<!--
inits=[]

if (!window.opera) {
	try {
	  document.execCommand("BackgroundImageCache", false, true);
	} catch(err) {}
}

function mainNewsClick(obj) {
	$(obj).click(function(){
		if ($('#news_dates div').length>0) {
			curNews = $('#news_dates div');
			$(curNews).replaceWith('<a class="act" href="#" rel="'+$(curNews).attr('value')+'">'+$(curNews).text()+'</a>');
			mainNewsClick($('#news_dates a.act'));
			$('#news_dates a.act').removeClass();
		}
		$('#right_target').html($(newsBlocks).filter($(this).attr('rel')).html());
		$(this).replaceWith('<div value="'+$(this).attr('rel')+'"><span>'+$(this).text()+'</span></div>');
		return false;
	})
}

function hoverActions() {
    $('button').mouseover(function(){
		$(this).css('color','#890004');
	})
	$('button').mouseout(function(){
		$(this).removeAttr('style');
	})
	$('.form_input').focus(function(){
		$(this).css({'border':'1px solid #436660','background':'#f9fdfd'});
	})
	$('.form_input').blur(function(){
		$(this).removeAttr('style');
	})
}

$(window).load(
    function() {
		if ($('#prlx').length>0) {
			$('#prlx').jparallax({
				yparallax: false
			},{},{},{
				xtravel: 0.01
			},{
				xtravel: 0.06
			},{
				xtravel: 0.07
			},{
				xparallax: false
			},{
				xtravel: 0.16
			})
		}
	}
);

$(document).ready(
	function() {
		((!-[1,])&&(jQuery.browser.version < 9)) ? ie = true : ie = false;
		((!-[1,])&&(jQuery.browser.version == 6)) ? ie6 = true : ie6 = false;
		
        
		//common deeds ------------------------------------------------------------------------------------------------------
		
		$('div.submenu').parent().mouseenter(function(){
			$('#menu li.act').removeClass('act');
			$(this).addClass('act');
		})
		$('div.submenu').parent().mouseleave(function(){
			$('#menu li.act').removeClass('act');
		})
		$('a.menu_link:first').css('background-image','url(/images/menu_btn_first.png)');
		
		//intro part ------------------------------------------------------------------------------------------------------
		
		$('#intro_display1_digits').add('#intro_display2_digits').each(function(){
			digits = $(this).text().match(/\d/g);
			$(this).html('<div class="display_digit" id="display_digit'+digits[0]+'"></div><div class="display_digit" id="display_digit'+digits[1]+'"></div>');
		})
		
		$('#intro_run_btn').parent().click(function(){
			$('#present_overlay').show();
			$('#present_container').css('top','100px');
			return false;
		})
		$('#present_close').add('#present_overlay').add('#present_container object').click(function(){
			$('#present_overlay').add('#present_container').removeAttr('style');
			return false;
		});
		
		//main part ------------------------------------------------------------------------------------------------------
		
		leftSwitchers = $('#left_switch li');
		$(leftSwitchers).each(function(){
			$(this).attr('id','left_switch'+($(leftSwitchers).index(this)+1));
		})
		bitLess = $('#main_text2_link a.less');
		bitMore = $('#main_text2_link a.more');
		$('#left_switch a').click(function(){
			if (!$(this).hasClass('act')) {
				$('#left_switch a.act').removeClass('act');
				$(this).addClass('act');
				bitName = $($(this).attr('href')+' span').text();
				mainBits = $($(this).attr('href')+' div');
				curBit = 0;
				$(bitLess).hide();
				$('#left_target').html($(mainBits).eq(0).html());
				if ($(mainBits).length>1) {
					$(bitMore).show();
					$(bitMore).text('Следующ'+bitName);
					$(bitLess).text('Предыдущ'+bitName);
				} else
					$(bitMore).hide();
			}
			return false;
		})
		$('#left_switch a').eq(0).click();
		$(bitMore).click(function(){
			curBit = curBit+1;
			$('#left_target').html($(mainBits).eq(curBit).html());
			if (curBit==$(mainBits).length-1)
				$(this).hide();
			if (curBit>0)
				$(bitLess).show();
			return false;
		})
		$(bitLess).click(function(){
			curBit = curBit-1;
			$('#left_target').html($(mainBits).eq(curBit).html());
			if (curBit==0)
				$(this).hide();
			if (curBit<$(mainBits).length-1)
				$(bitMore).show();
			return false;
		})
		newsBlocks = $('#news div');
		mainNewsClick($('#news_dates a'));
		$('#news_dates a').eq(0).click();
		$('a.info_btn_link').mouseover(function(){
			$('div.info_btn_text').removeAttr('style');
		})
		$('a.info_btn_link').click(function(){
			$(this).parent().find('div.info_btn_text').removeAttr('style').show(300);
			return false;
		})
		$('div.info_btn_text').mouseleave(function(){
			if (ie) {
				$(this).hide();
			} else {
				$(this).fadeTo(600,0,function(){
					$(this).removeAttr('style');
				});
			}
		})
		
		
		//inner part ------------------------------------------------------------------------------------------------------
		
      hoverActions();
        
      $('#print').click(function(){
			window.print();
			return false;
		})
		
		if ($('#cat').length>0) {
			$('div.cat_btn_in a').click(function(){return false})
			$('#house_info1').addClass('pied');
			if ($('.house_photo li').length>0) {
				($('.house_photo li').length%2==0) ? housePhotos = $('.house_photo li').length/2 : housePhotos = ($('.house_photo li').length/2)+0.5;
				$('.house_photo li').parents('div.house_slide').css('width',260*housePhotos+'px');
			}
			$('#cat').smoothDivScroll({
				scrollWrapper: '#cat_container',
				scrollableArea: '#cat_slider',
				scrollStep: 15,
				scrollInterval: 10,
				mouseDownSpeedBooster: 1
			});
			$('#cat a.less').click(function(){
				$('#cat').smoothDivScroll("moveToElement", "first");
				return false;
			})
			$('#animation_btn').click(function(){
				if ($.flash.available) {
					$('#house_img').fadeTo(100,0);
					$('#house_animation').animate({
						top: '2px'
					},500,function(){
						if ($('#house_animation_target').html()=='')
							$('#house_animation_target').html(mainFlash);
					})
				}
				return false;
			})
			$('#house_animation a').click(function(){
				$('#house_animation').animate({
						top: '-457px'
					},500,function(){
						$('#house_img').fadeTo(100,1);
					})
				return false;
			})
		}
		$('#contact_tabs li:last').css('margin-left','-2px');

		$('a.thickbox').add('a.lightbox').thickbox();
        
      for(var i=0;i<inits.length;i++) inits[i]();
	}
);

function submit_fbf(frm) {
   
   var log=true;
   var captcha='';
   var contacts=false;
   
   $(frm).find('[name]').each(function(n,element){
        var n=$(element).attr('name');
        var v=$(element).val();
        if(n=='fio' && v=='') {
            alert('Назовитесь, пожалуйста');   
            element.focus();
            log=false;
            return false;
        }  
        if(n=='email' && v=='') {
            alert('Укажите контактный e-mail');   
            element.focus();
            log=false;
            return false;
        }
        if(n=='mess' && v=='') {
            alert('Введите сообщение');   
            element.focus();
            log=false;
            return false;
        }
        //if(n=='captcha') captcha=v;
    });
    if(log) {
        //$.get("/captcha/index.php?check="+captcha,function(t) {
        //    if(t!='OK') {
        //		alert('Не верно введен код подтверждения');
		//		$('#captcha')[0].focus();
		//		return false;
		//	}    
			frm.submit();    					
		//});
    }
    return false;
}

inits.push(function(){
    $("#feedback-form").submit(function() {
       return submit_fbf(this);
    }); 
});

$(window).load(
	function() {
		$('#present_overlay').height($('#page_container').height());
	}
);

// -->

