cf																	= 0;


$(document).ready(function()
  {
  //correctPNG();
  cx_autoheight();
  
  Cufon.replace('#cx_links h2, .home-box h2',
    {
    hover															: true
    });
  
  $('.cx-jcarousel-lite').jCarouselLite(
	{
    btnNext: '.cx-weiter-working',
    btnPrev: '.cx-zurueck-working',
	visible: 6,
	start: parseInt($('.home-box[autostart=1]').attr('pos'))
	});
  
  
  /* jcarousel
  ----------------------------------------------------------------*/
  for(i=0;i<$('.cx-jcarousel-home-box .cx-jcarousel-lite a').length;i++)
    {
	$('.cx-jcarousel-home-box .cx-jcarousel-lite a:eq('+i+')').css('background-image','url('+$('.cx-jcarousel-home-box .cx-jcarousel-lite a:eq('+i+')').attr('cx_back')+')');
	}
  $('.home-box-selected').css('background-image','url('+$('.home-box-selected').attr('cx_back')+')');
  
  $('.cx-jcarousel-home-box .cx-jcarousel-lite a').click(function()
    {
	$('.cx-jcarousel-home-box .cx-jcarousel-lite li').removeClass('cx-selected');
	$(this).parents('li').addClass('cx-selected');
	$('.home-box').hide();
	
	if($('#'+$(this).attr('ref')).attr('geladen') != '1')
	  {
	  $('#'+$(this).attr('ref')).css('background-image','url('+$('#'+$(this).attr('ref')).attr('cx_back')+')');
	  $('#'+$(this).attr('ref')).attr('geladen',1);
	  }
	$('#'+$(this).attr('ref')).show();
	});
  
  /*
  if($('.home-box[autostart=1]').length && !$('.home-box[autostart=1]').hasClass('home-box-selected'))
    {
	$('.cx-jcarousel-lite ul li a[autostart=1]').trigger('click');
	$('.cx-jcarousel-lite ul li a[autostart=1]').parents('li').addClass('cx-selected');
	}
  */
  
  /* contentflow
  ----------------------------------------------------------------*/
  if($('#contentFlow').hasClass('ContentFlow'))
    {
	cf																= new ContentFlow('contentFlow',
      {
	  //reflectionType : 'none'
	  startItem: parseInt($('.ContentFlow .item[autostart=1]').attr('pos')),
	  scaleFactor: 1.8,
	  flowSpeedFactor: 0.3,
	  onclickActiveItem: function(obj)
	    {
		id_element													= obj.element.id;
		int_id_element												= id_element.replace(/[^0-9]/g,'');
		$('#lightbox_'+int_id_element+'_0').trigger('click');
		},
	  onMakeActive: function(obj)
	    {
		id_element													= obj.element.id;
		int_id_element												= id_element.replace(/[^0-9]/g,'');
		$('.cx-subnavi-publikationen ul li').removeClass('cx-selected');
		$('.cxid-'+int_id_element).addClass('cx-selected');
		}
	  });

	$('.pfeil-links a').click(function()
	  {
	  obj_aktiv														= cf.getActiveItem();
	  id_element													= obj_aktiv.element.id;
	  pos															= parseInt($('#'+id_element).attr('pos'))-1;

	  if(pos < 0)
	    {
		pos															= cf.getNumberOfItems()-1;
		}
	  cf.moveTo(pos);
	  });
	$('.pfeil-rechts a').click(function()
	  {
	  obj_aktiv														= cf.getActiveItem();
	  id_element													= obj_aktiv.element.id;
	  pos															= parseInt($('#'+id_element).attr('pos'))+1;

	  if(pos == cf.getNumberOfItems())
	    {
		pos															= 0;
		}
	  cf.moveTo(pos);
	  });
	}
  else
    {
	$('.pfeil-links a,.pfeil-rechts a').click(function()
	  {
	  if($(this).attr('rel') != '')
	    {
		document.location.href										= $(this).attr('rel');
		}
	  });
	}
  
  
  /* contentflow subnavi
  ----------------------------------------------------------------*/
  $('.cx-subnavi-publikationen ul li a[rel!=\'\']').click(function()
    {
	$('.cx-subnavi-publikationen ul li').removeClass('cx-selected');
	$(this).parents('li').addClass('cx-selected');
	cf.moveTo($(this).attr('rel'));
	});
  
  
  /* footer identische hoehen
  ----------------------------------------------------------------*/
  h_max																= 0;
  for(i=0;i<$('#cx_footer .cx-zeile-0 div').length;i++)
    {
	h_max															= Math.max(h_max,$('#cx_footer .cx-zeile-0 div:eq('+i+')').height());
	}
  $('#cx_footer .cx-zeile-0 div').height(h_max);
  h_max																= 0;
  for(i=0;i<$('#cx_footer .cx-zeile-1 div').length;i++)
    {
	h_max															= Math.max(h_max,$('#cx_footer .cx-zeile-1 div:eq('+i+')').height());
	}
  $('#cx_footer .cx-zeile-1 div').height(h_max);
  });

$(window).resize(function()
  {
  cx_autoheight();
  });


function cx_autoheight()
  {
  zusatz															= 2;
  if($('body').hasClass('breit'))
    {
	zusatz															= 2;
	}
  $('#cx_content').css('min-height',($(window).height()-$('#cx_footer').outerHeight()-$('#cx_header').outerHeight()-parseInt($('#cx_content').css('padding-top'))-parseInt($('#cx_wrap').css('padding-top'))-zusatz)+'px');
  if(ie6)
    {
	$('#cx_content').css('height',($(window).height()-$('#cx_footer').outerHeight()-$('#cx_header').outerHeight()-parseInt($('#cx_content').css('padding-top'))-parseInt($('#cx_wrap').css('padding-top'))-zusatz)+'px');
	}
  $('.cx-pfeil').height($('.inhalt').outerHeight()-10);

  if($('#jahrbuch_preise').length)
	{
	jahrbuch_init();
	}
  }


arr_preise                                                          = new Array();
arr_preise['individuell']                                           = new Array();
arr_preise['individuell2']                                          = new Array();
arr_preise['neutral']                                           	= new Array();
arr_preise['einleger']                                           	= new Array();
arr_kats                                                            = ['neutral','individuell','einleger','individuell2'];
str_kat_preis                                                       = 'neutral';
int_ausgabe                                                         = 0;
jahrbuch_ust                                                        = 0;

function jahrbuch_init()
  {
  jahrbuch_ust                                                      = parseInt($('#jahrbuch_preise').attr('title'));
  for(k=0;k<arr_kats.length;k++)
	{
	str_kat                                                         = arr_kats[k];
	for(i=0;i<$('.preise-'+str_kat+' div').length;i++)
	  {
	  arr                                                           = $('.preise-'+str_kat+' div:eq('+i+')').html().split(':');
	  arr_preise[str_kat][arr_preise[str_kat].length]               = [parseInt(arr[0]),parseFloat(arr[1])];
	  }
	}
  }


function jahrbuch_wie(str_val)
  {
  int_val                                                           = parseInt(str_val);
  $('#jahrbuch_mehr').hide();
  $('#jahrbuch_mehr2').hide();

  if(int_val)
	{
	$('#jahrbuch_mehr2').show();
	$('#jahrbuch_mehr').show();
	jahrbuch_berechne();
	}
  }


function jahrbuch_ausgabe(str_val)
  {
  str_kat_preis                                                     = 'neutral';
  int_val                                                           = parseInt(str_val);
  int_ausgabe                                                       = int_val;
  $('#tr_werbeseiten').hide();
  if(int_val == 2)
	{
	str_kat_preis                                                   = 'individuell';
	$('#tr_werbeseiten').show();
	}
  if(int_val == 3)
	{
	str_kat_preis                                                   = 'individuell2';
	$('#tr_werbeseiten').show();
	}

  jahrbuch_berechne();
  }

mit_werbeseiten                                                     = 0;
function jahrbuch_werbeseiten(int_zustand)
  {
  mit_werbeseiten                                                   = int_zustand;
  jahrbuch_berechne();
  }

function jahrbuch_berechne()
  {
  $('#jahrbuch_mehr2').hide();
  $('.versand0,.versand1').hide();
  int_menge                                                         = parseInt($('#f_jahrbuch_menge').val());

  if(int_menge == 1 && str_kat_preis == 'neutral')
	{
	$('.versand1').show();
	}
  else
	{
	$('.versand0').show();
	}

  if(int_menge)
	{
	$('#jahrbuch_mehr2').show();
	$('#kalk_preis_werbung').hide();
    preis_einzel                                                    = jahrbuch_preis_get(int_menge,str_kat_preis);
	preis_werbung                                                   = 0;

	if((int_ausgabe == 2 || int_ausgabe == 3) && mit_werbeseiten || !preis_einzel)
	  {
	  $('#kalk_preis_werbung').show();
	  //preis_werbung                                                 = jahrbuch_preis_get(int_menge,'einleger');

	  if(!preis_werbung || !preis_einzel)
		{
		if(int_menge < arr_preise[str_kat_preis][1][0] || !preis_einzel)
		  {
		  alert($('.zu-wenig').html().replace('XX',arr_preise[str_kat_preis][1][0]));
		  $('#jahrbuch_mehr2').hide();
		  }
		else if(int_menge > arr_preise[str_kat_preis][arr_preise[str_kat_preis].length-1][0])
		  {
		  alert($('.zu-viel').html().replace('XX',arr_preise[str_kat_preis][1][0]));
		  $('#jahrbuch_mehr2').hide();
		  }
		}
	  }

	preis_einzel_mit_werbung                                        = preis_einzel+preis_werbung;
	preis_alle                                                      = preis_einzel_mit_werbung*int_menge;
	preis_ust                                                       = (preis_alle*((100+jahrbuch_ust)/100))-preis_alle;
	preis_gesamt                                                    = preis_alle+preis_ust;


	$('#kalk_preis_einzel .s2').html(fz(preis_einzel)+' EUR');
	$('#kalk_preis_werbung .s2').html(fz(preis_werbung)+' EUR');
	$('#kalk_preis_ust .s2').html(fz(preis_ust)+' EUR');
	$('#kalk_preis_zs .s2').html(fz(preis_alle)+' EUR');
	$('#kalk_preis_gesamt .s2').html('<strong>'+fz(preis_gesamt)+' EUR</strong>');
	}
  }


function jahrbuch_preis_get(int_menge,str_kat_preis_ss)
  {
  preis                                                             = arr_preise[str_kat_preis_ss][0][1];
  for(r=0;r<arr_preise[str_kat_preis_ss].length;r++)
	{
	menge                                                           = arr_preise[str_kat_preis_ss][r][0];
	preis_r                                                         = arr_preise[str_kat_preis_ss][r][1];
	if(menge<int_menge)
	  {
	  preis                                                         = preis_r;
	  }
	}
  return preis;
  }


function fz(str_zahl)
  {
  str_zahl															= str_zahl+'';

  //dezimaltrennzeichen
  str_zahl															= str_zahl.replace('.',',');
  letztes_komma														= str_zahl.lastIndexOf(',');
  vorkomma															= str_zahl;
  nachkomma															= '';

  if(letztes_komma > 0)
    {
	trennen															= str_zahl.split(',');
	vorkomma														= trennen[0];
	nachkomma														= trennen[1];
	}

  neu_vorkomma														= '';
  i_komma															= 0;
  for(i_fz=vorkomma.length-1;i_fz>=0;i_fz--)
    {
	i_komma++;
	if(i_komma == 4)
	  {
	  i_komma														= 0;
	  neu_vorkomma													= '.'+neu_vorkomma;
	  }
	neu_vorkomma													= vorkomma.charAt(i_fz)+neu_vorkomma;
	}

  if(nachkomma.length > 2)
    {
	nachkomma                                                       = nachkomma.substr(0,2);
	}

  if(nachkomma != '')
    {
	neu_vorkomma													+= ','+nachkomma;
	}

  if(nachkomma.length == 1)
    {
	neu_vorkomma													+= '0';
	}
  if(nachkomma.length == 0)
    {
	neu_vorkomma													+= ',00';
	}

  return neu_vorkomma;
  }
