/**
 */
var qelpObject = new QelpObject;
var newLoad = false;
var clicky_custom = {};
clicky_custom.pageview_disable = 1;
clicky_custom.timer = 1;
var feedbackForm = false;

//$("html").hide();
$(document).ready(function() {
	qelpInit();
});

function qelpLoadJsFile(filename) { 
    var fileref = document.createElement('script'); 
    fileref.setAttribute("type", "text/javascript"); 
    fileref.setAttribute("src", filename);
    document.getElementsByTagName("head")[0].appendChild(fileref);
}

function qelpLoadCssFile(filename) { 
    var fileref = document.createElement("link"); 
    fileref.setAttribute("rel", "stylesheet");
    fileref.setAttribute("type", "text/css");
    fileref.setAttribute("href", filename);
    document.getElementsByTagName("head")[0].appendChild(fileref);
}

function loadJSFile(javascriptUrl){
	$.ajax({
		url: javascriptUrl,
		dataType: 'script',
		cache: true
	});
}

/**
 * Initialize Qelp Application
 */
function qelpInit(){
	qelpObject.init();
}

function QelpObject() {
	this.done = true;
	// customLoadComplete();
	var currentStep;
	var numSteps = 1;
	var customerSpecific;
	var gaEventTracker;
	var firstStep;
	var lastStepDone;
	var hyvesCount;
	var flashLoaded;
	/**
	 * Initialize qelpObject
	 */
	this.init = function() {
		// alert("init!");
		// $("body").hide();
		// generic loading of JS files
		qelpLoadJsFile("/default/javascript/plugins/jqMessage/1.0.0/jquery.jqMessage.js");
		qelpLoadJsFile("http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.12/jquery-ui.min.js");
		qelpLoadJsFile("/default/javascript/plugins/star-rating/3.13/jquery.rating.pack.js");
		qelpLoadJsFile("/default/javascript/plugins/qtip/1.0.0/jquery.qtip.js");
		/*qelpLoadJsFile("/default/javascript/plugins/multiselect/1.8/jquery.multiselect.min.js");*/
		
		this.flashLoaded = false;
		this.hyvesCount = 0;
		this.currentStep = 1;// this.getStep();
		this.numSteps = this.currentStep;
		this.customerSpecific = new CustomerObject();
		
		this.clickyDone = false;
		
		this.hasFlash = this.customerSpecific.init(this);
		
		// load feedback after init customer object
		if(typeof this.customerSpecific.isQelpClient == 'function'){
		    if(this.customerSpecific.isQelpClient()){
		        return false;
		    }
		}
		qelpLoadJsFile("/default/javascript/feedback.js");
		try {
			if (useWikiComments)
				SWFAddress.addEventListener(SWFAddressEvent.CHANGE, this.customerSpecific.handleAddressChange);
		} catch (error){}
		if (this.hasFlash) {
			try {
				// alert(location.pathname);
				if (!newLoad && SWFAddress.getValue() == "/") {
					SWFAddress.setValue(location.pathname.replace("index.html", ""));
					newLoad = true;
				}
			} catch (error){}
			if (!this.flashLoaded) this.customerSpecific.loadFlash();
		}
		this.checkShow();
		//$.getScript('http://static.getclicky.com/114346.js', function () { qelpObject.clickyDone = true;});		
	}
	
	/**
	 * Is all our work done? If so, show the application
	 */
	this.checkShow = function() {
		// alert("this.checkShow: " + this.done);
		if (this.done) {
			$("a").click(function() {
				var theHref = this;
				if (theHref.hostname && theHref.hostname !== location.hostname) 
					qelpObject.trackExternaLink($(this).attr("href"));
			})
			if (!this.hasFlash) {
				this.trackHTMLView();
				
				if ($("#stepNavigation").length > 0) {
					this.initYouTube();
					this.startStepNavigation();
				}
				if ($(".menu h4 a").length > 0) 
					this.setBackLink();
				/*if ($.browser.msie && $.browser.version < 7) {
					//$.getScript("/default/javascript/jquery.ifixpng.js", function(){
					//	$('img[src$=.png]').ifixpng();
					//	
					//});
					qelpLoadJsFile("/default/javascript/bgsleight.js");
				}*/
			}
			$("html").show();
			// $("body").show();
		}
	}
	
	/**
	 * Hack to enable an extra return to device selection link to the menu (to
	 * relieve V2's efforts at the time)
	 */
	this.setBackLink = function () {
		 
		var newLink = document.createElement("a");
		newLink.href = $(".menu h4 a").attr("href");
		
		$(".menu h2:first").wrapInner(newLink);	
	}
	
	/**
	 * Initialize google tracker
	 */
	this.initGoogle = function() {
		try {
			if (this.gaEventTracker == null) {
				this.gaEventTracker = _gat._getTracker("UA-6515291-2");
				this.gaEventTracker._setDomainName(location.hostname);
			}
		} catch (error) {}
	}
	
	
	/**
	 * Remove special characters, quite a function... :/
	 * 
	 * @param {Object}
	 *            event
	 */
	this.normalizeEvent = function(event) {
		var result = event.replace(/ /g, "-");
		result = result.replace(/[A\xaa\xc0-\xc5\xe0-\xe5\u0100-\u0105\u01cd\u01ce\u0200-\u0203\u0226\u0227\u1d2c\u1d43\u1e00\u1e01\u1e9a\u1ea0-\u1ea3\u2090\u2100\u2101\u213b\u249c\u24b6\u24d0\u3371-\u3374\u3380-\u3384\u3388\u3389\u33a9-\u33af\u33c2\u33ca\u33df\u33ff\uff21\uff41]/g, "A");
		result = result.replace(/[a\xaa\xc0-\xc5\xe0-\xe5\u0100-\u0105\u01cd\u01ce\u0200-\u0203\u0226\u0227\u1d2c\u1d43\u1e00\u1e01\u1e9a\u1ea0-\u1ea3\u2090\u2100\u2101\u213b\u249c\u24b6\u24d0\u3371-\u3374\u3380-\u3384\u3388\u3389\u33a9-\u33af\u33c2\u33ca\u33df\u33ff\uff21\uff41]/g, "a");
		result = result.replace(/[B\u1d2e\u1d47\u1e02-\u1e07\u212c\u249d\u24b7\u24d1\u3374\u3385-\u3387\u33c3\u33c8\u33d4\u33dd\uff22\uff42]/g,'B');
		result = result.replace(/[b\u1d2e\u1d47\u1e02-\u1e07\u212c\u249d\u24b7\u24d1\u3374\u3385-\u3387\u33c3\u33c8\u33d4\u33dd\uff22\uff42]/g,'b');
		result = result.replace(/[C\xc7\xe7\u0106-\u010d\u1d9c\u2100\u2102\u2103\u2105\u2106\u212d\u216d\u217d\u249e\u24b8\u24d2\u3376\u3388\u3389\u339d\u33a0\u33a4\u33c4-\u33c7\uff23\uff43]/g,'C');
		result = result.replace(/[c\xc7\xe7\u0106-\u010d\u1d9c\u2100\u2102\u2103\u2105\u2106\u212d\u216d\u217d\u249e\u24b8\u24d2\u3376\u3388\u3389\u339d\u33a0\u33a4\u33c4-\u33c7\uff23\uff43]/g,'c');
		result = result.replace(/[D\u010e\u010f\u01c4-\u01c6\u01f1-\u01f3\u1d30\u1d48\u1e0a-\u1e13\u2145\u2146\u216e\u217e\u249f\u24b9\u24d3\u32cf\u3372\u3377-\u3379\u3397\u33ad-\u33af\u33c5\u33c8\uff24\uff44]/g,'D');
		result = result.replace(/[d\u010e\u010f\u01c4-\u01c6\u01f1-\u01f3\u1d30\u1d48\u1e0a-\u1e13\u2145\u2146\u216e\u217e\u249f\u24b9\u24d3\u32cf\u3372\u3377-\u3379\u3397\u33ad-\u33af\u33c5\u33c8\uff24\uff44]/g,'d');
		result = result.replace(/[E\xc8-\xcb\xe8-\xeb\u0112-\u011b\u0204-\u0207\u0228\u0229\u1d31\u1d49\u1e18-\u1e1b\u1eb8-\u1ebd\u2091\u2121\u212f\u2130\u2147\u24a0\u24ba\u24d4\u3250\u32cd\u32ce\uff25\uff45]/g,'E');
		result = result.replace(/[e\xc8-\xcb\xe8-\xeb\u0112-\u011b\u0204-\u0207\u0228\u0229\u1d31\u1d49\u1e18-\u1e1b\u1eb8-\u1ebd\u2091\u2121\u212f\u2130\u2147\u24a0\u24ba\u24d4\u3250\u32cd\u32ce\uff25\uff45]/g,'e');
		result = result.replace(/[F\u1da0\u1e1e\u1e1f\u2109\u2131\u213b\u24a1\u24bb\u24d5\u338a-\u338c\u3399\ufb00-\ufb04\uff26\uff46]/g,'F');
		result = result.replace(/[f\u1da0\u1e1e\u1e1f\u2109\u2131\u213b\u24a1\u24bb\u24d5\u338a-\u338c\u3399\ufb00-\ufb04\uff26\uff46]/g,'f');
		result = result.replace(/[G\u011c-\u0123\u01e6\u01e7\u01f4\u01f5\u1d33\u1d4d\u1e20\u1e21\u210a\u24a2\u24bc\u24d6\u32cc\u32cd\u3387\u338d-\u338f\u3393\u33ac\u33c6\u33c9\u33d2\u33ff\uff27\uff47]/g,'G');
		result = result.replace(/[g\u011c-\u0123\u01e6\u01e7\u01f4\u01f5\u1d33\u1d4d\u1e20\u1e21\u210a\u24a2\u24bc\u24d6\u32cc\u32cd\u3387\u338d-\u338f\u3393\u33ac\u33c6\u33c9\u33d2\u33ff\uff27\uff47]/g,'g');
		result = result.replace(/[H\u0124\u0125\u021e\u021f\u02b0\u1d34\u1e22-\u1e2b\u1e96\u210b-\u210e\u24a3\u24bd\u24d7\u32cc\u3371\u3390-\u3394\u33ca\u33cb\u33d7\uff28\uff48]/g,'H');
		result = result.replace(/[h\u0124\u0125\u021e\u021f\u02b0\u1d34\u1e22-\u1e2b\u1e96\u210b-\u210e\u24a3\u24bd\u24d7\u32cc\u3371\u3390-\u3394\u33ca\u33cb\u33d7\uff28\uff48]/g,'h');
		result = result.replace(/[I\xcc-\xcf\xec-\xef\u0128-\u0130\u0132\u0133\u01cf\u01d0\u0208-\u020b\u1d35\u1d62\u1e2c\u1e2d\u1ec8-\u1ecb\u2071\u2110\u2111\u2139\u2148\u2160-\u2163\u2165-\u2168\u216a\u216b\u2170-\u2173\u2175-\u2178\u217a\u217b\u24a4\u24be\u24d8\u337a\u33cc\u33d5\ufb01\ufb03\uff29\uff49]/g,'I');
		result = result.replace(/[i\xcc-\xcf\xec-\xef\u0128-\u0130\u0132\u0133\u01cf\u01d0\u0208-\u020b\u1d35\u1d62\u1e2c\u1e2d\u1ec8-\u1ecb\u2071\u2110\u2111\u2139\u2148\u2160-\u2163\u2165-\u2168\u216a\u216b\u2170-\u2173\u2175-\u2178\u217a\u217b\u24a4\u24be\u24d8\u337a\u33cc\u33d5\ufb01\ufb03\uff29\uff49]/g,'i');
		result = result.replace(/[J\u0132-\u0135\u01c7-\u01cc\u01f0\u02b2\u1d36\u2149\u24a5\u24bf\u24d9\u2c7c\uff2a\uff4a]/g,'J');
		result = result.replace(/[j\u0132-\u0135\u01c7-\u01cc\u01f0\u02b2\u1d36\u2149\u24a5\u24bf\u24d9\u2c7c\uff2a\uff4a]/g,'j');
		result = result.replace(/[K\u0136\u0137\u01e8\u01e9\u1d37\u1d4f\u1e30-\u1e35\u212a\u24a6\u24c0\u24da\u3384\u3385\u3389\u338f\u3391\u3398\u339e\u33a2\u33a6\u33aa\u33b8\u33be\u33c0\u33c6\u33cd-\u33cf\uff2b\uff4b]/g,'K');
		result = result.replace(/[k\u0136\u0137\u01e8\u01e9\u1d37\u1d4f\u1e30-\u1e35\u212a\u24a6\u24c0\u24da\u3384\u3385\u3389\u338f\u3391\u3398\u339e\u33a2\u33a6\u33aa\u33b8\u33be\u33c0\u33c6\u33cd-\u33cf\uff2b\uff4b]/g,'k');
		result = result.replace(/[L\u0139-\u0140\u01c7-\u01c9\u02e1\u1d38\u1e36\u1e37\u1e3a-\u1e3d\u2112\u2113\u2121\u216c\u217c\u24a7\u24c1\u24db\u32cf\u3388\u3389\u33d0-\u33d3\u33d5\u33d6\u33ff\ufb02\ufb04\uff2c\uff4c]/g,'L');
		result = result.replace(/[l\u0139-\u0140\u01c7-\u01c9\u02e1\u1d38\u1e36\u1e37\u1e3a-\u1e3d\u2112\u2113\u2121\u216c\u217c\u24a7\u24c1\u24db\u32cf\u3388\u3389\u33d0-\u33d3\u33d5\u33d6\u33ff\ufb02\ufb04\uff2c\uff4c]/g,'l');
		result = result.replace(/[M\u1d39\u1d50\u1e3e-\u1e43\u2120\u2122\u2133\u216f\u217f\u24a8\u24c2\u24dc\u3377-\u3379\u3383\u3386\u338e\u3392\u3396\u3399-\u33a8\u33ab\u33b3\u33b7\u33b9\u33bd\u33bf\u33c1\u33c2\u33ce\u33d0\u33d4-\u33d6\u33d8\u33d9\u33de\u33df\uff2d\uff4d]/g,'M');
		result = result.replace(/[m\u1d39\u1d50\u1e3e-\u1e43\u2120\u2122\u2133\u216f\u217f\u24a8\u24c2\u24dc\u3377-\u3379\u3383\u3386\u338e\u3392\u3396\u3399-\u33a8\u33ab\u33b3\u33b7\u33b9\u33bd\u33bf\u33c1\u33c2\u33ce\u33d0\u33d4-\u33d6\u33d8\u33d9\u33de\u33df\uff2d\uff4d]/g,'m');
		result = result.replace(/[N\xd1\xf1\u0143-\u0149\u01ca-\u01cc\u01f8\u01f9\u1d3a\u1e44-\u1e4b\u207f\u2115\u2116\u24a9\u24c3\u24dd\u3381\u338b\u339a\u33b1\u33b5\u33bb\u33cc\u33d1\uff2e\uff4e]/g,'N');
		result = result.replace(/[n\xd1\xf1\u0143-\u0149\u01ca-\u01cc\u01f8\u01f9\u1d3a\u1e44-\u1e4b\u207f\u2115\u2116\u24a9\u24c3\u24dd\u3381\u338b\u339a\u33b1\u33b5\u33bb\u33cc\u33d1\uff2e\uff4e]/g,'n');
		result = result.replace(/[O\xba\xd2-\xd6\xf2-\xf6\u014c-\u0151\u01a0\u01a1\u01d1\u01d2\u01ea\u01eb\u020c-\u020f\u022e\u022f\u1d3c\u1d52\u1ecc-\u1ecf\u2092\u2105\u2116\u2134\u24aa\u24c4\u24de\u3375\u33c7\u33d2\u33d6\uff2f\uff4f]/g,'O');
		result = result.replace(/[o\xba\xd2-\xd6\xf2-\xf6\u014c-\u0151\u01a0\u01a1\u01d1\u01d2\u01ea\u01eb\u020c-\u020f\u022e\u022f\u1d3c\u1d52\u1ecc-\u1ecf\u2092\u2105\u2116\u2134\u24aa\u24c4\u24de\u3375\u33c7\u33d2\u33d6\uff2f\uff4f]/g,'o');
		result = result.replace(/[P\u1d3e\u1d56\u1e54-\u1e57\u2119\u24ab\u24c5\u24df\u3250\u3371\u3376\u3380\u338a\u33a9-\u33ac\u33b0\u33b4\u33ba\u33cb\u33d7-\u33da\uff30\uff50]/g,'P');
		result = result.replace(/[p\u1d3e\u1d56\u1e54-\u1e57\u2119\u24ab\u24c5\u24df\u3250\u3371\u3376\u3380\u338a\u33a9-\u33ac\u33b0\u33b4\u33ba\u33cb\u33d7-\u33da\uff30\uff50]/g,'p');
		result = result.replace(/[Q\u211a\u24ac\u24c6\u24e0\u33c3\uff31\uff51]/g,'Q');
		result = result.replace(/[q\u211a\u24ac\u24c6\u24e0\u33c3\uff31\uff51]/g,'q');
		result = result.replace(/[R\u0154-\u0159\u0210-\u0213\u02b3\u1d3f\u1d63\u1e58-\u1e5b\u1e5e\u1e5f\u20a8\u211b-\u211d\u24ad\u24c7\u24e1\u32cd\u3374\u33ad-\u33af\u33da\u33db\uff32\uff52]/g,'R');
		result = result.replace(/[r\u0154-\u0159\u0210-\u0213\u02b3\u1d3f\u1d63\u1e58-\u1e5b\u1e5e\u1e5f\u20a8\u211b-\u211d\u24ad\u24c7\u24e1\u32cd\u3374\u33ad-\u33af\u33da\u33db\uff32\uff52]/g,'r');
		result = result.replace(/[S\u015a-\u0161\u017f\u0218\u0219\u02e2\u1e60-\u1e63\u20a8\u2101\u2120\u24ae\u24c8\u24e2\u33a7\u33a8\u33ae-\u33b3\u33db\u33dc\ufb06\uff33\uff53]/g,'S');
		result = result.replace(/[s\u015a-\u0161\u017f\u0218\u0219\u02e2\u1e60-\u1e63\u20a8\u2101\u2120\u24ae\u24c8\u24e2\u33a7\u33a8\u33ae-\u33b3\u33db\u33dc\ufb06\uff33\uff53]/g,'s');
		result = result.replace(/[T\u0162-\u0165\u021a\u021b\u1d40\u1d57\u1e6a-\u1e71\u1e97\u2121\u2122\u24af\u24c9\u24e3\u3250\u32cf\u3394\u33cf\ufb05\ufb06\uff34\uff54]/g,'T');
		result = result.replace(/[t\u0162-\u0165\u021a\u021b\u1d40\u1d57\u1e6a-\u1e71\u1e97\u2121\u2122\u24af\u24c9\u24e3\u3250\u32cf\u3394\u33cf\ufb05\ufb06\uff34\uff54]/g,'t');
		result = result.replace(/[U\xd9-\xdc\xf9-\xfc\u0168-\u0173\u01af\u01b0\u01d3\u01d4\u0214-\u0217\u1d41\u1d58\u1d64\u1e72-\u1e77\u1ee4-\u1ee7\u2106\u24b0\u24ca\u24e4\u3373\u337a\uff35\uff55]/g,'U');
		result = result.replace(/[u\xd9-\xdc\xf9-\xfc\u0168-\u0173\u01af\u01b0\u01d3\u01d4\u0214-\u0217\u1d41\u1d58\u1d64\u1e72-\u1e77\u1ee4-\u1ee7\u2106\u24b0\u24ca\u24e4\u3373\u337a\uff35\uff55]/g,'u');
		result = result.replace(/[V\u1d5b\u1d65\u1e7c-\u1e7f\u2163-\u2167\u2173-\u2177\u24b1\u24cb\u24e5\u2c7d\u32ce\u3375\u33b4-\u33b9\u33dc\u33de\uff36\uff56]/g,'V');
		result = result.replace(/[v\u1d5b\u1d65\u1e7c-\u1e7f\u2163-\u2167\u2173-\u2177\u24b1\u24cb\u24e5\u2c7d\u32ce\u3375\u33b4-\u33b9\u33dc\u33de\uff36\uff56]/g,'v');
		result = result.replace(/[W\u0174\u0175\u02b7\u1d42\u1e80-\u1e89\u1e98\u24b2\u24cc\u24e6\u33ba-\u33bf\u33dd\uff37\uff57]/g,'W');
		result = result.replace(/[w\u0174\u0175\u02b7\u1d42\u1e80-\u1e89\u1e98\u24b2\u24cc\u24e6\u33ba-\u33bf\u33dd\uff37\uff57]/g,'w');
		result = result.replace(/[X\u02e3\u1e8a-\u1e8d\u2093\u213b\u2168-\u216b\u2178-\u217b\u24b3\u24cd\u24e7\u33d3\uff38\uff58]/g,'X');
		result = result.replace(/[x\u02e3\u1e8a-\u1e8d\u2093\u213b\u2168-\u216b\u2178-\u217b\u24b3\u24cd\u24e7\u33d3\uff38\uff58]/g,'x');
		result = result.replace(/[Y\xdd\xfd\xff\u0176-\u0178\u0232\u0233\u02b8\u1e8e\u1e8f\u1e99\u1ef2-\u1ef9\u24b4\u24ce\u24e8\u33c9\uff39\uff59]/g,'Y');
		result = result.replace(/[y\xdd\xfd\xff\u0176-\u0178\u0232\u0233\u02b8\u1e8e\u1e8f\u1e99\u1ef2-\u1ef9\u24b4\u24ce\u24e8\u33c9\uff39\uff59]/g,'y');
		result = result.replace(/[Z\u0179-\u017e\u01f1-\u01f3\u1dbb\u1e90-\u1e95\u2124\u2128\u24b5\u24cf\u24e9\u3390-\u3394\uff3a\uff5a]/g,'Z');
		result = result.replace(/[z\u0179-\u017e\u01f1-\u01f3\u1dbb\u1e90-\u1e95\u2124\u2128\u24b5\u24cf\u24e9\u3390-\u3394\uff3a\uff5a]/g,'z');
		result = result.replace(/(&#260;)|(&#261;)/g,'a');
		result = result.replace(/(&#280;)|(&#281;)/g,'e');
		result = result.replace(/(&#211;)|(&#243;)/g,'o');
		result = result.replace(/(&#262;)|(&#263;)/g,'c');
		result = result.replace(/(&#321;)|(&#322;)|([Łł])/g,'l');
		result = result.replace(/(&#323;)|(&#324;)/g,'n');
		result = result.replace(/(&#346;)|(&#347;)/g,'s');
		result = result.replace(/(&#377;)|(&#378;)|(&#379;)|(&#380;)/g,'z');
		return result;
	}
	
	/**
	 * Send the event to Google Analytics (and possibly clicky)
	 * 
	 * @param {Object}
	 *            event
	 */
	this.recordEvent = function(event) {
		if (this.gaEventTracker == null) this.initGoogle();
		try {
			if (swfobject.getQueryParamValue("showEvents") != "") alert(this.normalizeEvent(event));
			this.gaEventTracker._trackPageview(this.normalizeEvent(event));
			if (typeof(this.customerSpecific.recordEvent) != 'undefined') {
				this.customerSpecific.recordEvent(this.normalizeEvent(event));
			} 
			/*
			 * Execute clicky calls asynchronously, to prevent "waiting for
			 * clicky" issue.
			 */
			setTimeout(function() {
				if (qelpObject.clickyDone) clicky.log(qelpObject.normalizeEvent(event));
			}, 10);
		} catch(error) {
			// alert("recordError: " + error);
		}
	}
	
	/**
	 * Google Analytics Event Tracking, not used right now.
	 * 
	 * @param {Object}
	 *            category
	 * @param {Object}
	 *            action
	 * @param {Object}
	 *            optional_label
	 * @param {Object}
	 *            optional_value
	 */
	this.recordRealEvent = function(category, action, optional_label, optional_value) {
		// alert("recordRealEvent");
		if (this.gaEventTracker == null) this.initGoogle();
		try {
			if (swfobject.getQueryParamValue("showEvents") != "") alert(this.normalizeEvent(category) + ", " + 
																		this.normalizeEvent(action) + ", " + 
																		this.normalizeEvent(optional_label));
			// this.gaEventTracker._trackPageview(this.normalizeEvent(event));
			this.gaEventTracker._trackEvent(category, action, optional_label, optional_value);
		} catch(error){}
	}
	
	/**
	 * In case we don't use flash, or the end user has flash disabled, we need
	 * to record the pageview correctly.
	 */
	this.trackHTMLView = function() {
		eventString = this.getConvertedPath();
		
		if (eventString != null) {
			eventString += "/html";
			this.recordEvent(eventString);
		}
	}
	
	
	/**
	 * Track external links
	 * 
	 * @param {Object}
	 *            link
	 */
	this.trackExternaLink = function(link) {
		var brand = this.customerSpecific.getBrand();
	
		var event = "/" + brand + "/outgoingLink/" + link.replace(/\//g, "\\");
	
		this.recordEvent(event);
	}
	
	
	/**
	 * Track filedownloads
	 * 
	 * @param {Object}
	 *            link
	 */
	this.trackFileLink = function(link) {
		var brand = this.customerSpecific.getBrand();
		
		// var TYPE = 0;
		// var FILE = 1;
		// var linkParts = link.split("/");
		var event = "/" + brand + "/file/" + link;
		this.recordEvent(event);
		// this.recordRealEvent(brand, linkParts[TYPE].toLowerCase(),
		// linkParts[FILE]);
	}
	
	
	/**
	 * Find all references to files and add a clickEvent to track its download
	 * to it.
	 */
	this.initPdfTracking = function() {
		var LINK_START = "/files/";
		$("a").each(function (i) {
			if ($(this).attr("href").slice(0, 7) == LINK_START) {
				$(this).click(function(){
					qelpObject.trackFileLink($(this).attr("href").slice(7));
				})
			}	
		});
	}
	
	
	/**
	 * Convert the current path into our custom directory structure.
	 */
	this.getConvertedPath = function() {
		/* URL explodedPath index constants */
		var MANUFACTURER = 0;
		var DEVICE = 1;
		var CATEGORY = 2;
		var TOPIC = 3;
		/* end of constants */
		var pathname = location.pathname.replace("qelp/", "");
		if(typeof this.customerSpecific.getSubscriptionsPlans == "function") {
			// remove subscription plan from the path
			var subscriptionPlans = this.customerSpecific.getSubscriptionsPlans();
			$.each(subscriptionPlans,function(index,value){
				pathname = pathname.replace(value+"/","");
			});
		}
		var explodedPath = pathname.substr(1).split("/");
		var brand = this.customerSpecific.getBrand();
		var locale = this.customerSpecific.getLocale()
		
		var result;
		
		if (explodedPath[0] == 'tips')
		{
			result = '/' + brand + '/other/KPNSmsActie/Nokia-E75/100-Tips';// '/Nokia/E75/100-Tips/KPNSmsActie/';
			// alert(result);
		}
		else if (explodedPath[0] == 'snel')
		{
			result = '/' + brand + '/other/KPNSmsActie/Nokia-E75/InternetKosten'; //'/Nokia/E75/InternetKosten/KPNSmsActie/';
			// alert(result);
		}
		else if ((typeof this.customerSpecific.isGenericPage == 'function') && this.customerSpecific.isGenericPage()) {
			result = "/" + brand + "/genericPages/" + explodedPath[MANUFACTURER] + "/";
			var typeId = swfobject.getQueryParamValue("id");
			if (typeId != "") {
				switch (typeId) {
					case "1":
						result += "zorgeloos/"
					break;
					case "2":
						result += "maximaal/";
					break;
					case "3":
						result += "goedkoper/";
					case "4":
						result += "deviceLinkBox/";
					break;
				}
			}
			
			result += locale; 
			
		} else {
			switch (explodedPath.length) {
				case 1: // ROOT
					result = "/" + brand + "/manufacturers/" + 
										this.customerSpecific.getDefaultManufacturer() + "/" +  
										locale;
					break;
				case 2: // MANUFACTURER
					result = "/" + brand + "/manufacturers/" + 
										explodedPath[MANUFACTURER] + "/" + 
										locale;
					break;
				case 3: // DEVICE
					result = "/" + brand + "/devices/" + 
										explodedPath[MANUFACTURER] + "-" + 
										explodedPath[DEVICE] + "/" + locale;
					break;
				/*case 4: // CATEGORY
					result = "/" + brand + "/category/" + 
										explodedPath[CATEGORY] + "/" + 
										explodedPath[MANUFACTURER] + " " + 
										explodedPath[DEVICE];
					break;*/
				case 5: // USECASE
					result = "/" + brand + "/useCases/" + 
										explodedPath[CATEGORY] + " " + 
										explodedPath[TOPIC] + "/" + 
										explodedPath[MANUFACTURER] + " " + 
										explodedPath[DEVICE];
					break;
			}
		}
		
		return result;
	}
	

	/**
	 * Determine the current step to be displayed bashed on the # symbol. Not
	 * functional yet.
	 */
	this.getStep = function() {
		return 1;
	}
	
	
	/**
	 * Initialize HTML step navigation in a useCase
	 */
	this.startStepNavigation = function() {
		// $("#contentArea").css("overflow", "hidden");
		this.firstStep = true;
		this.lastStepDone = false;
	
		$("#stepNavigation").show();
		
		this.numSteps = $(".step").length;
		
		this.showStep(this.currentStep);
		
		$("#goPrevious").click(qelpObject.previousStep);
		$("#goNext").click(qelpObject.nextStep);
	}
	
	/**
	 * goto next step
	 */
	this.nextStep = function() {
		qelpObject.showStep(qelpObject.currentStep+1);
		return false;
	}
	
	/**
	 * goto previousStep
	 */
	this.previousStep = function() {
		qelpObject.showStep(qelpObject.currentStep-1);
		return false;
	}
	
	/**
	 * show the current step
	 * 
	 * @param {Object}
	 *            step
	 */
	this.showStep = function(step) {
		if (step != this.currentStep || this.firstStep) {
			this.currentStep = Math.max(1, Math.min(step, this.numSteps));
			
			$(".step").hide();
			
			if (this.currentStep == 1) $("#goPrevious").hide();
			else $("#goPrevious").show();
			
			if (this.currentStep == this.numSteps) $("#goNext").hide();
			else $("#goNext").show();
			
			$("#" + this.currentStep).show();
			
			this.customerSpecific.setCurrentStepText(this.currentStep, this.numSteps);
			
			if (!this.firstStep) this.trackStep();
			
			this.firstStep = false;
			this.lastStepDone = false;
		}
		
	}
	
	/**
	 * track the current HTML step
	 */
	this.trackStep = function() {
		var eventString;
		var explodedPath = location.pathname.replace("qelp/", "").substr(1).split("?");
		// alert('TRACKSTEP : '+explodedPath[1]);
		if (explodedPath[1] == 'forward=true')
		{
			if(this.getConvertedPath()!=undefined) {
				eventString = this.getConvertedPath().replace("useCases", "KPNSmsActie");
			}
		}
		else if (!this.lastStepDone && this.currentStep == this.numSteps) {
			this.lastStepDone = true;
			if(this.getConvertedPath()!=undefined) {
				eventString = this.getConvertedPath().replace("useCases", "completedUseCases");
			}
		} else {
			if(this.getConvertedPath()!=undefined) {
				eventString = this.getConvertedPath().replace("useCases", "useCaseSteps");
				eventString += "/" + this.currentStep;
			}
		}
		eventString += "/html";
		this.recordEvent(eventString);
	}
	
	/**
	 * 
	 */
	this.getCurrentStep = function(){
		return this.currentStep;
	}
	
	/**
	 * Load the flash file for this brand. Called by customerObject.
	 * 
	 * @param {Object}
	 *            swf : path to the swf to be loaded
	 * @param {Object}
	 *            width : width of the swf
	 * @param {Object}
	 *            height : height of the swf
	 * @param {Object}
	 *            version : minimum required flash player verison
	 * @param {Object}
	 *            color : background color
	 * @param {Object}
	 *            wmode : window mode (transparent, opaque, window)
	 */
	this.loadFlash = function(swf, width, height, version, color, wmode, subscriptionPlan) {
		if ( !$("#application").length ) $("body").html("<div id='application'></div>");
		var flashvars = {
			soapUrl: "http://" + location.hostname,
			prefix: "/flash/",
			locale: this.customerSpecific.getLocale(),
			colorScheme: swfobject.getQueryParamValue("colorScheme").toUpperCase(),
			subPlanId: subscriptionPlan
		};
		var params = {
			bgcolor: ((color == null)? "#FFFFFF":color)
		};
		var attributes = {
			id: 'application'	
				
		};
		
		if (wmode != null) params.wmode = wmode;
		
		if (typeof(manufacturerId) != 'undefined') flashvars.manufacturerId =  manufacturerId;
		if (typeof(deviceId) != 'undefined') flashvars.deviceId = deviceId;
		if (typeof(categoryId) != 'undefined') flashvars.categoryId = categoryId;
		if (typeof(topicId) != 'undefined') flashvars.topicId = topicId;
		if (typeof(subPlanId) != 'undefined' && typeof(subPlanId) != 'object') flashvars.subPlanId = subPlanId;
		

		// if (swfobject.getQueryParamValue("showDebug") != "")
		// flashvars.showDebug = "1";
		swfobject.embedSWF(swf, "application", width, height, version,"/default/flash/expressInstall.swf", flashvars, params, attributes);
		this.flashLoaded = true;
	}
	
	/**
	 * Initializes all Youtube movies in HTML if any are found.
	 */
	this.initYouTube = function() {		
		$(".step").each (function(i) {
			var id = $(this).attr("id");
			$(this).find("li").each (
				function(j) {
					var matchValue = new RegExp("http://www.youtube.com/watch\\?v=([^ &<'>\"])*", "g");
					// do we have a youtube link in this list item?
					if (matchValue.test($(this).html())) {
						var movieWidth = 320;
						var movieHeight = 265;
						// create embedCode
						var embedCode = '<object width="' + movieWidth + '" height="' + movieHeight + '">';
							embedCode += '<param name="movie" value="http://www.youtube.com/v/[ID]&hl=en&fs=1&"></param>';
							embedCode += '<param name="allowFullScreen" value="true"></param>';
							embedCode += '<param name="allowscriptaccess" value="always"></param>';
							embedCode += '<embed src="http://www.youtube.com/v/[ID]&hl=en&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="' + movieWidth + '" height="' + movieHeight + '"></embed>';
							embedCode += '</object>';
						
						// determine youtube movie id
						var matches = $(this).html().match(matchValue);
						var youtubeId = matches[0].split("=")[1];

						// place youtubeId into embed code and place it at image
						// area
						$("#" + id + " .stepImage").html(embedCode.replace(/\[ID\]/g, youtubeId));
						
						// remove youtube link from text
						$(this).remove();
					}
				}
			);
		});
	}
	
	
	/**
	 * Open a popup to the specified url and dimensions
	 */
	this.openPopup = function (url, title, width, height) {
		var newwindow = window.open(url, title, 'toolbar=0, status=0,width=' + width + ',height=' + height);
		if( !newWin )
			{
			newwindow = window.open('',title, options);
			newwindow.location.href = url;
			}
		if (window.focus) newwindow.focus()
	}
	
	/**
	 * Share this on facebook popup
	 */
	this.shareOnFacebook = function(deeplink) {
		// alert("shareOnFacebook: " + deeplink);
		u= this.fullDeeplink(deeplink);
		t=document.title;
		this.openPopup('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t), 'sharer', 626, 436);
		// window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
	}
	
	/**
	 * Share this on twitter popup
	 */
	this.shareOnTwitter = function (deeplink) {
		// alert("shareOnTwitter: " + deeplink);
		u= this.fullDeeplink(deeplink);
		window.open('http://twitter.com/home?status=' + encodeURIComponent(u),'sharer','toolbar=0,status=0,width=626,height=436');
	}
	
	
	/**
	 * Share this on hyves popup
	 */
	this.shareOnHyves = function(deeplink) {
		// alert("shareOnHyves: " + deeplink);
		u= this.fullDeeplink(deeplink);
		t=document.title;
		window.open('http://www.hyves.nl/profilemanage/add/tips/?name='+encodeURIComponent(t) + '&text=' +encodeURIComponent(u) + '&rating=5','sharer','toolbar=0,status=0,width=1000,height=600');
	}
	
	/**
	 * Small utility function that turns the provided social networking deeplink
	 * in a full URL
	 */
	this.fullDeeplink = function(deeplink) {
		return "http://" + location.hostname + "/" + this.normalizeEvent(deeplink);
	}	 
}
