/**
 * Funktionen in normalen Seiten
 *
 *
 *
 *
 */
//
//  ready?
//
$(document).ready(function(){
// Preisbox ein und ausblenden
  var allePreise =  $('#allePreise');
   allePreise.hide().prepend('<div  class="closeX" >close</div>');

  $('#preise a').toggle(function(e){
              e.preventDefault();
            allePreise.fadeIn('300');
        },
  function(e){
        e.preventDefault();
         allePreise.fadeOut('300');
  });
  $('div.closeX').click(function(){
                 $('#preise a').trigger('click');
        });
    /**
     * Sponsorenlogos grau-farbig tauschen
     */
	/*
	if($('#sponsor img').length){
		var startSrc = [];
		var sponsorenlogos = $('#sponsor img');
		var sponsorenpreloader = []; // array f�r die Bilder
		// Vorlader
		sponsorenlogos.each(function(index,elem){
			startSrc[index] = $(this).attr('src');
			var hreftemp = $(this).attr('src').replace(/uploads\/pics\//, "fileadmin/redaktion/bilder/sponsoren/"); // Stringteile ersetzen f�r URL des Farbbildes
			
		*/
			//hreftemp = hreftemp.replace(/grau\w*/, "c");
		/*
			sponsorenpreloader[index] = new Image();
			sponsorenpreloader[index].src = hreftemp;
		}); // Vorlader Ende
		sponsorenlogos.bind({ // Logos tauschen
			mouseover: function() {
				var index = sponsorenlogos.index(this);
				$(this).attr('src', sponsorenpreloader[index].src);		
			},
				mouseout: function() {
				var index = sponsorenlogos.index(this);
				$(this).attr('src', startSrc[index]);
			}
		})
	}
	*/
	/*
	if($('.sponsor_logo_grey').length){
		$('.sponsor_logo_color').hide();
		$('.sponsor_logo_grey').mouseover(function(){
			$(this).siblings('.sponsor_logo_color').show();
			$(this).hide()
		});
		$('.sponsor_logo_color').mouseout(function(){
			$(this).siblings('.sponsor_logo_grey').show();
			$(this).hide()
		});
	}
	*/
	
	//pagemachine:gbrandner:16.2.2012
	//display the images vertical centered within their wrappers
	$sl_wrapperHeight = $('.sponsor_logo_wrapper:first').height();
	$('.sponsor_logo_wrapper a img').each(function(){
		$sl_current_imageHeight = $(this).height();
		$sl_image_marginTop = Math.ceil(($sl_wrapperHeight-$sl_current_imageHeight)/2);
		$(this).css('margin-top',$sl_image_marginTop);
	});
	
	//pagemachine:gbrandner:16.2.2012
	//If hovering over an icon ... 
	$('.sponsor_logo_wrapper a').mouseover(function(){
		
		//... first remove all overlays, to prevent multiple openend overlays.
		$('.sponsor_info_overlay').remove();
		
		//... get the offset of the image, thatt the overlay can be displayed relative to the image position
		$sl_image = $(this).find('img');		
		if ($sl_image.length > 0) {
			$sl_image_position = $sl_image.offset();
			
			//... clone the infotext and insert it outside of everythig, so that the overlay lays above of all
			$sl_overlay = $(this).siblings('.sponsor_info').clone();
			$('body').append($sl_overlay);
			
			//... make some things with the overlay. The order of things inserted to the overlay is important.
			//Everything is inserted by prepend(). So all things are inserted as first element.
			//e.g the horizontal bar has to be inserted before the image, so when the image is inserted it is inserted before the bar
			$sl_overlay.addClass('sponsor_info_overlay');
			
			//insert the horizontal bar
			$sl_hr = '<hr class="sl_overlay_hr" />';
			$sl_overlay.prepend($sl_hr);
			
			//... insert the image in the overlay
			$sl_overlay.prepend($sl_image.clone());
			$('.sponsor_info_overlay').find('img').css('margin-top', '0');
			
			//... insert the close button
			$sl_overlay.prepend('<div class="sponsor_info_overlay_close">&nbsp;</div>');
			
			//... display the overlay
			$sl_overlay.show();
			
			//... insert the position of the overlay
			$sl_overlay.offset({
				top: $sl_image_position.top - 10,
				left: $sl_image_position.left - 10
			});
			
			
			$('.sponsor_info_overlay_close').click(function(){
				$('.sponsor_info_overlay').remove();
			});
			$sl_overlay.mouseleave(function(){
				$(this).remove();
			});
		}
	});
	
    /**
     *  aktives Navigationselement sichtbar lassen
     */
    $('#navBox').addClass('jsMenu');
    var aktivUL = $('#navBox.jsMenu li.visible ul');
     var aktivLi = $('#navBox.jsMenu ul .liAktiv');
         var liCollection = $('#navBox.jsMenu > ul >  li');
    if(liCollection.length > 0){
         liCollection.bind({mouseover : function(){
            $(this).find('ul li').addClass('liSichtbar');
            if(!($(this).hasClass('visible'))){
                aktivUL.addClass('visibleUnsichtbar');
              //  aktivLi.addClass('aktivUnsichtbar');
            }
        },
            mouseout : function(){
  $(this).find('ul li').removeClass('liSichtbar');
                 if(!($(this).hasClass('visible'))){
                     aktivUL.removeClass('visibleUnsichtbar');
            //    aktivLi.removeClass('aktivUnsichtbar');
            } // if ende
        } // mouseout ende
        }); // bind ende
        }// if liCollection length ende
}) // dom ready




