// JavaScript Document

$j = jQuery.noConflict();
var jobDeposit = 0.4;//40% deposit required
var imageSrc;
var imageTxt;
var imageIndex = -1;
var srcArray = new Array;
var txtArray = new Array;

$j(function(){
	txtDefault = $j(".mainPhoto .captionText").html();//capture initial caption text
	$j(".photoNav td a").each(function(){
		srcArray.push($j(this).attr('href'));
		txtArray.push(txtDefault + $j(this).attr('title'));
		var l = srcArray.length - 1;
		//remove bc default actions (onclick & rel attributes)
		//set click event
		$j(this).attr('onclick', null).attr("rel", null).click(function(e){
			e.preventDefault();//remove link action
			//set main image src to thumbnail pic
			imageIndex = l - 1;
			window.clearInterval(int);
			int = window.setInterval(rotateImage, 6000);
			rotateImage();
			return false; 
		});
	});
	var int = window.setInterval(rotateImage, 6000);
	rotateImage();
});

function rotateImage(){
	imageIndex++;
	if(imageIndex >= srcArray.length) imageIndex = 0;
/*	var newImg = document.createElement('img');
	newImg.src = srcArray[imageIndex];
*/	$j(".mainPhoto img").fadeOut('slow', function(){
		$j(this).attr('src', srcArray[imageIndex]).load(function(){
			$j(this).fadeIn('slow');
		});
	});
	$j(".mainPhoto .captionText").fadeOut('slow', function(){
		$j(this).html(txtArray[imageIndex]).fadeIn('slow');
	});
	/*var delay = window.setTimeout(function(){
		$j(".mainPhoto .captionText").slideDown('slow');
	}, 2000);*/
}

//highlight correct menu item for page
$j(function(){
	var url = location.pathname;
	var sel = false;
	var renoUri;
	$j("#navMain li a").each(function(){
		var conditions = false;
		if($j(this).attr('href') == url.substr(0, 22)) conditions = true;
		if($j(this).attr('href') == '/' && url == '/home') conditions = true;
		if($j(this).attr('href') == url) conditions = true;
		if($j(this).attr('href') == url.toLowerCase().substr(0, 4)) conditions = true;
		if($j(this).attr('href') == '/_blog/Renovation_Blog' && url.toLowerCase().substr(0,18) == '/blogretrieve.aspx') conditions = true;
		if(conditions){
			$j(this).parent().addClass('selected');
			sel = true;
		}
	});
	if(!sel){
		$j("#navMain li:first").addClass('selected');
	}
});

//Searchbox placeholder for IE
$j(function(){
	if(!supports_input_placeholder()){
		IE_placeholder($j("#CATSearch"), "Search");
		IE_placeholder($j("#loginname"), "Login Name");
		IE_placeholder($j("#password"), "Password");
		IE_placeholder($j("#CLFullName"), "Full Name");
		IE_placeholder($j("#CLEmailAddress"), "Email Address");
	}
});
function hideSearch(e){
			if(e.val() == 'Search'){
				e.val("");
			}
}

function supports_input_placeholder() {
  var i = document.createElement('input');
  return 'placeholder' in i;
}
function IE_placeholder(el, text){
		el.val(text).click(function(){
			hideSearch($j(this))
		}).focus(function(){
			hideSearch($j(this));
		}).blur(function(){
			if($j(this).val() == ""){
				$j(this).val(text);	
			}
		});
}

$j(function(){
//set deposit amount (jobDeposit set at top of this page)
	$j("#CAT_Custom_189361").bind("keyup blur", function(){
		var amt = ($j(this).val() * jobDeposit).toFixed(2);
		$j("#CAT_Custom_18936").val(amt);
		$j("#CAT_Custom_200251").val(amt);
		//#CAT_Custom_18936 is the amount textbox
	});
});

$j(function(){
	imageresize();//Triggers when document first loads    
	$j(window).bind("resize", function(){//Adjusts image when browser resized
		imageresize();
	});
});

//resize images for different size windows
function imageresize() {
	var wrapperwidth = $j('#wrapper').width();
	if ((wrapperwidth) < '321'){
		$j('#aboutImage').attr({src:'/img/outside_sm.jpg', width:'288', height:'176'});
	} else {
		$j('#aboutImage').attr({src:'/img/outside.jpg', width:'418', height:'255'});
	}
}








