$(document).ready(function(){
	$(".jsoff").removeClass("jsoff");
	tar_fbox.init();
	var path = window.location.pathname;
	
	$(".auxiliarycontent .primarylink").closest(".auxiliarycontent").addClass("sidebox_clickable");
	$(".sidebox_clickable").click(function(){
		window.location = $(this).children("p").children("a").attr("href");
	});
	
	$("#sealofquality #seal_about").hover(function(){
		$(this).parent().children(".seal_about").fadeIn();
	},function(){
		$(this).parent().children(".seal_about").hide();
	});
	$("#mce-EMAIL").bind('focus',function(){
		if (this.value == "enter your email address here") {
			this.value = "";
		}
	});
	$("#validator_checkfield").bind('focus',function(){
		if (this.value == "enter a web address here") {
			this.value = "";
		}
	});
	$("#validator_checkfield").bind('keydown',function(e){
		if (e.keyCode == 13) {
			validatecheckurl();
			return false;
		}
	});
	
	$("#validator_checkbutton").click(function(){
		validatecheckurl();
		return false;
	});
	
	$(".placardlink").hover(function(){
		$(this).find(".linktitle").stop().css({"display":"block"}).animate({"font-size":"1.3em","line-height":"20px"},100);
		$(this).find(".linkdescription").stop().animate({"right":0},300);
	},function(){
		$(this).find(".linktitle").stop().animate({"font-size":"1.8em","line-height":"69px"},100);
		$(this).find(".linkdescription").stop().animate({"right":"100%"},200);
	});
	
	$("#blog .article h2 span").each(function(){
		var lastspace=$(this).text().lastIndexOf(" ");
		var pre=$(this).text().substring(0,lastspace);
		var post=$(this).text().substring(lastspace+1);
		$(this).html(pre+"&nbsp;"+post);
	});
	//tar_utilities.dinject.code = {
	//	facebook_widget : '<div id="facebook" style="text-align: center;"><script type="text/javascript" src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php/en_US"></script' + '><script type="text/javascript">FB.init("203139e6bf25ea293e15ce1aa306f8d1");</script' + '><fb:fan profile_id="302901599754" stream="1" connections="48" logobar="0" width="900"></fb:fan><div style="font-size:8px; padding-left:10px"><a href="http://www.facebook.com/pages/MindSeed-Labs/302901599754">MindSeed Labs</a> on Facebook</div></div>'
	//}
	//tar_utilities.dinject.i();
	$(".state-changers a").bind("click",function(){
		var tclass=$(this).attr("class");
		var tdirec=(tclass=="off")?"on":"off";
		var eattr=$(this).find(".label").text().toLowerCase();
		var cval=$(this).find("."+tdirec).text().toLowerCase();
		$(this).removeClass(tclass).addClass(tdirec);
		$("#state-change").css(eattr,cval);
	});
	
	tar_autocleartext.init();
	
	if($(".blog-sidebar").length>0){
		tar_blogsidebar.init();
		tar_blogsearch.init();
	}
});

function validatecheckurl() {
	var curcheck = $("#validator_checkfield").attr("value");
	if (curcheck != "" && curcheck != "enter your web address" && curcheck.indexOf(".") > 0) {
		curcheck = (curcheck.indexOf("http") == 0) ? curcheck : "http://" + curcheck;
		curcheck = curcheck.replace("%s","&amp;doctype=XHTML+1.0+Strict");
		var gohref = "http://validator.w3.org/check?uri=" + curcheck;
		window.open(gohref);
		return false;
	} else {
		return false;
	}
}

tar_autocleartext={
	init:function(){
		$(".auto-clear-box").each(function(){
			tar_autocleartext.setup(this);
		});
	},
	setup:function(elem){
		$(elem).data({"defaultval":$(elem).attr("value")});
		$(elem).focus(function(){
			if($(this).val()==$(this).data("defaultval")&&!($(this).hasClass("has-content"))){
				$(this).val("").addClass("has-content");
			}
		}).blur(function(){
			if($.trim($(this).val())==""){
				$(this).val($(this).data("defaultval")).removeClass("has-content");
			}
		});
	}
}

tar_blogsidebar={
	slidetimer:"",
	defaults:{
		"speedthreshold":300,
		"animatespeed":300,
		"topoffset":20
	},
	fetch:function(get){
		return this[get];
	},
	init:function(){
		var seek=".blog-sidebar";
		var overrides={};
		if(arguments){for(i=0;i<arguments.length;i++){switch(typeof arguments[i]){
			case "string": seek=arguments[i]; break;
			case "object": overrides=arguments[i]; break;
		}}}
		$(seek).each(function(){
			var vars=tar_blogsidebar.buildvars(this,"var","title","text",overrides);
			$(this).data(vars);
			tar_blogsidebar.setup(this,vars,seek);
		});
		tar_blogsidebar.events(seek);
	},
	setup:function(elem,vars,seek){
		$(elem).data("threshold",$(elem).offset().top).data("origpos",$(elem).css("top"));
		$(elem).parent().css("min-height",parseInt($(elem).outerHeight())+parseInt($(elem).css("top")));
		tar_blogsidebar.checkscroll(seek);
	},
	events:function(seek){
		$(window).bind("scroll",function(){
			tar_blogsidebar.checkscroll(seek);
		});
	},
	checkscroll:function(seek){
		var vars=$(seek).data();
		if(parseInt($(window).scrollTop())+vars.topoffset>vars.threshold){
			var togo=parseInt($(window).scrollTop())-parseInt($(".pagewidth.blog").offset().top)+vars.topoffset;
			togo=(togo+parseInt($(seek).outerHeight())>parseInt($(seek).parent().outerHeight()))?parseInt($(seek).parent().outerHeight()-parseInt($(seek).outerHeight())):togo;
		}else{
			var togo=parseInt(vars.origpos);
		}
		if(togo){
			clearTimeout(tar_blogsidebar.slidetimer);
			tar_blogsidebar.slidetimer=setTimeout("tar_blogsidebar.animate(\""+seek+"\","+togo+","+vars.animatespeed+")",vars.speedthreshold);
		}
	},
	animate:function(seek,togo,speed){
		$(seek).dequeue().animate({"top":togo},speed);
	},
	buildvars:function(elem,node,k,v,overrides){
		var vars=this.fetch("defaults");
		for (i=0;i<$(elem).children(node).length;i++){
			var key=$(elem).children(node+":eq("+i+")").attr(k);
			var val=(v=="text")?$(elem).children(node+":eq("+i+")").text():$(elem).children(node+":eq("+i+")").attr(v);
			if(val=="true"||val=="false"){ val=this.bool(val); }
			vars[key]=val;
		}
		if(overrides){
			for(k in overrides){ vars[k]=overrides[k]; }
		}
		return vars;
	}
}

tar_blogsearch={
	init:function(){
		/*$(".blog-sidebar .search input[type=\"submit\"]").bind("click",function(){
			var searchpage=$(this).closest("form").attr("action");
			var searchterm=$(this).siblings("input[type=\"text\"]").val();
			document.location=searchpage+searchterm;
			return false;
		});*/
		$(".blog-sidebar .search form").bind("submit",function(){
			var searchpage=$(this).attr("action");
			var searchterm=$(this).find("input[type=\"text\"]").val();
			document.location=searchpage+searchterm;
			return false;
		});
	}
}
