	
	var is_ie6 = false;
	var is_ie7 = false;
	var is_ie8 = false;
	jQuery.each(jQuery.browser, function(i, val) {
		if(i=="msie" && jQuery.browser.version.substr(0,3)=="6.0"){is_ie6 = true;}
		if(i=="msie" && jQuery.browser.version.substr(0,3)=="7.0"){is_ie7 = true;}
		if(i=="msie" && jQuery.browser.version.substr(0,3)=="8.0"){is_ie8 = true;}
	});
	
	var animation_completed = true;
	var intro_timer, teaser_timer;
	
	
	// Border Hover
	$(document).ready(function(){
		$('div.projects ul li').hover(function(){
			$(this).css({'background-position':'0 100%'});
		}, function(){
			if (!$(this).hasClass('selected')) { $(this).css({'background-position':'0 0'}); }
		});
		$('div.villagers ul li').hover(function(){
			$(this).css({'background-position':'0 100%'});
		}, function(){
			if (!$(this).hasClass('selected')) { $(this).css({'background-position':'0 0'}); }
		});
		$('div.scheme').hover(function(){
			$(this).css({'background-position':'100% 100%'});
			$(this).find('div.bg').css({'background-position':'100% 0'});
		}, function(){
			$(this).css({'background-position':'0 100%'});
			$(this).find('div.bg').css({'background-position':'0 0'});
		});
		$('div.plans ul li').hover(function(){
			$(this).css({'background-position':'100% 100%'});
			$(this).find('div').css({'background-position':'100% 0'});
		}, function(){
			if (!$(this).hasClass('selected')) { $(this).css({'background-position':'0 100%'}); $(this).find('div').css({'background-position':'0 0'}); }
		});
		$('div.other_houses ul li').hover(function(){
			$(this).css({'background-position':'100% 100%'});
			$(this).find('div').css({'background-position':'100% 0'});
		}, function(){
			if (!$(this).hasClass('selected')) { $(this).css({'background-position':'0 100%'}); $(this).find('div').css({'background-position':'0 0'}); }
		});
		$('div.for_you div.links ul li').hover(function(){
			$(this).css({'background-position':'100% 0'});
			$(this).find('a').css({'text-decoration':'underline'});
		}, function(){
			$(this).css({'background-position':'0 0'});
			$(this).find('a').css({'text-decoration':'none'});
		});
	});
	
	
	// House Photos
	function nextHousePhoto(){
		animation_completed = false;
		$('div.house_photos div.photos img.plan').animate({opacity: 0.0}, 1000, function(){
			$('div.house_photos div.photos img.plan').remove();
		});
		var active = $('div.house_photos div.photos img.active');
		if ( active.length == 0 ) active = $('div.house_photos div.photos img:last');
		var next =  active.next().length ? active.next()
			: $('div.house_photos div.photos img:first');

		active.addClass('last-active');
		next.css({opacity: 0.0})
			.addClass('active')
			.animate({opacity: 1.0}, 1000, function() {
				active.removeClass('active last-active');
				animation_completed = true;
			});
	}
	function prevHousePhoto(){
		animation_completed = false;
		$('div.house_photos div.photos img.plan').animate({opacity: 0.0}, 1000, function(){
			$('div.house_photos div.photos img.plan').remove();
		});
		var active = $('div.house_photos div.photos img.active');
		if ( active.length == 0 ) active = $('div.house_photos div.photos img:last');
		var prev =  active.prev().length ? active.prev()
			: $('div.house_photos div.photos img:last');

		active.addClass('last-active');
		prev.css({opacity: 0.0})
			.addClass('active')
			.animate({opacity: 1.0}, 1000, function() {
				active.removeClass('active last-active');
				animation_completed = true;
			});
	}
	$(document).ready(function(){
		$('div.house_photos div.photos img').css({'display':'none'});
		$('div.house_photos div.photos img:first').addClass('active');
		$('div.house_photos div.photos img').css({'display':'block'});
		$('div.house_photos div.prev').hover(function(){
			$(this).css({'background-position':'0 100%'});
		}, function(){
			$(this).css({'background-position':'0 0'});
		});
		$('div.house_photos div.next').hover(function(){
			$(this).css({'background-position':'0 100%'});
		}, function(){
			$(this).css({'background-position':'0 0'});
		});
		$('div.house_photos div.prev').click(function(){
			if (animation_completed) { prevHousePhoto(); }
		});
		$('div.house_photos div.next').click(function(){
			if (animation_completed) { nextHousePhoto(); }
		});
		$('div.plans a').click(function(){
			img_src = $(this).attr('href');
			plan_img = '<img src="' + img_src + '" alt="" class="plan active" />';
			$('div.house_photos div.photos img.plan').removeClass('active');
			$('div.house_photos div.photos img.plan').remove();
			$('div.house_photos div.photos').append(plan_img);
			return false;
		});
	});
	
	
	// Home Page Intro
	function intro() {
		var active = $('div.intro div.photos img.active');
		if ( active.length == 0 ) active = $('div.intro div.photos img:last');
		var next =  active.next().length ? active.next()
			: $('div.intro div.photos img:first');

		active.addClass('last-active');
		next.css({opacity: 0.0})
			.addClass('active')
			.animate({opacity: 1.0}, 1000, function() {
				active.removeClass('active last-active');
			});
	}
	$(document).ready(function(){
		$('div.intro div.photos img').css({'display':'none'});
		$('div.intro div.photos img:first').addClass('active');
		$('div.intro div.photos img').css({'display':'block'});
	});
	
	
	// Home Page Teasers
	function teasers() {
		var active = $('div.teasers div.active');
		if ( active.length == 0 ) active = $('div.teasers div.teaser:last');
		var next =  active.next().length ? active.next()
			: $('div.teasers div.teaser:first');

		active.animate({opacity: 0.0}, 1000, function(){
			active.addClass('last-active');
			next.css({opacity: 0.0})
				.addClass('active')
				.animate({opacity: 1.0}, 1000, function() {
					active.removeClass('active last-active');
				});
		})
	}
	$(document).ready(function(){
		$('div.teasers div.teaser:eq('+ Math.floor(Math.random() * $('div.teasers div.teaser').length) +')').addClass('active');
	});
	
	
	// Body onload
	$(window).load(function(){
		if ($('div.intro div.photos img').length > 1) { intro_timer = setInterval( "intro()", 7500 ); }
		if ($('div.teasers div.teaser').length > 1) { teaser_timer = setInterval( "teasers()", 12500 ); }
	});
	
	
	// Home Page Slider
	$(document).ready(function(){
		animationCompleted = true;
		// Indicator
		indicator_html = '<ul class="indicator">';
		slider_length = $('div.double_adv div.slider ul li').length / 2;
		for (i = 0; i < slider_length; i++) {
			indicator_html = indicator_html + '<li></li>';
		}
		indicator_html = indicator_html + '</ul>';
		$('div.double_adv').prepend(indicator_html);
		$('div.double_adv ul.indicator li:first').addClass('selected');
		$('div.double_adv ul.indicator li').click(function(){
			if (!$(this).hasClass('selected')) {
				$('div.double_adv ul.indicator li').removeClass('selected');
				$(this).addClass('selected');
				li_index = $('div.double_adv ul.indicator li').index(this);
				li_width = $('div.double_adv div.slider ul li').width() * 2;
				sliderNewPosition = (li_index * li_width) / -1;
				if (animationCompleted == true) {
					animationCompleted = false;
					if (!$.browser.msie) {
						$('div.double_adv div.slider ul').animate({marginLeft: sliderNewPosition}, 500, function(){
							animationCompleted = true;
						});
					} else {
						$('div.double_adv div.slider ul').css({'margin-left':sliderNewPosition});
						animationCompleted = true;
					}
				}
			}
		});
		$('div.double_adv ul.indicator li:eq('+ Math.floor(Math.random() * $('div.double_adv div.slider ul li').length / 2) +')').click();
		// Next
		$('div.double_adv div.next').click(function(){
			var table = $('div.double_adv div.slider ul');
			var tableWidth = table.width();
			var tablePosition = parseFloat(table.css('margin-left'));
			var itemStep = 2;
			var tableCellWidth = table.find('li').width() * itemStep;
			var tableNewPosition = tablePosition - tableCellWidth;
			var maxSize = (tableWidth - $('div.double_adv div.slider').width()) / -1;
			if (tableNewPosition >= maxSize) {
				if (animationCompleted == true) {
					animationCompleted = false;
					$('div.double_adv ul.indicator li.selected').removeClass('selected').next().addClass('selected');
					if (!$.browser.msie) {
						table.animate({marginLeft: tableNewPosition}, 500, function(){
							animationCompleted = true;
						});
					} else {
						table.css({'margin-left':tableNewPosition});
						animationCompleted = true;
					}
				}
			}
			return false;
		});
		// Prev
		$('div.double_adv div.prev').click(function(){
			var table = $('div.double_adv div.slider ul');
			var tableWidth = table.width();
			var tablePosition = parseFloat(table.css('margin-left'));
			var itemStep = 2;
			var tableCellWidth = table.find('li').width() * itemStep;
			var tableNewPosition = tablePosition + tableCellWidth;
			if (tableNewPosition <= 0) {
				if (animationCompleted == true) {
					animationCompleted = false;
					$('div.double_adv ul.indicator li.selected').removeClass('selected').prev().addClass('selected');
					if (!$.browser.msie) {
						table.animate({marginLeft: tableNewPosition}, 500, function(){
							animationCompleted = true;
						});
					} else {
						table.css({'margin-left':tableNewPosition});
						animationCompleted = true;
					}
				}
			}
			return false;
		});
	});
	
	
	// Scheme Popup
	$(document).ready(function(){
		$('div.scheme a.lnk').click(function(){
			if (!$.browser.msie) {
				$('div.white').fadeIn(0).fadeTo(0, 0).fadeTo(500, 1, function(){
					$('div.popup').fadeIn(0).fadeTo(0, 0).fadeTo(250, 1);
				});
			} else {
				$('div.white').css({'display':'block'});
				$('div.popup').css({'display':'block'});
			}
			return false;
		});
		$('div.popup img.close').click(function(){
			if (!$.browser.msie) {
				$('div.popup').fadeOut(250);
				$('div.white').fadeOut(250);
			} else {
				$('div.white').css({'display':'none'});
				$('div.popup').css({'display':'none'});
			}
		});
	});
	
	
	// Fix Bottom Background
	function fixBG(){
		window_height = $(window).height();
		div_height = $('div.body_corner_br').height();
		$('div.body_corner_br').css({'display':'none'});
		if (div_height <= window_height) {
			$('div.body_corner_br').css({'min-height':window_height});
		} else {
			$('div.body_corner_br').css({'min-height':'10px'});
		}
		$('div.body_corner_br').css({'display':'block'});
	}
	$(document).ready(function(){
		fixBG();
	});
	$(window).resize(function(){
		$('div.body_corner_br').css({'min-height':'10px'});
		$('div.body_corner_br').css({'display':'none'});
		fixBG();
	});
