//
// BEN: Individual functions for channel-eight.de
//
var extended = 0;
function scaleFooterMain() {            
    if(extended == 0) {
        extended = 1;
        new Effect.Scale('main-footer',200,{scaleX:false,duration:0.5,scaleContent:false,scaleMode:{originalHeight:155},queue:{scope:'footerScope',limit:1}});

    } else {
        extended = 0;
        new Effect.Scale('main-footer',50,{scaleX:false,duration:0.5,scaleContent:false,scaleMode:{originalHeight:310},queue:{scope:'footerScope',limit:1}});
    }
}

function scaleFooterHome() {            
    if(extended == 0) {
        extended = 1;
        new Effect.Scale('home-footer',175,{scaleX:false,duration:0.5,scaleContent:false,scaleMode:{originalHeight:205},queue:{scope:'footerScope',limit:1}});
    } else {
        extended = 0;
        new Effect.Scale('home-footer',57,{scaleX:false,duration:0.5,scaleContent:false,scaleMode:{originalHeight:360},queue:{scope:'footerScope',limit:1}});
    }
}

function moveImageRowLeft(parentElement) {
	// Getting all images by their class-name inside of parentElement
	var myImages = document.getElementsByClassName ('csc-textpic-image',parentElement);
	// This is the width of the visible area
	var viewport = 475;
	var totalWidth = 0;
	// Calculating the width of all images in this row
	for(var i=1; i<=(myImages.length); i++){
		totalWidth += myImages[i-1].getWidth();	
	}
	// Canceling function if the images don't even exceed the visible area -> no scrolling needed
	if(totalWidth <= viewport){return;}
	var maxScroll = totalWidth-viewport;
	// Getting the actual position of parentElement, strip down to the pure value via parseFloat
	var scrolled = parseFloat(document.getElementById(parentElement).getStyle('left') || '0');
	var diffScroll = maxScroll-Math.abs(scrolled);
	// If no scrolling is needed cancel the function
	if(diffScroll == 0){return;}
	if (diffScroll >= viewport) {
		// Move parentElement left (one time the viewport) and add a queue-limit so the effect is exclusive in this scope
		new Effect.Move(parentElement,{x:-viewport,y:0,mode:'relative',queue:{scope:'imageRowScope',limit:1}});
	} else {
		// Else only move left the diffScroll-amount
		new Effect.Move(parentElement,{x:-diffScroll,y:0,mode:'relative',queue:{scope:'imageRowScope',limit:1}});
	}
}

function moveImageRowRight(parentElement) {
	var myImages = document.getElementsByClassName ('csc-textpic-image',parentElement);
	var viewport = 475;
	var totalWidth = 0;
	for(var i=1; i<=(myImages.length); i++){
		totalWidth += myImages[i-1].getWidth();	
	}
	if(totalWidth <= viewport){return;}
	var maxScroll = 0;
	var scrolled = parseFloat(document.getElementById(parentElement).getStyle('left') || '0');
	var diffScroll = Math.abs(scrolled) - maxScroll;
	if(diffScroll == 0){return;}
	if (diffScroll >= viewport) {
		new Effect.Move(parentElement,{x:viewport,y:0,mode:'relative',queue:{scope:'imageRowScope',limit:1}});
	} else {
		new Effect.Move(parentElement,{x:diffScroll,y:0,mode:'relative',queue:{scope:'imageRowScope',limit:1}});
	}
}

var W3CDOM = (document.createElement && document.getElementsByTagName);
function initFileUploads() {
	if (!W3CDOM) return;
	var fakeFileUpload = document.createElement('div');
	fakeFileUpload.className = 'fakeupload';
	fakeFileUpload.appendChild(document.createElement('input'));
	var image = document.createElement('img');
	image.src = 'fileadmin/templates/img/form-browse.png';
	fakeFileUpload.appendChild(image);
	var x = document.getElementsByTagName('input');
	for (var i=0;i<x.length;i++) {
		if (x[i].type != 'file') continue;
		if (x[i].parentNode.className != 'upload') continue;
		x[i].className = 'tx-srfeuserregister-pi1-uploader hidden';
		var uploadClone = fakeFileUpload.cloneNode(true);
		x[i].parentNode.appendChild(uploadClone);
		x[i].relatedElement = uploadClone.getElementsByTagName('input')[0];
		x[i].onchange = x[i].onmouseout = function () {
			this.relatedElement.value = this.value;
		}
	}
}