function initTagesgeldEvents() {
  $('.tagesgeldItem').click(function() {
    var imageUrl = 'http://tabellen.fmh.de/images/' + this.id + '.jpg';
    window.open(imageUrl, "blank", "toolbar=no, width=760, height=570");
  });
}

function hoverTableCol() {


  $('.flexTable .flexRow td').mouseover(function() {
    
    var cells = $(this).parent("tr").children("td");
    var position = jQuery.inArray(this, cells) + 1;
    
    var cellClass = '.flexCell' + position;
    
    var flexCell = this;
    
    $(this).closest("table").find(cellClass).each(function() {
      
      if ($(this).closest('tr').hasClass('rowAlt0')) {
        if($(this).hasClass('cellAlt0')) {
          $(this).addClass('cellAlt0Hover');
          $(this).removeClass('cellAlt0');
        } else if($(this).hasClass('cellAlt1')) {
          $(this).addClass('cellAlt1Hover');
          $(this).removeClass('cellAlt1');          
        }
      }
      else if ($(this).closest('tr').hasClass('rowAlt1')) {
        if($(this).hasClass('cellAlt1')) {
          $(this).addClass('cellAlt0Hover');
          $(this).removeClass('cellAlt1');
        } else if($(this).hasClass('cellAlt0')) {
          $(this).addClass('cellAlt1Hover');
          $(this).removeClass('cellAlt0');          
        }
      }
    });    
  });
  
  $('.flexTable .flexRow td').mouseout(function() {
    var cells = $(this).closest("tbody").find(".cellAlt0Hover, .cellAlt1Hover").each(function(){
      if ($(this).closest('tr').hasClass('rowAlt0')) {
        if($(this).hasClass('cellAlt0Hover')) {
          $(this).addClass('cellAlt0');
          $(this).removeClass('cellAlt0Hover');
        } else if($(this).hasClass('cellAlt1Hover')) {
          $(this).addClass('cellAlt1');
          $(this).removeClass('cellAlt1Hover');          
        }
      }
      else if ($(this).closest('tr').hasClass('rowAlt1')) {
        if($(this).hasClass('cellAlt1Hover')) {
          $(this).addClass('cellAlt0');
          $(this).removeClass('cellAlt1Hover');
        } else if($(this).hasClass('cellAlt0Hover')) {
          $(this).addClass('cellAlt1');
          $(this).removeClass('cellAlt0Hover');          
        }
      }
    });
  });
}

function initTagesgeldItemsEvents() {
  $('.tagesgeldItem').click( function(){
      var imageUrl = '/resources/assets/' + this.id + '.jpg';
      window.open(imageUrl, "blank", "toolbar=no, width=760, height=570");
      return false;
  });
}

function initRightBarForm() {
  $('#rightBar .entryPoint :radio').change(function() {
    var closestForm = $(this).closest('form');
    var url = closestForm.attr('action') + "?" + closestForm.serialize();
    //alert(url);
    window.location = url;
  });
}


/*
 * uncrypt mail from
 * http://www.derwok.de/service/email_stopspam/
 */
function UnCryptMailto(s, shift) {
	var n=0;
	var r="";
	for(var i=0;i<s.length;i++) { 
		n=s.charCodeAt(i); 
		if (n>=8364) {n = 128;}
		r += String.fromCharCode(n-(shift)); 
	}
	return r;
}

function linkTo_UnCryptMailto(s, shift)	{
	location.href=UnCryptMailto(s, shift);
}

function initHeiseSocial() {
  $('#rightBar').append('<div id="socialshareprivacy"></div>');
  if($('#socialshareprivacy').length > 0){
    $('#socialshareprivacy').socialSharePrivacy({
      services : {
        facebook : {
          'app_id'       : '216330905093396', 
          'perma_option' : 'off',
          'dummy_img'    : 'http://www.fmh.de/resources/javascripts/socialshareprivacy/socialshareprivacy/images/dummy_facebook.png'
        }, 
        twitter : {
            'status'     : 'off'
        },
        gplus : {
          'status'       : 'off'
        }
      },
      'css_path' : 'http://www.fmh.de/resources/javascripts/socialshareprivacy/socialshareprivacy/socialshareprivacy.css'
    });
  }
}

$(document).ready(function() {
  initTagesgeldEvents();
  hoverTableCol();
  initTagesgeldItemsEvents();
  initRightBarForm();
  initHeiseSocial();
});
