// Fix background image flickering in IE
try {
  document.execCommand('BackgroundImageCache', false, true);
} catch(e) { }


/* ***********************Begin Open Blank Window*********************** */
function BlankWin (url) {
     blankWin = window.open(url,'_blank');
  }
/* ***********************End Open Blank Window*********************** */
/* ***********************begin toggle div tags***********************  */
function toggledivs() {
  var inc, endInc=arguments.length;
  for (inc=0; inc<endInc; inc+=2) {
    var id = arguments[inc];
    if (arguments[inc+1] == 'none') param = "none";
    else if(arguments[inc+1]=='block') param = "block";
    if (document.layers) document.layers['container'].layers[id].visibility = param;
    else if (document.all) eval("document.all." + id + ".style.display = \"" + param + "\"");
    else if (document.getElementById) eval("document.getElementById(id).style.display = \"" + param + "\"");
  }
}
/* ***********************end toggle div tags***********************  */


/* begin function for the partner locator table */
var partnerLocator = {
	init: function() {
		$('tr.company-info').hide().prev().find('a[@href=#hide]').hide();
		$('a[@href=#hide]').click(
			function() {
			  partnerLocator.hideInfo($(this).parent());
				return false;
			}
		);
		$('a[@href=#show]').click(
			function() {
			  partnerLocator.showInfo($(this).parent());
				return false;
			}
		);
		// Need to make this state aware if we show some info on page load
		$('a.name').toggle(
			function() {
			  partnerLocator.showInfo($(this).parent());
				return false;
			},
			function() {
			  partnerLocator.hideInfo($(this).parent());
				return false;
			}
		);
	},
	showInfo: function(el) {
	  // el is the td of the row that contains the company name to show info for
		var l = el.parent().next().find('.logo');
		var i = l.find('img');
		if (i.length == 0)
		{
		  var data = l.attr('title').split('||');
		  l.append('<img src="'+data[0]+'" alt="'+data[1]+'" />');
		}

		el.parent().addClass('infoVisible').next().show();
		el.find('a[@href=#hide]').show();
		el.find('a[@href=#show]').hide();
    // $('#gAbout').hide();
	},
	hideInfo: function(el) {
	  // el is the td of the row that contains the company name to hide info for
		el.parent().removeClass('infoVisible').next().hide();
		el.find('a[@href=#show]').show();
		el.find('a[@href=#hide]').hide();
    // $('#gAbout').show();
	}
};
$(function() { partnerLocator.init(); });
/* end function for the partner locator table */

/* begin - Make entire homepage tiles clickable */
var homepageTiles = {
  init: function() {
    $('#homeMast div.c').click(this.click);
  },
  click: function(e) {
    e.stopPropagation();
    var url = '';
    $(this).find('p.more a').each( function() { url = this.getAttribute("href"); } );
    window.location.href = url;
  }
};
$(window).load( function() { homepageTiles.init(); } );
/* end - Make entire homepage tiles clickable */

/* begin - Make partner directory submit on pulldown change if JavaScript is available */
var partnerDirControl = {
  init: function() {
    $('#updateButton').hide();
    $('#region').change(
      function(event) {
        document.location.href = event.target.options[event.target.selectedIndex].value;
        return false;
      }
    );
  }
};
$(function() { partnerDirControl.init(); } );
/* end - Make partner directory submit on pulldown change... */

/* begin - Primary Navigation */
var primaryNavigation = {
  init: function() {
    if ($.browser.msie) // iframe to fix dropdowns over select items
        $('#primaryNav > li').append('<iframe style="display: none;" src="javascript:false;" frameBorder="0" scrolling="no"></iframe>');
		
    $('#primaryNav > li').hover(
      function() {
        $(this).addClass('over');
        $(this).children('a').addClass('over');
  	    if ($.browser.msie) {
  				var h = $(this).children('ul').height();
  				var w = $(this).children('ul').width() + 1;
  				var i = $(this).children('iframe');
  				if (i.length > 0 && h != null && w != null)
  				  i.height(h).width(w).show();
		    }
      },
      function() {
        $(this).removeClass('over');
        $(this).children('a').removeClass('over');
        if ($.browser.msie)
          $(this).children('iframe').hide();
      }
    );
  }
};
$(function() { primaryNavigation.init(); });
/* end - Primary Navigation */
