$(function() {
	// center main window
	onResizeWindow();
	onResizeWindow();
	$(window).resize( function() {
		onResizeWindow();
		onResizeWindow();		
	});
	
	$('form input:text, form textarea')
		.focus( function() {
                        var val = $(this).attr('value');
                        $(this).data('val', val);
			$(this).attr('value', '');
	});
	// $('form input:text, form textarea')
                // .blur( function() {
                        // var val = $(this).data('val');
                        // if(val != 'undefined')
                            // $(this).attr('value', val);
        // });
	
	if( $('*').is('.tplFacts') ) {
		$('.tab-1 a, .tab-2 a, .tab-3 a').click( function(e) {
			e.preventDefault();
			$('.text-1, .text-2, .text-3').css('display', 'none');
			//alert($(this).parent().parent().attr('class'));
			//alert($('.text-'+$(this).parent().parent().attr('class').substr(5,1)).css('display'));
			$('.text-'+$(this).parent().parent().attr('class').substr(4,1)).css('display', 'block');
		});
	}
	
	if( $('*').is('.tplClients') ) {
		$('.tplClients div.client-img > a > img').hover( function() {
			$(this).attr('src', $(this).parent().next().attr('src'));
		}, function() {
			$(this).attr('src', $(this).parent().next().next().attr('src'));
		});
	}
	
	if( $('*').is('.tplTeam') ) {
		$('.person-1, .person-2, .person-3, .person-4').mouseover( function() {
                        var isHighlighted = $(this).parent().data('isHighlighted');
                        if (isHighlighted != true) {
                            $('.description div').css('display', 'none');
                            $('.text-'+$(this).attr('class').substr(7,1)).css('display', 'block');

                            if( $(this).find('img').attr('src').lastIndexOf('1') ) {
                                    switch( $(this).attr('class') ) {
                                            case 'person-1':
                                                    $width = '114px';
                                                    $height = '217px';
                                                    break;
                                            case 'person-2':
                                                    $width = '126px';
                                                    $height = '217px';
                                                    break;
                                            case 'person-3':
                                                    $width = '136px';
                                                    $height = '217px';
                                                    break;
                                            case 'person-4':
                                                    $width = '144px';
                                                    $height = '217px';
                                                    break;
                                    }
                                    var $top = parseInt( $(this).css( 'top' ) )-20+'px';
                                    var $left = parseInt( $(this).css( 'left' ) )-10+'px';	
                                    var $fileAr = $(this).find('img').attr('src').split('/');
                                    $(this).find('img').attr('src', 'fileadmin/user_upload/characters/2'+$fileAr[$fileAr.length-1].substr(1, 1)+'.png');
                                    $(this).find('img').stop().animate( { 'width':$width, 'height':$height }, 100 );
                                    $(this).stop().animate( { 'top':$top, 'left':$left }, 100 );
                                    $(this).parent().data('isHighlighted', true);
                            }
                        }
			/*
			}, function() {
				switch( $(this).attr('class') ) {
					case 'person-1':
						$top = '0';
						$left = '60px';
						$width = '93px';
						$height = '182px';
						break;
					case 'person-2':
						$top = '0';
						$left = '170px';
						$width = '105px';
						$height = '182px';
						break;
					case 'person-3':
						$top = '0';
						$left = '280px';
						$width = '112px';
						$height = '182px';
						break;
					case 'person-4':
						$top = '0';
						$left = '400px';
						$width = '120px';
						$height = '182px';
						break;
				}
				$(this).find('img').stop().animate( { 'width':$width, 'height':$height }, 100 );
				$(this).stop().animate( { 'top':$top, 'left':$left }, 100, '', function() {
					var $fileAr = $(this).find('img').attr('src').split('/');
					$(this).find('img').attr( { 'src':'fileadmin/user_upload/characters/1'+$fileAr[$fileAr.length-1].substr(1, 1)+'.png' } );
				} );*/
		});		
	}
	
});

function onResizeWindow() {
	
	var $w = $(window);
			var $layer = $('#wrapper');
			$wWidth = parseInt( $w.width() );
			$wHeight = parseInt( $w.height() );
			$lWidth = parseInt( $layer.css('width') );
			$lHeight = parseInt( $layer.css('height') );
			if( $wWidth > $lWidth ) {
				$layer.css( 'margin', '10px 0 0 0' );
				$layer.css( 'left', ($wWidth/2-$lWidth/2)+'px' );
			} 
			if( $wHeight > $lHeight ) {
		      $layer.css( 'margin', '10px 0 0 0' );
				$layer.css( 'top', ($wHeight/2-$lHeight/2)+'px' );
		   } else {
				$layer.css( 'margin', '10px 0 0 0' );
				$layer.css( 'top', '0' );
			}
			
		   var $bgWidthHeight = 1024;
		   var $bgLeft = ($wWidth/2)-($bgWidthHeight/2);
		   var $bgTop = ($wHeight/2)-($bgWidthHeight/2);
}

function flashToTheFront() {
	$('#teaser').css('z-index', 1000);
	$('#col-1, #col-2, #col-3').css('display', 'none');
	$('#metanav ul').find('li:eq(1)').remove().end().find('li:eq(0) > a').text('ZURÜCK ZUR HOMEPAGE').attr('href', location.href);
}


