/*
 * This code searches for all the <script type="application/processing" target="canvasid">
 * in your page and loads each script in the target canvas with the proper id.
 * It is useful to smooth the process of adding Processing code in your page and starting
 * the Processing.js engine.
 */

if ( window.addEventListener ) {
	window.addEventListener("load", function() {
		var scripts = document.getElementsByTagName("script");
		
		for ( var i = 0; i < scripts.length; i++ ) {
			if ( scripts[i].type == "application/processing" ) {
				var src = scripts[i].src, canvas = scripts[i].nextSibling;
	
				if ( src && src.indexOf("#") ) {
					canvas = document.getElementById( src.substr( src.indexOf("#") + 1 ) );
				} else {
					while ( canvas && canvas.nodeName.toUpperCase() != "CANVAS" )
						canvas = canvas.nextSibling;
				}

				if ( canvas ) {
					Processing(canvas, scripts[i].text);
				}
			}
		}
	}, false);
}

function animateMenu() {
	setTimeout(function() {
	  jQuery('.home #menu-blog, .s-category-general #menu-blog, .slug-projects #menu-projects, .slug-code #menu-code, .parent-pageid-23 #menu-code, .slug-about #menu-about').each(function() {
		var corner1 = Math.floor(20 + (Math.random()*25));
		var corner2 = Math.floor(20 + (Math.random()*35));
		var corner3 = Math.floor(20 + (Math.random()*35));
		var corner4 = Math.floor(20 + (Math.random()*30));
		jQuery(this).animate({
		WebkitBorderTopLeftRadius: corner1, 
		WebkitBorderTopRightRadius: corner2, 
		WebkitBorderBottomLeftRadius: corner3, 
		WebkitBorderBottomRightRadius: corner4, 
		MozBorderRadiusTopleft: corner1, 
		MozBorderRadiusTopright: corner2,
		MozBorderRadiusBottomleft: corner3, 
		MozBorderRadiusBottomright: corner4
		}, 2000, animateMenu);});
	}, 1000);
}

if (!jQuery.browser.msie) {
	jQuery(document).ready(function(){  
	  // Pass the script through to a string using jQuery.ajax();
	  var script = jQuery.ajax({url: "/wp-content/themes/keyvan2009/flowerheader.pjs", async: false}).responseText;
	  // Store the Canvas element in an object alias
	  var canvas = jQuery('canvas#animated-header').get(0);
	  // Initialize the Processing.js script
	  Processing(canvas, script);
	  // animate menu border
	  //animateMenu();
	});
}