
tb_pathToImage = "/fileadmin/templates/images/ajax-loader.gif";

var pageInit = function( $page, IsAjax ){
	
	/* THICKBOX_CONTENT: */
		
		jQuery.each($page.find('.IVspalten a.internal-link-new-window, a.internal-thickbox'), function(){
			var url = jQuery(this).attr('href');
			url = url + ( url.indexOf('?')>0 ? '&':'?' ) + 'thickboxed=true&TB_iframe=true&height=415&width=740';
			jQuery(this)
			.addClass('thickbox')
			.attr('href', url )
			.click(function(){
				var t = this.title || this.name || null;
				var a = this.href || this.alt;
				var g = this.rel || false;
				tb_show(t,a,g);
				return false;
			});
		});
		if( document.location.href.indexOf('thickboxed=true')>0 ){
			jQuery.each($page.find('form'), function(){
				jQuery(this).attr('action', jQuery(this).attr('action') + '?thickboxed=true');
			});
		}
		
	/* :THICKBOX_CONTENT */
	
	/* IMAGE_HEIGHT_FIX: */
		
		jQuery.each($page.find('.csc-textpic'), function(){
			var maxH = jQuery(this).find('.csc-textpic-image img:eq(0)').attr('height');
			maxH = maxH<=0 ? 200 : maxH;
			jQuery(this).find('.csc-textpic-imagewrap, .csc-textpic-imagecolumn').css({ height: maxH + 'px', overflow:'hidden' });
		});
		
	/* :IMAGE_HEIGHT_FIX */
	
	/* IMAGE_GALLERY: */
		
		if( typeof(IsAjax)!='undefined' && IsAjax ){
			tb_init($page.find('.csc-textpic-image a'));
		}
		jQuery.each($page.find('.csc-textpic-imagewrap'), function(){
			var $thisG = jQuery(this);
			var steps = $thisG.find('.csc-textpic-image').length;
			if( steps==1 ){
				$thisG.find('.csc-textpic-imagecolumn').append('<div class="info"><span class="current">+</span></div>');
			}else{
				var stepsW = $thisG.find('img:first').attr('width') / steps;
				$thisG.find('.csc-textpic-imagecolumn').append('<div class="info"><span class="current">1</span>/<span class="count">' + steps + '</span></div>');
				$thisG.find('.csc-textpic-imagecolumn').css({position:'relative'}).mousemove(function(e){
					var iPos = e.pageX - $thisG.position().left;
					for(var i=0; i<steps; i++){
						if( iPos > (i*stepsW) && iPos < ((i+1)*stepsW) ){
							$thisG.find('.csc-textpic-image').hide();
							$thisG.find('.csc-textpic-image:eq(' + i + ')').show();
							$thisG.find('.info .current').html( i+1 );
						}
					}
					
				});
				$thisG.find('.csc-textpic-image')
					.css({position:'absolute', top:0, left:0})
					.hide();
				$thisG.find('.csc-textpic-image:first').show();
			}
		});
		
	/* :IMAGE_GALLERY */
	
	/* LAZYLOAD: */
		
		$page.find('img:not(#statement)').lazyload({         
			placeholder: '/fileadmin/templates/images/grey.gif',
			container: jQuery("#content_scroll")
		});
		
	/* :LAZYLOAD */
	
}

/* NEWSLETTER_FORM: */
	
	var success = 'Vielen Dank fuer die Abonnierung unseres Newsletters.';
	var failed = 'Bitte geben Sie eine gueltige Emailadresse ein.';
	function alertSubscribed(){
		doc = document.forms['em_newsletter'];
		if( doc.email.value.replace(/\s/,"").length == 0 ){
			alert(failed);
			return false;
		}else{
			alert(success);
			return true;
		}
	}
	
	jQuery(function($){
		jQuery('#em_newsletter input:eq(0)').focus(function(){
			var val = jQuery(this).val();
			if( val=='Sign Newsletter' ){
				jQuery(this).val('');
			}
		}).blur(function(){
			var val = jQuery(this).val();
			if( val=='' ){
				jQuery(this).val('Sign Newsletter');
			}
		});
	});
	
/* :NEWSLETTER_FORM */

jQuery(function($){
	pageInit( jQuery('body') );
});

