	var curshowing = "scroller";
	var v_content_timeout = 5000;
	var v_inter_timeout = 5000;
	var rotations = 0;
	var adpos = 2;

	
	function URLEncode (clearString) {
		var output = '';
		var x = 0;
		clearString = clearString.toString();
		var regex = /(^[a-zA-Z0-9_.]*)/;
		while (x < clearString.length) {
			var match = regex.exec(clearString.substr(x));
			if (match != null && match.length > 1 && match[1] != '') {
				output += match[1];
				x += match[1].length;
			} 
			else {
				if (clearString[x] == ' ')
					output += '+';
				else {
					var charCode = clearString.charCodeAt(x);
					var hexVal = charCode.toString(16);
					output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();
				}
				x++;
			}
		}
		return output;
	}
	
	function show_inter() {
		curshowing = "inter";
		$("#scroller_main").hide();
		$("#scroller_inter").show();
		rotate_scroller();		
	}
	
	function show_scroller() {
		curshowing = "scroller";
		$("#scroller_inter").hide();
		if ( adpos > 1 )
			$("#scroller_ad" + (adpos-1)).hide();
		else
			$("#scroller_ad3").hide();
			
		$("#scroller_ad" + adpos).show();
		$("#scroller_main").show();
		adpos++;
		if ( adpos > 3 )
			adpos = 1;
		rotate_scroller();		
	}

	function rotate_scroller() {
		rotations++;
		if ( rotations <= 6 ) {
			if ( curshowing == "scroller" )
				tmout = setTimeout("show_inter()", v_content_timeout);
			else
				tmout = setTimeout("show_scroller()", v_inter_timeout);
		}
		else {
			if ( curshowing == "inter" )
				tmout = setTimeout("show_scroller()", v_inter_timeout);
		}
	}
	
	function load_boxes ( insec ) {
		var server = Math.floor(Math.random()*2+1);
		//var v_url = "http://www.iafrica.com/test/scroller/f.php?p_u=http://web" + server + ".iac.iafrica.com";
		var v_url = "/php-bin/iac/scroller/fnew.php?p_u=";
		for ( i = 7; i <= 10; i++ ) {
			load_url = v_url + URLEncode(url_arr[insec][i]);
			var item = $("#scroller_box_" + (i-6));
			item.html("<img src=\"http://www.iafrica.com/pics/ajax-loader.gif\"> Loading");
			item.load(load_url);
		}
	}
	
	function get_urlsection() {
		var v_tmp = new Array();
		var page_url = document.location.href;
		v_tmp = page_url.split('.');
		
		v_section = v_tmp[0].substring(7);
		if ( v_section == 'technology' )
			v_section = 'cooltech';
		if ( v_section == 'personalfinance' )
			v_section = 'financialfitness';
		return v_section;
	}
	
	function find_currsection ( insec ) {
		var v_found = -1;
			
		for ( i = 0; i < section_arr.length; i ++ ) {
			v_tmp = section_arr[i];
			v_compare = v_tmp.replace(' ', '');
			v_compare = v_compare.toLowerCase();
			if ( v_compare == insec )
				v_found = i;
		}		
		
		return v_found;
	}
	
	function manual_skip() {
		clearTimeout(tmout);
		show_scroller();
	}
	
	$(document).ready(function(){
		v_curr = find_currsection(get_urlsection());

		if ( v_curr != -1 )	{
			curr_section = v_curr;
			arr_start = v_curr;
		}

		v_content_timeout = url_arr[section_arr[curr_section]][11] * 1000;
		v_inter_timeout = url_arr[section_arr[curr_section]][12] * 1000;
		
		load_boxes(section_arr[curr_section]);
		
		if ( url_arr[section_arr[curr_section]][13] == "Y" ) {
			server = Math.floor(Math.random()*2+1);
			var big_ad = "/php-bin/iac/scroller/content_files/int_" + get_urlsection() + ".htm";
			v_url = "/php-bin/iac/scroller/fnew.php?p_u=";
			load_url = v_url + big_ad + "&int=Y";
			$("#scroller_inter").load(load_url);
			rotate_scroller();
		}
	});