google.load("jquery", "1.3.2");
 
google.setOnLoadCallback(function() {
	
	// make the sidebar & main equal height

		var sidebarHeight = $('.sidebar').height();
		var mainHeight    = $('.main').height();

		if( sidebarHeight > mainHeight ) {
			$('.main .container').height(sidebarHeight);
		} else {
			$('.sidebar').height(mainHeight);
		};
		
		equalHeight($(".col .container"));
		
		function equalHeight(group) {
		         tallest = 0;
		         group.each(function() {
		             thisHeight = $(this).height();
		             if(thisHeight > tallest) {
		                 tallest = thisHeight;
		             }
		         });
		         group.height(tallest);
		     }

		

	// make the product-info & tech-info equal height

		var prodiHeight = $('.product-info').height();
		var techiHeight = $('.tech-info').height();

		if( techiHeight > prodiHeight ) {
			$('.product-info .container').height(techiHeight);
		} else {
			$('.tech-info').height(prodiHeight);
		};
		
	// calculate margin
	
		var logosWidth = 0;
		var logoNr = $(".partners a").size();
		var partnersWidth = 940; 
		$(".partners a").each(function(i){ 
			var logoWidth = $(this).width(); 
			logosWidth += logoWidth; 
		}); 
	
		var logoMarginTotal = 940 - logosWidth;
		var logoMargin = logoMarginTotal / logoNr;
		// alert(logoMargin);

		$('.partners a:not(:last)').css('margin-right', logoMargin);
		
		$('.partners a').wrapAll('<div class = "partners-inside"></div>');
		$('.partners-inside').width(logosWidth + logoMargin * logoNr - logoMargin).append('<div class="clear"></div>')	
		
		// scrollTop

		    $('.go-top').each(function (i) {
		        $(this).click(function() {
		      		$('html, body').animate({scrollTop:0}, 'slow'); return false;
		        });          
		    });

		// news section forst and last element
		
		$('.sidebar p:last').addClass('last');
		$('.sidebar p:first').addClass('first');

		// slider with one element shown once

	    var prevButton    = $("#prev-img");
	    var nextButton    = $("#next-img");

		var elementTag = $(".mini-gallery-holder ul li");
		var elementHolder = $(".mini-gallery-holder ul");

	    var elementWidth  = 460;
	    var holderPosition  = 0;
	    var elementWidthTotal = elementTag.length * elementWidth;

	    elementHolder.width(elementWidthTotal);

		hideControl();

	    prevButton.click(function() {
	        if(holderPosition < 0) {
	            holderPosition  = holderPosition + elementWidth;
	            elementHolder.animate({
	                'left': holderPosition + 'px'
	            });
				hideControl();
	        }
	        return false;
	    });

	    nextButton.click(function() {
	    		if((holderPosition-elementWidth) > -(elementWidthTotal)) {
	            holderPosition  = holderPosition - elementWidth;
	            elementHolder.animate({
	                'left': holderPosition + 'px'
	            });
				hideControl();
	        }
	        return false;
	    });

		function hideControl() {
			switch(holderPosition) {
				case 0:
					prevButton.hide();
					break;
				case -(elementWidthTotal - elementWidth):
					nextButton.hide();
					break;
				default:
					prevButton.show();
					nextButton.show();
			}
		}
});

