// ** Stop IE 6 Background Flicker **
// **                              **
if ($.browser.msie && (parseInt($.browser.version)==6)) {
  try { document.execCommand("BackgroundImageCache", false, true); } catch(err) {}
};

// bookmark function
function addBookmark(title, url){
  if(window.sidebar){ // Firefox
    window.sidebar.addPanel(title, url,'');
  }else if(window.opera){ //Opera
    var a = document.createElement("A");
    a.rel = "sidebar";
    a.target = "_search";
    a.title = title;
    a.href = url;
    a.click();
  } else if(document.all){ //IE
    window.external.AddFavorite(url, title);
  } else {
		alert("Use your browser to bookmark this location.");
	}
}

// toggle value function
jQuery.fn.toggleVal = function(focusClass) {
	this.each(function() {
		$(this).focus(function() {
			// clear value if current value is the default
			if($(this).val() == this.defaultValue) { $(this).val("").removeClass("faded"); }
			
			// if focusClass is set, add the class
			if(focusClass) { $(this).addClass(focusClass); }
		}).blur(function() {
			// restore to the default value if current value is empty
			if($(this).val() == "") { $(this).val(this.defaultValue).addClass("faded"); }
			
			// if focusClass is set, remove class
			if(focusClass) { $(this).removeClass(focusClass); }
		});
	});
}

// toggle value for certain input fields
$(document).ready(function() {
	$("#input-phone").addClass("faded").toggleVal();
});

// ** Add click to show for client logos **
// **                                    **
/*
$(function(){ // (executes when the dom is ready)
	
	//$("#client-logos img").wrap("<span></span>");
	
	$("#client-logos").find("img").click(function(){
		// hide others
		$(".client-desc").addClass("hide");
		// display related info for this image
		$("."+$(this).attr("rel")).removeClass("hide");
		// remove span arrows
		//$("span.arrow").remove();
		// add arrow span
		//$(this).before("<span class='arrow'></span>");
		// make active
		$("#client-logos img").removeClass('active');
		$(this).addClass("active");
	});
	
	$("#client-logos").find("img").hover(function(){
		$(this).addClass("hover");
	},function(){
		$(this).removeClass("hover");
	});
	
});
*/

// ** Rotate quotes **
// **               **
$(function(){ // (executes when the dom is ready)
	setInterval("rotateQuotes()", 10000);
});
function rotateQuotes() {
	// only do this if there are more than one
	if ($(".quote-wrap").length<2) {
		return false;
	}
	// find quotes
	$(".quote-wrap").each(function(i){
		// find quote that's not hidden
		if (! $(this).hasClass("hide")) {
			$(this).css("display","block").addClass("hide");
			// is this the last quote
			if (i==$(".quote-wrap").length-1) {
				// last one, so repeat to first
				$(".quote-wrap:first").css("display","none").removeClass("hide");
				$(".quote-wrap:first").fadeIn("slow");
			} else {
				$(this).next().css("display","none").removeClass("hide");
				$(this).next().fadeIn("slow");
			}
			$(this).fadeOut("normal").addClass("hide");
			return false;
		};
	});
};



// ** Misc **
// **      **
$(function(){ // (executes when the dom is ready)
	
	// make logo a link to go back to home page
	$("#header h1").click(function(){
		document.location = "/";
	}).css("cursor","pointer");
	
	// add border
	if ($.browser.msie && (parseInt($.browser.version)<=6)) {
		$("#navigation-links li:first").addClass("first");
	};
	
	// add form classes for ie (to mimic our css selectors)
	if ($.browser.msie && (parseInt($.browser.version)<=6)) {
		$("input:checkbox").addClass("type-checkbox");
		$("input:radio]").addClass("type-radio");
		$("input:text]").addClass("type-text");
		$("input[@type=password]").addClass("type-password");
		$("input[@type=image]").addClass("type-image");
	};
	
	// convert hr's to div.hr instead
	if ($.browser.msie && (parseInt($.browser.version)<=7)) {
		$("hr").wrap("<div class='hr'></div>");
	};
	
	// stripe tables
	$(".news-table tr:odd").addClass("odd");
	$(".news-table tr:even").addClass("even");
	$(".events-table tr:odd").addClass("odd");
	$(".events-table tr:even").addClass("even");
	
	// 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=1, resizable=0, width=580, height=530');
		return false;
	});
	
	// make rel="flashdemo" open pop up windows
	$("a[@rel$='flashdemo']").click(function(){
		window.open(this.href, '', 'menubar=0, toolbar=0, scrollbars=0, resizable=0, width=640, height=395');
		return false;
	});
	
	// make close button close the window (used with popup window)
	$("#login-close").click(function(){
		self.close();
	}).css("cursor","pointer");
	
});

