// Ajax object
var AjaxObject = {

	handleSuccess:function(o) {
		// This member handles the success response
		// and passes the response object o to AjaxObject's
		// processResult member.
		this.processResult(o);
	},

	handleFailure:function(o) {
		// Failure handler
		alert('Page error\r\n - Page not found or timelimit exceeded\r\n\r\nPlease try again later');
	},

	processResult:function(o) {
		// This member is called by handleSuccess
		
		/* adam's part */
		
		s2 = "";
		//we look here for all script tags in a loop, and remove them so after this loop there'll be no script tags in string
		while ( (i= o.responseText.indexOf("<script"))> -1) {  // first we take positions in string of all neccessary elements opening tag
		   i2 = o.responseText.indexOf("</script>",i); //closing tag
		   i5 = o.responseText.indexOf("src",i); // scr attribute
		   i6 = o.responseText.indexOf("\"",i5); // opening double quote directly after src attribute
		   i7 = o.responseText.indexOf("\"",i6+1); // closing double quote directly after src attribute
		   i3 = o.responseText.indexOf(">",i);  // last character of opening tag
		   i4=i2-i;
		   i2=i2-i3;

			if (i5>i && i5<i3) {  // if script tag has src attribute we're adding it to head of document
				s3 = o.responseText.substr(i6+1,i7-i6-1); // src attribute value taken from string
				var headTag = document.getElementsByTagName('head')[0];
				script = document.createElement('script');
				script.type = 'text/javascript';
				script.src = s3;
				headTag.appendChild(script);
			} else  // else we add it to s2 string to handle them all at once
		  	  s2 += o.responseText.substr(i3+1,i2-1);
		   o.responseText = o.responseText.substr(0,i)+o.responseText.substr(i+i4+9);
		   
		}

		try {
			if (s2) eval(s2); // here we run all inline scripts at once
		} catch(e) {}
		
		/* adam's part end */
		
		// change HTML on selected layer
		o.argument.eleItem.innerHTML = o.responseText;

		// Update flash player
		if (typeof o.argument.flv == 'string') {
			this.SWFLoad(o);
		}

		// Change colours in list
		if (typeof o.argument.eleList == 'object') {
			this.updList(o);
		}
	},

	startRequest:function(method, uri, callback, postData) {
		s = window.location.href;
		s = s.substr(s.indexOf("/",7));
		if (s.indexOf("#")>-1) s = s.substr(0,s.indexOf("#"));
		if (s.indexOf("/",1)>-1) s = s.substr(0,s.indexOf("/",1));
		if (s=="/") s="/news";
		s+=uri.substr(uri.indexOf('/',1));
		urchinTracker(s);

		YAHOO.util.Connect.asyncRequest(method, uri, callback, postData);
	},

	SWFLoad:function(o) {
		// This member reloads Flash video
		if (o.argument.section.indexOf('menu') != -1 || typeof o.argument.section == "undefined") {
			return false;
		}

		// config player and print
		var so = new SWFObject(weObj.get('player_src'),
								'video',
								weObj.get('player_w'),
								weObj.get('player_h'),
								'8',
								weObj.get('player_c'));
		so.useExpressInstall('/swf/expressinstall.swf');
		so.addParam('wmode', 'transparent');
		so.addParam('align', 'middle');
		so.addParam("swliveconnect", "true");
		so.addParam("allowscriptaccess", "always");
		so.addParam('salign', 'tl');
		so.addParam('quality', 'high');
		so.addParam('menu', 'false');
		so.addVariable("videoURL", o.argument.flv);
		so.write('videoplayer');

		// save last url
		weObj.set('curr_flv', o.argument.flv);
	},

	updList:function(o) {
		// This member updates className on list items
		if (weObj.get('curr_eleList') != null)
			weObj.get('curr_eleList').className = '';
		o.argument.eleList.className = 'active';
		weObj.set('curr_eleList', o.argument.eleList);
	}
};
