$(document).ready(function() {

	var IEVersion = getIEVersion();

    slideText('div#mainMenu', ' ul li a', 16, 10);
    stretchText('div#rightColumn', ' a.newslink', 0.03, 0, 444, 50);
    animateFontSize('div#upperNav', .95, 0.1);
	initFancyGalery();
	initLightBoxImages();
    
    if( IEVersion < 8 && IEVersion > -1 )
    {
    	showIEWarning();
    }
    
$("#mainMenu a[title]").tooltip({
	position: "center  right",
	offset: [0, 10],
	effect: "fade"
	});    
    
});

function slideText(navigation_id, nav_subelements, pad_out, pad_in) {

    var link_elements = navigation_id + nav_subelements;
    var theSubAncors = navigation_id + " li ul li a";

    $(link_elements).each(function(i) {
        $(this).hover(
    		function() {
    		    $(this).stop().animate({ paddingLeft: pad_out }, 470);
    		},
    		function() {
    		    $(this).stop().animate({ paddingLeft: pad_in }, 150);
    		});
    });
    
    $(theSubAncors).unbind('mouseover').unbind('mouseout');    
}

function stretchText(navigation_id, nav_subelements, stretchValue, defaultValue, stretchTime, defaultTime) {

    var link_elements = navigation_id + nav_subelements;

    $(link_elements).each(function(i) {
        $(this).hover(
    		function() {
    		    $(this).stop().animate({letterSpacing: stretchValue + "em"}, stretchTime);
    		},
    		function() {
    		    $(this).stop().animate({letterSpacing: defaultValue + "em"}, defaultTime);
    		});
    });
}

function animateFontSize(navigation_id, theFontSize, fontSizeDelta) {

    var theAncors = navigation_id + " a";

    if (theFontSize > 0) {

        $(theAncors)
	    .css({ fontSize: theFontSize + "em" })
	    .mouseover(function() {
	        $(this).stop().animate(
			    { fontSize: theFontSize + fontSizeDelta + "em" },
			    { duration: 250 })
	    })
	    .mouseout(function() {
	        $(this).stop().animate(
			    { fontSize: theFontSize + "em" },
			    { duration: 70 })
	    })

    }
 }
 
 function getIEVersion(){

   var rv = -1;
   if (navigator.appName == 'Microsoft Internet Explorer')
   {
      var ua = navigator.userAgent;
      var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
      if (re.exec(ua) != null)
         rv = parseFloat( RegExp.$1 );
   }
   return rv;
}
 
function showIEWarning() {
	$("body").prepend('<p id="attention_ie6"><a href="http://www.browserchoice.eu/" target="_blank" title="Einen aktuellen Webbrowser ausw&auml;hlen!"><b>Hinweis: Ihr Internet-Browser ist veraltet!</b><br /> Einige Bereiche dieser Internetseite k&ouml;nnen m&ouml;glicherweise  nicht korrekt angezeigt werden. Klicken Sie hier, um einen aktuellen Internetbrowser zu erhalten.</a></p>');
	  $("#attention_ie6").css('display','none');
	  $("#attention_ie6").slideDown(1000);
}

function initFancyGalery() {

	var theHREFs;
	var theParentId = '';
	var item;
	
	jQuery('div.image_galery').each(function() {
		
		jQuery('a.fancyGaleryLink', this).click(function() {
		
			var theParent = jQuery(this).parent();
			
			//die passende div suchen
			while(theParent && theParent.attr("class") != 'image_galery')
				theParent = theParent.parent();
				
			theHREFs = new Array();
			
			//alle Anker mit der Klasse 'fancyboxImg' verwenden
			theParentId = '#' + theParent.attr("id")  + ' .fancyboxImg';
			
			jQuery(theParentId).each(function() {
				item = {href: jQuery(this).attr("href"), title: '<b>' + jQuery(this).attr("title") + '</b>'};
				theHREFs.push(item);
			});	
			
			jQuery.fancybox(theHREFs,
				{
					'padding'		: 0,
					'transitionIn'	: 'elastic',
					'transitionOut'	: 'elastic',
					'type'			: 'image',
					'hideOnContentClick': true,
					'titleShow'		: true,
					'titlePosition' : 'over',
					'easingIn': 'swing',
					'easingOut': 'easeInBack',
					'overlayShow': true,
					'overlayOpacity': 0.7,
					'overlayColor': '#000',
					'centerOnScroll': true,
					'titleFormat': formatTitle
				}
			);
		});
			
	});
}

function initLightBoxImages() {

	var theLink = "";
	
	jQuery(document).ready(function() {
	
		jQuery('img.lightbox').each(function() {
			theLink = jQuery(this).attr("src");
			theLink.split("&")[0].split("=")[1]; 
			theLink = theLink.replace('[(site_url)]','');
			theLink = theLink.replace('thumb_','');
			jQuery(this).wrap('<a rel="imagegroup" href="'+theLink+'" class="fancybox" title="'+this.title+'"></a>');
		});
		
				  
		jQuery('a.fancybox').fancybox({
			'padding': 0,
			'speedIn': 500,
			'speedOut': 300,
			'changeSpeed': 300,
			'transitionIn': 'elastic',
			'transitionOut': 'elastic',
			'titlePosition': 'over',
			'titleShow': true,
			'easingIn': 'swing',
			'easingOut': 'easeInBack',
			'overlayShow': true,
			'overlayOpacity': 0.7,
			'overlayColor': '#000',
			'centerOnScroll': true,
			'hideOnContentClick': true,
			'onStart': function() {
				jQuery('#fancybox-title').hide();
			},
			'onComplete' : function() {
				jQuery('#fancybox-wrap').hover(function() {
					jQuery('#fancybox-title').show();
				}, function() {
					jQuery('#fancybox-title').hide();
				});},
	        'titleFormat': formatTitle	
			});			  
		
		});
		
}

function formatTitle(title, currentArray, currentIndex, currentOpts) {
	return '<span id="fancybox-title-over">Bild ' + (currentIndex + 1) + '/' + currentArray.length + ': ' + title + '</span>';
};


