

  $j(document).ready(function(){

      CFGlobal.Categories.observeListCategoryChanged('#cf-videos-sort-prefs');
  });      

 
/**
 * Image slider for TeaserThree special module
 * based on: http://net.tutsplus.com/tutorials/javascript-ajax/a-bullet-proof-content-viewer/ 
 * 
 * @param moduleId
 * @param delay
 * @returns
 */
var TeaserThreeModule = CFClass.extend({
      
      /**
       * @method initialize
       */
    init: function(moduleId, delay, panelWidth, maxIdx) {
        this.moduleSuffix = '_' + moduleId;
  
        this.panelWidth = (-1) * (panelWidth ? panelWidth : 594);
        this.delay = !delay ? 4000 : delay + 0; 
        
        this.teaserthreeSlider = undefined;
        this.currentIdx = 1;
        this.direction = 'u';
        
        this.maxIdx = maxIdx ? maxIdx : 3;
        
        this.minIdx = 1;
        this.tracked = [];
        
        var that = this;
  
        $j("#nav" + this.moduleSuffix + " a img ").hover(  
            function() {  
                $j(this).animate({
                  opacity: 1.0,
              },'fast');
            }, function() {
              $j(this).animate({
                  opacity: 0.7,
              },'fast');  
        });  
  
        //handle nav click  
        $j("#nav" + this.moduleSuffix + " a").click(function(e){  
            that.currentIdx = $j(this).attr('indx');
            //stop browser default  
            e.preventDefault();  
            e.stopPropagation();
     
            that.slideToPanel(that.currentIdx);
        });  

        // handle mouseover thumbnail image
        if (maxIdx > 1)
        {
            $j("#nav" + this.moduleSuffix + ", .titleurl" + this.moduleSuffix + ", .titleimg" + this.moduleSuffix).hover(function() { 
                clearInterval(that.teaserthreeSlider);
                }, function() { 
                    that.teaserthreeSlider = setInterval(function() {
                        that.slideStuff();
                    },  that.delay);
                });
        }
        
        this.trackPanel(1); // track first teaser image, this is shown when page loads

        if (maxIdx > 1)
        {
            this.teaserthreeSlider = setInterval(function() {
                that.slideStuff();
            },  this.delay);
        }
    },
  
    /**
     * Tracking pixel request, if available and not tracked before
     */
    trackPanel: function(idx)
    {
        var that = this;
        var trackingPixel = $j("#panel" +  this.moduleSuffix + '_' + idx + " a img").attr('trackingsrc');
        if (trackingPixel != '' && this.tracked[idx] != true )
        {
            $j.get(trackingPixel, function(){
                that.tracked[idx] = true;    
            });
        }
    },

    /**
     * Image/Panel sliding action with tracking pixel 
     */
    slideToPanel: function(idx)
    {
        var that = this;
        $j("#slider" + this.moduleSuffix).animate({  
            marginLeft: that.panelWidth * (idx -1)  
        });  
        this.trackPanel(idx);
    },
    
    /**
     * Calculate next sliding position, based on current panel position and direction
     */
    slideStuff: function()
    {
        if (this.direction == 'u' && this.currentIdx == this.maxIdx)
        {
            this.direction = 'd';
        }
        else if (this.direction == 'd' && this.currentIdx == this.minIdx)
        {
            this.direction = 'u';
        }
        if (this.direction == 'u')
        {
            this.currentIdx++;
        } 
        else
        {
            this.currentIdx--;
        }
        this.slideToPanel(this.currentIdx);
    }

});


/***************************** Candidates + Fans ****************************/
/*
 * for reference only, if fan functions will be activated again...
*/
  
  /*
function becomeFan(specialID,fanId,el) {
	var elParent = $(el).up(0);

	var requestUri = 
		page.basepath + 
        application.jsonDispatcher +  '/' +
        'specialjson/addFan/special/' + specialID + '/fan/' +  fanId;

	    new Ajax.Request(requestUri, {
		method: 'get',
		onSuccess: function(transport) {
		    var data;
		    try
		    {
			data = transport.responseText.evalJSON(true);				
			if (data.success == true)
			{	
				// TODO: evtl �ber class?
			    elParent.innerHTML = '<div class="fanerror">Du bist Fan. <br /><a href="javascript:;" id="cf-special-fanlink" onclick="unsetFan('+specialID+','+fanId+',this);">Bin kein Fan mehr </a></div>';				
			} else {
				if(data.error.errorcode='11y999') {
					elParent.innerHTML = '<div class="fanerror">Du musst angemeldet sein, um dieses Feature zu nutzen</div>';
				}
			}
			
		    }
		    catch (e)
		    {
			return false;
		    }
		}
	    });	
}
function unsetFan(specialID,fanId,el) {
	var elParent = $(el).up(0);

	var requestUri = 
		page.basepath + 
        application.jsonDispatcher +  '/' +
        'specialjson/removeFan/special/' + specialID + '/fan/' +  fanId;

	    new Ajax.Request(requestUri, {
		method: 'get',
		onSuccess: function(transport) {
		    var data;
		    try
		    {
			data = transport.responseText.evalJSON(true);				
			if (data.success == true)
			{				
				// TODO: evtl �ber class?
			    //elParent.innerHTML = '<a href="javascript:;" id="cf-special-fanlink" onclick="becomeFan('+specialID+','+fanId+',this);">Fan werden </a>';
				var elParent2 = elParent.up(0);
				elParent2.innerHTML = '<div><a href="javascript:;" id="cf-special-fanlink" onclick="becomeFan('+specialID+','+fanId+',this);"><IMG SRC="'+page.imagebase+'v2/spacer.gif" WIDTH="115" HEIGHT="114" BORDER="0" ALT="Fan werden" title="Fan werden" /></a></div>';
			}
			
		    }
		    catch (e)
		    {
			return false;
		    }
		}
	    });	
}
  
  */
