$(document).ready(function() {

	/* Galerie: */
	if ($('.galeriebild').length > 0)
	{
		var imgCount = 0;
		var groupCount = 0;
		var curClassName = "group_0";
		$(".galeriebild").each(function(index) {
		   imgCount+= 1;
		   $(this).addClass(curClassName);
		   $("."+curClassName).equalizeCols();
		   if(imgCount==4)
		   {
			imgCount=0
			groupCount+= 1;
			curClassName = "group"+groupCount;
				    $(this).addClass("last");
				   }
				});
			$(".galeriebild a").fancybox({
		      'titleShow' : true,
		      'titlePosition' : 'inside'
		    });
		
		$('.galeriebild').each(function(index) {
			$(this).hover(
			  function () {
				$(this).addClass('hover');
			  }, 
			  function () {
				$(this).removeClass('hover');
			  }
			);
		});
	}

  //Lightview Inhaltsbild
  if($('a.lightbox').length>0){
    $('a.lightbox').fancybox();
    var lbox = $('.lightbox'); 
    lbox.attr('rel','');
    lbox.append('<span class="lbox_append"><span>&nbsp;</span></span>')
    lbox.fancybox();
  }
  
  if($('a.fancyframe').length>0){
	$('a.fancyframe').fancybox({
		'type':'iframe',
		'width':620,
		'height':'99%'
		});
  }

  /* new CD random loader */
  loadNewCDs();
  setInterval(loadNewCDs, 10000);
  function loadNewCDs(){
    $("#ajaxcontent").fadeOut("slow", function() {
      if($('#ennewcovers').length>0) var newcdurl = 'intellisearchv2/newcovers.php?sprache=EN&country=US';
      else var newcdurl = 'intellisearchv2/newcovers.php';
      $("#ajaxcontent").load(newcdurl, function() {
      // $("#ajaxcontent").load("http://sonoton.com/intellisearchv2/newcovers.php", function() {
        $("#ajaxcontent").fadeIn("slow");
      });
    });
  }
  
  /* Search Suggest */
  $('#fldFulltext').keyup(function() {
    var input = $(this).val();
    $('#sonofindsuggest').hide();
    if(input.length>2){
      if($('#ennewcovers').length>0) var postdata = {country:'US',sprache:'EN',word:input};
      else var postdata = {country:'DE',sprache:'DE',word:input};
      $.post('intellisearchv2/intellisearch_proxy.php?mode=native', postdata, function(data) {
        var resultarray = eval(data);
        if(resultarray.length>0){
          $('#sonofindsuggest').html('');
          $('#sonofindsuggest').append('<ul></ul>');
          $('#sonofindsuggest').show();
          $.each(resultarray, function(index, value){
            var suggest = value.replace('"','');
            suggest = suggest.replace('"','');
            $('#sonofindsuggest ul').append('<li>'+suggest+'</li>');
          });
          $('#sonofindsuggest ul li').click(function(){
            $('#fldFulltext').val($(this).text());
            $('#sonofindsuggest').hide();
          });
        }
      });
    }else{
      $('#sonofindsuggest').hide();
    }
  });
  
  /* References: */
  if($(".content-box").length){
    $(".content-box").fancybox({
      'padding' : '0'
    });
  }

  if($("#more_refs_button").length){
    $('#more_refs_button').click(function() {
      $('#refmoretoggle').slideToggle('slow', function() {
      });
    });
  }
  
  /* Team Hover */
  if($(".team-box").length){
    $(".team-box img").each(function(){
      var ori = $(this).attr('src');
      var hov = $(this).attr('rel');
      if(hov!=""){
        $(this).hover(function(){
          //mouse in
          $(this).attr('src', hov);
        }, function(){
          //mouse out
          $(this).attr('src', ori);
        });
      }
      //alert($(this).attr('rel'));
    });
  }
  
  /* Footer Bottom */
    // alert(($("#resize-content").height()+244)+" - "+$(window).height());
  if(($("#resize-content").height()+244)<$(window).height()){
    // $('#resize-content').height($('#wrap').height()-244);
    $('#resize-content').css('min-height', $('#wrap').height()-244);
  }
  
  // $(window).resize(function() {
    // if(($("#resize-content").height()+244)<$(window).height()){
        // $('#resize-content').css('min-height', $('#wrap').height()-244);
    // }  
  // });
  
  
  /* Lizenzboxen */

  if((".licence-box").length){
		var liimgCount = 0;
		var ligroupCount = 0;
		var licurClassName = "group_0";
		$(".licence-box").each(function(index) {
		   liimgCount+= 1;
		   $(this).addClass(licurClassName);
		   $("."+licurClassName).equalizeCols();
		   if(liimgCount==3)
		   {
			liimgCount=0
			ligroupCount+= 1;
			licurClassName = "group"+ligroupCount;
				    $(this).addClass("last");
			 }
		});
  }
  
	/* Drucken */
	$("a[href=#print]").click(function() {
	  window.print();
	  return false;
	 });
	$("a.printlink").click(function() {
	  window.print();
	  return false;
	 });
   /* Toplink */
 	$("#toplink").click(function() {
	  $(window).scrollTop(0);
	  return false;
	 });
 
});
