var toggleImgMainNav = function(over){
	var $this = $(this);
	var hoverState = $.data(this, 'hoverState'); 
	
	if(hoverState === undefined){
		hoverState = {};
		var src = $this.attr('src');
		var sufIndex = src.lastIndexOf('.');
		if(sufIndex > 0) {
			hoverState.pathBase = src.substring(0, sufIndex);
			hoverState.suffix = src.substring(sufIndex, src.length);
		}
	}
	hoverState.over = over;
	$this.attr('src', hoverState.pathBase + (hoverState.over ? '_over' : '') + hoverState.suffix);
	$.data(this, 'hoverState', hoverState);
}
	
$(document).ready(function () {
	$('img.MainNav').hover(function(){return toggleImgMainNav.call(this, true);}, function(){return toggleImgMainNav.call(this, false);});
});

//IndustryID IndustryRealEstate IndustryMortgage FirstName LastName City State Country
//CountryUS CountryCA CompanyName
//FranchiseID
//CSR PublicRating Certified WebURL
//SearchSubmitByLocation

$(document).ready(function(){
	$('form#SearchForm .CheckboxLabel').each(
		function(){
			var $this = $(this).css('cursor', 'default');
			$this.bind('click',
				$this.prev(':radio, :checkbox'),
				function(event){ event.data.click(); });
		})
});

$(document).ready(function(){
	$('table#HeaderTabBins a').each(
		function(){
			var loc = document.location.toString().toLowerCase();
			if(loc.match($(this).attr('href').toLowerCase())){
				var $this = $(this); //.css('color', 'red');
				$('table#HeaderTabBins td.Active').removeClass('Active');
				$this.parent().parent().parent().parent().parent().parent().parent().parent().addClass('Active');
			}
			//var tab = $this.parents('table#HeaderTabBins td');
			//tab.removeClass('Active');
			/*
			$this.bind('click',
				$this.prev(':radio, :checkbox'),
				function(event){ event.data.click(); });
			*/
			
//if (myFile.match('#')) { // the URL contains an anchor
  // click the navigation item corresponding to the anchor
//  var myAnchor = '#' + myFile.split('#')[1];
//  $('ol#nav li a[href="' + myAnchor + '"]').parent().click();
//} else {
  // click the first navigation item
//  $('ol#nav li:first').click();
//}

		});
});

/*
<table id="HeaderTabs" border="0" cellpadding="0" cellspacing="0" width="720">
<tbody>
<tr>
<td>

<table border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td class="Active">

<div class="HeaderTabBottomCenter">
  <div class="HeaderTabTopCenter">
    <div class="HeaderTabMidLeft">
      <div class="HeaderTabMidRight">
        <div class="HeaderTabTopRight">
          <div class="HeaderTabBottomLeft">
            <div class="HeaderTabTopLeft">
              <a href="<%=siteRoot%>default.aspx">
*/


$(document).ready(function(){
	$('form#SearchForm .InternalLabel').each(
		function(){
			var $this = $(this);
			var inputText = $this.next(':text');
			if(inputText.length == 1){
				$.data(inputText[0], 'labelValue', $this.text().split(':')[0]);
				$this.text('');
				if($.trim(inputText[0].value) == '')
				inputText[0].value = $.data(inputText[0], 'labelValue');
				inputText.bind('focus', function(){
				if($.trim(this.value) == $.data(this, 'labelValue'))
					this.value = '';
				});
				inputText.bind('blur', function(){
				if($.trim(this.value) == '')
					this.value = $.data(this, 'labelValue');
				});
			}
		})
});
$(document).ready(function(){
	var searchForm = $('form#SearchForm');
	//searchForm.find('#SearchFormReset').hide();
	var reset = searchForm.find('#SearchFormResetImg');
	reset.attr('href', 'javascript:void(0);');
	reset.bind('click', searchForm, function(event){
		event.data[0].reset();
		event.data.find('#Franchise').val('');
		event.data.find('#State').val('');
		event.data.find('.InternalLabel').each(function(){
			var $this = $(this);
			var inputText = $this.next(':text');
			if(inputText.length == 1)
			inputText[0].value = $.data(inputText[0], 'labelValue');
		});
	event.data.find(':checkbox').each(function(){
		this.checked = false;
	});
	});
	
	var advanced = searchForm.find('#SearchFormAdvanced').show();
	var hideHideable = searchForm.find('#SearchHideHideable');
	//alert(hideHideable.val());
	if(hideHideable.val() == 'true'){
	searchForm.find('.ToHide').hide();
	}
	advanced.bind('click', hideHideable, function(event){
	//alert(event.data.val());
	
	if(event.data.val() == 'true'){
		event.data.val('false');
	} else {
		event.data.val('true');
	}
	$('form#SearchForm .ToHide').each(function(){
		if($(this).css('display') == 'none'){
		$(this).show();
		} else {
		$(this).hide();
		}
	});
	})
});
