$(document).ready(function(){ 

		//property table preview rollovers
		if ($('#propertyPreview').length != 0){
			//preload
			var imgArray = [];

			$('.views-field-address a span.imagePath img').each(function(){
    			var imagePath = $(this).attr("src").replace('/files/','/files/imagecache/featured/');
		    	var preImage = document.createElement('img');
       			preImage.src = imagePath;
      			imgArray.push(preImage);
      		});
		
			$(".views-field-address a").mouseover(function(){
				var imgPath = $(this).find('span.imagePath img').attr("src").replace('/files/','/files/imagecache/featured/');
				var address = $(this).text();
			
				if ((imgPath) && (imgPath.substring(imgPath.lastIndexOf('/') + 1).length > 6)){ //check that src exists and is file			
					$('#propertyPreview').html("<img src='" + imgPath + "'><p>" + address + "</p>");
					$('#propertyPreview').css('background-image', 'url(' + imgPath + ')');
				} else {
					$('#propertyPreview').html("&nbsp;");
					$('#propertyPreview').css('background-image', 'none');
				};
			
			});
		
		//table preview fixed scroller	
			var top = $('#propertyPreview').offset().top - parseFloat($('#propertyPreview').css('marginTop').replace(/auto/, 0));
				
			$(window).scroll(function (event) {
				var y = $(this).scrollTop();
						 
				if (y >= top) {
			   	 	$('#propertyPreview').addClass('fixed');
				} else {
		         	$('#propertyPreview').removeClass('fixed');
			   }
			});
		
		}; //end #propertyPreview check
		

	   //property page thumbs
	   
			//add images to array and preload them
			var imgArray = [];

    		$('div.propertyThumb img').each(function(){
    			var imagePath = $(this).attr("src").replace('/imagecache/thumb','');
    			var preImage = document.createElement('img');
       			    preImage.src = imagePath;
      			imgArray.push(preImage);
    		});
		
		//show large image when thumb clicked			
		$('div.propertyThumb').click(function() {
			
			propImg = $(this).find("img")
			
			if ($(propImg).hasClass('similarProperty')){
				imgPathPre = $(propImg).attr("src").replace('/imagecache/thumb','/imagecache/similar_property');
			}else{
				imgPathPre = $(propImg).attr("src").replace('/imagecache/thumb','');
			};
			
			//imgPathPre = $(this).find("img").attr("src").replace('/imagecache/thumb','');
			imgPath = "url(" + imgPathPre + ")";
			
			$('#propertyPhoto').css('background-image', imgPath); 
		
		});
				
		//display first property image on load of property page
		$('.propertyThumb:first').click();
		
		//flyer download button
		$('a[@href$=pdf].sidebarButtonPDF').prepend('<img src="/themes/ciha/images/icons/icon_pdf.png">');
		
		//subpage theming to match section
		//check if node has parent then set class to = parent title
		parentPage = $('#primary li.active-trail a').attr('href');
		
		if(parentPage){
			$('#pageContainer').addClass(parentPage.replace('/', ""));
		} 
		
	    // add facebook icon to footer menu. hacky fix, revisit.
	    $('#secondary').append('<li class="facebookLink"><a href="http://www.facebook.com/pages/Cook-Inlet-Housing-Authority/111381402222148" ><img src="/themes/ciha/images/icons/iconFacebook.png"></a></li>');
	    				
});

