var scroll_strdata = [];
var scroll_page = [];
var scroll_offset = [];
var scroll_max = [];
var scroll_width = [];
var anidiv = [];

function trim(str) {
	return str.replace(/^\s+|\s+$/g, "");
};


function scroll(direction, scroll_id) {
	scroll_offset[scroll_id] = scroll_offset[scroll_id] + direction;
	var strdata = scroll_strdata[scroll_id] + '&scroll_offset=' + scroll_offset[scroll_id];

	if (!$.browser.msie) {
		$("#anim1_" + scroll_id).fadeTo(200, 0.3);
		$("#anim2_" + scroll_id).fadeTo(200, 0.3);
	}	
			
	jQuery.post(
	scroll_page[scroll_id],
	strdata,
	function(data){
		if (data.substr(0,4) == 'FEJL' ) {
			alert(data)
		} else {
			//Page is loaded, fill the div:
		    var d = document.getElementById('scroll_' + anidiv[scroll_id] + '_' + scroll_id);
		    var d1 = document.getElementById('anim1_' + scroll_id);
		    var d2 = document.getElementById('anim2_' + scroll_id);

			//place the divs before animation:
			switch (anidiv[scroll_id]) {
				case "anim1":
					switch (direction) {
						case -1: //move the divs right
							d1.style.left = -scroll_width[scroll_id];
						break;
						case 1:  //move the divs left
							d1.style.left = scroll_width[scroll_id];
						break;
					}
				break;
				case "anim2":
					switch (direction) {
						case -1: //move the divs right
							d2.style.left = -scroll_width[scroll_id];
						break;
						case 1:  //move the divs left
							d2.style.left = scroll_width[scroll_id];
						break;
					}
				break;
			}

		    d.innerHTML = data;
			//Compile the JavaScript of the newly loaded HTML:
			var x = d.getElementsByTagName("script");   
			for(var i=0;i<x.length;i++)  
			{  
			   eval(x[i].text);  
			} 
			
			/*
			//suspend animation in flashes:                                                                                                          
			var o = document.getElementsByTagName("object");   
			for(var i=0;i<o.length;i++)  
			{  
				var cmdfunc = o[i].sendCommandFromHtml;
				if (cmdfunc) cmdfunc('stop');
			}
			*/
			 


			
			$("#anim1_" + scroll_id).animate({ left : "-="+(direction * scroll_width[scroll_id]) },(scroll_width[scroll_id] / 2));
			$("#anim2_" + scroll_id).animate({ left : "-="+(direction * scroll_width[scroll_id]) },(scroll_width[scroll_id] / 2), function() {
		    
					if (!$.browser.msie) $("#"+anidiv[scroll_id]+"_" + scroll_id).fadeTo(200, 1);

				//toggle anidiv:
				if (anidiv[scroll_id] == 'anim2') anidiv[scroll_id] = 'anim1'; else anidiv[scroll_id] = 'anim2';
			    //remove hidden content
			    var d = document.getElementById('scroll_' + anidiv[scroll_id] + '_' + scroll_id);
			    d.innerHTML = '';

			    
			    //If this is offset 0 then hide the left-side arrow-button, otherwise show it:
		    	var imgarrowprev = document.getElementById('scroll_prev_' + scroll_id);
			    if (scroll_offset[scroll_id] == 0) {imgarrowprev.style.display = 'none'} else {imgarrowprev.style.display = 'block';}
		    	
		    	//Hide the older-arrow, if this is the last scroll-offset:
		    	var imgarrownext = document.getElementById('scroll_next_' + scroll_id);
			    if (scroll_offset[scroll_id] == (scroll_max[scroll_id]-1)) {imgarrownext.style.display = 'none'} else {imgarrownext.style.display = 'block';}
			    
				/*
				//resume animation in flashes:
				var o = document.getElementsByTagName("object");   
				for(var i=0;i<o.length;i++)  
				{  
					var cmdfunc = o[i].sendCommandFromHtml;
					if (cmdfunc) cmdfunc('play');
				}
				*/ 
				
				
			}); 
		};
	},
	"text");
	return false;
}

