/* stop IE6 flicker */
try { document.execCommand("BackgroundImageCache", false, true); } catch(err) {}

// embed our flash with UFO
// samples page flash
var homeFlashObject = { movie:"/flash/home.swf", width:"838", height:"309", majorversion:"9", build:"0", bgcolor:"#FFFFFF", wmode:"opaque", menu:"false", name:"surgient-home", flashvars:"globalAssetPath=/flash/assets/" };
UFO.create(homeFlashObject, "flash-area");


// ** highlight sub navigation **
// **                          **
$(function(){ // (executes when the dom is ready)
	// search for snav-something in the body tag
	// this tells us if a link should be active by default
	// (this is because each of our nav links uses an id, e.g. nav-home, so we define
	//  active links by simply declaring this id in the body tag of each page as a class name)
	$("body[@class*=nav-]").each(function(i) {
		var bodyClasses = $(this).attr("class").split(" ");
		var regex1 = /\bnav-\b/;
		var regex2 = /\bsnav-\b/;
		$.each(bodyClasses, function(i, n) {
			if (regex1.test(n) || regex2.test(n)) {
				// add class "active" to the first link in the li#nav-something or li#snav-something
				$('#'+n+'>a').addClass("active");
			};
		 });
	});
});

// ** add shadows to images **
// **                       **
$(function(){ // (executes when the dom is ready)
	$(".add-shadow").each(function(i){
		if (this.className.length > 0) {
			$(this).wrap('<div class="image-shadow"><div class="image-shadow-inside"></div></div>');
			var thisClassName = this.className;
			this.className = "";
			$(this).parent().parent().addClass(thisClassName);
		};
	});
	$(".image-header").wrap('<div class="image-shadow2 image-header"><div class="image-shadow2-inside"></div></div>');
});

// ** table functions **
// **                 **
$(function(){ // (executes when the dom is ready)
	
	$(".core-table tr:even").addClass("stripe");
	$(".core-table tr td:first-child").addClass("first");
	$(".core-table tr td:last-child").addClass("last");
	$(".core-table tr th:last-child").addClass("last");
	
});

// ** Misc **
// **      **
$(function(){ // (executes when the dom is ready)
	// make logo a link to go back to home page
	$("#logo").click(function(){
		document.location = "/";
	}).css("cursor","pointer");
	// make any links with rel="external" to open in new windows
	$("a[@rel$='external']").click(function(){
		this.target = "_blank";
	});
	// make rel="popup" open pop up windows
	$("a[@rel$='popup']").click(function(){
		window.open(this.href, '', 'menubar=0, toolbar=0, scrollbars=0, resizable=0, width=775, height=530');
		return false;
	});
	// make close button close the window (used with popup window)
	$("#close").click(function(){
		self.close();
	}).css("cursor","pointer");
	// misc IE 6 stuff
	if ($.browser.msie && ($.browser.version <= 6)) {
		// give radio buttons and checkboxes "type-checkbox" and "type-radio" classes for ie
		$(":checkbox").addClass("type-checkbox");
		$(":radio").addClass("type-radio");
		// fix rollovers for ie 6-
		$("#navigation a, #quick-navigation a").hover(function(){ $(this).addClass("hover"); },function(){ $(this).removeClass("hover"); });
		// find first-child for footer li
		$("#footer-links li:first-child").addClass("first-child");
	};
	if ($.browser.msie && ($.browser.version <= 7)) {
		// find first-child for footer li
		$(".hr-faded").replaceWith('<div class="hr-faded"></div>');
		$(".hr-faded2").replaceWith('<div class="hr-faded2"></div>');
	};
	
});