
/**********************************
 *
 * Full cusomizable Scrollbar
 *
 * ********************************
 */
function initScrollbar(){
	//Damit beim Neuladen der Scrollbar, der scrollbare Inhalt wieder nach oben gescrollt ist (Ausgangsposition)
	$('ScrollableContent').scrollTop = 0;

	/* Höhe des kompletten Inhalts */
	hoehe = getHoehe('ContentInput');

	/* unangepasste Höhe der ScrollHandle */
	hoeheScrollhandle = getHoehe('ScrollHandle');

	/* Höhe des (sichtbaren) Content-Bereichs */
	hoeheContentBereich = getHoehe('ScrollableContent');

	/*Die Scrollhandle an die Höhe des zu scrollenden Contents anpassen*/
	$('ScrollHandle').style.height = (((hoeheContentBereich/hoehe)*hoeheScrollhandle)+15)+"px";

	slideRangeDivider = 20;

	/* Je größer sliderRange -> feinere Abschnitte -> langsamer aber genauer Scrollen (mit dem Mousewheel)
	   Je höher der scrollbare Bereich, desto größer sliderRange */
	sliderRange = hoehe/slideRangeDivider;

	// Scroll-Slider wird instanziiert
	slider1 = new Control.Slider('ScrollHandle', 'ScrollTrack', {
		axis: 'vertical',
		range: $R(0, sliderRange),
		onSlide: function(v) { scrollVertical(v, $('ScrollableContent'), slider1);  slider1Value = v; },
		onChange: function(v) { scrollVertical(v, $('ScrollableContent'), slider1); slider1Value = v; }
	});

	// wenn nicht gesrcollt werden muss -> ausblenden
	//alert("hoehe="+hoehe+"||offsetHeight="+$('ScrollableContent').offsetHeight);
	if (hoehe < $('ScrollableContent').offsetHeight) {
		slider1.setDisabled();
		$('Scrollbar').hide();
	} else {
		$('Scrollbar').show();
	}

	// Mozilla
	Event.observe('ScrollableContent', 'DOMMouseScroll', wheel);
	Event.observe('Scrollbar', 'DOMMouseScroll', wheel);

	// IE/Opera
	Event.observe('ScrollableContent', 'mousewheel', wheel);
	Event.observe('Scrollbar', 'mousewheel', wheel);

	/* Diese Variablen enthalten den momentanen Scroll-Wert der Slider. Initialisierung mit Wert 0 */
	slider1Value = 0;


	/* Wenn der Browser scrollHeight oder offsetHeight nicht akzeptiert -> Scrollbar ausblenden und eine normale Scrollbar verwenden */
	if ($('ScrollableContent').scrollTop == $('ScrollableContent').offsetHeight){
		slider1.setDisabled();
		$('Scrollbar').hide();
		$('ScrollableContent').addClassName('normalScrollbars');
	}


	/* Events für den ScrollDown-Button */
	$('Btn_ScrollDown').onmousedown = function(){
		scroll('down');
	}
	$('Btn_ScrollDown').onmouseup = function(){
		scroll('stop');
	}
	$('Btn_ScrollDown').onmouseout = function(){
		scroll('stop');
	}

	/* Events für den ScrollUp-Button */
	$('Btn_ScrollUp').onmousedown = function(){
		scroll('up');
	}
	$('Btn_ScrollUp').onmouseup = function(){
		scroll('stop');
	}
	$('Btn_ScrollUp').onmouseout = function(){
		scroll('stop');
	}

}//Ende Fkt initScrollbar()

//Zum Scrollen des Elements
function scrollVertical(value, element, slider) {
	element.scrollTop = Math.round(value/slider.maximum*(hoehe-element.offsetHeight));
}

/* Ab hier folgt der Code für die Mouswheel-Scroll-Funktion */
function handle(delta) {
	slider1.setValueBy(-delta);
}

/** Event Handler für das Scrolling per Mausrad */
function wheel(event){

	var delta = 0;
	if (!event) /* For IE. */
		event = window.event;
	if (event.wheelDelta) { /* IE/Opera. */
		delta = event.wheelDelta/120;
		if (window.opera)
			delta = delta;
	} else if (event.detail) { /** Mozilla case. */
		delta = -event.detail/1;
	}
	if (delta)
		handle(delta);
	if (event.preventDefault)
		event.preventDefault();

	event.returnValue = false;
}

function scroll(direction){
	if (direction == "stop"){
		try {
			clearInterval(steppingInterval);
		} catch (e){

		}
	}else if (direction == "up"){
		steppingInterval = window.setInterval("slider1.setValue(slider1Value - 1);", 30); /* letzter Parameter bestimmt die Größe  der Schrittfolgen */
	}else if (direction == "down"){
		steppingInterval = window.setInterval("slider1.setValue(slider1Value + 1);", 30); /* letzter Parameter bestimmt die Größe der Schrittfolgen */
	}
}

//Fkt, um die aktuelle Höhe des Elements abzufragen
function getHoehe(objid){
  if (window.getComputedStyle){
	obj=document.getElementById(objid);
	wert = (document.defaultView.getComputedStyle(obj,"").getPropertyValue('height'));
	wert = wert.substr(0, (wert.length-2)); /* "px" am Ende wird abgeschnitten */
	return wert;

  }else{//getComputedStyle wird durch den Browser NICHT unterstützt.

	dimensions = $(objid).getDimensions();
	return(dimensions.height);
  }
}


/**** Vertical Sushibar ****/


moved = 0;
yValue = 76;
working = false;
function sushiUp(div) {
	if(!working) {
		working = true;
		if(moved > yValue ) {
			new Effect.Move(div, {x:0,y:yValue,duration:0.3, afterFinish:function(){working=false;}});
			moved -= yValue;
		} else {
			new Effect.Move(div, {x:0,y:moved,duration:0.3, afterFinish:function(){working=false;}});
			moved = 0;
		}
	}
}

function sushiDown(div) {
	if(!working) {
		working = true;
		totalHeight = getHoehe("Movable");
		if(totalHeight - 395 - yValue -moved >= -yValue) {
			new Effect.Move(div, {x:0,y:(yValue*-1),duration:0.3, afterFinish:function(){working=false;}});
			moved += yValue;
		} else working = false;
	}
}


//Tourdaten
openItem = '';
working = false;
function toggleDetail(id) {
	if(!working) {
		working = true;
		if(openItem == '') { // Everything is closed. New items gets opened.
			Effect.BlindDown(id, {duration:0.7,afterFinish:afterToggle});
			openItem = id;
			$(id+'ToggleButton').src = '/notp/images/structure/icons/arrow_up.gif';
		} else { // Current open item gets closed
			Effect.BlindUp(openItem, {duration:0.4, afterFinish:afterToggle});
			$(openItem+'ToggleButton').src = '/notp/images/structure/icons/arrow_down.gif';
			if(id != openItem) { // Clicked on item gets opened if was not the same
				Effect.BlindDown(id, {duration:0.7, afterFinish:afterToggle});
				openItem = id;
				$(id+'ToggleButton').src = '/notp/images/structure/icons/arrow_up.gif';
			} else openItem = '';
		}
	}

}




function toggleDetailLarge(id) {
	if(!working) {
		working = true;
		if(openItem == '') { // Everything is closed. New items gets opened.
			Effect.BlindDown(id, {duration:0.7,afterFinish:afterToggle});
			openItem = id;
			$(id+'ToggleButton').src = '/notp/images/structure/icons/arrow_up_large.png';
		} else { // Current open item gets closed
			Effect.BlindUp(openItem, {duration:0.4, afterFinish:afterToggle});
			$(openItem+'ToggleButton').src = '/notp/images/structure/icons/arrow_down_large.png';
			if(id != openItem) { // Clicked on item gets opened if was not the same
				Effect.BlindDown(id, {duration:0.7, afterFinish:afterToggle});
				openItem = id;
				$(id+'ToggleButton').src = '/notp/images/structure/icons/arrow_up_large.png';
			} else openItem = '';
		}
	}

}




function afterToggle() {
	//initScrollbar();
	working = false;
}

function popup(url, winW, winH, scrollBar) {
			winX = (screen.width/2)-(winW/2);
			winY = (screen.height/2)-(winH/2);
			popupLegal = window.open(url,'name','width='+winW+',height='+winH+',top='+winY+',left='+winX+',scrollbars='+scrollBar);
		}

function tellafriendPopup() {
	url = "http://www3.nokia.de/notp/frontend/tafPopup";
	popup(url, 650, 450, 'no');
}

function cyopPopup() {
	url = "http://www3.nokia.de/notp/frontend/cyopPopup";
	popup(url, 650, 450, 'yes');
}

function tourmapPopup() {
	url = "http://"+document.domain+"/notp/frontend/tourmapPopup";
	popup(url, 650, 820, 'yes');
}



function toggleCheckBox(boxId, competition) {
	if($(boxId+'Checkbox').src == "http://"+document.domain+'/notp/images/structure/icons/checkbox_false.gif') {
		$(boxId+'Checkbox').src = "http://"+document.domain+'/notp/images/structure/icons/checkbox_true.gif';
		$(competition+'_'+boxId).value = "on";
	}	else {
		$(boxId+'Checkbox').src = "http://"+document.domain+'/notp/images/structure/icons/checkbox_false.gif';
		$(competition+'_'+boxId).value = "";
	}
}

artistId = 0;
function toggleRadio(objId) {
	if(artistId == 0){
		$('radio'+objId).src = '/notp/images/structure/buttons/radio_true.png';
		artistId = objId;
	}	else {
		$('radio'+artistId).src='/notp/images/structure/buttons/radio_false.png';
		$('radio'+objId).src = '/notp/images/structure/buttons/radio_true.png';
		artistId = objId;
	}
}

function executeCyop() {
	if(artistId != 0) {
		Effect.Appear('Cyop');
		$('cyopErrorMsg').style.display = 'none';
	}
	else $('cyopErrorMsg').style.display = 'inline';
}

function radioHover(obj) {
	if(obj.src == "http://"+document.domain+"/notp/images/structure/buttons/radio_false.png")
		obj.src = "http://"+document.domain+"/notp/images/structure/buttons/radio_hover.png";
	else if(obj.src == "http://"+document.domain+"/notp/images/structure/buttons/radio_hover.png")
		obj.src = "http://"+document.domain+"/notp/images/structure/buttons/radio_false.png";

}

artistIsOpen = '';
function reloadScrollbar(artist) {
	if(artistIsOpen == artist) {
		$('ContentInput').style.height = "150px";
		artistIsOpen = '';
		$('Scrollbar').hide();
	}	else {
		$('ContentInput').style.height = "300px";
		artistIsOpen = artist;
		initScrollbar();
	}

}




function reloadScrollbarDL(artist, height) {
	if(artistIsOpen == artist) {
		$('ContentInput').style.height = "650px";
		artistIsOpen = '';
		$('Scrollbar').hide();
	}	else {
		$('ContentInput').style.height = height+"px";
		artistIsOpen = artist;
		initScrollbar();
	}

}



var currentGalleryDetailItemZindex = 120;
function openGalleryDetail(event_id, id) {
	event_id = event_id.split("/");
	$('GalleryDetails').show();
	$('DetailImage').src = "/notp/images/content/event/"+event_id[0]+"/"+id+".jpg";
	$('DetailImageId').innerHTML = id;
	$('DetailImage').style.zIndex = currentGalleryDetailItemZindex+1;
}

working = false;
var lastDirection = "none";
function showNextGalleryItem(cityCode) {
	if(!working) {
		working = true;
		if(lastDirection == "previous") {
			$('DetailDivPrevious').hide();
		}
		id = $('DetailImageId').innerHTML;
		if(id < maxImages) {
			$('DetailImage').style.zIndex = currentGalleryDetailItemZindex;
			$('DetailDivNext').style.zIndex = currentGalleryDetailItemZindex+1;

			new Effect.Move('DetailDivNext', {x:508,y:0,duration:0.0});
			$('DetailImageNext').src = "/notp/images/content/event/"+cityCode+"/"+(Number(id)+1)+".jpg";
			$('DetailDivNext').show();
			$('DetailDivNext').style.visibility = "visible";
			new Effect.Move('DetailDivNext', {x:-508,y:0,duration:0.3, afterFinish: function(
			){$('DetailImage').src = "/notp/images/content/event/"+cityCode+"/"+(Number(id)+1)+".jpg";working = false;}});
			$('DetailImageId').innerHTML = Number(id)+1;
			currentGalleryDetailItemZindex++;
			lastDirection = "next";
		} else {
			working = false;
		}
	}

}

function showPreviousGalleryItem(cityCode) {
	if(!working) {
		working = true;
		if(lastDirection == "next") {
			$('DetailDivNext').hide();
		}
		id = $('DetailImageId').innerHTML;
		if(id > 1) {

			$('DetailImage').style.zIndex = currentGalleryDetailItemZindex;
			$('DetailDivPrevious').style.zIndex = currentGalleryDetailItemZindex+1;
			new Effect.Move('DetailDivPrevious', {x:-508,y:0,duration:0.0});
			$('DetailImagePrevious').src = "/notp/images/content/event/"+cityCode+"/"+(Number(id)-1)+".jpg";
			$('DetailDivPrevious').show();
			$('DetailDivPrevious').style.visibility = "visible";
			new Effect.Move('DetailDivPrevious', {x:508,y:0,duration:0.3, afterFinish: function(
			){$('DetailImage').src = "/notp/images/content/event/"+cityCode+"/"+(Number(id)-1)+".jpg";working = false;}});
			$('DetailImageId').innerHTML = Number(id)-1;
			currentGalleryDetailItemZindex++;
			lastDirection = "previous";
		} else {
			working = false;
		}
	}

}

function closeGalleryDetailLayer() {
	$('GalleryDetails').hide();
	$('DetailDivNext').style.display = "none";
	$('DetailDivNext').style.visibility = "hidden";
	$('DetailDivPrevious').style.display = "none";
	$('DetailDivPrevious').style.visibility = "hidden";
}

var activeImage = "wp_desk1";
var activeBox = "";
var dlPath = "";
function toggleDownloadSize(type, size) {
	imgId = type+"_"+size;
	if(imgId == activeBox) {
		$(imgId).src = "/notp/images/structure/buttons/radio_false.png";
		activeBox = "";
	} else {
		if(activeBox != "") $(activeBox).src = "/notp/images/structure/buttons/radio_false.png";
		$(imgId).src = "/notp/images/structure/buttons/radio_true.png";
		activeBox = imgId;
		dlPath = "/notp/downloads/"+activeImage+"_"+size+".jpg";
	}

}

function toggleDownloadImage(obj) {
	if(obj.id != activeImage) {
		$(activeImage).src = "/notp/images/content/"+activeImage+"_inactive.jpg";
		obj.src = "/notp/images/content/"+obj.id+"_active.jpg";
		activeImage = obj.id;
	}
}

function closeLayer(name) {
	Element.hide(name);
	return false;
}