function loadDropDown() {

 var timeout    = 500;
 var closetimer = 0;
 var ddmenuitem = 0;

 function menu_open()
 {  menu_canceltimer();
    menu_close();
    ddmenuitem = $(this).find('ul').css('visibility', 'visible');}

 function menu_close()
 {  if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');}

 function menu_timer()
 {  closetimer = window.setTimeout(menu_close, timeout);}

 function menu_canceltimer()
 {  if(closetimer)
    {  window.clearTimeout(closetimer);
       closetimer = null;}}

 $('#Menulist > li').bind('mouseover', menu_open);
 $('#Menulist > li').bind('mouseout',  menu_timer);

 //document.onclick = menu_close;

};

jQuery.fn.liScroll = function(settings) {
		settings = jQuery.extend({
		travelocity: 0.07
		}, settings);		
		return this.each(function(){
				var $strip = jQuery(this);
				$strip.addClass("newsticker")
				var stripWidth = 0;
				var $mask = $strip.wrap("<div id='news'></div>");
				var $tickercontainer = $strip.parent().wrap("<div id='newsCont'></div>");								
				var containerWidth = $strip.parent().parent().width();	//a.k.a. 'mask' width 	
				$strip.find("li").each(function(i){
				stripWidth += jQuery(this, i).width();
				});
				$strip.width(stripWidth);			
				var defTiming = stripWidth/settings.travelocity;
				var totalTravel = stripWidth+containerWidth;								
				function scrollnews(spazio, tempo){
				$strip.animate({left: '-='+ spazio}, tempo, "linear", function(){$strip.css("left", containerWidth); scrollnews(totalTravel, defTiming);});
				}
				scrollnews(totalTravel, defTiming);				
				$strip.hover(function(){
				jQuery(this).stop();
				},
				function(){
				var offset = jQuery(this).offset();
				var residualSpace = offset.left + stripWidth;
				var residualTime = residualSpace/settings.travelocity;
				scrollnews(residualSpace, residualTime);
				});			
		});	
};


$(document).ready(function(){

  $.ajax({url:'nowplaying?randval='+ Math.random(),dataType:'script'});

  var fixed = false;

  $(document).scroll(function() {
    if( $(this).scrollTop() >= 308 && $(window).height()+$(this).scrollTop()+155 <= $(document).height()) {
      $('#bannerR').addClass('fixedtop');
    } else {
      $('#bannerR').removeClass('fixedtop');
      if ($(window).height()+$(this).scrollTop() >= $(document).height()-155) {
        $('#bannerR').addClass('fixedbottom');
      } else {
        $('#bannerR').removeClass('fixedbottom');
      }
    }
  });

  loadDropDown();

// --- HITPARADE ABSTIMMUNG ---

  if($('.hitparade').length){

    if( $('.tyText').is(':visible') ) {  
      $('a.myVote').fadeOut('slow');
    }

    $('body').append('<div id=\'pollOverlay\'><div class=\'contentWrap\'></div></div>');



    $('.hitparade a.myVote[rel]').live('click', function () {
	
      var clickLink = $(this).overlay({
 
        mask: '#4F411D',
        fixed: false,
        top: 'center',
	 
        onBeforeLoad: function() {
            $("#pollOverlay .contentWrap").html("<span class=\"loader\">...wird geladen</span>");
            var path = this.getTrigger().attr("href").split('?')[0];
            var para = this.getTrigger().attr("href").split('?')[1];
            var pollId = this.getTrigger().parents(".hitparade").attr("id");
            if($.browser.msie && parseFloat($.browser.version) == 7){
                $("#pollOverlay").css("display","block");
            }
            loadHitPoll(path,para,pollId);
            $('#content object').css('visibility','hidden');

        },
        onClose: function() {
            $("#pollOverlay .contentWrap").html("<span class=\"loader\">\&nbsp\;</span>");
            $('#content object').css('visibility','visible');
        }
 
      });

        //initiates overlay
	$(this).overlay().load();
        //loads above overlay settings
	clickLink.load();
	return false;
    });



    function loadHitPoll (path,para,pollId) {
        $.ajax({url:path+'/'+pollId+"/hit_commit_request", data:para+"&style=0", cache:"false", dataType:"text/html", success:function(html){
            $("#pollOverlay .contentWrap").html(html);
            reloadHitPoll();
            }
        });
    };

    function reloadHitPoll() {
      $("form#commitRequest").submit(function(){
        if($('#cpt').val()=='') {
         alert('Captcha-Code muss einen Wert haben');
         return false;
        } else {
          var pollId = $("input[name=pollId]").val();
          $("#pollOverlay .contentWrap").append("<span class=\"loader\">\&nbsp\;</span>");

          $.ajax({url:pollId+"/hit_commit_vote", data:$(this).serialize(), cache:"false", dataType:"text/html", success:function(html){
             $("#pollOverlay .contentWrap").html(html);


             if ($('#vStatus').text()=='1') {
                  $('a.myVote').fadeOut('slow');

                  $.ajax({url:pollId+'/hit_display_results', dataType:"text/html", success:function(html){
                      $(".hitList").html(html);
                      $('form.hitTab input').removeClass('active');
                      $('form.hitTab input#tabRes').addClass('active');
                      $('.hitparade .hitList p.tyText').remove();
                      $('.hitparade').prepend('<p class=\"tyText\"><strong>Vielen Dank für Ihre Stimme, <br/>in <span class="countdown">120</span> Sekunden können Sie erneut abstimmen.</strong></p>');
                      $("#pollOverlay .contentWrap").prepend('<p class=\"tyText\"><strong>Vielen Dank für Ihre Stimme, <br/>in <span class="countdown">120</span> Sekunden können Sie erneut abstimmen.</strong></p><p class=\"tyText\"><iframe height=\"65\" frameborder=\"0\" width=\"400\" scrolling=\"no\" marginwidth=\"0\" marginheight=\"0\" src=\"/fb/likebutton\"></iframe></p>');
                    }
                  });

                  setHitVoteTimer(120);

              }

              reloadHitPoll();

            }
          });


          return false;
        }
      });
    }; 

  }


// --- POLL FLOWPLAYER ---

  $f("a.pollPlayer", "common/flowplayer.commercial-3.2.7.swf", {
        key:'#@f8ac585a19056de35ba',
        canvas: {
          backgroundGradient: "none",
          backgroundColor: '#000000'
        },
        clip: {
         scaling: 'fit'
        },
	logo: {
		url: 'watermark_img.png',
		fullscreenOnly: false,
		displayTime: 2000
	},
  	// perform custom stuff before default click action
	onBeforeClick: function() {

		// unload previously loaded player
		$f().unload();
		
		// get wrapper element as jQuery object
		var wrap = $(this.getParent());
		
		// hide nested play button
		wrap.find("img").fadeOut();
		
		// start growing animation
		wrap.animate({width:526, height:296}, 500, function() {
		        $(this).css('margin','0 0 20px 0');
			// when animation finishes we will load our player
			$f(this).load();
			
		});	
		
		// disable default click behaviour (player loading)
		return false; 
	}, 

	// unload action resumes to original state		
	onUnload: function() {
		$(this.getParent()).animate({width:120, height:70}, 500, function()  {
		        $(this).css('margin','0 20px 0 0');
			// make play button visible again
			$(this).find("img").fadeIn();		
		});
	}, 
	
	// when playback finishes perform our custom unload action
	onFinish: function() {
		this.unload();	
	}
  });


 if ($('.poll').length) {
  $('body').append('<div id=\'pollOverlay\'><div class=\'contentWrap\'></div></div>');

  $(".poll a.myVote[rel]").overlay({
      mask: '#4F411D',
      fixed: false,
      top: 'center',
      onBeforeLoad: function() {
          $("#pollOverlay .contentWrap").html("<span class=\"loader\">...wird geladen</span>");
          var path = this.getTrigger().attr("href").split('?')[0];
          var para = this.getTrigger().attr("href").split('?')[1];
          var pollId = this.getTrigger().parents(".poll").attr("id");
          if($.browser.msie && parseFloat($.browser.version) == 7){
              $("#pollOverlay").css("display","block");
          }
          loadPoll(path,para,pollId);
          $('#content object').css('visibility','hidden');

      },
      onClose: function() {
          $("#pollOverlay .contentWrap").html("<span class=\"loader\">\&nbsp\;</span>");
          $('#content object').css('visibility','visible');
      }
  });


  function loadPoll (path,para,pollId) {
      $.ajax({url:path+'/'+pollId+"/getAjaxContent", data:para+"&style=0", cache:"false", dataType:"text/html", success:function(html){
          $("#pollOverlay .contentWrap").html(html);
          reloadPoll();
          }
      });
  };
  function reloadPoll() {
    $("form").submit(function(){
      if($('#cpt').val()=='') {
       alert('Captcha-Code muss einen Wert haben');
       return false;
      } else {
        var pollId = $("input[name=pollId]").val();
        $("#pollOverlay .contentWrap").append("<span class=\"loader\">\&nbsp\;</span>");
        $.ajax({url:pollId+"/getAjaxContent", data:$(this).serialize(), cache:"false", dataType:"text/html", success:function(html){
            $("#pollOverlay .contentWrap").html(html);
            if ($('#vStatus').text()=='1') {
                $('a.myVote').fadeOut('slow');
                $('.pollArrow').fadeOut('slow');
                $('.poll').prepend('<p class=\"tyText\"><b>Vielen Dank für Ihre Stimme, <br/>in <span class="countdown">120</span> Sekunden können Sie erneut abstimmen.</b></p>');
                $.ajax({url:pollId+'/test_getlist?randval='+ Math.random(), dataType:"script", success:function(res){
                        for (var i in votes){
                          $("#"+votes[i][0]+" span.results").html(votes[i][1]);
                        }

                    }
                });
                setVoteTimer(120);
//                clearInterval(voteTimer);
//                var voteTimer = setInterval("$('a.myVote, .pollArrow').fadeIn('slow');$('p.tyText').fadeOut('slow')", 120000);
            }
            reloadPoll();
          }
        });
        return false;
      }
    });
  };

 }

// --- ADVENTSKALENDER ---

  $('.aCal a.door').click(function() {
    $(this).fadeOut().delay(15000).fadeIn();
    return false;
  });



// --- KURZ-BIOS ---
  $("#index li.ixAlpha",this).mouseover(function(){$(this).addClass('alphaActive');}).mouseout(function(){$(this).removeClass('alphaActive');});

  $("#index li.ixAlpha",this).click(function(){
    $("#index li.ixAlpha").removeClass('alphaActive2');
    $(this).addClass('alphaActive2');
    $("div.indexA").html("<div class=\"loader\">Kurz-Biografien werden geladen...</div></div>").fadeIn();
    $.ajax({type:"POST", url:"getBios", data: "ch="+$(this).attr("title"), success:function(html){$("div.indexA").html(html);}});
  });

  $("div.graphic",this).mouseenter(function(){$("div.imgZoom",this).fadeIn();});
  $("div.graphic",this).mouseleave(function(){$("div.imgZoom",this).fadeOut();});

  $('textarea#wish[maxlength]').keyup(function(){
     var max = parseInt($(this).attr("maxlength"));
     if($(this).val().length > max){
         $(this).val($(this).val().substr(0, $(this).attr("maxlength")));
     }
     $(this).parent().parent().find('.charsRemaining').html('Max. 150 Zeichen. Sie haben noch ' + (max - $(this).val().length) + ' Zeichen zu Verfügung.');
  });



});

$(function () {
 $('div#newsCont').marquee('pointer').mouseover(function () {
  $(this).trigger('stop');
 }).mouseout(function () {
  $(this).trigger('start');
 });
});

function setHitVoteTimer(count) {
  var countdown = setInterval(function(){
    $("span.countdown").html(count);
    if (count == 0) {
      var pollId = $(".hitparade").attr("id");
      $.ajax({url:pollId+"/hit_display_list", cache:"false", dataType:"text/html", success:function(html){
          $(".hitList").html(html);
          $('form.hitTab input').removeClass('active');
          $('form.hitTab input#tabList').addClass('active');
        }
      });

      $('a.myVote').fadeIn('slow');
      $('p.tyText').fadeOut('slow');
      clearInterval(countdown);
    }
    count--;
  }, 1000);
};
function setVoteTimer(count) {
  var countdown = setInterval(function(){
    $("span.countdown").html(count);
    if (count == 0) {
//      window.location = ""
      $('a.myVote').fadeIn('slow');
      $('.pollArrow').fadeIn('slow');
      $('p.tyText').fadeOut('slow');
      clearInterval(countdown);
    }
    count--;
  }, 1000);
};
