// JavaScript Document

// jquery swfobject - for inserting flash into a document
(function(E,B){var C=function(G){var F,H=[];for(F in G){H.push(F+'="'+G[F]+'"')}return H.join("")},D=function(H){var F,J,I=[],G;for(F in H){if(typeof H[F]=="object"){G=[];for(J in H[F]){G.push([J,"=",encodeURIComponent(H[F][J])].join(""))}H[F]=G.join("&amp;")}I.push(['<param name="',F,'" value="',H[F],'" />'].join(""))}return I.join("")},A=false;E[B]=(function(){var F="0,0,0",G=navigator.plugins["Shockwave Flash"]||ActiveXObject;F=G.description||(function(){try{return(new G("ShockwaveFlash.ShockwaveFlash")).GetVariable("$version")}catch(H){}}());F=F.match(/^[A-Za-z\s]*?(\d+)[\.|,](\d+)(?:\s+r|,)(\d+)/);return{available:F[1]>0,activeX:!G.name,version:{major:F[1]*1,minor:F[2]*1,release:F[3]*1},hasVersion:function(I){var L=this.version,J="major",K="minor",H="release";I=(/string|number/.test(typeof I))?I.toString().split("."):I||[0,0,0];I=[I[J]||I[0]||L[J],I[K]||I[1]||L[K],I[H]||I[2]||L[H]];return(I[0]<L[J])||(I[0]==L[J]&&I[1]<L[K])||(I[0]==L[J]&&I[1]==L[K]&&I[2]<=L[H])},expressInstall:"expressInstall.swf",create:function(H){if(!E[B].available||A||!typeof H=="object"||!H.swf){return false}if(H.hasVersion&&!E[B].hasVersion(H.hasVersion)){H={swf:H.expressInstall||E[B].expressInstall,attrs:{id:"SWFObjectExprInst",height:Math.max(H.height||137),width:Math.max(H.width||214)},params:{flashvars:{MMredirectURL:location.href,MMplayerType:(E[B].activeX)?"ActiveX":"PlugIn",MMdoctitle:document.title.slice(0,47)+" - Flash Player Installation"}}};A=true}else{H=E.extend(true,{attrs:{height:H.height||180,width:H.width||320},params:{wmode:H.wmode||"opaque",flashvars:H.flashvars}},H)}return"<object "+(C(H.attrs))+(E[B].activeX?' classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"><param name="movie" value="'+H.swf+'" />':' type="application/x-shockwave-flash" data="'+H.swf+'">')+(D(H.params))+"</object>"}}}());E.fn[B]=function(F){if(typeof F=="object"){this.each(function(){var G=document.createElement(B);G.innerHTML=E[B].create(F);if(G.childNodes[0]){this.appendChild(G.childNodes[0])}})}else{if(typeof F=="function"){this.find("object").andSelf().filter("object").each(function(){var H=this,G="jsInteractionTimeoutMs";H[G]=H[G]||0;if(H[G]<660){if(H.clientWidth||H.clientHeight){F.call(this)}else{setTimeout(function(){E(H)[B](F)},H[G]+66)}}})}}return this}}(jQuery,"flash"));

// General init function
function init() {
	// Set up homepage scroll pane
	if (typeof $.fn.jScrollPane != 'undefined') {
		$('#pane1.scroll-pane').jScrollPane();
	}

	// Set up input 'hinting'
  $("input.TextInput").focus(function(){
    if ($(this).val()==$(this).attr('title')) {$(this).removeClass('lttxt').val('');}
  }).blur(function(){
    if ($(this).val()==''||$(this).val()==$(this).attr('title')) {$(this).val($(this).addClass('lttxt').attr('title'));}
  }).blur();

	// Set up 'tell a friend' form to use ajax
	$('#TellaFriend form').ajaxForm({
		dataType: 'json',
		success: function(data){
			$('#TellaFriend form').replaceWith(data.message);
		}
	});

	// Show ecard flash when req'd
	$('#ecardpreview,#viewecard').each(function(){
    var span = $('span',$(this)).remove();
		var swf = 'ecards/'+span.attr('class')+'.swf';
		$(this).flash({
			swf: swf,
			height: span.css('height'),
			width: '100%'
		}).height(span.css('height'));
	});

	// Set up 'ecard' form to use ajax
	$('#ecardform').ajaxForm({
		dataType: 'json',
		success: function(data){
			$('#ecardpreview').empty().append(data.message);
		}
	});
}
