/*
 * put jQuery into noconflict mode
 * if conflicts with other Javascript libaries, e.g. Prototype on GoDaddy PreviewDNS
 */
	//jQuery.noConflict();
		

/* 
 * jQuery actions when DOM is loaded
 */ 

$(document).ready(function(){

	/* tag external links */
	$("body").externalLinks(
		{
		     cssClass: "external",
			 target: "_blank",
		     gaPrefix: "/linkout/",
		     gaTracking: false,
			 log: true
		}
	);

	/* uncloack email addresses */
	$("body").emailUncloak({
		at:"--[at]--"
	});


	// replace search box text on focus
		var searchElement = $("#search-form #search-text");
		var searchDefaultLabel = "Search...";
		var searchCurrentLabel = searchElement.attr("value");
		// set default label if blank
		if (searchCurrentLabel == "") {
			searchElement.attr("value",searchDefaultLabel);
		}
		// clear label on focus event if not default label
		searchElement.focus(function(){
			var searchCurrentLabel = $(this).attr("value");
			if (searchCurrentLabel == searchDefaultLabel) {
				$(this).attr("value","");
			}		
		});



	/* messages effects */
	
		// set CSS display: none;
		$(".server-message, .server-error")
			.append("<a href='#' class='close'>Close</a>")
			.fadeIn('slow')
			.find(".close")
				.fadeTo(0, .5)
				.click(function(){
					$(this).parent().fadeOut('slow');
				})
		;


	/* fancy tables */
	
		$("table.fancy").each(function(){
			$(this).find("tr:even").addClass("even");
			$(this).find("tr:odd").addClass("odd");
			$(this).find("tr:first").removeClass("even").addClass("header");
		});

	/* rounded page background if not home page */
	
		if(!$("body").hasClass("home")){
			$("body")
				.addClass("rounded")
				.find(".main")
					.prepend('<div id="rounded-top"></div>')
					.append('<div id="rounded-bottom"></div>')
			;
		}

	/* Simplimation hover effect */
		var op = .5;
		$(".site-info #simplimation")
			.fadeTo(0, op)
			.hover(
				function(){$(this).stop().fadeTo(100,1)},
				function(){$(this).stop().fadeTo(1000, op);})
		;


	/*
	 * slide-out content reveals
	 */
	
		// hide reveal content blocks
		$(".reveal-content").hide();
		// reveal trigger event
		$(".reveal-trigger").each(function(){
			// get id
			var id = $(this).attr("rel");
			$.log(id);
			$(this).click(function(){
				// show content block
				$("#"+id).slideDown('fast');
				// hide reveal trigger
				$(this).fadeOut('fast');
				// cancel anchor
				return false;
			});
		});

	/* copy nav to quick links */
	/*
	// clone nav block
	$(".nav")
		.clone()
		.appendTo(".wrapper-footer")
			.removeClass("nav")
			.addClass("nav-quick");
	// append pipes to nav items
	var count = $(".nav-quick a").size();
	$(".nav-quick a")
			.each(function(i,el){
				if (i+1 < count) {
					$(this).append("<span>|</span>");
				}	
			})
	;
	*/
	

	
	/* 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
	 */
	/*
	$.getScript("http://www.google-analytics.com/ga.js",function(){
		// execute page tracker function when script loaded
		var pageTracker = _gat._getTracker("UA-5475261-1");
		pageTracker._trackPageview();
	});
	*/
	
	/*
	 * GA page and event tracking
	 */
	//pageTracker._trackEvent(category, action, optional_label, optional_value);
	//pageTracker._trackPageview(url);

	/* IE6 fix
	 * insert relatively positioned elements to fix IE6 bug on absolutely positioned stuff
	 */ 
	//$("#absolutelyPositionedElements").before("<div></div>");

	

/* 
 *  fix IE6 link background image flicker bug
 */
		
	//try {  document.execCommand("BackgroundImageCache", false, true); } catch(err) {} 


/* 
 *   prevent right click on images
 */
		/*
		$("img").bind("contextmenu",function(e){
			$.log("right-clicked on image");
			//return false;
		});
		*/
		
/* fix body height if less than full browser window */
	/*
		var b = $("body").height();
		var w = $(".body-wrap").height();
		if (w < b){
			$(".body-wrap").css("height","100%");
		}
	*/

/*
 *  PNG fixer for IE6
 *  requires jquery_pngfix.js to be loaded before this script
 *	, use inline IMG width and height	
 */
	
		// $("img[@src$=png]").pngFix();

/* alernateive PNG fixer
 * no included script required
 */

		/*
		function fix_pngs() {
			 if (navigator.appVersion.match(/MSIE [0-6]\./)) {
				 $('.png').each(function () {
			 		if (this.currentStyle.backgroundImage != 'none') {
			 			var image = this.currentStyle.backgroundImage;
			 			image = this.currentStyle.backgroundImage.substring(5, image.length - 2);
				 		if(image.indexOf(".png") !=-1) {
					 		$(this).css({
				 			'backgroundImage': 'none',
			 				'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=crop, src='" + image + "')"
			 				});
			 			}
				 	}
			 	});
			 }
			}
		*/
		
	
/*
 *  preload images
 */

		/*
		var preloads = [
			"images/ajax-loading-white.gif"
		];
		$.each(preloads,function(i,img){
			var x = new Image;
			x.src = img;
		});
		*/

/* popup blocker detector */
	/*
	winHandle=window.open('yourfile.htm' + "?newwin=true", "_top", "width="+wwidth+",height="+wheight+",location=0,menubar=0,resizable=no,scrollbars=no,status=yes,titlebar=no,dependent=yes");
	if(winHandle==null){
		alert("Error: While Launching New Window...nYour browser maybe blocking up Popup windows. nn  Please check your Popup Blocker Settings");
	}
	*/


/* Delayed functions
 * 
 */

	/*
		window.setTimeout(function(){
			// do stuff
		},2000);
	 */

		
/*
 *  rounded Nifty corners
 *  docs: http://www.html.it/articoli/niftycube/index.html
 */

		// $("#page_wrap").nifty("normal");
	


/* set minimum page width (needed instead of CSS for IE) */
	/*
	function setPageWidth(){
		var minimumWidth = 850;
		var w = $(window).width();
		$.log(w);
		if (w < minimumWidth) {
			$("#page_wrap").width(minimumWidth);
		}
		else {
			$("#page_wrap").width("");
		}
	}
	$(window).resize(function()){
		setPageWidth();
	}
	*/
});
