/*
 * put jQuery into noconflict mode
 * if conflicts with other Javascript libaries, e.g. Prototype on GoDaddy PreviewDNS
 */
	//jQuery.noConflict();
		
/*
 * Console logger
 *  %s	String
 *  %d, %i	Integer (numeric formatting is not yet supported)
 *  %f	Floating point number (numeric formatting is not yet supported)
 *  %o	Object hyperlink
 * 
 *  only logs if globalVars.log = true
 */

	$.log = function() {
	  	if(window.console) {
			if($.browser.safari){
				// Safari console
				var args = "";
				$.each(arguments,function(i,val){
					args += " " + val;
				});
				window.console.log(args); // fix to show args, Safari doesn't like .apply
			}
			if ($.browser.mozilla) {
				// Firefox with firebug
				window.console.log.apply(this, arguments);
			}
	  	} else {
	  		// no Firebug
	    	//alert(message);
		}
	};
	

/* 
 *  fix IE6 link background image flicker bug
 */
		
	//try {  document.execCommand("BackgroundImageCache", false, true); } catch(err) {} 


/* 
 * jQuery actions when DOM is loaded
 */ 

$(document).ready(function(){

/*
 *  De-obfuscate email addresses
 * 
 *  replaces email address @ in "mailto" links and link text
 * 
 */
	function deobfuscate(x){
		return x.replace("--@--","@");
	}
	$("a").each(function (i){
		var h = this.href;
		if (h.indexOf("mailto")==0) {
			var t = deobfuscate($(this).html());
			this.href = deobfuscate(h);
			$(this).html(t);
		}
	});

	/* search box text replacement */
	$("#search-text").focus(function(){
		if($(this).val() == "Search..."){
			$(this).val("");
		}
	});

	/* email signup text replacement */
	$("#signup-email").focus(function(){
		if($(this).val() == "Email address..."){
			$(this).val("");
		}
	});
	

	/* drop down menus */
	$(".nav>ul>li").hover(
		function(){
			/* hide menus */
			$(".nav .dropdown").hide();
			/* show menu */
			var menu = $(".dropdown",this);
			menu.show();
			menu.hover(
				function(){},
				function(){
					$(this).hide();
			});
		},
		function(){}
	);
	
	
	

	/* Google Analytics delayed loader
	 *    loads GA tracking script after page loads
	 *  external links
	 *  tags with class="external" target="_blank"
	 *  optional Google Analytics tracking code trigger
	 */

		var pre = "/LINK/";				// prefix to add to URL for GA tracking code
		$('a[href^="http://"]').each(function(){
			var href = $(this).attr("href");
			if(href.indexOf("http://www.spokaneuniversitydistrict.com")!=0){	// don't include this site's pages
				$(this).addClass('external');			// add CSS class for styling
				$(this).attr('target', '_blank');		// open in popup window
				$(this).click(function(){				// GA tracking code
					var href = $(this).attr("href");
					href = href.substr(7,9999);	// trim off http://
					var i = href.indexOf("www.");	// trim off www.
					if (i===0){
						href = href.substr(4,9999);
					}
					href = encodeURI(href);		// encode URL
					$.log(pre + href);			// log href to console
					//urchinTracker(pre + href)	// old GA tracker code
					//pageTracker._trackPageview(pre + href)	// GA tracker code
					//return false;				// cancel link action
			
				});
			}
		});

	/*
	 *  Innerfade slideshows
	 *  docs: http://medienfreunde.com/deutsch/weblog/aus_der_praxis.html?nid=162
	 *  in CSS set the following to prevent images from showing while page loads:
	 * 	 #container img { display: none; }
	 */ 
 
		$("#sidebar-rotator-top").innerfade({
			animationtype: 'fade',
			speed: 1500,
			timeout: 4000,
			type: 'sequence',
			containerheight: '158px'
		});
		window.setTimeout(function(){
			$("#sidebar-rotator-bottom").innerfade({
				animationtype: 'fade',
				speed: 1500,
				timeout: 4000,
				type: 'sequence',
				containerheight: '135px'
			});
		},2000);


	/* panoramic gallery */
		var op = .75;
		$(".panoramic-gallery a")
			.fadeTo('fast',op)
			.attr("title","Click to view larger image")
			.hover(
				function(){
					$(this).fadeTo('fast',1);
				},
				function(){
					$(this).fadeTo('fast',op);
				}
			);
	
	/* header panoramic slider */
	
		$('.imageRotator')
			.append("<img src='images/header-panoramic.jpg' alt='' />")
			.append("<img src='images/header-panoramic.jpg' alt='' />")
			.crossSlide({
			  speed: 35,
			  fade: .01
			}, [
			  { src: 'images/header-panoramic.jpg', dir: 'left'},
			  { src: 'images/header-panoramic.jpg', dir: 'right'}
			])
		;
	
	/* header overlay */	
		$('.header').append("<div id='header-overlay'><img src='images/header-overlay.png' alt='' /></div>");
		
	/* fix PNG for IE */
		$("#header-overlay img").pngFix();
	
	$("a.video-player").videoPlayer({
		playerpath: "/js/",
		backcolor: "000000",
		frontcolor: "a0abbd",
		lightcolor: "f28453",
		width: "320px",
		height: "260px"
	});
	
});