//fade boxes konfiguration
var boxes_temp = 0; //anzahl der boxen
var boxFadeSpeed = 'slow';
var boxChangeSpeed = 7000;
var boxesArray = new Array('#twitter_boxes .twitter_box','#fb_boxes .fb_box');

$(document).ready(function(){

  for (var x in boxesArray){
    $(boxesArray[x]).each(function(i){
      $(this).attr('id', 'box_'+x+'_'+i);
      boxes_temp = i;
    });
    changeBox(0, boxesArray[x], x, boxes_temp);
  }

  $(".vimeo").click(function() {
    $.fancybox({
      'padding' : 20,
      'autoScale' : false,
      'title' : this.title,
      'width' : 600,
      'height' : 360,
      'href' : this.href.replace(new RegExp("([0-9])","i"),'moogaloop.swf?clip_id=$1'),
      'type' : 'swf',
      'onStart' : function(){$('#fancybox-outer').corner();}
    });
    return false;
  });

  $('.bildergallerie_bilder a').fancybox({
    'onStart' : function(){$('#fancybox-outer').corner();}
  });

  $('#werbespot').fancybox({
    'width' : 600,
    'height' : 350,
    'autoScale' : false,
    'type' : 'iframe',
    'onComplete' : function(){$('#fancybox-outer').corner();}
  });

  $('.fancy').fancybox({
    'onComplete' : function(){$('#fancybox-outer').corner();}
  });

  $('.gewinnspielpartner_fancy a').fancybox();

	if (typeof use_scrollpane === "undefined" || use_scrollpane !== false) {
    window.setTimeout('init_scrollbar()', 500);
  }

 // Flash Message in Kraftquellen-View ... top => 50px;
  if ($('.flash_success').html()) {
    $('.kraftquellen_view_item').find('.kraftquellen_view_item_fblink').css('top', '50px');
  }

  $('#kraftquellen_add_item').css('width', '920px');
  $('#add_guest, #add_login').fancybox({
    'width' : 940,
    'height' : 540,
    'autoScale' : false,
    'padding' : 10,
    'margin' : 0,
    'title' : false,
    'centerOnScroll' : false,
    'hideOnContentClick' : false,
    'hideOnOverlayClick' : false,
    'autoDimensions' : true,
    'onComplete' : function(){$('#fancybox-outer').corner();}
  });

  $('.stilleswasser').each(function(){
    if($(this).attr('value') == 'keine'){
      $(this).bind('click',function(){
        $('.wasseroft').attr('disabled','disabled');
        $('.wasseroft').removeAttr('checked');
      });
    } else {
      $(this).bind('click',function(){
        $('.wasseroft').removeAttr('disabled');
      });
    }
  });

  $('.geschmackwasser').each(function(){
    if($(this).attr('value') == 'keine'){
      $(this).bind('click',function(){
        $('.geschmackoft').attr('disabled','disabled');
        $('.geschmackoft').removeAttr('checked');
      });
    } else {
      $(this).bind('click',function(){
        $('.geschmackoft').removeAttr('disabled');
      });
    }
  });
   

});

var rand_range = 10;
var rand_display = 5;
var pause;
function changeBox(actualBox, selector, whichBox, boxes){
  pause = 0;
  if (selector == '#twitter_boxes .twitter_box'){ 
    rand = Math.round(Math.random()*rand_range);
    if (rand > rand_display){
      pause = 1;
      $(selector).fadeOut(boxFadeSpeed);
    }
  }
  if (pause == 0){
    temp = actualBox;
    $('#box_'+whichBox+'_'+actualBox).fadeIn(boxFadeSpeed,
      function(){
        $(selector+':not(#box_'+whichBox+'_'+temp+')').fadeOut(boxFadeSpeed);
      }
    );
  }
  if (actualBox == boxes){actualBox = 0;} else {actualBox++;}
  window.setTimeout("changeBox('"+actualBox+"','"+selector+"','"+whichBox+"','"+boxes+"')", boxChangeSpeed);
}

function homeInit(){
  window.setTimeout("$('#main_flash_hidden, #twitter_boxes, #fb_boxes').fadeIn('slow')", 2000);
  var flashvars = false;
  var params = {
    wmode: 'transparent'
  };
  var attributes = {
    id: 'main_flash',
    name: 'main_flash'
  };

  //swfobject.embedSWF('swf/VolvicMainAnimation.swf', 'main_flash_hidden', '1000', '520', '9.0.0','swf/expressInstall.swf', flashvars, params, attributes);
}

function login_toggle(){
  if ($('#login_popup').hasClass('active')){

    $('#login_popup').removeClass('active');
    $('#login_popup').animate({top: '-150px'}, 'slow', 'swing',function(){$('#login_popup_container').hide()});
  } else {
    $('#login_popup_container').show();
    $('#login_popup').animate({top: '0px'}, 'slow', 'swing');
    $('#login_popup').addClass('active');
  }
  return false;
}

function init_scrollbar() {
	$('.jScrollPaneContainer').css('overflow', 'auto');
	if ($('#scroller')[0]){
    $('#scroller').jScrollPane({
      showArrows:true,
      scrollbarWidth: 8,
      scrollbarMargin: 20,
      dragMinHeight : 38,
      dragMaxHeight : 38
    });
  }
	$('a, div').bind('focus', function(){
    $(this).blur();
  });

}
