/* Hack for all browsers to load the slider nicier way. The #slider has default property of display:none in css(for nice IE loading), then when js is loaded it changes to block (so Opera can
render height of the slider properly while loading images), and then hides it again. Later, when all images are loaded - the fadeIn function kicks in. */
jQuery('#slider').css({display: "block"}).hide();

/* Start of functions initialized after full load of page */
jQuery(window).load(function(){
	
	jQuery('#sliderkunden').fadeIn(900);
	jQuery('#sliderkunden .df_container a').each(function()
	{
		$(this).appendTo('#sliderkunden');
	});
	jQuery('#sliderkunden .df_container IMG').each(function()
	{
		$(this).appendTo('#sliderkunden');
	});
	
	jQuery('#sliderkunden .df_container').remove();
	
	
	jQuery('#sliderkunden').nivoSlider({
		effect:"fade",
        slices:15,
        boxCols:4,
        boxRows:4,
        animSpeed:500,
        pauseTime:3000,
        startSlide:0,
        directionNav:true,
        directionNavHide:true,
        controlNav:false,
        controlNavThumbs:false,
        controlNavThumbsFromRel:true,
        keyboardNav:true,
        pauseOnHover:true,
        manualAdvance:false
	});

	
	/* Add special rounded corners to the Slider */
	jQuery('.inner_main .nivoSliderheader').append('<div class="slider_cover_tl png_bg"></div><div class="slider_cover_tr png_bg"></div><div class="slider_cover_br png_bg"></div><div class="slider_cover_bl png_bg"></div>');
	
	/* Make the Slider navigation bullets align to center automaticly */
	var dotsMargin = jQuery('.inner_main .nivo-controlNav').width();
	jQuery('.inner_main .nivo-controlNav').css('margin-left', -dotsMargin/2);
	
	/* Adding some Border magic */
	var borderSubject = jQuery('.inner_main .border_magic, #footer .border_magic');
	borderSubject.wrap('<div class="add_border" />');
	
	/* Transfering alignment to added border */
	var bordered = jQuery('.inner_main .add_border, #footer .add_border');
	bordered.find('.alignleft').removeClass('alignleft').parent().addClass('alignleft');
	bordered.find('.alignright').removeClass('alignright').parent().addClass('alignright');
	bordered.find('.no_bottom_margin').removeClass('no_bottom_margin').parent().addClass('no_bottom_margin');
	
	
	/* Making the added border width completely automatic */
	borderSubject.each(function(){
	var addBordi = jQuery(this).width();
	jQuery(this).parent().width(addBordi+10);
	});
	
	/* Smooth image load */
	borderSubject.fadeIn(1500).parent().delay(1500).queue(function() {jQuery(this).css('background-image','url(css/img/zoom.png)');});
	
	/* Catch the height of longest footer column and stretch the others to the same size */
	var highHeels = 0;
	jQuery('#footer .widget').each(function(){
	var topHeels = jQuery(this).height();
	if(topHeels > highHeels){highHeels = topHeels};
	});
	jQuery('#footer .widget').height(highHeels);
	
	/* Cycle the "Hot stuff this week" */
	jQuery('.hotstuff ul, ul.testimonials').cycle({
		fx: 'fade',
		timeout:       4000,
		speed:         1000,
		before: onAfter
	});
	function onAfter(curr, next, opts, fwd){
        //get the height of the current slide
        var ht = jQuery(this).height();
        //set the container's height to that of the current slide
        jQuery(this).parent().animate({height: ht});
	}
});


jQuery(document).ready(function() {
	$('.showhide').click(function() {
		  $('#'+$(this).attr("name")).slideToggle('fast', function() {
			// Animation complete.
		  });
		});
});
