
$(document).ready(function() {
	
	$('#searchSubmitContainer').click(function() {
		$('#searchF').submit();
	});

	if(Modernizr) {
		if(Modernizr.inputtypes.search) { //if the html5 search input type is supported, reset the style (as the background image won't look right)
			$('#q1').css('color', '#000')
					.css('background', '#fff');
		}
	}

	//ie6 fixes
	if($.browser.msie && $.browser.version < 7){
		var h;
		
		$('label').each(function() {
			var $this =$(this);
			h =$this.html();
			$this.replaceWith('<span class="label">'+h+'</span>');
		
		});
		
		$('#container').css('background-image', 'url(/ui/img/shaded-ie6.png)');
		$('#header').css('background-image', 'url(ui/img/shaded-top-ie6.png)');
		$('#navigation').css('background-image', 'url(ui/img/nav/panel-bg-ie6.png)');
		$('img[src*=.png],#container, #header, #navigation, #breadcrumbs ul li, .blackBar, #contactBar').ifixpng(); 
		
		
	}
	
	//fade on scroll
	$(window).bind('scrollstop scrollstart', function() {
		if($(window).scrollTop()=='0') {
			if($('#background').css('opacity')<1) $('#background').fadeTo(600, '1.0');
		}
		else if ($('#background').css('opacity')==1) $('#background').fadeTo(600, 0.25);
	});
	
	
	//nav
	var current =$('#navigation .current img');
	if(current.length>0) current.attr('src', current.attr('src').replace(/-off\.gif$/, '-on.gif'));
	
	
	var currentSub =$('#subnavigation .current img');
	if(currentSub.length>0) currentSub.attr('src', currentSub.attr('src').replace(/-off\.gif$/, '-on.gif'));
	
	//homepage
	$('#createBrochureHowButton').click(function() {
		var maskHeight = $(document).height();  
		var maskWidth = $(window).width();  
		$('#mask').css({'width':maskWidth,'height':maskHeight});  
      	$('#mask').fadeIn(300);      
        $('#mask').fadeTo(500,0.8);    
		$('#createBrochureModal').fadeIn();
	});
	$('#modalButton a').click(function() {
		$('#mask').fadeOut(500);
		$('#createBrochureModal').fadeOut(1000);
		
	});
	
	
	//careers navigation
	$('#careersList li').each(function() {
		var $this =$(this);
		var id =$this.attr('id').replace(/[^0-9]/g,'');
		$this.children('a').click(function() {
			$('#wideRight .job').hide();
			$('#wideRight #job-'+id).show();
			$('#careersList li.current').removeClass('current');
			$this.addClass('current');
		});
		
		//simulate click on first item
		$('#careersList li:first-child a').trigger('click');
	});
	
	
	//faqs navigation
	$('#midLeft .question').each( function() {
		var $this =$(this);	
		$this.click(function() {
			var id =$this.attr('id').replace(/[^0-9]/g, '');
			$('#midLeft .current').removeClass('current');
			$('#midRight .answer').hide();
			$('#midRight #answer-'+id).show();
			$('html, body').animate({scrollTop:0}, 300);
			$this.addClass('current');
		});
	});
	//show first answer
	$('#midRight .answer:first').show();
	
	
	//services modals
	$('#createBrochureHowButton').click(function() {
		var maskHeight = $(document).height();  
		var maskWidth = $(window).width();  
		$('#mask').css({'width':maskWidth,'height':maskHeight});  
	  	$('#mask').fadeIn(300);      
	    $('#mask').fadeTo(500,0.8);    
		$('#createBrochureModal').fadeIn();
	});
	$('#modalButton a').click(function() {
		$('#mask').fadeOut(500);
		$('#createBrochureModal').fadeOut(1000);
		
	});
	
	
	$('.caseStudyCTA').each(function() {
		var $this =$(this);
		var id =$this.attr('id').replace(/[^0-9]/g, '');
		$this.children('a').click(function(event) {
			event.preventDefault();
			var maskHeight = $(document).height();  
			var maskWidth = $(window).width();  
			$('#mask').css({'width':maskWidth,'height':maskHeight}); 
			$('#mask').fadeIn(300);      
			$('#mask').fadeTo(500,0.8);    
			$('#modalCaseStudy-'+id).fadeIn();
		});
	});
	
	$('.modal .modalButton a').click(function() {
		$('#mask').fadeOut(500);
		$('.modal').fadeOut(1000);
	});
	
	$("#but_view_our_information_library").click(function(){
		$("#residential_property_management").hide();
		$("#information_library").show();
	});
	
	$("#information_library_back").click(function(){
		$("#information_library").hide();
		$("#residential_property_management").show();
	});
	
	$(".but_commerical_property_details_view").click(function(){
		var currentId = $(this).attr('id');
		$("#commercial_properties").hide();
		$("#commercial_property_details_" + currentId).show();
		$( 'html, body' ).animate( { scrollTop: 0 }, 0 );
	});
	
	$(".commercial_property_details_back").click(function(){
		var currentId = $(this).attr('id');
		$("#commercial_property_details_" + currentId).hide();
		$("#commercial_properties").show();
	});
	
	$("#but_commercial_property_management_services").click(function(){
		var maskHeight = $(document).height();  
		var maskWidth = $(window).width();  
		$('#mask').css({'width':maskWidth,'height':maskHeight});  
	  	$('#mask').fadeIn(300);      
	    $('#mask').fadeTo(500,0.8);    
		$('#modalCommercialPropertyManagementServices').fadeIn();
	});
	
	$("#modalCPDVCloseButton").click(function(){
		$('#mask').fadeOut(500);
		$('.modal').fadeOut(1000);
	});
	
	$("#navServices").click(
	
		function(e){
			$('#navigation ul .current').removeClass('current');
			$("#navigation #navServices").addClass('current');
			$("#navigation #navServices a img").attr("src","/ui/img/nav/services-on.gif");
			e.stopPropagation();
			$('#ddServices').show();
			
		}
		
	);
	
	$("#container").click(function(){
		if($("#ddServices").is(':visible')){
				$("#ddServices").hide();
			}
	});
	
});
