$("document").ready(function(){


	if (navigator && 
		navigator.appName &&
		navigator.appName == 'Microsoft Internet Explorer' || (
		navigator &&
		navigator.userAgent &&
		navigator.userAgent.indexOf("MSIE") != -1
		)
		) {
			
			$("body").prepend("<div style='font-weight:bold;padding-left:20px;font-family:arial;font-size:14px;text-align:left;width:3000px;height:30px;position:absolute;top:0px;left:0px;z-index:100;background-color:red;color:black'>you are using an outdated browser; <a style='color:white;' href='http://www.mozilla.com'>please upgrade here</a> to view this site correctly.</div>");
			
		}


	setInterval( function (){ 
		
		$("[title][tipped!=yes]").tooltip(); 
		$("[title][tipped!=yes]").attr("tipped","yes");
	},2000);
	
	//_worker = new Worker("/js/testworker.js");
	//_worker.postMessage( $ );

	if (document.location.href==='http://www.redbeanphp.com/' ||
		document.location.href==='http://redbeanphp.com/'
	) {
	
	
	//anounce version
	//$("#wrapper").prepend("<img  style='position:absolute;top:40;height:500%;width:500%;' src='/img/final.png' id='fnl'>");$('#fnl').animate({height:'103px',width:'97px','marginLeft':'650px','marginTop':'200px'},500,'swing');setTimeout(function(){$('#fnl').fadeOut(1000)},1000);
	
	//birthday
	//$(".tagline").html("<img style='cursor:help' alt='RedBean turns 1' title='RedBean turns 1, the first version of RedBean appeared April 17th 2009' src='/img/birthday.png' id='fnl'>").css("padding-bottom","0px;");
	//$(".blokje").css("position","relative");
	//$(".blokje").css("top","-60px");
	//$("div.blokje,a").click(function(){ $(".blokje").css("top","0px"); });
	
	
	}	

	var firsttime=1;
	var supercache = {};
	var oldurl='';
	var loader = function( theURL, cb ) {
		if (Math.round(Math.random()*5)==5) {
			theURL += '&refresh='+Math.random(); //1 in 5 chance to force uncaching
		}
		return $.get(theURL, cb);
	}
	
	$("a[href*=http]").click(function(e){
    	e.stopPropagation();
	})
	
	__sidebar = {
		"def":"/htmlsnippets/manual.html?ax&x0122cxs",
		"features":"/htmlsnippets/live.html?ax&3122",
		"example":"/htmlsnippets/live.html?ax&223",
		"demo":"/htmlsnippets/joinus.html?ax",
		"community":"/htmlsnippets/joinus.html?ax",
		"contact-me":"/htmlsnippets/joinus.html?ax"

	};
	window.getSideBarContent = function( pg ) {
		var surl = __sidebar["def"];
		if (__sidebar[pg]) {
			surl = __sidebar[pg];
		}
		if (supercache[surl]){
			$('#sdbar').html(supercache[surl]);
		}
		else {
			loader(surl,function(d){ 
				supercache[surl]=d; 
				$('#sdbar').html(d);
				
			})
		}
		
	}
	$("#comfortlink_goto_download").click(function(){document.location.href="#/download"});
	$("#comfortlink_goto_features").click(function(){document.location.href="#/features"});
	$("#comfortlink_goto_docs").click(function(){document.location.href="#/tutorial123"});
	$("#comfortlink_goto_community").click(function(){document.location.href="#/contact-me"});
	
	
	
	$(".bullet").html("&para;");
	$("#nav div").mouseover( function() {
		$(this).find(".col").css("color","#B00");
		$(this).find(".bullet").css("color","#DDD");
	});
	
	$("#nav div").mouseout( function() {
		$(this).find(".col").css("color","#DDD");
		$(this).find(".bullet").css("color","#B00");
	});
	$(".code").each(function(){
		var h = $(this).html();
		h = h.replace(/\t/g,"&nbsp;");
		h = h.replace(/\n/g,"<br>");

		$(this).html(h);
	});
	
	var cachedhref = '';
	setInterval( function(){
		
		if (typeof(linkhref) != 'undefined' && cachedhref!=linkhref){
				setTimeout(function(){		
					$("a").removeClass("marker");
					$("a[href="+linkhref+"],.sectionblock a[href="+linkhref+"]").addClass("marker");
					
					cachedhref=linkhref;
				
				},10);
		}
		
		
		var loc = (document.location.href.toString())
		if (loc.indexOf('#')>-1){
			var newurl = loc.split('#')[1];
			if (oldurl!=newurl){
				oldurl=newurl;
				var url = "/"+newurl.replace("#","").replace("/","")+"&ax";
				if (firsttime) {
					firsttime = 0;
					$("#header").animate({"height":"0px"} ,500, "swing", function(){ $(this).hide(); $("#section_orm").fadeIn(500);
					$("#nav").css("position","relative").css("top","-40px"); }); 
					//$("#wrapper").prepend("<img  id='lg' src='/img/logotiny.png'>")
					$('#lg').css('opacity',0).fadeTo(500, 0.7);
					$("#lg").css("position","absolute").css("left","10px").css("top","0px").css("cursor","pointer").click(function(){
						document.location.href="http://www.redbeanphp.com";
					});
				}
				linkhref = '#'+newurl;
				$("a").removeClass("marker");
				$("a[href="+linkhref+"],.sectionblock a[href="+linkhref+"]").addClass("marker");
				//$("a[href="+newurl+"]").addClass("marker");
				
				setTimeout(function(){try{
				__URL = document.location.href.toString().split('#')[1].toString().replace(/\W/g,'');
				pageTracker._trackPageview(__URL);
				google.friendconnect.container.setParentUrl('/' /* location of rpc_relay.html and canvas.html */);
				google.friendconnect.container.renderWallGadget(
 { id: 'div-8606906698423702700',
   site: '16756703352910678924',
   'view-params':{"disableMinMax":"false","scope":"ID","features":"video,comment","docId":__URL,"startMaximized":"false"}
 },
  skin);}catch(e){}},2000);
				
								
				if (typeof(supercache[url])!="undefined") {
					$('#section_orm').html(supercache[url]);
				
				
				
				}
				else {
					loader(url,function(d){
						supercache[url] = d;
						$('#section_orm').html(d);
						
				
						
					});
				}
			}
		}
		$('a').each(function(){
			if (!$(this).attr("href")) return;
			if ($(this).attr("href") && $(this).attr("href").indexOf("http")===0) return; //external link
			if ($(this).attr("href") && $(this).attr("href").indexOf("#")===0) return; //external link
			var hrf = $(this).attr("href");
			$(this).attr("href", "#"+hrf);
		});
	},200);
});
