/* Basis-Script */
	
var onloadHooks = [];
		
window.onload = function()
{
	// Get onload scripts
	for(i = 0; i < onloadHooks.length; i++)
	{
		onloadHooks[i]();
	}

	// Blurlinks
	var blurlinks = $$("a");
	for(var i = 0, o; o = blurlinks[i]; i++)
	{
		o.addEvents({'focus': function(e) {
			this.blur();
		}});
	}
	
}

onloadHooks.push(function(){ 
	init();
	checkscroll();
});



var isinsideshare = 0;
var showingsharebuttons = 0;

function init (){
	$$("a").addEvent('focus', function(e) {
		this.blur();
	});
	
	
	var wrapper = $$('.sharewrapper');
	for(var i = 0; i<wrapper.length; i++){
		wrapper[i].addEvent('mouseover', function(){
			insideshare();
		});
		wrapper[i].addEvent('mouseout', function(){
			outsideshare();
			hidesharebuttons('hover');
		});
	}
	
	
	if($('sharebutton')){
			$('sharebutton').addEvent('mouseover', function(){
				this.setStyle('background', 'url(../../../fileadmin/templates/img/sharebutton.gif) no-repeat bottom left');
				this.setStyle('color', '#333333');
			});
			
			$('sharebutton').addEvent('mouseout', function(){
				this.setStyle('background', 'url(../../../fileadmin/templates/img/sharebutton.gif) no-repeat top left');
				this.setStyle('color', '#7F7F80');
			});
	}
	
	
	if($('buttonfield')){
		$('buttonfield').setStyle('display', 'none');
	}
	
	if($('navi') && !$('nav_555'))
	{
		makeNavi();			
	}
		
	if($('kontosticky'))
	{
		$('kontosticky').addEvent('click',makeKontodaten);
	}
	
	/*if(Browser.Engine.trident && !checkBrowserName('MSIE 8'))
	{
		genLinkPfeil();
	}*/
			
}

function checkBrowserName(name){  
    var agent = navigator.userAgent.toLowerCase();  
    if (agent.indexOf(name.toLowerCase())>-1) {  
      return true;  
    }  
    return false;  
}

function makeKontodaten()
{
	var text = $$('.kontodaten')[0].get('html');
	var elem = new Element('div',{'id':'kontodatenlayer'});
	var ahref = new Element('a',{'class':'closeSticky','href':'javascript:void(0);','text':'x'}).injectInside($(elem));
	var html = new Element('div',{'class':'kontodaten','html':text}).injectAfter($(ahref));
//	html.appendText('IBAN: DE75 3706 0193 0000 1010 10SWIFT-BIC: GENODED1PAX');
	
	var iban = new Element('div',{'class':'kontodaten-zeile'}).setStyle('margin-top','10px').injectInside($(html));
	var field1 = new Element('div',{'class':'field1','html':'IBAN'}).injectInside($(iban)); 
	var ibanNr = new Element('div',{'class':'field4','html':'DE75 3706 0193 0000 1010 10'}).injectAfter($(field1));
	
	var swift = new Element('div',{'class':'kontodaten-zeile'}).injectInside($(html));
	var field1 = new Element('div',{'class':'field1','html':'SWIFT-BIC'}).injectInside($(swift)); 
	var swiftNr = new Element('div',{'class':'field4','html':'GENODED1PAX'}).injectAfter($(field1));			

	var myWin = new StickyWin({
    		content: elem,
    		draggable: true,
    		allowMultiple: false,
    		relativeTo: $('kontosticky'),
			offset: {x: 0, y: 0},
			edge: 'upperRight',
			position: 'bottomRight',
			destroyOnClose:true,
			onDisplay: function(){
				this.pin();			
			}								    		
	});		
} 

function makeNavi(){
	
	if($$('.sub') != "" && $$('.sub').length )
	{	
		
		$$('.sub')[0].setStyles({
				'border' : '1px solid #d4d4d4',
				'padding' : '0',
				'position' : 'absolute',
				'top' : ($$('.sub')[0].getParent().getCoordinates().top-1)+'px',
				'left' : (($$('.sub')[0].getParent().getCoordinates().left-$('wrap').getCoordinates().left)-1)+'px',
				'z-index' : '99',
				'float' : 'left',
				'padding-left':'15px',
				'padding-right':'5px',
				'height' : '27px',
				'background-position' : '3px 8px'
			});
			
			
			$$('.sub')[0].getParent().setStyles({
			'width' : ($$('.sub')[0].getParent().getChildren()[0].getCoordinates().width-2)+'px',
			'height' : ($$('.sub')[0].getParent().getChildren()[0].getCoordinates().height-1)+'px',
			'display' : 'block',
			'margin-bottom' : '0px'
			});	
			
				
	}
	
	
	$$('.menuHGM2Links').addEvents({
	
		'mouseenter' : function()
		{				
			
			if(!this.getChildren()[0].hasClass('sub'))
			{
				if(this.getChildren().length > 1)
				{
					this.getChildren()[0].setStyles({
						'border' : '1px solid #d4d4d4',
						'border-bottom' : 'none',
						'padding' : '0',
						'position' : 'absolute',
						'top' : (this.getCoordinates().top-1)+'px',
						'left' : ((this.getCoordinates().left-$('wrap').getCoordinates().left)-1)+'px',
						'z-index' : '99',
						'float' : 'left',
						'padding-left':'15px',
						'padding-right':'5px',
						'height' : '28px',
						'background-position' : '3px 8px',
						'background-color' : '#eeeeee'
					});
				}
				else
				{
				
					this.getChildren()[0].setStyles({
						'border' : '1px solid #d4d4d4',
						'padding' : '0',
						'position' : 'absolute',
						'top' : (this.getCoordinates().top-1)+'px',
						'left' : ((this.getCoordinates().left-$('wrap').getCoordinates().left)-1)+'px',
						'z-index' : '99',
						'float' : 'left',
						'padding-left':'15px',
						'padding-right':'5px',
						'height' : '28px',
						'background-position' : '3px 8px',
						'background-color' : '#eeeeee'
					});
				}
				
				this.setStyles({
				'width' : (this.getChildren()[0].getCoordinates().width-2)+'px',
				'height' : '27px',
				'display' : 'block',
				'margin-bottom' : '0px'
				});
			}
			else
			{
							
				this.getChildren()[0].setStyles({
					'border-bottom' : 'none',
					'padding' : '0',
					'position' : 'absolute',
					'top' : (this.getCoordinates().top-1)+'px',
					'left' : ((this.getCoordinates().left-$('wrap').getCoordinates().left)-1)+'px',
					'z-index' : '99',
					'float' : 'left',
					'padding-left':'15px',
					'padding-right':'5px',
					'height' : '28px',
					'background-position' : '3px 8px',
					'background-color' : '#eeeeee'
				});
				
				
				this.setStyles({
				'width' : (this.getChildren()[0].getCoordinates().width-2)+'px',
				'height' : '27px',
				'display' : 'block',
				'margin-bottom' : '0px'
				});
				
			}
			
			if(this.getChildren().length > 1)
			{
				this.getLast().setStyles({
					'top' : (this.getCoordinates().top+27)+'px',
					'left' : ((this.getCoordinates().left-$('wrap').getCoordinates().left)-9)+'px'
				});
				
				this.getLast().addClass('hover');
			}
			
		
		},
		
		'mouseleave' : function()
		{	
			if(!this.getChildren()[0].hasClass('sub'))
			{
				
				this.getChildren()[0].setStyles({
				'border' : 'none',
				'padding' : '0',
				'padding-left' : '15px',
				'padding-right':'5px',
				'position' : 'static',
				'display' : 'block',
				'height' : '27px',
				'background-position' : '3px 8px',
				'background-color' : '#ffffff'
				});
						
				this.setStyles({
				'margin-bottom' : '1px',
				'height' : '27px'
				});
			}
			else
			{					
				this.getChildren()[0].setStyles({
					'height' : '27px',
					'border' : '1px solid #d4d4d4',
					'background-color' : '#ffffff'
				});
			
				this.setStyles({
				'height' : '27px'
				
				});				
			}
			
			this.getLast().removeClass('hover');
		}
		
		});

}



function insideshare(){
	isinsideshare = 1;
}

function outsideshare(){
	isinsideshare = 0;
}

function hidesharebuttons(){
	if(showingsharebuttons){
		var warte = hidebuttonsdelay.delay(500);
	}
}

function hidebuttonsdelay(){
	if(!isinsideshare){
		$('buttonfield').setStyle('display', 'none');
		$('sharebutton').setStyle('background', 'url(../../../fileadmin/templates/img/sharebutton.gif) no-repeat left top');
		$('sharebutton').setStyle('color', '#7F7F80');
		showingsharebuttons = 0;
			
		$('sharebutton').removeEvents();
		
		$('sharebutton').addEvent('mouseover', function(){
			this.setStyle('background', 'url(../../../fileadmin/templates/img/sharebutton.gif) no-repeat bottom left');
			this.setStyle('color', '#333333');
		});
		
		$('sharebutton').addEvent('mouseout', function(){
			this.setStyle('background', 'url(../../../fileadmin/templates/img/sharebutton.gif) no-repeat top left');
			this.setStyle('color', '#7F7F80');
		});
	}
}

function showsharebuttons(){
	if(showingsharebuttons){
		$('buttonfield').setStyle('display', 'none');
		$('sharebutton').setStyle('background', 'url(../../../fileadmin/templates/img/sharebutton.gif) no-repeat left top');
		$('sharebutton').setStyle('color', '#7F7F80');
		
		$('sharebutton').removeEvents();
		
		$('sharebutton').addEvent('mouseover', function(){
			this.setStyle('background', 'url(../../../fileadmin/templates/img/sharebutton.gif) no-repeat bottom left');
			this.setStyle('color', '#333333');
		});
		
		$('sharebutton').addEvent('mouseout', function(){
			this.setStyle('background', 'url(../../../fileadmin/templates/img/sharebutton.gif) no-repeat top left');
			this.setStyle('color', '#7F7F80');
		});
		
		showingsharebuttons = 0;
	}else{
		$('buttonfield').setStyle('display', 'block');
		$('sharebutton').setStyle('background', 'url(../../../fileadmin/templates/img/sharebutton.gif) no-repeat left bottom');
		$('sharebutton').setStyle('color', '#333333');
		
		$('sharebutton').removeEvents();
		
		$('sharebutton').addEvent('mouseover', function(){
			this.setStyle('background', 'url(../../../fileadmin/templates/img/sharebutton.gif) no-repeat bottom left');
			this.setStyle('color', '#333333');
		});
		
		showingsharebuttons = 1;
	}
}


function checkscroll(){
	if($$('.scrolltext_outer') && $$('.scrolltext_inner')){
		var innerScroll = $$('.scrolltext_outer .scrolltext_inner');
		for(var i = 0; i < innerScroll.length; i++){
			var outerScroll = innerScroll[i].getParent();
			var innenhoehe = innerScroll[i].getStyle('height').toInt();
			var aussenhoehe = outerScroll.getStyle('height').toInt();
			if(innenhoehe > aussenhoehe){
				var innenbreite = innerScroll[i].getStyle('width').toInt();
				
				var aussenbreite = outerScroll.getStyle('width').toInt();
				innerScroll[i].setStyle('width', (aussenbreite - 15));
				var hochscroller = new Element('a', {
					'href'		: 'javascript:;',
					'styles'	: {
						'width'				: '14px',
						'height'			: '14px',
						'position'		: 'absolute',
						'top'					: '0',
						'right'				: '0',
						'background'	: 'url(typo3conf/ext/ig_fotoalbum/res/img/pfeil-up.gif) no-repeat top left'
					},
					'events'	: {
						'mousedown'		: function(){
							textscrolling = 1;
							scrollUP(this.getParent().getFirst());
						},
						'mouseup'		: function(){
							textscrolling = 0;
						}
					}
				});
				hochscroller.injectInside(outerScroll);
				var runterscroller = new Element('a', {
					'href'		: 'javascript:;',
					'styles'	: {
						'width'				: '14px',
						'height'			: '14px',
						'position'		: 'absolute',
						'bottom'					: '0',
						'right'				: '0',
						'background'	: 'url(typo3conf/ext/ig_fotoalbum/res/img/pfeil-down.gif) no-repeat top left'
					},
					'events'	: {
						'mousedown'		: function(){
							textscrolling = 1;
							scrollDOWN(this.getParent().getFirst());
						},
						'mouseup'		: function(){
							textscrolling = 0;
						}
					}
				});
				runterscroller.injectInside(outerScroll);
			}
		}
	}
}

function scrollUP(elem){
	var schrittweite = Math.round((elem.getStyle('height').toInt() - elem.getParent().getStyle('height').toInt())/10);
	if(schrittweite < 15){
		schrittweite = 15;
	}
	var maxtextscroll = 0;
	var startpunkt = elem.getStyle('top').toInt();
	var framespersecond = 30;
	var dauer = 50;
	var endpunkt = startpunkt + schrittweite;
	if(startpunkt < maxtextscroll){
		Scroller = new Fx.Morph(elem, {duration:dauer, transition:'linear', fps:framespersecond});
		Scroller.addEvent('complete', function(){
			if(textscrolling){
				scrollUP(elem);
			}
		});
		Scroller.start({
			'top': [startpunkt, endpunkt]
		});
	}
}

function scrollDOWN(elem){
	var schrittweite = Math.round((elem.getStyle('height').toInt() - elem.getParent().getStyle('height').toInt())/10);
	if(schrittweite < 15){
		schrittweite = 15;
	}
	var maxtextscroll = elem.getParent().getStyle('height').toInt()-elem.getStyle('height').toInt();
	var startpunkt = elem.getStyle('top').toInt();
	var framespersecond = 30;
	var dauer = 50;
	var endpunkt = startpunkt - schrittweite;
	if(startpunkt >= maxtextscroll){
		Scroller = new Fx.Morph(elem, {duration:dauer, transition:'linear', fps:framespersecond});
		Scroller.addEvent('complete', function(){
			if(textscrolling){
				scrollDOWN(elem);
			}
		});
		Scroller.start({
			'top': [startpunkt, endpunkt]
		});
	}
}
/*
function genLinkPfeil()
{
	var links = $$('#sub_col_m a');
	
	links.each(function(elem){
		if(elem.target != "thePicture" && !elem.hasClass('anker'))
		{
			var teile = elem.innerHTML.split(" ");
			letztes_wort = teile[(teile.length-1)];
			teile[(teile.length-1)] = '<span class="mehr">'+letztes_wort+"</span>";
			elem.innerHTML = teile.join(" ");
		}
	});	
}*/

function makemaillink(pt1, pt2){
	location.href = "mailto:"+pt1+"@"+pt2;
};

function printme(text){
	text=document;
	print(text);
	//document.print();
}
