jQuery.noConflict();
jQuery(function($){
	highlightDisabled = false;
	viewHeight = $(window).height();
	
	// setup all pages heights
	setHeight = function(i, elem){
		$elem = $(elem);
		
		if($elem.outerHeight() < viewHeight){
			var height = $.browser.msie ? 'height' : 'min-height';
			$elem.css(height, viewHeight);
		}
	}
	$('.content-slide').each(setHeight);
	$(window).resize(function(){
		$('.content-slide').each(setHeight);
	});
	
	// submenu
	$('#menu li ul').hide();
	
	// hook up menu switching effects
	$('#menu a').click(function(){
		$(this).blur();
		
		var hash = $(this).attr('href');
		if(hash.indexOf('#') != 0){
			return true;
		}
		var position = $(hash).offset().top;
		var selector = $.browser.safari ? 'body' : 'html';
		highlightDisabled = true;
		
		if($.browser.msie && $.browser.version == 6){
			$('#menu>li.active>a').css('background', "url(images/tab-inactive-bg.png)");
			$(this).css('background', "url(images/tab-active-bg.png)");
		}
		
		$('#menu li').removeClass('active');
		$(this).parents('li').addClass('active');
		
		$('#menu>li').not($(this).parents('#menu>li')).find('ul').slideUp();
		
		$(selector).animate({
			scrollTop: position+'px'
		}, 500, 'easeInOutQuart', function(){
			highlightDisabled = false;
			if(!$.browser.safari){
				window.location.hash = hash.replace('#', '');
			}
		});
		
		return false;
	});
	
	$('#menu>li').hover(function(){
		$(this).find('ul').slideDown();
	},function(){
		$(this).not('.active').find('ul').slideUp();
	});
	
	// menu highlight
	$(window).scroll(function(){
		if(highlightDisabled) return;
		
		$('.content-slide').each(function(){
			$el = $(this);
			scrollTop = $(document).scrollTop();
			elemTop = $el.offset().top;
			if(scrollTop <= elemTop && scrollTop + 100 > elemTop){
				$('#menu li').removeClass('active');
				$('#menu li:has(a[href=#'+$el.attr('id')+'])').addClass('active');
			}
		});
	});
	
	$(window).trigger('scroll');
	
	// setup fancybox
	//$('.portfolio-item a').fancybox();
	//$('.property').fancybox();
	
	//SETUP CONTACT FORM
	$('#contactForm').submit(function(){
		$.post(
			'contactengine.php',
			$(this).serialize(),
			function(data){
				$('#message').html(data).slideDown();
			}
		);
		
		return false;
	});
	
	$('#brochureForm').submit(function(){
		$.post(
			'contactengine.php',
			$(this).serialize(),
			function(data){
				$('#brochure').html(data).slideDown();
			}
		);
		
		return false;
	});
	
});
/**
 *	these are animation functions used by the animate() function
 */
var animFunc1 = function(rows, cols){
	var n = rows*cols;
	for(i = 0; i < n; i++){
		setTimeout(
			"jQuery('#square'+"+i+").stop().animate({'opacity': 1}, "+anim_speed+");", 
			Math.round(Math.random() * anim_speed)
		);
	}
}

var animFunc2 = function(rows, cols){
	var n = rows*cols;
	for(i = 0; i < n; i++){
		setTimeout(
			"jQuery('#square'+"+i+").stop().animate({'opacity': 1}, "+anim_speed+");", 
			i * 70
		);
	}
}

var animFunc3 = function(rows, cols){
	var n = 0;
	for(i = 0; i < cols; i++){
		for(j = 0; j < rows; j++){
			setTimeout(
				"jQuery('#square'+"+(j*10+i)+").stop().animate({'opacity': 1}, "+anim_speed+");", 
				n * 70
			);
			n++;
		}
	}
}

/**
 *	this function is in charge of swapping images and running the animation functions
 */

