Cufon.replace("h1");
Cufon.replace("h2");
Cufon.replace("h3");			
Cufon.replace("h4");			
   


window.addEvent("domready", function() {
	// setup
	var Scroll = new Fx.SmoothScroll();
	var TheTips = new Tips($$('.tooltip'));
	
	// some definitions
	window.startfolio = $('more');
	window.lp = $('launchportfolio');
	window.lp.hide();
	window.lp.set({
		"styles" : {
			"height" : "650px"
		}
	});
	
	// google voice - added 10/6/09
	var str = '<object type="application/x-shockwave-flash" data="https://clients4.google.com/voice/embed/webCallButton" width="230" height="85"><param name="movie" value="https://clients4.google.com/voice/embed/webCallButton" /><param name="wmode" value="transparent" /><param name="FlashVars" value="id=31f22fc7daf6ab64c817559efcb1f4fd407b0196&style=0" /></object>';
	$('gv').set("html", str);

	// add events to morelinks
	
	window.startfolio.addEvent('click', function() {
		  if (window.alreadylaunched !== true ) {

  			var request = new Request.JSON({url: '/image.php',
  			data: {'id' : 1},
  			method : 'get',
  			onSuccess: function(responseJSON) {
  					var myChain = new Chain();
  					myChain.chain(function() {
  						$('slide-title').set('html', responseJSON.thetitle);
  						$('slide-body').set('html', responseJSON.thecaption);
  						//$('more').style.backgroundImage = "url(/explore_going.gif)";
  						window.photoframe = new Element('img', {
  							"id" : "slide-photoframe",
  							"alt" : "Image of website, click URL link below to be redirected to the live website.",
  							"src" : responseJSON.thephoto,
  							"height" : 500,
  							"width" : 700,
  							"events" : {
  								'click' : function() {
  									launchBig(window.theid);
  								}
  							}
  						});
  						// resize the image to fit current user's window
  						resizeImage(window.photoframe);
						
  						// initiate tooltips
						
  						// set the featured-image status
  						$('slide-featured').set('text', responseJSON.thefeaturedstatus);					
						
  						// initiate arrows
  						$('arrows').set('html', responseJSON.arrows);
  						return true;
  					},
  					function() {
  						$('slide-photo').adopt(window.photoframe);
  						$('slide-photo').adopt(new Element('div', {
  							"id" : "slide-overlay",
  							"styles" : {
  								"backgroundImage" : "url(/images/ajax-loader-3.gif)",
  								"backgroundColor" : "black",
  								"backgroundRepeat" : "no-repeat",
  								"backgroundPosition" : "50% 50%",
  								"position" : "absolute",
  								"display" : "none",
  								"top" : "10px",
  								"left" : "10px"
  							},
  							"html" : "&nbsp;"
  						}));
  						return true;
  					},
  					function() {
  						setTimeout("window.lp.reveal()", 200);
  						var fx = new Fx.Morph($('more'), {'duration':600, 'transition' : Fx.Transitions.Sine.easeOut});
  						var x = window.getSize().x;
  						//fx.start({'left' : x+150+'px'});
  						return false;
  					}
  					);
  					while (myChain.callChain()) {}
					}
  			}).send();
  		window.alreadylaunched = true;
      }
	  });
  });

function SlideTo(id) {
 	var request = new Request.JSON({url: '/image.php',
	data: {'id' : id},
	method : 'get',
	onRequest: function() {
		$("slide-overlay").set("styles", {
			"display" : "block",
			"width" : getTheSize().thex+1+'px',
			"height" : getTheSize().they+1+'px',
		});
		var myeffect = new Fx.Morph($('slide-photoframe'), {"duration" : "short"});
		myeffect.start({'height': getTheSize().they+'px', 'width' : getTheSize().thex+'px'});
	},
	onSuccess: function(responseJSON) {
		// meta
		$('slide-title').set('html', responseJSON.thetitle);
		$('slide-body').set('html', responseJSON.thecaption);
		
		// photo
		$('slide-photoframe').set('src', "/images/"+id+"_resized_processed.jpg");
		
		// arrows
		$("arrows").set("html", responseJSON.arrows);

		// featured status
		$('slide-featured').set('text', responseJSON.thefeaturedstatus);		
		
		// remove blinds
		setTimeout("$('slide-overlay').set('styles', {'display' : 'none'});", 500);		
		
		resizeImage(window.photoframe);				
		
		window.theid = id;
		
	}}).send();
}

function resizeImage(el) {
	if (window.getSize().x < 1170) {
		var x = window.getSize().x-50-50;
		x = .66*x-40;
		y = x*.71429;
		window.photoframex = x;
		window.photoframey = y;
		el.set('styles', {'width' : x, 'height' : y});
		$('slide-photo').set('styles', {'height': y});
	}
}

function getTheSize() {
	if (window.getSize().x < 1170) {
		x = window.getSize().x-50-50;
		x = .66*x-40;
		y = x*.71429;
	} else {
		x = 700;
		y = 500;
	}
	var myobj = new Object();
	myobj.thex = x;
	myobj.they = y;
	return myobj;
}

function launchBig(theid) {
	// roll to height
	var size = window.getSize();
	var thecontent = $("thecontent");
	var bodyel = $("bodyel");
	el = new Element("div", {
		"id" : "port-frame",
		"styles": {
			"color" : "white",
			"padding" : "0 10px",
			"-webkit-box-shadow" : "2px 2px 10px black",
			"-moz-box-shadow" : "2px 2px 10px black",				
			"opacity" : 0,
			"backgroundColor" : "black",
			"position" : "fixed",
			"overflow" : "auto",
			"left": "-50px",
			"right" : "-50px",
			"top" : "-50px",
			"bottom" : "-50px",
			"width" : "auto",
			"margin" : "0 auto"
		}
	});
	bodyel.adopt(el);
	
	var elfx = new Fx.Morph(el, {duration: 500});
	var thecontentfx = new Fx.Morph(thecontent, {duration: 'short', transition: Fx.Transitions.Quad.easeIn});
	thecontentfx.start({
			'opacity' : .5
		}).chain(function(){
			// executes immediately after completion of above effect
			elfx.start({
				'opacity' : 1,
				"left": "45px",
				"right" : "45px",
				"top" : "45px",
				"bottom" : "45px"					
			}).chain(function() {
					var elfx2 = new Fx.Morph(el, {duration: 200});
					elfx2.start({
						"left": "30px",
						"right" : "30px",
						"top" : "30px",
						"bottom" : "30px"						
				}).chain(function() {
					loadPortImage(el, theid);
				});
			});
		});
}

function loadPortImage(el, which) {
	if (which == null) {
		which = 1;
	}
	el.set("html", "<div id='loading'><a id='return' onclick='unLaunchbig();' href='#theportfolio'>Close <b>X</b></a><h4 id='port-title'></h4><div id='port-image'><img id='port-imageframe' src='/images/"+which+".jpg' alt='' /></div></div>");
	var currimage = new Request.JSON({url: "/image.php",
		data: { "id" : which },
		method: "get",
		onSuccess: function(myjson) {
			$('port-title').set('text', myjson.thetitleStripped);
		},
		onFailure: function() {
			alert("there was an error loading the portfolio.");
		}
	}).send();
}


/* http://robertnyman.com/roblab/javascript-remove-tags.htm */
function stripHTML(){
	if(document.getElementById && document.getElementById("input-code")){
		var strInputCode = document.getElementById("input-code").innerHTML;
		/* 
			This line is optional, it replaces escaped brackets with real ones, 
			i.e. &lt; is replaced with < and &gt; is replaced with >
		*/	
		strInputCode = strInputCode.replace(/&(lt|gt);/g, function (strMatch, p1){
			return (p1 == "lt")? "<" : ">";
		});
		var strTagStrippedText = strInputCode.replace(/<\/?[^>]+(>|$)/g, "");
		alert("Input code:\n" + strInputCode + "\n\nOutput text:\n" + strTagStrippedText);	
	}	
}

function unLaunchbig() {
	$('port-frame').nix(true);
	var newfx = new Fx.Tween($('thecontent'), {'property' : 'opacity', 'duration' : 'short'});
	newfx.start(100);
}

