// JavaScript Document

rec=0;		//recursion counter
dcount = 0;	//debug-counter
cswitch=1;	//cycle switch eingeschaltet

function mydebug(debugstring){
	
	if(!document.all && !(typeof(console) == 'undefined'))
	{
		console.log(dcount++ +' | ' + debugstring);
		}
	
	}

mydebug('running');


	/* ChekForm */
	
function formcheck()
	{
		//mydebug($('#callback_numbername').attr('defaultValue'));
		
		if(
			$('#callback_numbername').val().length > 3 &&
			$('#callback_numbername').val() != $('#callback_numbername').attr('defaultValue')
			//auf nummer und zahl testen?
			){
				mydebug('gute Inhalte');
				return true;
				}
		$('#callback_numbername').css('border-color','#f00');
		
		/*
		$('#callback_numbername').tipTip({
			edgeOffset: 6,
			fadeOut: 400,
			maxWidth:'300px',
			content:'Na... mehr als drei Zeichen werden Sie doch für mich haben?!',
			enter:function(){
				/*
				setTimeout(function(){
					$('#callback_numbername').tipTip();
					},3000)//
				}
			});*/
		return false;
	}



function cycle(elem,fspeed,cwait){
	
	/*
	element:	selector
	fspeed:		fading speed
	cwait:		cycle wait: time between fadings; 0 => no recursion
	*/
	
	mydebug('cycle()['+ rec++ +'] '+fspeed+' | '+cwait);
	
	$(elem+':first')
		.animate({
			opacity: 0,
			height: 'toggle'
			},fspeed,function(){
				//move li
				saveme=$(this);		//li zwischenspeichern
				$(this).remove();
				$('#list_projects').append(saveme);
				
				$(this).css({
					opacity: 1,
					display: 'block'
					})
				
				if(cwait!=0 && cswitch!=0)
					ctimer=window.setTimeout(function(){cycle(elem,fspeed,cwait);}, cwait);	//rekursiv aufrufen
			})
	}



$(document).ready(function() {
	
	mydebug("ready");

	
	/*XING-Events*/
	xew_height=$("#xew").css("height");if(xew_height=="auto")xew_height="255px";
	window.setTimeout(function(){
		$("#xew").animate({
					"height":"80px",
					"opacity":0.3,
					"-moz-box-shadow":"0 0 1px #aaa",
					"-webkit-box-shadow":"0 0 1px #aaa",
					"box-shadow":"0 0 1px #aaa"
					  }, 1000, function() {
						// Animation complete.
					  });
	},1000);
	
	$("#xew")
	.bind('mouseenter',function(){
		
		$(this).stop().animate({
				"height":xew_height,
				"opacity":1,
				"-moz-box-shadow":"2px 2px 5px #aaa",
				"-webkit-box-shadow":"2px 2px 5px #aaa",
				"box-shadow":"2px 2px 5px #333333"
				  }, 400, function() {
					// Animation complete.
				  });
		})
	.bind('mouseleave',function(){
							  
		$(this).stop().animate({
				"height":"80px",
				"opacity":0.3,
				"-moz-box-shadow":"0 0 1px #aaa",
				"-webkit-box-shadow":"0 0 1px #aaa",
				"box-shadow":"0 0 1px #aaa"
				  }, 200, function() {
					// Animation complete.
				  });
		})
	
	
	/*TitleTip*/
	
	$(".help").tipTip({
		edgeOffset: 6,
		fadeOut: 400,
		maxWidth:'300px'
		});
	$('#callback_numbername').tipTip({
		activation:'focus',
		fadeOut: 400,
		fadeIn: 600
		});
	
	
	/*Cycle*/
	
	ctimer=window.setTimeout(function(){cycle('#list_projects li',2000,4000);}, 1000);//fspeed, cwait, 1st delay
	
	$('#cycle_next, #list_projects')
	.bind('mouseenter',function(){
		
		cswitch=0;				//naechste rekursion verhindern
		clearTimeout(ctimer);	//aktueller timer
		
		/*
		$('#list_projects')
		.stop().animate({
			'height':'8.5em'
			},500)*/
		
		mydebug('manuell: enter | cswitch='+cswitch);
		
		})
	.bind('mouseleave',function(){
		mydebug('manuell: leave');
		ctimer=window.setTimeout(function(){cycle('#list_projects li',2000,4000)},300);	//sofort normal weiter
		cswitch=1;				//naechste rekursion erlauben
		
		/*
		$('#list_projects')
		.stop().animate({
			'height':'5em'
			},1000)*/

		})
	$('#cycle_next')
	.bind('click',function(){
		mydebug('manuell: click next');
		cycle('#list_projects li',500,0)		//0-> no recursion		
		})
	
	
	/*callback-form*/
	
	$('#callback_numbername')
	.bind('focusin focusout', function(){
		
		$(this).toggleClass('active');
		

		if(this.value == this.defaultValue){
			this.value="";
			}else
				if(this.value=="")
					{this.value = this.defaultValue}
		})//bind numbername

	.bind('keypress',function(){
		
		if((this.value != this.defaultValue) && (this.value.length >2)){
			$(this).css({
					'color':'#000',
					'background-color':'#fff',
					'background-image':'none'
					});
			$('#callback_submit').css('color','#09c');
			}
		
		})
	
	$('#callback_submit')
	.bind('focusin focusout', function(){
		$(this).toggleClass('active');					   
		})//bind submit
	
	
	/*boxen springen*/
	
	$('.bbox')
		.bind('mouseenter', function(){
			
			$(this).stop().animate({
				bottom: '20px'
				  }, 200, function() {
					// Animation complete.
				  });			
			})
		.bind('mouseleave', function(){
			
			$(this).stop().animate({
				bottom: '0'
				  }, 500, function(){
					// Animation complete.
				  });			
			
			})
	/*Menge der Projekteinträge ausgeben*/
	$('#list_projects_len')
		.html(
			"("+
				$('#list_projects li').length
			+")")
		.tipTip({
			defaultPosition:'top',
			maxWidth:'150px',
			content: 'Auswahl aus allen Projekten. Mehr Informationen zu den Inhalten und weiteren Arbeiten gern auf Anfrage'
			})
		.addClass('help');
	
	/* PNGfix für IE5.5+ */
	$(document).pngFix();

	})
