if (!applesearch)	var applesearch = {};

applesearch.init = function ()
{
	// add applesearch css for non-safari, dom-capable browsers
	if ( navigator.userAgent.toLowerCase().indexOf('safari') < 0  && document.getElementById )
	{
		this.clearBtn = false;
	}
}

// called when on user input - toggles clear fld btn
applesearch.onChange = function (fldID, btnID)
{
	// check whether to show delete button
	var fld = document.getElementById( fldID );
	var btn = document.getElementById( btnID );
	if (fld.value.length > 0 && !this.clearBtn)
	{
		btn.style.background = "white url('http://www.macrepair.nl/applesearch/srch_r_f2.gif') no-repeat top left";
		btn.fldID = fldID; // btn remembers it's field
		btn.onclick = this.clearBtnClick;
		this.clearBtn = true;
	} else if (fld.value.length == 0 && this.clearBtn)
	{
		btn.style.background = "white url('http://www.macrepair.nl/applesearch/srch_r.gif') no-repeat top left";
		btn.onclick = null;
		this.clearBtn = false;
	}
}

// clears field
applesearch.clearFld = function (fldID,btnID)
{
	var fld = document.getElementById( fldID );
	fld.value = "";
	this.onChange(fldID,btnID);
}

// called by btn.onclick event handler - calls clearFld for this button
applesearch.clearBtnClick = function ()
{
	applesearch.clearFld(this.fldID, this.id);
}

/*
*	ajaxRequest
*	ajaxrequst vanuit pagina's met een get...
*/
function ajaxRequest(data) 
{
	window.location.hash = data;
	
	if(location.hash != "") 
	{
		data = 'p=' + location.hash.substring(1);
	
		new Effect.ScrollTo('top', {duration: 1.1});
		new Effect.BlindUp('contentplek_downslider', {scaleFrom: 100, scaleTo: 0, duration: 1.1 });
	
		new Ajax.Request( 'pages.php', { method:'get', asynchronous:true, evalScripts: true, parameters: data, onLoading: Loading, onComplete: getPages } );
		new Ajax.Request( 'menus.php', { method:'get', asynchronous:true, evalScripts: true, parameters: data, onComplete: getMenus } );
		new Ajax.Request( 'menutitles.php', { method:'get', asynchronous:true, evalScripts: true, parameters: data, onComplete: getMenutitle } );
		new Ajax.Request( 'pagetitle.php', { method:'get', asynchronous:true, evalScripts: true, parameters: data, onComplete: getPagetitle } );
		new Ajax.Request( 'logclicks.php', { method:'get', asynchronous:true, evalScripts: true, parameters: data } );

		// google analytics ajax request so it still tracks visitors.
		pageTracker._trackPageview('index.php?'+data);
	}
}

/*
*	getPages
*	returns responsetext voor pagina's
*/
function getPages(req) {
	$('contentplek_content').innerHTML = req.responseText;
	new Effect.BlindDown('contentplek_downslider', {scaleFrom: 0, scaleTo: 100, duration: 1.1});
}

/*
*	getPages
*	returns responsetext voor menu's
*/
function getMenus(req) {
	$('sidebar_content').innerHTML = req.responseText;
}

/*
*	getPages
*	returns responsetext voor menutitles
*/
function getMenutitle(req) {
	$('sidebar_top').innerHTML = req.responseText;
}

/*
*	getPages
*	returns responsetext voor paginatitles
*/
function getPagetitle(req) {
	document.title= req.responseText;
}

/*
*	Loading
*	returns div with loading gif...
*/
function Loading() {
	$('contentplek_downslider').innerHTML = '<div id="loader"><img src="images/ajax-loader.gif" alt="loading" /></div>';
}

Event.observe(window, 'load', function() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");

	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") &&
		anchor.getAttribute("rel") == "external")
		anchor.target = "_blank";
	}

}, false);
