$(function(){

	// slidehow
	$( '#slideshow div.gallery' ).css( 'overflow', 'visible' );
	$( '#slide-left, #slide-right' ).show();
	$( '#slideshow div img' ).slidingGallery({

		Lwidth: 412,
		Lheight: 249,
		Lzoom: function(dimension) {
					return dimension * 1.4;
				},
		gutterWidth: 0,
		container: $( '#slideshow div' )

	});

	var slideRightPoint = function(){
		
		var relImg;
		var imgLngth = $( '#slide-points' ).children( 'img' ).length;

		$( '#slide-points' ).children( 'img' ).each(function(){

			if( $(this).attr('src') == 'images/slide-nav_point_blue.png' ){
				relImg = $(this).attr('id');
			}

			$( this ).attr( 'src', 'images/slide-nav_point_grey.png' );

		});

		relImg = ( parseInt(relImg.substr(6)) >= imgLngth ? 0 : parseInt(relImg.substr(6)) );

		$( 'img[id="slide-'+ ++relImg +'"]' ).attr( 'src', 'images/slide-nav_point_blue.png' );

	};
	
	var slideLeftPoint = function(){
		
		var relImg;
		var imgLngth = $( '#slide-points' ).children( 'img' ).length;

		$( '#slide-points' ).children( 'img' ).each(function(){

			if( $(this).attr('src') == 'images/slide-nav_point_blue.png' ){
				relImg = $(this).attr('id');
			}

			$( this ).attr( 'src', 'images/slide-nav_point_grey.png' );

		});

		relImg = ( parseInt(relImg.substr(6)) <= 1 ? ++imgLngth : parseInt(relImg.substr(6)) );
		relImg--;

		$( 'img[id="slide-'+ relImg +'"]' ).attr( 'src', 'images/slide-nav_point_blue.png' );

	};

	$( '#slide-right' ).click(function(){

		slideRightPoint();

	});
	$( '#slide-left' ).click(function(){

		slideLeftPoint();

	});
	
	// boxes bottom
	$( '.box' ).children( 'p,ul' ).hide();
	$( '.box-btn' ).click(function(){
		
		$( '.box' ).children( 'p,ul' ).slideUp();
		if ( $( this ).parent().children( 'p,ul' ).is(':visible') ){
			
			$( this ).parent().children( 'p,ul' ).slideUp();
		
		} else{
			
			$( this ).parent().children( 'p,ul' ).slideDown();
			
		}
		

		return false;
		
	});
	
	var boxid;
	
	boxid = $( 'body' ).attr( 'id' );
	$( '#box-'+ boxid ).children( 'p,ul' ).slideDown();

	if ( $( '.'+ boxid ).parent().attr('class') == 'n-166' ){
		
		boxid = 'projektentwicklung';
		
	} else if ( $( '.'+ boxid ).parent().attr('class') == 'n-167' ){
		
		boxid = 'bauausfuehrung';
		
	} else if ( $( '.'+ boxid ).parent().attr('class') == 'n-168' ){
		
		boxid = 'frachten-und-transport';
		
	}

	$( '#box-'+ boxid ).children( 'p,ul' ).show();
	
	$( '.box a' ).each(function(){

		getLink = $( this ).attr( 'href' );	
		$( this ).attr( 'href', getLink +'#ct' );		
		
	});
	
	
	// footer slide
	$( '.imgsmall' ).each(function(){

		var getSrc,
			cut;
		
		cut = '_t';

		$( this ).mouseover(function(){

			getSrc = $( this ).attr( 'src' );
			getSrc = getSrc.split( cut );

			$( '#imgbig' ).attr( 'src', getSrc[0] + getSrc[1] );

		});

	});
	
	
	// Accordion
	$("#accordion").accordion({ autoHeight: false, header: "h6" });


	// font replacements
	Cufon.replace( '#nav ul li a, ul#nav li div h3, #slideshow h3', { fontFamily: 'Myriad Pro' } );
	Cufon.replace( '#content div.box h3', { fontFamily: 'Helvetica93-ExtendedBlack' } );
	Cufon.replace( 'a.box-btn', { fontFamily: 'Helvetica83-ExtendedHeavy' } );

});

