window.addEvent('domready', function() {
	
	
	var IE6 = (navigator.userAgent.toLowerCase().indexOf('msie 6') != -1) && (navigator.userAgent.toLowerCase().indexOf('msie 7') == -1);  	
	var IE7 = (navigator.userAgent.toLowerCase().indexOf('msie 6') == -1) && (navigator.userAgent.toLowerCase().indexOf('msie 7') != -1);  	

	var closeButton = new Element('img', {'id': 'closeButton', 'class': 'closeButton', 'src': '/fileadmin/templates/adelholzener/bilder/button_schliessen.gif'});
		
	//if there's a csc-invisible item on a page, open it on click
	$$('a.internal-link-new-window').addEvent('click', function(e) {
		
		e.stop();
		
		//alert(this.getParent().getNext('div'));
		targetDiv = this.getParent().getNext('div');
		targetDiv.position({
		relativeTo: $('content')
  		,position: 'upperLeft'
  		,edge: 'upperLeft'
		,offset: {x: 30, y: 0}  
		});
		
		targetDiv.setStyles({
			display: 'block' 
			,opacity: 0
		});

		//inject a close-button 
		targetDiv.grab(closeButton);
		
		closeButton.position({
		
		relativeTo: 'presenter'//this // targetDiv
  		,position: 'upperRight'
  		,edge: 'upperRight'
		,offset: {x: 0, y: 0}  
		
		});
		

		targetDiv.fade('in');
		
	});

	/*$$('div.csc-frame-invisible').addEvent('click', function(e){
		this.fade('out');
	});*/
	
	//the closebutton closes its parent div
	closeButton.addEvent('click', function(e){
		//alert('you clicked me');
		this.getParent('div').fade('out');
		
	});
	
	//osx-link-highlighting 
	//var iL = $$('a');
	//iL.addEvent('click',function(e) {
	////	iL .removeClass('clicked'); //remove from others
	//	this.addClass('clicked');
	//});
	

	var topMenuItems = $$('#topmenue div.topbutton2');
	
	//preload the mouseover-images used in the top navigation
	//topMenuItems.each(function(p){
	//	img = p.get('rel');
	//	x = new Asset.images(img);
		//alert('preloading ' + img);
	//});

	//console.log(topMenuItems);
	
	//alert(topMenuItems);
	var oldhtml = "";
	var oldclass = "";
	var oldid = "";
	
	
	/*topMenuItems.addEvent('mousemove', function(e) {
		this.images = $$(this.getElements('img'));
		this.images.each(function(image){
			cos = (image.getPosition().x+image.getSize().x/2 - e.client.x)/50;
			cos = Math.max(Math.min(cos,Math.PI/2),-Math.PI/2);

			image.setStyle('bottom',0);
			image.setStyle('height',(Math.max((50*Math.cos(cos)),20)).toInt());
			image.getParent('div').setStyle('height', (Math.max((50*Math.cos(cos)),20)).toInt());
			image.setStyle('width',(Math.max((142*Math.cos(cos)),100)).toInt()); 
			//image.retrieve('caption').setStyle('left',e.client.x-15);
		},this);


	});*/



	topMenuItems.addEvent('mouseenter', function(e) {
		//oldhtml = this.getChildren('a').get('html');
		
	//deactivated linkimage = this.getElement('img');
		//$$('div.topbutton a img');//this.getChildren('img');
		//alert(linkimage);
		oldid = this.get('id');
		oldclass = this.get('class');
		//alert(this);
		
		//console.log('before: ' + this.get('class'));

		this.set('class', 'topbuttonactive');
		
		//console.log('after: ' + this.get('class'));

		//this.set('id', 'buttonover');
		//this.getChildren('a').set('html', '<img border="0" align="top" src="'+this.get('rel')+'>');
		
	});
	
	topMenuItems.addEvent('mouseleave', function(e) {
		//oldhtml = this.getChildren('a').get('html');
		//alert('hallo');
		//this.set('id', oldid);
		this.set('class', oldclass);
		//this.getChildren('a').set('html', oldhtml ).set('class', 'button');
	});

	//click-enlarge-images become tooltips
	/*var t = new Tips('.photoZoom');
	
	//fade in/out
	t.addEvents({
		'show': function(tip) {
				tip.fade('in');
		},
		'hide': function(tip) {
			tip.fade('out');
		}
	});*/
	
	//var clickEnlargers = $$('.photoZoom', {maxOpacity: .9});
	
	/*$$('.photoZoom').each(function(tip){
		var imgSrc = tip.get('href');// tip.retrieve('tip:text');getElement('img').
		//var imgAlt = tip.retrieve('tip:title');
		tip.store('tip:text', new Element('img',{'src':imgSrc}));
	});*/
	
	//var daMask = new Mask($('presenter'), {hideOnClick: true, destroyOnHide: false});
	//var daMask = new Spinner($('presenter'), {hideOnClick: true, destroyOnHide: false});


	
	$$('.photoZoom').each(function(i) {
	
		i.addEvent('click', function(el){
	//		daMask.show();
	/*		daMask.position({
  				x: 'center',
				y: 'center'
			
			});
*/
//alert(i.get('href'));

/*
var theReq = new Request({
  url: i.get('href'),
    update: $('presenter'),
        useSpinner: true,
        method: 'get'

}).send();
*/

//$('presenter').setStyles({width: '1px', height: '1px'});

$('presenter').set('text', '');
//Inject the new DOM elements into the results div.
$('presenter').set('html', '<img src="' +i.get('href') + '">').fade('in');;

//$('presenter').fade('0.95');
//$('presenter').tween('width', 340);
//$('presenter').addEvent('click', function(p) {this.fade('out')});
		
		
		//inject a close-button 
		$('presenter').grab(closeButton);
		
		closeButton.position({
		
		relativeTo: $('presenter')
  		,position: 'upperRight'
  		,edge: 'upperRight'
		,offset: {x: 0, y: 0}  
		
		});	

	if(IE7) topoffset = 340;
	else topoffset = 0;
		
		$('presenter').position({relativeTo: $('content')
  		,position: 'upperLeft'
  		,edge: 'upperLeft'
		,offset: {x: 0, y: topoffset}  });	
		

/*
var req = new Request({
    url: i.get('href'),
    update: $('presenter')
   // useSpinner: true
   // spinnerOptions: {...etc...}
})*/

		
//daMask.unspin();			
			//daMask.setStyles('margin-left', 'auto', 'margin-right', 'auto');
		});
		
	});
	
	//textpic captions should also click enlarge
	$$('.csc-textpic-caption').addEvent('click', function(e) {
		//alert('caption clicked');
		this.getPrevious('dt').getElement('a.photoZoom').fireEvent('click');
	
	});
	
	
	
	/*clickEnlargers.addEvent('click', function(e) {
		e.stop();
		//alert('you clicked da image');
		
		
		
	}
	
	);*/

	
	// news items popups
	// var newsItems = $$('a.linkOpener');
	var newsItems = $$('span.news-list-morelink a');
	// span class="news-list-morelink"
	
	//alert(newsItems);
	newsItems.addEvent('click', function(e){
	
		e.stop();
		
		//alert('you clicked da link');
		var detailText = this.getParent().getParent().getNext('.news-list-popupcontent');
		//alert(detailText);
		detailText.setStyle('opacity', 0);
		detailText.setStyle('z-index', 1000001);
		//detailText.setStyle('height', '300px');
		detailText.setStyle('display', 'block').fade('in');
		
		var closeItems = detailText.getElements('.news-popup-backlink');
		//alert(closeItems);
		closeItems.addEvent('click', function(f) {
			f.stop();
			detailText.fade('out');
			//detailText.setStyle('display', 'none');
		});
	
	});
	
	//sponsoren-links
	$$('a.sponsor').addEvent('click', function(e) {
	
		e.stop();
		//alert('you clicked the more link: ' + this.href);
		
		//open the href inside our presenter div
		pr = $('presenter');
		
		pr.set('text', '');
		pr.setStyle('display', 'block');
		
		pr.position({relativeTo: $('content')
  		,position: 'upperLeft'
  		,edge: 'upperLeft'
		,offset: {x: 0, y: 0}  });
		
				
		
		
		pr.setStyles({
			'display': 'block' 
			,'opacity': 0
			,'padding': '20px 30px 20px 10px'
		});
		
		//alert('preparing to request '+this.href);

		req = new Request.HTML({
	    		url: this.href
	    		//,update: $('presenter')
	    		,useSpinner: true
	    		
	    		//////////77
	    		,onSuccess: function(html) {
			//Clear the text currently inside the results div.
			pr.set('text', '');
			//Inject the new DOM elements into the results div.
			pr.adopt(html);
			///$('presenter').fade('0.85');
			pr.grab(closeButton);
			closeButton.position({
		
		relativeTo: pr
  		,position: 'upperRight'
  		,edge: 'upperRight'
		,offset: {x: -43, y: 0}  
		
		});

		}
	    		/////////////

	    		 
		});
		req.get();
//inject a close-button 
		
		
		
		pr.fade('in');
	
	});


	

});

