var check2 = 0;
var go_ajax = function (element, updateid, column) {
		var to_update = $(updateid);
		$$(element + ' a').each(function(el){
			el.onclick = function(){
				if (check2 == 0) {
					check2++;
					$$(element + ' a').each(function(chk){
						if (chk.getProperty('class')) {
							chk.removeProperty('class');
						}
					});
					this.setProperty('class', 'activeproject');
					var url = el.href;
					var search = /[0-9]{2}/;
					var found = search.exec(url);
					var urlextend = url + "?request=" + column + "&items="+found;
					var myTween = new Fx.Tween(to_update, {
						duration: 500
					});
					myTween.start('opacity', 0).chain(function(){
  						myTween.start('opacity', 0, 1); 
						new Request.HTML({
							url: urlextend, 
							method: 'post',
							update: to_update,
							onRequest: function(){
								var setloadIMG = new Element('img', {
									src: 'res/img/ajax-loader.gif',
									alt: ''
								});
								
								var setloaddiv = new Element('div', {
									'id': 'ajaxload'
								});
								setloadIMG.injectInside(setloaddiv);
								setloaddiv.injectInside($('pdb_slider_top'));
								
							},
							onComplete: function(response){
								//location.hash = '#'+escape(url);
								$('ajaxload').dispose();


								check2--;
								
							}
						}).send();
					}); 
				}
				return false;
			}
		});
}




/*
Author: Joe Ray Gregory
Lisence: LGPL
Version: 0.1 alpha
.....................
Kontakt:
_____________________
joe@may17.de
http://www.may17.de
.....................
*/

var ulID = 'slider';		//ID des Holders
var testset = 0;
var _checkStyle = function(ele, val, todo) {
	var out = ele.getFirst().getElement(val).getStyle(todo).toInt();
	return out;
}



window.addEvent('domready',function(){
	var _id = $(ulID);
	
	if (_id) {
		var imgWidth = _checkStyle(_id, 'img', 'width');
		var PaddingLinkLeft = _checkStyle(_id, 'a', 'paddingLeft');
		var PaddingLinkRight = _checkStyle(_id, 'a', 'paddingRight');
		var paddingLiRight = _checkStyle(_id, 'li', 'paddingRight');
		var paddingLiLeft = _checkStyle(_id, 'li', 'paddingRight');
		var countELWidth = paddingLiRight + paddingLiLeft + imgWidth +PaddingLinkRight +PaddingLinkLeft;
		
		var paddingLinkTop = _checkStyle(_id, 'a', 'paddingTop');
		var paddingLinkBottom = _checkStyle(_id, 'a', 'paddingBottom');
		var singleSize = _checkStyle(_id, 'img', 'height');
		if (navigator.appName == 'Microsoft Internet Explorer') {
			var elheight = 50;
		} else {
			var elheight = paddingLinkTop + paddingLinkBottom + singleSize;
		}
		var PaddingUL = _id.getElement('ul').getStyle('marginLeft').toInt();
		if (navigator.appName == 'Microsoft Internet Explorer') {
			var totalLength = 568;
		}
		else {
			var totalLength = (countELWidth * 8) + PaddingUL;
		}
		_id.setStyles({
			'overflow': 'hidden',
			'height': elheight + 'px',
			'width': totalLength+'px',
			'marginRight': PaddingUL+'px'
		});
		var singleSize = _id.getFirst().getElement('img').getStyle('width').toInt();
		var paddingLi = _id.getFirst().getElement('li').getStyle('padding').toInt();
		
		
		function say(styleTyp, Width, vor, elson){
			if(!vor) {
				var lastel = _id.getElement('ul').getLast();
				lastel.setStyles({
					'marginLeft': '-'+Width+'px'
				});
				lastel.injectBefore(_id.getElement('ul').getFirst());
			}
			var firstel = _id.getElement('ul').getFirst();
			
			var efx = firstel.set('tween',{
				duration: 300,
				property: styleTyp,
				transition: Fx.Transitions.SineInOut,
				onStart: function() {
					testset++;
				},
				wait: false,
				onComplete: function(){
					if(vor) {
						_id.getElement('ul').getFirst().injectAfter(_id.getElement('ul').getLast());
						_id.getElement('ul').getLast().setStyle('marginLeft', '0px');
					}
					testset--;
				}
			});

			/*var efx = firstel.effect(styleTyp, {
				duration: 500,
				transition: Fx.Transitions.Bounce.easeOut,
				onStart: function() {
					testset++;
				},
				wait: false,
				onComplete: function(){
					if(vor) {
						_id.getElement('ul').getFirst().injectAfter(_id.getElement('ul').getLast());
						_id.getElement('ul').getLast().setStyle('marginLeft', '0px');
					}
					testset--;
				}

			});*/			
			if(vor) {
				efx.tween(0, -Width);
			} else {
				efx.tween(-Width, 0);
			}
		}
		
		function seta(section, count, settrue) {
			if(section == 'left') {
				var setturn = 'right';
			} else {
				var setturn = 'left';
			}
			
			section = new Element('div', {
				events: {
					click: function(ast){
						if (testset == 0) {
							say('marginLeft', count, settrue);
						}
					},
					mouseover: function() {
						this.setStyles({
							'backgroundPosition': '10px -40px'
						});
					},
					mouseout: function() {
						this.setStyles({
							'backgroundPosition': '10px 8px'
						});
					}
				},
				'class': 'arrow-slider',
				'id': 'arrow-'+setturn
			});
			if (settrue) {
				section.injectBefore(_id);
			} else {
				section.injectAfter(_id);
			}
		}
		seta('left', countELWidth, false);
		seta('right', countELWidth, true);
	
	
       go_ajax(
            '#slider', // ID oder class des/der divs in dem die a tags liegen die aufgerufen werden sollen
            'changeelement', // id des divs, welcher geupdated werden soll, ohne Raute!
            'ajax' // Angabe der Spalte die man benutzen möchte
        );
	}
});