/* =========================================================

// jquery.pd_fish

// Datum: 2008-07-25
// Firma: purpled
// Autor: florian schade
// Mail: f.schade@purpled.com
// Web: http://www.purpled.com

// ========================================================= */

jQuery.fn.pd_fish = function(options) {
	this.find("ul").attr("style","top: -9999px; visibility: visible;");
	
	this.find('li').hover(
		function(){
			$(this).children("ul").attr("style","left: 0; top: "+$(this).height()+"px; visibility: visible;");
			$(this).addClass( 'over' )
			$(this).children().addClass( 'over' )
		},function(){
  			$(this).children("ul").attr("style","top: -9999px;");
  			$(this).removeClass( 'over' )
  			$(this).children().removeClass( 'over' )
	});
	
	this.children().find("li").hover(
		function(){
  			$(this).children("ul").attr("style","left:"+($(this).width()) + "px; visibility: visible;");
  			
		},function(){
  			$(this).children("ul").attr("style","right:-9999px; display: none; visibility: visible;");;
	});
};


jQuery.fn.pd_fish_footer = function(options) {
	this.find("ul").attr("style","top: -9999px; visibility: visible;");
	
	this.find('li').hover(
		function(){
			$(this).children("ul").attr("style","right: 0; bottom: "+$(this).height()+"px; visibility: visible;");
			$(this).addClass( 'over' )
			$(this).children().addClass( 'over' )
		},function(){
  			$(this).children("ul").attr("style","top: -9999px;");
  			$(this).removeClass( 'over' )
  			$(this).children().removeClass( 'over' )
	});
	
	this.children().find("li").hover(
		function(){
  			$(this).children("ul").attr("style","left:"+($(this).width()) + "px; visibility: visible;");
  			
		},function(){
  			$(this).children("ul").attr("style","right:-9999px; display: none; visibility: visible;");;
	});
};



/* =========================================================

// jquery.pd_wfit

// Datum: 2008-07-25
// Firma: purpled
// Autor: florian schade
// Mail: f.schade@purpled.com
// Web: http://www.purpled.com

// ========================================================= */

jQuery.fn.pd_wfit = function(options) {
	var v_width = this.width() / this.children().length;
	this.children().css({width: v_width-0.1})
};




(function($){  
  $.fn.extend({   
    promoter: function(options) {  
      var defaults = {  
        appendTo: "",
        elClass: "",
        linkAll: false,
        pause: 5000,
        times: 5,
        transition: 1000,
        limit: 100
      };
          
      var o =  $.extend(defaults, options);  
      
      o.pause = o.pause + o.transition * 2;
      
      var i = 0;
      
      var times = 1;
      
      var limit = 0;
      
      this.each(function() {
        var promote = _init(this, o);
      });
      
      var kids = $(o.appendTo).children('.' + o.elClass);
      
      _start_animation();
      
      kids.eq(0).addClass('active').trigger('slideIn');
      
      var total = kids.length - 1;

      function _init(obj, o) {

        if(o.limit == limit){
          return false;
        } else {
          limit += 1;
        }
        
        var el = $(obj);
        var appendTo = $(o.appendTo);
        
        el = el.clone().addClass(o.elClass);
        
        appendTo.append(el);
        
        el.css('left', -1 * el.outerWidth())
          .bind('slideIn', function(evt) { _slideIn(evt, el, o);})
          .bind('slideOut', function(evt) { _slideOut(evt, el, o);})
          .bind('click', function(evt) { _findLink(evt, el, o);});
          
        
        return el;
        
      };
      
      function _slideIn(evt, el, o){
        el.animate({
          left: 0
        }, o.transition);
      }
      
      function _findLink(evt, el, o){
        var location = el.find('a:first').attr('href');
        if(o.linkAll && location ) {
          window.location.href = location;
        } else {
          _stop_animation();
        }
      }
      
      function _slideOut(evt, el, o){
        el.animate({
          left: -1 * el.outerWidth()
        }, o.transition);
      }
      
      function _stop_animation(){
        clearInterval(interval);
        kids.eq(i).trigger('slideOut');
      }
      
      function _start_animation(){
        interval = setInterval(function(){ _animate(); }, o.pause);
      }
      
      function _animate(){
        kids.eq(i).trigger('slideOut');
        kids.eq(i).queue(function() {
        
          $(this).dequeue();
        });

        if(i >= total){
          i = 0;
          times += 1;
        } else {
          i += 1; 
        };
        
        if(times > o.times) {
          clearInterval(interval);
          return false;
        }
        
        kids.eq(i).trigger('slideIn');        
      }
    }  
  });  
})(jQuery);


/* =========================================================
// ========================================================= */
$(document).ready(function() {

  $('#main .promote').promoter({
    elClass: "promotionBox",
    appendTo: "#billboard",
    pause: 5000,
    times: 5,
    transition: 2000,
    linkAll: true,
    limit: 100
  });
  
  $('#c3861').promoter({
    elClass: "promotionBox",
    appendTo: "#billboard",
    pause: 5000,
    times: 3,
    transition: 2000,
    linkAll: true,
    limit: 100
  });
  
	$('#navigationMain').pd_fish();
	$('#footer .navigationHorizontal').pd_fish_footer();
});
