// JavaScript Document

function setupUI()
{
	$$('.middlecolumn h1, .rightdoublecolumn h1, .maincolumn h1').each( function(h){
		var h_next = h.next();
		if ( h_next && h_next.nodeName == 'EM')
		{
			h.addClassName("pagetitle");
			h_next.addClassName('h1_subtext-' + ui_nav_colour );
		}
	})
	
	$$('.h1_subtext').each( function(el){
																		
			el.addClassName('h1_subtext-' + ui_nav_colour );
																		});
	
	// setup search field
	
	var tf = $('f_search_kw'); 
	if (tf)
	{
		tf.observe('focus',function(e){
			this.removeClassName("tf-search-inactive");	
			if ( this.value == 'Search' ) this.value = '';
	  	}.bind(tf));
	  	
	  	tf.observe('keypress', function(e,b){
			if ( e.keyCode == Event.KEY_RETURN )
			{
				doSearch();		
				return false;
			} 
	  	});
																			 
	}																			 
	
	var ssEl = $('logo-slideshow');
	if ( ssEl )
	{
		var ss = new SlideShow( {containerEl:ssEl, height:70, delay:8000 } )		
	}
	
	
	doSetupOutboundTracking();
}



function doSetupOutboundTracking()
{
	
	var httpCutLen = "http://".length;
	var currentDomain = false;
	
	switch( siteIdent )
	{
		case "download":
			currentDomain = "downloads";
			break;
		default:
			currentDomain = siteIdent;
			break;
	}
	
	$$('a').each( function(el){
		
		var href = el.href + "";
		
		if ( href.indexOf("/") == 0 ) // quick check to skip more expensive hrefs.
		{
			// do nothing!
		}
		else if( !href.match("192.168.1.86") && !href.match("klipfolio.com") )
		{
			$(el).observe('click', trackOutbound.bind(href) );		
		}
		else if( href.match("klipfolio.com") )
		{
			var sd = href.substring(0, href.indexOf(".") );
			sd = sd.substring( httpCutLen  );
			if ( sd != currentDomain )
			{
				$(el).observe('click', trackIntra.bind(href) );						
			}
		}
		
		// track personal downloads
		// -------------------------
		if ( href.match("klipfolio-pd-install.exe"))
		{
			$(el).observe("click", function(){
				pageTracker._trackPageview("/ga_goals/download_personal");					
			});
		}
	});
}

function trackIntra()
{
	var href = this;
	href = href.replace("http://","");
	href = href.replace(/\/$/,"");
	href = "/intra/" + href;	
	
	pageTracker._trackPageview(href);	
	
	return false;
}

function trackOutbound()
{
	var href = this;
	href = href.replace("http://","");
	href = href.replace(/\/$/,"");
	href = "/outbound/" + href;	
	
	pageTracker._trackPageview(href);	
	return false;
}

function trackSaasGoal()
{
    pageTracker._trackPageview("/saas/event/signup");
}

 
function doSearch()
{
	var kw =$F('f_search_kw');			
	var type = $F('f_search_type');
	var base = $F('search_base_url');
	var ident = $F('f_search_ident');	
	var url = base + "/sident-"+ident+"/stype-" + type + "/kw-"+ kw;
	document.location = url;
}

