function filmstripScroll(scrollLeft, amount) {
	var left = parseInt($("#filmstrip_scroll_content").css("left"));
	if(!isNaN(left) && !isNaN(amount)) {
		var newLeft = 0;
		var maxLeft = 0;
		var maxScrollRight = scrollWidthVisible-scrollWidth;
		if(scrollLeft) {
			newLeft = left+amount;
			maxLeft = 0;

			if(left == maxScrollRight && newLeft > maxScrollRight) {
				$("#filmstrip_right_nav").show();
			}
		}
		else {
			newLeft = left-amount;
			maxLeft = maxScrollRight;

			if(left == 0 && newLeft < 0) {
				$("#filmstrip_left_nav").show();
			}
		}

		if((scrollLeft && newLeft < maxLeft) || (!scrollLeft && newLeft > maxLeft)) {				
			$("#filmstrip_scroll_content").css("left", newLeft+"px");
		}
		else {
			//No more scrolling possible
			$("#filmstrip_scroll_content").css("left", maxLeft+"px");

			if(scrollLeft) {
				$("#filmstrip_left_nav").hide();
			}
			else {
				$("#filmstrip_right_nav").hide();
			}
			
			if(scrollInterval != null) {
				window.clearInterval(scrollInterval);
				scrollInterval = null;
			}				
		}
	}
}

function filmstripScrollLeft() {
	filmstripScroll(true, 2);
}

function filmstripScrollLeftFast() {
	filmstripScroll(true, 5);
}

function filmstripScrollRight() {
	filmstripScroll(false, 2);			
}

function filmstripScrollRightFast() {
	filmstripScroll(false, 5);			
}

function filmstripScrollTouch(scrollLeft) {
	var left = parseInt($("#filmstrip_scroll_content").css("left"));
	if(!isNaN(left)) {
		var amount = 606;
		var newLeft = 0;
		var maxLeft = 0;
		var maxScrollRight = scrollWidthVisible-scrollWidth;
		if(scrollLeft) {
			newLeft = left+amount;
			maxLeft = 0;

			if(left == maxScrollRight && newLeft > maxScrollRight) {
				$("#filmstrip_right_nav").show();
			}
		}
		else {
			newLeft = left-amount;
			maxLeft = maxScrollRight;

			if(left == 0 && newLeft < 0) {
				$("#filmstrip_left_nav").show();
			}
		}

		var hideButtons = false;
		if((scrollLeft && newLeft >= maxLeft) || (!scrollLeft && newLeft < maxLeft)) {				
			newLeft = maxLeft;
			hideButtons = true;
		}

		if(left == newLeft) {
			if(left == 0) {
				newLeft = 40;
			}
			else {
				newLeft = newLeft-40;
			}
			
			$("#filmstrip_scroll_content").animate(
		        	{ left: newLeft }, {
		            	duration: 250
		            });
			$("#filmstrip_scroll_content").animate(
		        	{ left: left }, {
		            	duration: 250
		            });
			
			if(scrollLeft) {
				$("#filmstrip_left_nav").hide();
			}
			else {
				$("#filmstrip_right_nav").hide();
			}			
		}
		else {
			$("#filmstrip_scroll_content").animate(
		        	{ left: newLeft }, {
		            	duration: 'slow',
		                easing: 'easeOutBack'
		            });
			
			if(hideButtons) {
				if(scrollLeft) {
					$("#filmstrip_left_nav").hide();
				}
				else {
					$("#filmstrip_right_nav").hide();
				}				
			}
		}
	}		
}

function filmstripScrollLeftTouch() {
	filmstripScrollTouch(false);
}

function filmstripScrollRightTouch() {
	filmstripScrollTouch(true);
}

function scrollUpTouch(id, visibleHeight) {
	var scrollTopVal = $(id).scrollTop()-$(id).height()/2;
	if(scrollTopVal < 0) {
		scrollTopVal = 0;
	}
	/*
	$(id).animate(
		{	scrollTop: scrollTopVal }, {
        	duration: 'slow',
            easing: 'easeOutBack'
        });
	*/
	$(id).scrollTop(scrollTopVal);
}

function scrollDownTouch(id, visibleHeight) {
	var scrollTopVal = $(id).scrollTop()+$(id).height()/2;
	if(scrollTopVal > $(id)[0].scrollHeight) {
		scrollTopVal = $(id)[0].scrollHeight;
	}
	
	$(id).scrollTop(scrollTopVal);
	//alert($(id).scrollTop());
	/*
	$(id).animate(
		{	scrollTop: scrollTopVal }, {
        	duration: 'slow',
            easing: 'easeOutBack'
        });
        */
	//alert($(id).scrollTop());
}

function gotoLink(link) {
	window.location.href=link;
}

function isTouchDevice(){
	try{
		document.createEvent("TouchEvent");
		return true;
	}catch(e){
		return false;
	}
}

function touchScroll(id) {
	if(isTouchDevice()){ //if touch events exist...
		var el=document.getElementById(id);
		var scrollStartPos=0;

		document.getElementById(id).addEventListener("touchstart", function(event) {
			scrollStartPos=this.scrollTop+event.touches[0].pageY;
			event.preventDefault();
		},false);

		document.getElementById(id).addEventListener("touchmove", function(event) {
			this.scrollTop=scrollStartPos-event.touches[0].pageY;
			event.preventDefault();
		},false);
	}
}

function adjustTextColumnHeight() {
	if ($("#contentteaser").length > 0 && $("#contenttext").length > 0 && $("#contentteaser").height() > $("#contenttext").height()) {
		if($("#contentteaser").height()-$("#contenttext").height() > 12) {
			$("#contenttext").css("height", ($("#contentteaser").height()-12)+"px");
		}
		else {
			$("#contenttext").css("height", $("#contentteaser").height()+"px");
		}
	}
}

