
/*!
 * jQuery UI Widget-factory plugin boilerplate (for 1.8/9+)
 * Author: @addyosmani
 * Further changes: @peolanha
 * Licensed under the MIT license
 *http://jqueryui.com/demos/widget/
 TIMER
 http://bililite.com/blog/extending-jquery-ui-widgets/ GUTE ADDRESSE
 */



;(function ( $, window, document, undefined ) {
 
var countB=0;
	
$.widget( "CE.Session_Participant_View", $.CE.DataElement, {
        options: 
        {
         ObjName:'<span style="color:">PV </span>',
         PHPSessionID:'',
         ActivRatingSessionID:'',
         ActivRatingSession_DataRow:'',
         ParticipantID:'',
         IdeaIDs:[],
         Participants:[],
         SessionSteps:[],
         ActivSessionStepID:0,
         DataMapping:[{DataTableName:'Participant',DataID: '', DataAttributes: ['data_PHPSessionID','PHPSessionID','data_activSessionStepID','ActivSessionStepID', 'data_DataID', 'ParticipantID']}],
         DataMappingBetweenDataElements:[{UpdateAttribut:'ActiveStepID', MappedAttribute:'ActivSessionStepID', sendData:false, getData:true, needForGettingData: false}],
         debug_it:true,
         Notfall_Break_Index:0,
         
         hasVisualitation: false
         
         },
        _create: function () {      },
        _init: function(){

        	var w=this, e=w.element, o=w.options;

        	//############# SetOPTIONS - Defaults ###########
   			
   			e.addClass('CE_Session_Admin_View'); 
   			
   			e.append('<div id="MIDDLE_POINT_DIV"></div>');
   			e.find('#MIDDLE_POINT_DIV').MIDDLE_POINT_DIV();
        	e.append('<span id="phpSessionID" style="display:none;"></span>');

			w._initArrowKeysForNavigation();
			w._initDataElement();
        },
         _initArrowKeysForNavigation: function()
         {
         	var w=this, e=w.element, o=w.options;
		
		  	$(document).keyup(function(event)
        	{
        			//debug(o.ObjName+event.keyCode+' was pressed',false,o.debug_it);
					
					$('.CE-StepSlide-ACTIVE').trigger('USE_KEYUPsFROMDOCUMENT', event)
					
					
					if(event.keyCode == 37 || event.keyCode == 39)
         			{
         				event.stopPropagation();
         		
         			}
					
        	}); 
        	
        	// prevent false interaction because of arrow keys
        	var ar=new Array(33,34,35,36,37,38,39,40);

			$(document).keydown(function(event) 
			{
    		 	var key = event.which;

      	
      			if($.inArray(key,ar) > -1) 
      			{
         			event.preventDefault();
          			event.returnValue= false;
      			}
      		
      			return true;
			}); 	
         },
        _afterGettingDataFromDatatables: function()
        {
        	var w=this, e=w.element, o=w.options;
        	//debug(o.ObjName+' > _afterGettingDataFromDatatables('+o.ActivSessionStepID+')', true, o.debut_it);

        	
        	w._setPHPSessionID();
        
        },
        _setPHPSessionID: function()
        {
        	var w=this, e=w.element, o=w.options;
        	
        	if(o.PHPSessionID=='' || o.PHPSessionID===0 )
        	{
        		$('#phpSessionID').load('get_phpSessionID.php', function()
        		{
        			o.PHPSessionID=$(this).html();
        			//debug(o.ObjName+'_setPHPSessionID('+o.PHPSessionID+')',false,o.debug_it);
        			w._getRunningRatingSession();
        			
        			
        		});
        	}
        },
        _getRunningRatingSession: function(isRecursion)
        {
        	var w=this, e=w.element, o=w.options;
        	
        	var RunningSessions=$('#db_datatables .data_table[datatablename="RatingSession"] .data_row[data_state!="ended"][data_is_template="0"]').first();

        	if(RunningSessions.attr('data_DataID')!=undefined)
        	{
        		e.find('.SLIDE_Laden').fadeOut('fast', function(){$(this).remove();});
        		e.append('<div class="SLIDE_Laden"><div class="CE-StepSlideItem"><br>Ideenfindung wird geladen.<br><br><b>'+RunningSessions.attr('data_SessionName')+'</b><br><br>'+RunningSessions.attr('data_SessionGoal')+'<br><br> Bitte warten Sie kurz...<br><br></div></div>');
        		
        		e.find('.SLIDE_Laden').fadeIn();
        		
        		o.ActivRatingSessionID=RunningSessions.attr('data_DataID');
        		o.ActivRatingSession_DataRow=RunningSessions;
        		
        		var HasVis=RunningSessions.attr('data_with_visualization');
				if(HasVis==true || HasVis=='true')
				{
					o.hasVisualitation=true;
				
				}
			//
        		
        		
        		o.AllParticipantIDs=RunningSessions.attr('data_array_of_ParticipantIDs').split(',');
        		
        		w._getParticipantID();
        	}else
        	{
        		if(isRecursion!=true) $('<div class="SLIDE_Laden"></div>').appendTo(e).DataE_SessionStepSlide(
        		{
        			Headline:'<br><br><br><br>Eine Ideenfindung wird vorbereitet.<br><br>Bitte warten Sie kurz...',
        			Text:''
        		}).trigger('show_slide');
        		
        		 e.find('.SLIDE_Laden h1').effect("shake", {times:6, distance:2}, 100);
        		
        		e.oneTime(5000, 'TIMER_Loading', function()
        		{
        				 $('#db_datatables').trigger('loadDataFromDBAll');//TriggerloadDataFromDB: function(CountToTrigger, TriggerTimeInMS, IsImportantChange)
        				w._getRunningRatingSession(true);
        				
        				
        		});  
        	}
        },
        _getParticipantID: function()
        {
        	var w=this, e=w.element, o=w.options;
        	
        	var participant_exist=true;
    	
        	// Fall 1 - für die gegebene PHPSessionID gibt es in der aktuellen RatingSession einen passenden Teilnehmer - TN nutzen (TN war schon mal eingeloggt)
			var Participant=$('#db_datatables .data_table[datatablename="Participant"] .data_row[data_PHPSessionID="'+o.PHPSessionID+'"][data_ParticipantSessionID="'+o.ActivRatingSessionID+'"]');
			
			// Fall 2 - für die gegebene PHPSessionID wurde kein passender Teilnehmer gefunden, aber es gibt noch freie Plätze - TN nutzen (TN war ist neu)
        	if(Participant.attr('data_PHPSessionID')==undefined)
        	{
        		Participant=$('#db_datatables .data_table[datatablename="Participant"] .data_row[data_PHPSessionID="0"][data_ParticipantSessionID="'+o.ActivRatingSessionID+'"]').first();
        		participant_exist=false;
        					
        	}
        	
        	// Fall 3 - für PHPSessionID wurde kein passender Teilnehmer gefunden, es gibt keine freien ABER sehr alte Plätze (TN neu besetzen - vor allem im Übungsbetrieb)
        	if(Participant.attr('data_PHPSessionID')==undefined)
        	{
        		var ActuelleZeit=getActuallyTime();
        		var CDate=new Date();
        		var CDate_min=CDate.getHours()*60+CDate.getMinutes();
        		var MAX_TIME_inMIN=60;
				//var string_my=''+CDate.getFullYear()+'-'+(CDate.getMonth()+1)+'-'+CDate.getDate()+' '+CDate.getHours()+':'+CDate.getMinutes()+':'+CDate.getSeconds();
        		
        		//2012-01-13 11:17:52
        		
        		var AllParticipants=$('#db_datatables .data_table[datatablename="Participant"] .data_row[data_ParticipantSessionID="'+o.ActivRatingSessionID+'"]');
        		
        		//debug(o.ObjName+'_getParticipantID - AllParticipants:'+AllParticipants.length,false,o.debug_it);
	
        		AllParticipants.each(function()
        		{
        			var tmp_DateString=$(this).attr('data_time_updated');
        			
        			if(tmp_DateString!=undefined && Participant.attr('data_PHPSessionID')==undefined)
        			{	
						var tmp_DateArray=tmp_DateString.replace('-', ',').replace('-', ',').replace(' ', ',').replace(':', ',').replace(':', ',').split(',');
        				
        				////debug(o.ObjName+'_getParticipantID()-getTime('+tmp_DateArray[1]+'->'+tmp_Date+')',false,o.debug_it);
        				
        				if(tmp_DateArray[0]<CDate.getFullYear()) 
        				{
        					Participant=$(this);  // vom letzen Jahr
        				}
        				else if(tmp_DateArray[1]<(CDate.getMonth()+1)) 
        				{
        					Participant=$(this); // vom letzen Monat
        				}
        				else if(tmp_DateArray[2]<CDate.getDate())
        				{ 
        					Participant=$(this); // vom letzten Tag
        				}
        				else
        				{
        					var actual_min=parseInt(tmp_DateArray[3])*60+parseInt(tmp_DateArray[4]);
        					if((actual_min)<(CDate_min-MAX_TIME_inMIN))
        					{
        						Participant=$(this);  // seit MAX_TIME nicht mehr aktualisiert
        					}
        				}
        				
        				
        			}	
        		});
        		
        		participant_exist=false;
        					
        	}
        	
        	// Fall 4 - es gibt keine passenden, keine freien und keine alten Plätze
        	if(Participant.attr('data_DataID')==undefined)
        	{
        		e.find('.SLIDE_Laden').fadeOut('fast', function(){$(this).remove();});

        		 $('<div class="SLIDE_Laden"></div>').appendTo(e).DataE_SessionStepSlide(
        		{
        			Headline:'<br><br><br><br>Eine Ideenfindung wird gerade gestartet.<br><br>Bitte warten Sie kurz......',
        			Text:''
        		}).trigger('show_slide');
        		
        		 e.find('.SLIDE_Laden h1').effect("shake", {times:6, distance:2}, 100);
        		
        		e.oneTime(5000, 'TIMER_Loading', function()
        		{
        				 $('#db_datatables').trigger('loadDataFromDBAll');//TriggerloadDataFromDB: function(CountToTrigger, TriggerTimeInMS, IsImportantChange)
        				w._getRunningRatingSession(true);
        				
        				
        		});  
				
        	}else
        	{
        		o.ParticipantID=Participant.attr('data_DataID');
        	
        		w._setDataID(Participant.attr('data_DataID'));
        		
        		o.ActivSessionStepID=Participant.attr('data_activSessionStepID');
        		
        		//debug(o.ObjName+' TRY _getParticipantID >>>>>>>>>> '+Participant.attr('data_DataID'), true, o.debug_it);
        		
        		if(!participant_exist)
        		{
        			w._setOption('PHPSessionID',o.PHPSessionID, true);	
        		}else
        		{
        			w._getDataFromDatatables();
        		}
        	
        		w._usingRunningRatingSession();
        	}
        	
        },
        _usingRunningRatingSession: function()
        {
        	var w=this, e=w.element, o=w.options, rs=o.ActivRatingSession_DataRow, IA=o.IdeaIDs, PA=o.Participants, SA=o.SessionSteps ;

			var IdeaArray=rs.attr('data_array_of_IdeaIDs').split(',');        	
        	var ParticpantArray=rs.attr('data_array_of_ParticipantIDs').split(','); 
        	var StepArray=rs.attr('data_array_of_stepIDs').split(','); 
        	
        
        	
        
        	//debug(o.ObjName+' _usingRunningRatingSession('+rs.attr('data_DataID')+' - Ideas('+IdeaArray.length+') TN('+ParticpantArray.length+') Schritte('+StepArray.length+') ActiveSessionID='+o.ActivSessionStepID+')', true, o.debug_it);
			
			
for(var i=0; i<IdeaArray.length; i++)
			{
				var Idea=$('#db_datatables .data_table[datatablename="Idea"] .data_row[data_DataID="'+IdeaArray[i]+'"]').first();
				IA.push(Idea);
				
				//debug(o.ObjName+' _usingRunningRatingSession( IA-push('+Idea.attr('data_title')+'))', true, o.debug_it);
			}
			
			
			
			for(var i=0; i<ParticpantArray.length; i++)
			{
				var TN=$('#db_datatables .data_table[datatablename="Participant"] .data_row[data_DataID="'+ParticpantArray[i]+'"]').first();
				PA.push(TN);
				
				//debug(o.ObjName+' _usingRunningRatingSession( PA-push('+TN.attr('data_DataID')+' - '+TN.attr('data_ParticipantName')+'))', true, o.debug_it);
			}
       	
        	for(var i=0; i<StepArray.length; i++)
			{
				var SS=$('#db_datatables .data_table[datatablename="SessionStep"] .data_row[data_DataID="'+StepArray[i]+'"]').first();
				SA.push(SS);
				
				//debug(o.ObjName+' _usingRunningRatingSession( SA-push('+SS.attr('data_DataID')+' - '+SS.attr('data_step_name')+'))', true, o.debug_it);
			}
			
			
			
		
			
			// SessionGoal hinzufügen
			
			var SessionGoal=rs.attr('data_SessionGoal');
			$('<div id="RatingSession_Goal_Area"><span>'+SessionGoal+'</span></div>').appendTo('#div_window');
			
        	
        	w._creatingStepSlides();    	
        },
        _creatingStepSlides: function()
        {
        	var w=this, e=w.element, o=w.options, rs=o.ActivRatingSession_DataRow, SA=o.SessionSteps ;
        
        	//debug(o.ObjName+' _creatingStepSlides('+SA.length+')', true, o.debug_it);
        	
        	var tmp_prev_SS_id=0;
        	var tmp_next_SS_id=0;
        	
        	
			for(var i=0; i<SA.length;i++)
        	{
        		tmp_prev_SS_id=0;
        		tmp_next_SS_id=0;
        	
        		if(i>0) tmp_prev_SS_id=SA[i-1].attr('data_DataID');
        		if(i<(SA.length-1)) tmp_next_SS_id=SA[i+1].attr('data_DataID');
        	
        		e.prepend('<div SS_ID="'+SA[i].attr('data_DataID')+'"></div>');
        		
        		var SS_TYP=SA[i].attr('data_step_typ');
        		
        		if(SS_TYP=='login')
        		{
        			e.find('div[SS_ID="'+SA[i].attr('data_DataID')+'"]').DataE_SessionStepSlide_Login(
        			{
        				ObjName: 'SS('+SS_TYP+') - '+SA[i].attr('data_DataID')+' -',
        				DataMapping:[{DataTableName:'SessionStep',DataID: SA[i].attr('data_DataID'), DataAttributes: ['data_step_name','Step_name', 'data_headline', 'Headline', 'data_text', 'Text', 'data_picture', 'Picture', 'data_description', 'Description','data_step_typ','TYP', 'data_DataID', 'StepDataID']}],
        				Prev_SS_id: tmp_prev_SS_id,
        				Next_SS_id: tmp_next_SS_id,
        				ParticipantID:o.ParticipantID,
        				AllParticipantIDs: o.AllParticipantIDs,
        				ActivRatingSessionID: o.ActivRatingSessionID,
        				hasVisualitation:o.hasVisualitation
        			});
        		}else if(SS_TYP=='ratingA')
        		{
        			e.find('div[SS_ID="'+SA[i].attr('data_DataID')+'"]').DataE_SessionStepSlide_Rating(
        			{
        				ObjName: 'SS('+SS_TYP+') - '+SA[i].attr('data_DataID')+' -',
        				DataMapping:[{DataTableName:'SessionStep',DataID: SA[i].attr('data_DataID'), DataAttributes: ['data_step_name','Step_name', 'data_headline', 'Headline', 'data_text', 'Text', 'data_picture', 'Picture', 'data_description', 'Description','data_step_typ','TYP', 'data_DataID', 'StepDataID']}],
        				Prev_SS_id: tmp_prev_SS_id,
        				Next_SS_id: tmp_next_SS_id,
        				ParticipantID:o.ParticipantID,
        				AllParticipantIDs: o.AllParticipantIDs,
        				ActivRatingSessionID: o.ActivRatingSessionID,
        				TriggerDataLoad: true,
        				RatingModus: 'local_pre_rating',
        				SIGNAL_NAME: 'PRE_RATING_IS_DONE',
        				hasVisualitation:o.hasVisualitation
        			});
        		}else if(SS_TYP=='ratingB')
        		{
        			e.find('div[SS_ID="'+SA[i].attr('data_DataID')+'"]').DataE_SessionStepSlide_Rating(
        			{
        				ObjName: 'SS('+SS_TYP+') - '+SA[i].attr('data_DataID')+' -',
        				DataMapping:[{DataTableName:'SessionStep',DataID: SA[i].attr('data_DataID'), DataAttributes: ['data_step_name','Step_name', 'data_headline', 'Headline', 'data_text', 'Text', 'data_picture', 'Picture', 'data_description', 'Description','data_step_typ','TYP', 'data_DataID', 'StepDataID']}],
        				Prev_SS_id: tmp_prev_SS_id,
        				Next_SS_id: tmp_next_SS_id,
        				ParticipantID:o.ParticipantID,
        				AllParticipantIDs: o.AllParticipantIDs,
        				ActivRatingSessionID: o.ActivRatingSessionID,
        				TriggerDataLoad: true,
        				RatingModus: 'local_post_rating',
        				SIGNAL_NAME: 'POST_RATING_IS_DONE',
        				PRE_SIGNAL_NAME:'GLOBAL_RANKING_IS_DONE',
        				OrderBottomWaiting: 'Bitte warten Sie noch auf die anderen Teilnehmer.',
        				OrderTopShort:'',
        				OrderTopLeft: '',
               			OrderTopRight: '',
                		OrderRight:'Wenn die Idee, dem Kriterium <span class="green"><b>mehr entspricht</b></span> schieben Sie die Idee <b>hier</b> rein!',
                		OrderLeft: 'Wenn die Idee, dem Kriterium <span class="red"><b>weniger</b> entspricht</span> schieben Sie die Ideen in diesen Container!',
                		TextLeftSide: 'Ideen erf&uuml;llen das Kriterium <span class="red">weniger als die Gesamtidee</span>.',
                		TextRightSide: 'Ideen <span class="green">erf&uuml;llen</span> das Kriterium <span class="green">mehr als die Gesamtidee</span>.',
        				hasVisualitation:o.hasVisualitation
        			});
        		}else if(SS_TYP=='ideaRatingList')
        		{
        			e.find('div[SS_ID="'+SA[i].attr('data_DataID')+'"]').DataE_SessionStepSlide_IdeaList(
        			{
        				ObjName: 'SS - '+SA[i].attr('data_DataID')+' - IdeaList',
        				DataMapping:[{DataTableName:'SessionStep',DataID: SA[i].attr('data_DataID'), DataAttributes: ['data_step_name','Step_name', 'data_headline', 'Headline', 'data_text', 'Text', 'data_picture', 'Picture', 'data_description', 'Description','data_step_typ','TYP', 'data_DataID', 'StepDataID']}],
        				Prev_SS_id: tmp_prev_SS_id,
        				Next_SS_id: tmp_next_SS_id,
        				ParticipantID:o.ParticipantID,
        				AllParticipantIDs: o.AllParticipantIDs,
        				ActivRatingSessionID: o.ActivRatingSessionID,
        				hasVisualitation:o.hasVisualitation
        			});
        		}else
        		{
        		
        			e.find('div[SS_ID="'+SA[i].attr('data_DataID')+'"]').DataE_SessionStepSlide(
        			{
        				ObjName: 'SS - '+SA[i].attr('data_DataID')+' -',
        				DataMapping:[{DataTableName:'SessionStep',DataID: SA[i].attr('data_DataID'), DataAttributes: ['data_step_name','Step_name', 'data_headline', 'Headline', 'data_text', 'Text', 'data_picture', 'Picture', 'data_description', 'Description','data_step_typ','TYP', 'data_DataID', 'StepDataID']}],
        				Prev_SS_id: tmp_prev_SS_id,
        				Next_SS_id: tmp_next_SS_id,
        				ParticipantID:o.ParticipantID,
        				AllParticipantIDs: o.AllParticipantIDs,
        				ActivRatingSessionID: o.ActivRatingSessionID,
        				hasVisualitation:o.hasVisualitation
        			});
        		
        		}
        	}

        	
        	w._showActiveSS();
        
        },
        _showActiveSS:function()
        {
        
        	var w=this, e=w.element, o=w.options;
        	
        	var ActiveSS=w._getActiveSS();
        	
        	//debug(o.ObjName+' _showActiveSS('+ActiveSS+')', true, o.debug_it);
        	
        	e.find('.SLIDE_Laden').fadeOut('fast', function(){$(this).remove();});

        	if(ActiveSS!=undefined && ActiveSS!=false)
        	{
        		e.find('div[SS_ID="'+ActiveSS+'"]').trigger('show_slide');
        		w._initProgressbar();
        	}else
        	{
        		 e.append('<div class="SLIDE_FehlerSessionAnzeigen"><div class="CE-StepSlideItem"><br>Die aktive Phase konnte nicht gefunden werden. <br><br>Bitte warten wenden sie sich an den Versuchsleiter...<br><br></div></div>');
        		e.find('.SLIDE_FehlerSessionAnzeigen').DataE_SessionStepSlide({is_enabled:true});    
        	}  
     	   	
        },
        _initProgressbar: function()
        {
        	var w=this, e=w.element, o=w.options;
        	
        	
        	
        	$('#div_window').append('<div id="Session-Progressbar"></div>');

			
			$('#Session-Progressbar').SessionStep_Progressbar(
        	{
        		ObjName: 'Progressbar',
        		debug_it:true,
        		ActivSessionStepID: o.ActivSessionStepID,
        		SessionSteps:o.SessionSteps,
        		ParticipantID: o.ParticipantID,
        		DataMappingBetweenDataElements:[{UpdateAttribut:'ActiveStepID', MappedAttribute:'ActivSessionStepID', sendData:false, getData:true, needForGettingData: false}]
        	}); 
	
        } ,       
        _getActiveSS: function()
        {
        	var w=this, e=w.element, o=w.options, SA=o.SessionSteps;
        	
        	//debug(o.ObjName+'_getActiveSS('+SA.length+' - '+o.ActivSessionStepID+')',false,o.debug_it);
        	
        	
        	if(SA.length>0 && o.ActivSessionStepID!=0)
        	{
        		return o.ActivSessionStepID;
        	
        	}else if(SA.length>0)
        	{
        		return SA[0].attr('data_DataID');      	
        	}
        	return false;
        },
        destroy: function () { },
        setOption: function ( key, value, animate, commitToDatabase ) 
        { 
        	//ActivSessionStepID
        	var w=this, e=w.element, o=w.options, d=o.DataMapping, a=o.ArrayMonitoredAttributes;         	

           	
        	
        	if(key!=null && key!=undefined && (o[key]!=value))
            {	   
            	//debug(o.ObjName+' setOptionSS('+key+','+o[key]+'->'+value+')', true, o.debug_it);
                   
            		switch (key) 
            		{        	
                  		case "ActivSessionStepID":
                			o.key = value;
               	 			o[key] = value;
          					w._setOption(key, value);
                			            			
                  			break;
                  		default:
               	 		o.key = value;
               	 		o[key] = value;
                		break;
           			}
           			
           			if(commitToDatabase)  w._setOption(key, value);
            }  
        	$.Widget.prototype._setOption.apply( this, arguments );
        } 
    });
    
 	//########################################################## Session_Dis_View  ###################################
/*  ! ... CE. Session_Dis_View ........................................................................................ (Bookmark for Coda)  */     
    
    
       
    $.widget( "CE.Session_Dis_View", $.CE.DataElement, {
        options: 
        {
         ObjName:'<span style="color:">PV </span>',
         ActivRatingSessionID:'',
         ActivRatingSession_DataRow:'',
         IdeaIDs:[],
         Participants:[],
         SessionSteps:[],
         debug_it:true,
         was_init: false,
         
         hasVisualitation: false
         
         },
        _init: function(){

        	var w=this, e=w.element, o=w.options;

        	//############# SetOPTIONS - Defaults ###########
   			
   			e.addClass('CE_Session_Dis_View'); 
   			
   			e.append('<div id="MIDDLE_POINT_DIV"></div>');
   			e.find('#MIDDLE_POINT_DIV').MIDDLE_POINT_DIV();

			w._initDataElement();
			w._initArrowKeysForNavigation();
			
        },
        _initArrowKeysForNavigation: function()
         {
         	var w=this, e=w.element, o=w.options;
		
		  	$(document).keyup(function(event)
        	{
        			//debug(o.ObjName+event.keyCode+' was pressed',false,o.debug_it);
					
					$('.CE-StepSlide-ACTIVE').trigger('USE_KEYUPsFROMDOCUMENT', event)
					
					
					if(event.keyCode == 37 || event.keyCode == 39)
         			{
         				event.stopPropagation();
         		
         			}
					
        	}); 
        	
        	// prevent false interaction because of arrow keys
        	var ar=new Array(33,34,35,36,37,38,39,40);

			$(document).keydown(function(event) 
			{
    		 	var key = event.which;

      	
      			if($.inArray(key,ar) > -1) 
      			{
         			event.preventDefault();
          			event.returnValue= false;
      			}
      		
      			return true;
			}); 	
         },
        _afterGettingDataFromDatatables: function()
        {
        	var w=this, e=w.element, o=w.options;
        	
        	if(o.was_init!=true)
        	{
        		w._getRunningRatingSession();
        	}
        	
        	o.was_init=true; 	
        },
        _getRunningRatingSession: function(isRecursion)
        {
        	var w=this, e=w.element, o=w.options;
        	
        	
        	var RunningSessions=$('#db_datatables .data_table[datatablename="RatingSession"] .data_row[data_state!="ended"][data_is_template="0"]').first();
        	
			//debug(o.ObjName+'_getRunningRatingSession('+RunningSessions.attr('data_DataID')+')',true,o.debug_it);
			
        	if(RunningSessions.attr('data_DataID')!=undefined)
        	{
        		e.find('.SLIDE_Laden').fadeOut('fast', function(){$(this).remove();});
        		e.append('<div class="SLIDE_Laden"><div class="CE-StepSlideItem"><br>Ideenfindung wird geladen.<br><br><b>'+RunningSessions.attr('data_SessionName')+'</b><br><br>'+RunningSessions.attr('data_SessionGoal')+'<br><br> Bitte warten Sie kurz...<br><br></div></div>');
        		
        		e.find('.SLIDE_Laden').fadeIn();
        		
        		o.ActivRatingSessionID=RunningSessions.attr('data_DataID');
        		o.ActivRatingSession_DataRow=RunningSessions;
        		
        		var HasVis=RunningSessions.attr('data_with_visualization');
				if(HasVis==true || HasVis=='true')
				{
					o.hasVisualitation=true;
				
				}
        		
        		w._getDataFromRunningRatingSession();
        	}else
        	{
        		if(isRecursion!=true) $('<div class="SLIDE_Laden"></div>').appendTo(e).DataE_SessionStepSlide(
        		{
        			Headline:'<br><br><br><br>Zur Zeit findet keine Ideenfindung statt<br><br>Bitte warten Sie kurz...',
        			Text:''
        		}).trigger('show_slide');
        		
        		 e.find('.SLIDE_Laden h1').effect("shake", {times:6, distance:2}, 100);
        		
        		e.oneTime(5000, 'TIMER_Loading', function()
        		{
        				$('#db_datatables').trigger('loadData');
        				w._getRunningRatingSession(true);        				
        		});  
        	}
        },
        _getDataFromRunningRatingSession: function()
        {
        	var w=this, e=w.element, o=w.options, rs=o.ActivRatingSession_DataRow, IA=o.IdeaIDs, PA=o.Participants, SA=o.SessionSteps ;

			var IdeaArray=rs.attr('data_array_of_IdeaIDs').split(',');        	
        	var ParticpantArray=rs.attr('data_array_of_ParticipantIDs').split(','); 
        	var StepArray=rs.attr('data_array_of_stepIDs').split(','); 
   			
   			o.AllParticipantIDs=ParticpantArray;   			
   			
			for(var i=0; i<IdeaArray.length; i++)
			{
				var Idea=$('#db_datatables .data_table[datatablename="Idea"] .data_row[data_DataID="'+IdeaArray[i]+'"]').first();
				IA.push(Idea);
			}
			
			for(var i=0; i<ParticpantArray.length; i++)
			{
				var TN=$('#db_datatables .data_table[datatablename="Participant"] .data_row[data_DataID="'+ParticpantArray[i]+'"]').first();
				PA.push(TN);
			}
       	
        	for(var i=0; i<StepArray.length; i++)
			{
				var SS=$('#db_datatables .data_table[datatablename="SessionStep"] .data_row[data_DataID="'+StepArray[i]+'"]').first();
				SA.push(SS);
			}
			
			// SessionGoal hinzufügen
			
			var SessionGoal=rs.attr('data_SessionGoal');
			$('<div id="RatingSession_Goal_Area"><span>'+SessionGoal+'</span></div>').appendTo('#div_window');

        	w._creatingStepSlideForGroupDis();    	
        },
        _creatingStepSlideForGroupDis: function()
        {
        	var w=this, e=w.element, o=w.options, rs=o.ActivRatingSession_DataRow, IA=o.IdeaIDs, PA=o.Participants, SA=o.SessionSteps ;

			//debug(o.ObjName+' _creatingStepSlideForGroupDis()', true, o.debug_it);
        	for(var i=0; i<SA.length;i++)
        	{        	
        		var SS_TYP=SA[i].attr('data_step_typ');
        		
        		if(SS_TYP=='groupDis')
        		{
        	
        			$('<div SS_ID="CE_Session_Dis_View_RatingSlide"></div>').appendTo(e).DataE_SessionStepSlide_Rating(
        			{
        				ObjName: '<span style="color:#FFEE00;">DisRatingSLIDE</span> -',
        				DataMapping:[{DataTableName:'SessionStep',DataID: SA[i].attr('data_DataID'), DataAttributes: ['data_step_name','Step_name', 'data_headline', 'Headline', 'data_text', 'Text', 'data_picture', 'Picture', 'data_description', 'Description','data_step_typ','TYP', 'data_DataID', 'StepDataID']}],
        				Prev_SS_id: 0,
        				Next_SS_id: 0,
        				ParticipantID: 0,
        				AllParticipantIDs: o.AllParticipantIDs,
        				ActivRatingSessionID: o.ActivRatingSessionID,
        				TriggerDataLoad: false,
        				RatingModus: 'global_rating',
        				is_global: true,
        				SIGNAL_NAME:'GLOBAL_RANKING_IS_DONE',
        				PRE_SIGNAL_NAME:'PRE_RATING_IS_DONE',
        				OrderBottomWaiting: 'Jetzt gehen Sie bitte wieder zur Einzelbewertung.',
        				OrderTopShort:'Schw&auml;chste, akzeptierte Gesamtidee',
        				CloseRatingIfEveryIdeaIsRated:false,
        				hasVisualitation:o.hasVisualitation
        			}).trigger('show_slide');
        		}
        	}
        	
        	e.find('.SLIDE_Laden').remove();
      }  	
         
    });
    
    
    
    
    
	//########################################################## DataE_SessionStepSlide  ###################################
/*  ! ... CE. DataE_SessionStepSlide ........................................................................................ (Bookmark for Coda)  */     

	 $.widget( "CE.DataE_SessionStepSlide" ,$.CE.DataElement, {
        options: { 
                // Debugging
                ObjName:'SessionStepSlide ',
                debug_it:false,
                // Variables for DataMapping
                Step_name:'',
                Headline:'',
                Text:'',
                Picture:'',
                Description:'',
                TYP:'',
                SessionStep_DataRow:'',
                ParticipantID:0,
                AllParticipantIDs:0,
                ActivRatingSessionID:0,
                
                // Relation to other slides
                MyActiveStepID: 0,
                Next_SS_id:0,
                Prev_SS_id:0,
                // State of the Slide
                StepDataID:0,
                is_Active: false,                
                is_enabled: false,                
                Slide_isVisible:false,
                AllowKeyNavigation: true,
                SIGNAL_NAME:'',
                // Buttons
                ButtonLeft:'',
                ButtonRight:'',
              	ButtonLeft_isVisible:true,
              	ButtonRight_isVisible:true,
                ButtonLeftEnabled: false,
                ButtonRightEnabled: false,
                
                hasVisualitation:false
                
        },
        _init: function()
        {
			var w=this, e=w.element, o=w.options;
			
			w._initSessionStep();	
        },
        _initSessionStep: function()
        {
			var w=this, e=w.element, o=w.options;
			w._initArrowKeysForNavigation();
			//debug(o.ObjName+' _initSessionStep('+o.TYP+') mit ('+o.Prev_SS_id+' <-'+o.MyActiveStepID+'->'+o.Next_SS_id+')');
			w._initDataElement();
			
			// INIT HTML + CSS 
			e.css('opacity',0);
			e.addClass('CE-StepSlide');
			e.addClass('MIDDLE_POINT_CONNECTED');
    		
    		e.bind('update_position', function(event)
        	{
        		w.update_position();
        		event.stopPropagation();	
        	});
        	
        	e.bind('show_slide', function(event, param1)
        	{
        		w.show_slide(param1);
        		event.stopPropagation();	
        	});
        	
        	e.bind('hide_slide', function(event,param1)
        	{
        		w.hide_slide(param1);	
        		event.stopPropagation();
        	});
        	
        	// INIT NEXT and PREV Button 
        	e.append('<div class="SlideButtonLeft" ></div>');
        	o.ButtonLeft=e.find('.SlideButtonLeft');

        	e.append('<div class="SlideButtonRight"></div>');
        	o.ButtonRight=e.find('.SlideButtonRight');
        	
        	o.ButtonLeft.click(function(){ if(o.ButtonLeft_isVisible) w.showPrevSlide();});
			o.ButtonRight.click(function(){if(o.ButtonRight_isVisible) w.showNextSlide();});	
			
			w.hideButton();
			// GET DATA FROM DATABASE and USE IT
			w._getDataFromDatatables(true);
			
			var img='';
			if(o.Picture!='' && o.Picture!=undefined)
			{
				img='<div align="center"><img src="'+o.Picture+'"/></div>';
			}		
			e.append('<div class="CE-StepSlideItem"><h1>'+o.Headline+'</h1><p class="text">'+o.Text+'</p>'+img+'</div>');
			
			
        },
        _initArrowKeysForNavigation: function()
        {
        	var w=this, e=w.element, o=w.options;
        	
        	//debug(o.ObjName+'init AAAAAAAAAROOOOOOOOOOW KEYs',false,o.debug_it);
        	
        	
        	e.addClass('USE_KEYUPsFROMDOCUMENT');
        	
         	e.bind('USE_KEYUPsFROMDOCUMENT', function(event, keyevent)
         	{
         		//debug(o.ObjName+keyevent.keyCode+' was pressed ##################',true,o.debug_it);
         	
         		if(o['Slide_isVisible']==true && o.AllowKeyNavigation==true)
        		{
         				
         				keyevent.stopPropagation();
         				event.stopPropagation();
         					
         					
         			if(keyevent.keyCode == 37 && o.ButtonLeft.is(':visible')) // left
        				{
        					//debug(o.ObjName+keyevent.keyCode+' was pressed',true,o.debug_it);
        					w.showPrevSlide();	
        				}else
        				if(keyevent.keyCode == 39 && o.ButtonRight.is(':visible')) // right
        				{
        					//debug(o.ObjName+keyevent.keyCode+' was pressed',true,o.debug_it);
        					w.showNextSlide();
        				}
         			
         		} 		
         	}); 	
         },
        _sendParticipantStateSignalToDataBase: function(SignalString_New, removeSignalString, forceSave)
        {
        	var w=this, e=w.element, o=w.options;
     		
     		var SignalString=w._getParticipantStateSignalFromDatabase();     		
     		
     		if(SignalString===false ) return false;
     		
     		var indexOfNewSignal=-1;
     		for(var i=0; i< SignalString.length; i++)
     		{
     			if(SignalString[i]==SignalString_New)
     			{
     				indexOfNewSignal=i;
     				break;
     			}
     		}
     		
     		
     		//debug(o.ObjName+'_sendParticipantStateSignalToDataBase('+indexOfNewSignal+') ->'+SignalString_New,true,true);

     		if(removeSignalString==true )
     		{
				if(indexOfNewSignal>-1 || forceSave==true)
				{
					SignalString.splice(indexOfNewSignal,1);	
					w._sendDataToDatatables('Participant', o.ParticipantID, 'data_array_of_states', SignalString, 0, 0, true, false, false);
				}
     		}else
     		{
     			if(indexOfNewSignal==-1 || forceSave==true)
				{
					SignalString.push(SignalString_New);
					SignalString=SignalString.join(",");	
					w._sendDataToDatatables('Participant', o.ParticipantID, 'data_array_of_states', SignalString, 0, 0, true, false, false);
					
				}	
     		}
     		
     		//debug(o.ObjName+'_sendParticipantStateSignalToDataBase() ->'+SignalString,false,o.debug_it);
        },
        _sendSingnalToAllParticipants:function(Signal, removeSignalString, forceSave)
        {
        	
var w=this, e=w.element, o=w.options;

			debug(o.ObjName+'_sendSingnalToAllParticipants('+Signal+')',true,true);
        	
        	if(o.AllParticipantIDs==0 || o.AllParticipantIDs==undefined) return false;
        	        	
        	for(var i=0; i< o.AllParticipantIDs.length; i++)
        	{
        		var SignalString=$('#db_datatables .data_table[DataTableName="Participant"] .data_row[data_DataID="'+o.AllParticipantIDs[i]+'"]').first().attr('data_array_of_states').split(',');	
        	
        		if(SignalString==undefined || SignalString=='0' || SignalString==0)
        		{
        			return false;
        		}
        		
        		var indexOfNewSignal=-1;
        		
        		
        		for(var j=0; j< SignalString.length; j++)
     			{
     				if(SignalString[j]==Signal)
     				{
     					indexOfNewSignal=i;
     					break;
     				}
     			}
     			
     			
     			if(removeSignalString==true )
     			{
					if(indexOfNewSignal!=-1)
					{
						SignalString.splice(indexOfNewSignal,1);	
						SignalString=SignalString.join(",");
					}	
     			
     			}else
     			{ 
     				if(indexOfNewSignal==-1)
     				{
						SignalString.push(Signal);
						SignalString=SignalString.join(",");
     				}
     			}
     			
				if((removeSignalString==true && indexOfNewSignal!=-1) || (removeSignalString!=true && indexOfNewSignal==-1) || forceSave==true)
				{
					if( i< o.AllParticipantIDs.length-1)
					{
						w._sendDataToDatatables('Participant', o.AllParticipantIDs[i], 'data_array_of_states', SignalString, 1, 0, true, false, false);
					}else
					{
						w._sendDataToDatatables('Participant', o.AllParticipantIDs[i], 'data_array_of_states', SignalString, 0, 0, true, false, false);
					}
				}
     			
        	}

 
        },
        _getParticipantStateSignalFromDatabase: function()
        {
        	var w=this, e=w.element, o=w.options;
        
        	var SignalString=$('#db_datatables .data_table[DataTableName="Participant"] .data_row[data_DataID="'+o.ParticipantID+'"]').first().attr('data_array_of_states');	
        	
        	if(SignalString==undefined)
        	{
        		return false;
        	}
        
        	//debug(o.ObjName+'_getParticipantStateSignalFromDatabase('+o.ParticipantID+') ->'+SignalString,false,o.debug_it);
        
        	return SignalString.split(',');
        },
        _hasParticipantSignal: function(Signal)
        {
        	var w=this, e=w.element, o=w.options;
        	
        	return w._hasASpecialParticipantSignal(Signal,o.ParticipantID);
        },
        _hasASpecialParticipantSignal: function(Signal, PID)
        {
        
        	var w=this, e=w.element, o=w.options;
        
        	var SignalString=$('#db_datatables .data_table[DataTableName="Participant"] .data_row[data_DataID="'+PID+'"]').first().attr('data_array_of_states');	
        	
        	if(SignalString==undefined || SignalString=='0' || SignalString==0 || PID==0 || PID=='0' || PID == undefined)
        	{
        		return false;
        	}
        	
        	SignalString=SignalString.split(',');
        	
        	if(SignalString==false) return false;
     		
     		for(var i=0; i< SignalString.length; i++)
     		{
     			if(SignalString[i]==Signal)
     			{
     				return true;
     			}
     		}
     		
     		return false;
        
        
        },
        _hasAllParticipantsSignal: function(Signal)
        {
        	var w=this, e=w.element, o=w.options;
        
        	if(o.AllParticipantIDs==0 || o.AllParticipantIDs==undefined) return false;
        	        	
        	for(var i=0; i< o.AllParticipantIDs.length; i++)
        	{
        		var SignalString=$('#db_datatables .data_table[DataTableName="Participant"] .data_row[data_DataID="'+o.AllParticipantIDs[i]+'"]').first().attr('data_array_of_states').split(',');	
        	
        		if(SignalString==undefined || SignalString=='0' || SignalString==0)
        		{
        			return false;
        		}
        		
        		var tmp_has_Signal=false;
        		
        		for(var j=0; j< SignalString.length; j++)
     			{
     				if(SignalString[j]==Signal)
     				{
     					tmp_has_Signal=true;
     					break;
     				}
     			}
     			
     			if(!tmp_has_Signal)
     			{
     				return false;
     			}	
        	}
        	
        	return true;
        },        
        show_slide: function(fromLeft)
        {
        	var w=this, e=w.element, o=w.options;
        	
        	e.addClass('CE-StepSlide-ACTIVE');
        	
        	w._sendDataToOtherDataElements('ActiveStepID',o.StepDataID);
        	
        	w._updateButton();
        	
        	w.updateElement();
        	
        	if(fromLeft!=true)
        	{ 
        		w.fadeInFromRight();
        	}else
        	{
        		w.fadeInFromLeft();
        	} 	
        	
        	w._trigger('was_fadeIn');
        },
        hide_slide: function(fromRight)
        {
        	var w=this, e=w.element, o=w.options;
        	
        	e.removeClass('CE-StepSlide-ACTIVE');
        	
        	if(fromRight!=true)
        	{
        		w.fadeOutToLeft();
        	}        	
        	else 
        	{
        		w.fadeOutToRight();
        	}
        	
        	w._trigger('was_fadeOut');
        }, 
        showNextSlide: function()
        {
        	var w=this, e=w.element, o=w.options;
        	
        	w.hide_slide();
        	
        	$('.CE_Session_Admin_View').find('div[ss_id="'+o.Next_SS_id+'"]').trigger('show_slide');        
        },
        showPrevSlide: function()
        {
        	var w=this, e=w.element, o=w.options;
        	
        	w.hide_slide(true);
        	
        	$('.CE_Session_Admin_View').find('div[ss_id="'+o.Prev_SS_id+'"]').trigger('show_slide',true);
        },        
        _updateButton: function()
        {
        	var w=this, e=w.element, o=w.options;
        	
        	var ShowLeftButton=true;
        	var ShowRightButton=true;
        	
        	if(o.Prev_SS_id==0 || o.Prev_SS_id==undefined ) ShowLeftButton=false;
        	if(o.Next_SS_id==0 || o.Next_SS_id==undefined ) ShowRightButton=false;
        	
        	//debug(o.ObjName+' _updateButton ('+o.Prev_SS_id+'('+ShowLeftButton+') - <'+o.StepDataID+'> -'+o.Next_SS_id+'('+ShowRightButton+'))',false,o.debug_it);
        	
        	w.showButton(!ShowLeftButton, !ShowRightButton); 	
        },
        hideButton: function(hideLeftButtonNot, hideRightButtonNot, withoutlookingonconditions)
        {
        
        	var w=this, e=w.element, o=w.options;
	
        	if((hideLeftButtonNot!=true && o.ButtonLeft_isVisible) || withoutlookingonconditions==true)
        	{
        		o.ButtonLeft_isVisible=false;
        		o.ButtonLeft.hide('drop', {direction: 'right'});
        	}
        	
        	
        	if((hideRightButtonNot!=true && o.ButtonRight_isVisible)|| withoutlookingonconditions==true)
        	{
        		o.ButtonRight_isVisible=false;
        		o.ButtonRight.hide('drop', {direction: 'left'});
        	} 
        	
        	
        },
        showButton: function(showLeftButtonNot, showRightButtonNot)
        {
        	var w=this, e=w.element, o=w.options;

        	if(showLeftButtonNot!=true && !o.ButtonLeft_isVisible)
        	{ 
        		o.ButtonLeft_isVisible=true;
        		o.ButtonLeft.animate({top: ((e.height()/2)-32)+'px'},'fast');    		
        		o.ButtonLeft.show('drop', {direction: 'left'});
        	} 
        	
        	//debug(o.ObjName+'showButton'+o.ButtonRight_isVisible, false,o.debug_it);
        	
        	if(showRightButtonNot!=true  && !o.ButtonRight_isVisible)
        	{
        		
        		o.ButtonRight_isVisible=true;
        		o.ButtonRight.animate({top: ((e.height()/2)-32)+'px'},'fast');
        		o.ButtonRight.show('drop', {direction: 'right'});
        	} 
        },
        getNewPosition: function()
        {
        	var w=this, e=w.element, o=w.options;
        	var position=e.position();
			var MyTop=position.top;
			var MyLeft=position.left;
			var MyWidth=e.width();
			var MyHeight=e.height();
			
			var NewTop2=$('#MIDDLE_POINT_DIV').attr('top')-MyHeight/2+75;
			var NewLeft2=$('#MIDDLE_POINT_DIV').attr('left')-MyWidth/2;
			
			var NewPosition={left:NewLeft2, top:NewTop2};
			
			return NewPosition;
        },
        fadeInFromLeft: function(Speed)
        {
        	this.FadeMoveMiddePoint(true, Speed, 'Left');
        
        },
        fadeOutToLeft: function(Speed)
        {
        	this.FadeMoveMiddePoint(false, Speed, 'Left');  
        },     
        fadeInFromRight: function(Speed)
        {
        	this.FadeMoveMiddePoint(true, Speed, 'Right'); 
        },
        fadeOutToRight: function(Speed)
        {
        	this.FadeMoveMiddePoint(false, Speed, 'Right');  
        },
        FadeMoveMiddePoint: function(FadeIn, Speed, Direction)
        {
        	var w=this, e=w.element, o=w.options;
        	
        	// Neue Position			
			var PositionA=w.getNewPosition();
        	        	
        	//Direction -> PositionB
        	var PositionB={left:0, top:0};
        	var NewDirection='Right';
			if(Direction!=undefined)NewDirection=Direction;
			
			switch(NewDirection)
			{
				case "Right":
            		PositionB={left:$(window).width(), top:PositionA.top};
            	break;				
				case "Left":
            		PositionB={left:-e.outerWidth(), top:PositionA.top};
            	break;
            	case "Top":
            		PositionB={left:PositionA-left, top:-e.outerHeight()-75};
            	break;
            	case "Bottom":
            		PositionB={left:PositionA-left, top:$(window).Height()};
            	break;
			}

			// Geschwindigkeit
			var NewSpeed=1500;
			//if(Speed!=undefined)NewSpeed=Speed;
			
			var NewEasing='easeOutExpo'; //easeInOutBack, easeOutBack //http://jqueryui.com/demos/effect/easing.html
			
			var OpacityA=0;
			var OpacityB=1;
			
			o.Slide_isVisible=true;
			o['Slide_isVisible']=true;
			
			
			if(FadeIn==false)
			{
				var tmp=PositionB;
				PositionB=PositionA;
				PositionA=tmp;
				OpacityA=1;
				OpacityB=0;	
				o.Slide_isVisible=false;
				o['Slide_isVisible']=false;
			}		
				
			e.css('top', PositionB.top).css('left',PositionB.left).css('opacity',OpacityA).css('display','auto');
			
			e.stop();
			
			e.animate({top: PositionA.top, left: PositionA.left, opacity:OpacityB}, NewSpeed, NewEasing, function()
			{
					
			});	
        },updateElement: function() // zum Überschreiben
        {
        	var w=this, e=w.element, o=w.options;
        },
        update_position: function(withAnimation)
        {
        	var w=this, e=w.element, o=w.options;
        	
        	var NewPosition=w.getNewPosition();
							
			if(withAnimation)
			{
				e.animate({top: NewPosition.top, left: NewPosition.left}, 'fast');	
			}
			else 
			{ 
				e.css('top', NewPosition.top).css('left',NewPosition.left);
			}
        },    
        setOption: function ( key, value, animate, commitToDatabase, without_comparison ) 
        {
           	var w=this, e=w.element, o=w.options, d=o.DataMapping, a=o.ArrayMonitoredAttributes;         	

           	
        	
        	if(key!=null && key!=undefined && (o[key]!=value))
            {	 
            	//debug(o.ObjName+' setOptionSS('+key+','+o[key]+'->'+value+')', true, o.debug_it);         
            		switch (key) 
            		{        	
            			case "last_change_number":
            				o.key = value;
            				break;
            			case "is_enabled":
                				o.key = value;
                				                			              			
                  			break;
                  		case "ActivDataID":
                			o.key = value;
          			
                			            			
                  			break;
                  		default:
               	 		o[key] = value;
                		break;
           			}
           			
           			if(commitToDatabase)  w._setOption(key, value);
            }  
        }
    });


	//########################################################## LOGIN ##################################################
/*  ! ... CE. LOGIN ........................................................................................ (Bookmark for Coda)  */     
	 $.widget( "CE.DataE_SessionStepSlide_Login", $.CE.DataE_SessionStepSlide, {
        options: 
        {
        	ModulBwasInit: false,
        	SIGNAL_NAME:'LOGIN_IS_DONE',
        	debug_it:true
         },
        _init: function(){
			
			var w=this, e=w.element, o=w.options;
			w._initSessionStep();
			
			e.find('.CE-StepSlideItem').append('<div class="SS-Login-Modul-A" ></div>');
			
			e.find('.SS-Login-Modul-A').append('<div class="SS-Login-Input" style="width:400px; textAlign:left;"></div>');
			
			e.find('.SS-Login-Input').DataE_Inputfield(
        	{
        		label: 'Als Erstes geben Sie bitte <b>Ihren Namen</b> ein!', 
        		text:'Bitte den richtigen Namen.', 
        		is_enabled:true,
        		ObjName: 'Inputfield_Login_Name ',
        		DataMapping:[{DataTableName:'Participant',DataID: o.ParticipantID, DataAttributes: ['data_ParticipantName','input_value']}],
        		hasSubmitButton:true,
        		has_savedChange: function()
        		{
        			w._sendParticipantStateSignalToDataBase(o.SIGNAL_NAME, false);
        			w.updateElement();
        		},
        		has_init: function()
        		{
        			if(o.ParticipantID!=0)
					{
        				e.find('.SS-Login-Input').trigger('getDataFromDatatables');
						e.find('.SS-Login-Input').trigger('updateView');
					}
        		}
        	});
        	
        	w.updateElement();
			
        },
        updateElement: function()
        {
        	var w=this, e=w.element, o=w.options;
        	
        	//debug(o.ObjName+'updateElement() 1',true,o.debug_it);
        	
        	
        	var isReady=w._hasAllParticipantsSignal(o.SIGNAL_NAME);
        	
        	//debug(o.ObjName+'updateElement('+isReady+') 2',true,o.debug_it);
        	
        	if(isReady==true)
        	{
        		w._updateButton();
        	}else
        	{
        		w.hideButton();
        	}
        	
        	var isParticpantReady=w._hasParticipantSignal(o.SIGNAL_NAME);
        	
        	var ParticipantName=$('#db_datatables .data_table[DataTableName="Participant"] .data_row[data_DataID="'+o.ParticipantID+'"]').first().attr('data_ParticipantName');	
        	
        	if(isParticpantReady==true)
        	{	
        		w._initModulB();
        	}else if(ParticipantName!=undefined && ParticipantName!='')
        	{
        		w._sendParticipantStateSignalToDataBase(o.SIGNAL_NAME, false);
        		w._initModulB();
        	}
        },
        _initModulB: function()
        {
        	var w=this, e=w.element, o=w.options;
        	
        	
        	
        	var ParticipantName=e.find('.SS-Login-Input').DataE_Inputfield('option','input_value');
        	
        	
        	//debug(o.ObjName+'_initModulB (Name='+ParticipantName+')',true,o.debug_it);
        	
        	if(ParticipantName==false || o.ModulBwasInit==true) return false;
        	        	
        	o.ModulBwasInit=true;
        	
        	e.find('.CE-StepSlideItem').append('<div class="SS-Login-Modul-B"></div>');
			
			for(var i=0; i< o.AllParticipantIDs.length; i++)
			{
				var ClassAddition='';
				
				if(o.ParticipantID==o.AllParticipantIDs[i])
				{
					ClassAddition='SS-Login-Modul-B-Participant-OWN';
				}
				
				e.find('.SS-Login-Modul-B').append('<div class="SS-Login-Modul-B-Participant '+ClassAddition+'" PID="'+o.AllParticipantIDs[i]+'">'+i+'.Teilnehmer ('+o.AllParticipantIDs[i]+')</div>');
			}
			
			e.find('.SS-Login-Modul-B').append('<div class="SS-Login-Modul-B-Text">Jetzt warten wir nur, bis sich alle angemeldet haben...</div>');
			
        	w._updateModulBIfAllReady(0);

        },
        _updateModulBIfAllReady: function(index)
        {
        	var w=this, e=w.element, o=w.options;
        	
        	//debug(o.ObjName+'_hasAllParticipantsSignal('+w._hasAllParticipantsSignal(o.SIGNAL_NAME)+')',false,o.debug_it);
        
        	var all_participants_ready=true;
        	
        	for(var i=0; i< o.AllParticipantIDs.length; i++)
        	{
        		var tmp_Participant=$('#db_datatables .data_table[DataTableName="Participant"] .data_row[data_DataID="'+o.AllParticipantIDs[i]+'"]').first();	
        		
        		var tmp_p_div=e.find('.SS-Login-Modul-B').find('div[PID="'+o.AllParticipantIDs[i]+'"]');
        		
        		// Ggf Namen schon hinzufügen
        		var Name=tmp_Participant.attr('data_ParticipantName');
        		
        		if(Name!='' && Name!=undefined)
        		{
        			tmp_p_div.html(i+'.TN ('+Name+')');
        		}
        		
        		var SignalString=tmp_Participant.attr('data_array_of_states').split(',');
        		
        		// Test op der Teilnehmer bereit ist
        		var tmp_participant_is_ready=false;
        		
        		for(var j=0; j< SignalString.length; j++)
     			{
     				if(SignalString[j]==o.SIGNAL_NAME)
     				{
     					tmp_participant_is_ready=true;
     					break;
     				}
     			}
     			
     			
     			if(tmp_participant_is_ready==true) 
     			{
     				tmp_p_div.removeClass('SS-Login-Modul-B-Participant-Waiting').addClass('SS-Login-Modul-B-Participant-Ready');
     					
     			}else
     			{
     				tmp_p_div.addClass('SS-Login-Modul-B-Participant-Waiting').removeClass('SS-Login-Modul-B-Participant-Ready');
     				all_participants_ready=false;
     			}
        	}
        	
        	var text_div=e.find('.SS-Login-Modul-B').find('div.SS-Login-Modul-B-Text');
        	
        	if(all_participants_ready)
        	{
        		w.updateElement();
        		text_div.html('Jetzt gehts los. Nutzen sie den rechten Pfeil, um weiter zu kommen');
        	}else
        	{
        		var WaitingPoints='';
        		for(var i=0; i<index%5; i++)
        		{
        			WaitingPoints=WaitingPoints+' . ';
        		}
        		
        		text_div.html('Jetzt warten wir nur, bis sich alle angemeldet haben'+WaitingPoints);
        		
        		e.oneTime(1000, 'TIMER_Waiting', function()
        		{
        				if(index%5==0) $('#db_datatables').trigger('loadData');//TriggerloadDataFromDB: function(CountToTrigger, TriggerTimeInMS, IsImportantChange)
        				w._updateModulBIfAllReady(++index);
        		}); 
        		
        	}
        }
        
    });
    
    
    //########################################################## IdeaList ##################################################
/*  ! ... CE. IdeaList ........................................................................................ (Bookmark for Coda)  */     
	 $.widget( "CE.DataE_SessionStepSlide_IdeaList", $.CE.DataE_SessionStepSlide, {
        options: 
        {
        	debug_it:true
         },
        _init: function(){
			
			var w=this, e=w.element, o=w.options;
			w._initSessionStep();
			
			e.find('.CE-StepSlideItem').append('<div class="IdeaList">IDEALIST is COMMING</div>');

			
        },
        _initIdeaList: function()
        {
        
        
        
        },
        _updateIdeaList: function()
        {
        
        
        
        
        },
        _afterGettingDataFromDatatables: function()
        {
        	var w=this, e=w.element, o=w.options;

        	var last_change_number_global=$('#db_datatables').attr('last_change_number');
    	
        	var my_last_changenumber=Math.abs(o.last_change_number);

        	if(my_last_changenumber<last_change_number_global)
        	{
        		w.setOption('last_change_number',last_change_number_global, true, false); 
        		if(o['Slide_isVisible']==true) w._updateIdeaList();
        	
        	}	
        }      
    });
    
    

    
    	//########################################################## Rating ##################################################
/*  ! ... CE. Rating ........................................................................................ (Bookmark for Coda)  */     
	 $.widget( "CE.DataE_SessionStepSlide_Rating", $.CE.DataE_SessionStepSlide, {
        options: 
        {
                TextLeftSide: 'Ideen erf&uuml;llen das Kriterium <span class="red">nicht ausreichend</span>.',
                TextRightSide: 'Ideen <span class="green">erf&uuml;llen</span> das Kriterium <span class="green">ausreichend</span>.',
                TextKriterium: 'Besser Ideen finden',                
                RatingModus:'local_pre_rating',
                zIndexForIdeas:4000,
                TriggerDataLoad: false,
                OrderTopLeft: 'W&auml;hlen Sie die Idee aus, welche das Kriterium <span class="orange"><b>am ehesten</b></span> erf&uuml;llt!',
                OrderTopRight: 'W&auml;hlen Sie die Idee aus, welche das Kriterium <span class="orange"><b>am wenigsten</b></span> erf&uuml;llt!',
                OrderRight:'Wenn die Idee, dem Kriterium <span class="green"><b>entspricht</b></span> schieben Sie die Idee <b>hier</b> rein!',
                OrderLeft: 'Wenn die Idee, dem Kriterium <span class="red"><b>nicht</b> entspricht</span> schieben Sie die Ideen in diesen Container!',
                OrderBottomWaiting: 'Jetzt warten wir auf die anderen',
                OrderBottomNext: 'Jetzt gehts weiter, gehe zum n&auml;chsten Schritt',
                OrderTopShort: 'Stellvertreter',
                SIGNAL_NAME: 'RATING_DONE',
                PRE_SIGNAL_NAME:'',
                is_waiting_for_pre_signal:false,
                RATING_WAS_DONE: false,
                debug_it: true,
                CloseRatingIfEveryIdeaIsRated: true,
                is_global:false,
                enabled: false,
                NoVisClass:''
         },
        _init: function(){
			var w=this, e=w.element, o=w.options;
			w._initSessionStep();
			
			if(o.hasVisualitation!=true)
			{
				o.NoVisClass='NoVis';
			}
			
			w._waiting_forPreSignal();				
        },
         _waiting_forPreSignal:function()
         {
         	var w=this, e=w.element, o=w.options;
         	
         	debug(o.ObjName+'_waiting_forPreSignal(1 - '+o.PRE_SIGNAL_NAME+')',true,o.debug_it);
         	
         	if(o.PRE_SIGNAL_NAME==undefined || o.PRE_SIGNAL_NAME=='' || o.PRE_SIGNAL_NAME==false)
         	{ 
         		w._initRatingModul(); 
         		return true;
         	
         	}
         	
         	var HasAllParticipant=w._hasAllParticipantsSignal(o.PRE_SIGNAL_NAME);
         	        	
         	debug(o.ObjName+'_waiting_forPreSignal(2 -'+HasAllParticipant+')',true,o.debug_it);
         	
         	if(HasAllParticipant==true)
         	{
         		w._initRatingModul();
         	}else
         	{
         		
         		if(o.is_waiting_for_pre_signal!=true)
         		{
         			$('<h1 class="waiting_2">WIR WARTEN NOCH AUF ANDERE TEILNEHMER</h1>').appendTo(e.find('.CE-StepSlideItem')).effect("shake", {times:12, distance:2}, 100);
         			o.is_waiting_for_pre_signal=true;   
         			o.TriggerDataLoad=true;    
         			o.Slide_isVisible=true;
         			w.hideButton();  			
         		}else
         		{
         			e.find('.waiting_2').effect("shake", {times:12, distance:2}, 100);
         		}
					
         			w._activatedTrigger();
         	}
         
         },
         _initRatingModul: function()
         {
         	var w=this, e=w.element, o=w.options;
			
			o.is_waiting_for_pre_signal=false;   
         	o.Slide_isVisible=false;  
			
			e.removeClass('CE-StepSlide').addClass('CE-StepSlide-Rating');
			e.find('.CE-StepSlideItem').remove();			
			e.append('<div class="CE-StepSlideItemRating"><h1>'+o.Text+'</h1></div>');		
			
			e.append('<div class="CE-StepSlide-Rating-Background"></div>');
			
			e.append('<div class="CE-StepSlide-Rating-Left "><div class="CE-StepSlide-Rating-Mini-Left-Text CE-StepSlide-Rating-JUST-TEXT "></div></div>');
			e.append('<div class="CE-StepSlide-Rating-Middle "></div>');
			e.append('<div class="CE-StepSlide-Rating-Right "><div class="CE-StepSlide-Rating-Mini-Right-Text CE-StepSlide-Rating-JUST-TEXT "></div></div>');
			e.append('<div class="CE-StepSlide-Rating-Bottom "></div>');
			
			
			e.append('<div class="CE-StepSlide-Rating-Order-Top">'+o.OrderTopShort+'</div>');
			e.append('<div class="CE-StepSlide-Rating-Top"></div>');
			
			
			e.append('<div class="CE-StepSlide-Rating-Order-ArrowLeft"></div>');
			e.append('<div class="CE-StepSlide-Rating-Order-ArrowRight"></div>');
			
			e.append('<div class="CE-StepSlide-Rating-Order CE-StepSlide-Rating-Order-Right CE-StepSlide-Rating-JUST-TEXT">'+o.OrderRight+'</div>');
			
			e.append('<div class="CE-StepSlide-Rating-Order CE-StepSlide-Rating-Order-Left CE-StepSlide-Rating-JUST-TEXT">'+o.OrderLeft+'</div>');
			
			e.append('<div class="CE-StepSlide-Rating-Order CE-StepSlide-Rating-Order-TopRight CE-StepSlide-Rating-JUST-TEXT">'+o.OrderTopRight+'</div>');
			e.append('<div class="CE-StepSlide-Rating-Order CE-StepSlide-Rating-Order-TopLeft CE-StepSlide-Rating-JUST-TEXT">'+o.OrderTopLeft+'</div>');
			
			if(o.is_global!=true)
			{
			
				e.append('<div class="CE-StepSlide-Rating-Order-ArrowBottomWaiting"></div>');
				e.append('<div class="CE-StepSlide-Rating-Order-ArrowBottomNext"></div>');
				e.append('<div class="CE-StepSlide-Rating-Order CE-StepSlide-Rating-Order-BottomWaiting">'+o.OrderBottomWaiting+'</div>');
				e.append('<div class="CE-StepSlide-Rating-Order CE-StepSlide-Rating-Order-BottomNext">'+o.OrderBottomNext+'</div>');
			}
			
			e.append('<div class="CE-StepSlide-Rating-Order CE-StepSlide-Rating-Order-BottomWaiting">'+o.OrderBottomWaiting+'</div>');
			
			$('<div class="CE-StepSlide-Rating-ButtonLeft"></div>').appendTo(e).click(function(event)
			{
				w._moveCurrentIdeaToLeft();
				event.stopPropagation();
			});
			$('<div class="CE-StepSlide-Rating-ButtonRight"></div>').appendTo(e).click(function(event)
			{
				w._moveCurrentIdeaToRight();
				event.stopPropagation();
			});
			
			
			$('<div class="CE-StepSlide-Rating-ButtonBottom"></div>').appendTo(e).click(function(event)
			{
				w._moveIdeaToTheBottomOfStaple('');
				event.stopPropagation();
			});
			
			
			e.append('<span class="CE-StepSlide-Rating-AnimatedHandle" AnimatedHandelNr="0"/>');
			e.append('<span class="CE-StepSlide-Rating-AnimatedHandle" AnimatedHandelNr="1"/>');
			e.append('<span class="CE-StepSlide-Rating-AnimatedHandle" AnimatedHandelNr="2"/>');
			e.append('<span class="CE-StepSlide-Rating-AnimatedHandle" AnimatedHandelNr="3"/>');
			e.append('<span class="CE-StepSlide-Rating-AnimatedHandle" AnimatedHandelNr="4"/>');
			e.find('.CE-StepSlide-Rating-AnimatedHandle').css('opacity', '0');
			
			
			if(o.hasVisualitation==true)
			{
				w._initMiniRatingVisualizations();
			}
			
			w._setTextForSides();
			w._createItemsForRelatedIdeaRatings();
			w._initArrowKeysForNavigation_Rating();
			
			o.was_fadeIn=function(event)
				{
					//w._activatedTrigger();
					w._updateMyView();
					event.stopPropagation();
					//w._activateFunctionality();
				};
			
			o.was_fadeOut=function(event)
				{
					w._deactivatedTrigger();
					w._deactivateFunctionality();
					event.stopPropagation();
				}	
			
			e.bind('AnimationEnd', function(event)
			{				
				if(o['Slide_isVisible']==true)
				{
					//debug(o.ObjName+'AnimationEnd ################# ',true,o.debug_it);
					w._updateMyView();
							
					event.stopPropagation();
				}
				
			});
         
         
         
         
         },
        _initArrowKeysForNavigation_Rating: function()
        {
        	var w=this, e=w.element, o=w.options;
        	
         	e.bind('USE_KEYUPsFROMDOCUMENT', function(event, keyevent)
         	{
         		//debug(o.ObjName+keyevent.keyCode+' was pressed 2 ('+o['Slide_isVisible']+' && '+o.AllowKeyNavigation+')',true,o.debug_it);
         	
         		if(o['Slide_isVisible']==true && o.AllowKeyNavigation==false)
        		{
         				
         				keyevent.stopPropagation();
         				event.stopPropagation();
         					
         					
         			if(keyevent.keyCode == 37) // left
        				{
        					//debug(o.ObjName+keyevent.keyCode+' was pressed',false,o.debug_it);
        					
        					w._moveCurrentIdeaToLeft();
        					
        				}else
        				if(keyevent.keyCode == 39) // right
        				{
        					//debug(o.ObjName+keyevent.keyCode+' was pressed',false,o.debug_it);
        					
        					w._moveCurrentIdeaToRight();
        					
        				}else
        				if(keyevent.keyCode == 32) // right
        				{
        					//debug(o.ObjName+keyevent.keyCode+' was pressed (now)',false,o.debug_it);
        					w._moveIdeaToTheBottomOfStaple('');
        				}
         		}		
         	});
        	   	
         },
         _afterGettingDataFromDatatables: function()
         {
         	var w=this, e=w.element, o=w.options;
         	
         	var last_change_number_global=$('#db_datatables').attr('last_change_number');
    	
        	var my_last_changenumber=Math.abs(o.last_change_number);
        	
        	
        	
        	if(my_last_changenumber<last_change_number_global)
        	{
        		w.setOption('last_change_number',last_change_number_global, true, false); 
        		if(o['Slide_isVisible']==true) w._updateMyView();
        	
        	}     
         },
        _activatedTrigger: function()
        {
        	var w=this, e=w.element, o=w.options;
        	
        	if(o.Slide_isVisible!=true) return false;
        	
        	if(o.TriggerDataLoad==true)
        	{
        		e.stopTime();
        		e.everyTime(4000, 'TIMER_USE', function()
        		{      			
        			$('#db_datatables').trigger('loadData');
        			
        			if(o.is_waiting_for_pre_signal==true)
        			{
        				e.find('.waiting_2').effect("shake", {times:12, distance:2}, 100);
        			}
        		});	
        	}
        
        },
        _deactivatedTrigger: function()
        {
        	var w=this, e=w.element, o=w.options;
        	e.stopTime();
  
        },
        _activateFunctionality: function()
        {
        	var w=this, e=w.element, o=w.options;
        	
        	if(o.Slide_isVisible!=true) return false;
        	
        	o.enabled=true;
        	
        	e.find('.CE-StepSlide-Rating-Left, .CE-StepSlide-Rating-Middle, .CE-StepSlide-Rating-Right, .CE-StepSlide-Rating-Top').sortable(
        	{
        		disabled: false
        	});

        	//debug(o.ObjName+' ACTIV',true,o.debug_it);      	
        
        },
         _deactivateFunctionality: function()
        {
        	var w=this, e=w.element, o=w.options;

        	o.enabled=false;
        	
        	e.find('.CE-StepSlide-Rating-Left, .CE-StepSlide-Rating-Middle, .CE-StepSlide-Rating-Right, .CE-StepSlide-Rating-Top').sortable(
        	{
        		disabled: true
        	}); 
        	
        	
        
        	//debug(o.ObjName+' DEACTIV',true,o.debug_it);
        },        
        _createItemsForRelatedIdeaRatings: function()
        {
        	var w=this, e=w.element, o=w.options;
        
        	//debug(o.ObjName+'_createItemsForRelatedIdeaRatings()',false,o.debug_it);
        	
        	switch(o.RatingModus)
        	{
        		case 'local_pre_rating':
        			w._createItemsForRelatedIdeaRatings_local_pre_rating();
        		break;
        		case 'global_rating':
        			w._createItemsForRelatedIdeaRatings_global_rating();
        		break;
        		case 'local_post_rating':
        			w._createItemsForRelatedIdeaRatings_local_post_rating();
        		break;
        		
        		default:        		
        		break;        	
        	
        	}
        	
        	w._initLinkedListAndDragFunction();
        	w._initLinkedBrushFunction();
       		w._updateMyView();
        },
        _createItemsForRelatedIdeaRatings_local_pre_rating: function()
        {
        	var w=this, e=w.element, o=w.options;
        	
        	var IdeaRatings=$('#db_datatables .data_table[DataTableName="Idea_Rating_Participant"] .data_row[data_ParticipantID="'+o.ParticipantID+'"]');
        	
        	if(IdeaRatings.length==0 || IdeaRatings=='' || IdeaRatings==undefined) return false;
        	
        	IdeaRatings.each(function(index)
        	{
        	    var idea_html_template_tmp=w._getHTMLTemplateForIdeaID($(this).attr('data_IdeaID'), $(this).attr('data_DataID'), index);
        	    
        	    var state_of_idea=$(this).attr('data_'+o.RatingModus);

        	    var RatingClasses='RATING_A_'+$(this).attr('data_local_pre_rating')+' ';

        	     var ZielBereich='';
        	      
        	      
        	      switch (state_of_idea) 
            	{        	
            		case 'is_not_rated':
            			ZielBereich='.CE-StepSlide-Rating-Middle';
            			break;
               		case 'is_local_threshold':
            			ZielBereich='.CE-StepSlide-Rating-Top';
            			break;
            		case 'is_preaccepted':
            			ZielBereich='.CE-StepSlide-Rating-Right';
            			break;
            		case 'is_prereject':
            			ZielBereich='.CE-StepSlide-Rating-Left';
            			break;
            		default:
               	 		ZielBereich='.CE-StepSlide-Rating-Middle';
                	break;
           		}
           		
           		$(idea_html_template_tmp).appendTo(e.find(ZielBereich)).addClass(RatingClasses);
           });
        
        },
        _createItemsForRelatedIdeaRatings_local_post_rating: function()
        {
        	var w=this, e=w.element, o=w.options;
        	
        	var IdeaRatings=$('#db_datatables .data_table[DataTableName="Idea_Rating_Participant"] .data_row[data_ParticipantID="'+o.ParticipantID+'"], #db_datatables .data_table[DataTableName="Idea_Rating_Participant"] .data_row[data_global_rating="is_global_threshold"][data_SessionID="'+o.ActivRatingSessionID+'"]');
        	
        	if(IdeaRatings.length==0 || IdeaRatings=='' || IdeaRatings==undefined) return false;
        	
        	
        	IdeaRatings.each(function(index)
        	{
        	    var idea_html_template_tmp=w._getHTMLTemplateForIdeaID($(this).attr('data_IdeaID'), $(this).attr('data_DataID'), index);
        	    
        	    
        	     
        	     //debug(o.ObjName+'_createItems(Idea('+$(this).attr('data_DataID')+') - '+state_of_idea+')',false,o.debug_it);
        	     var RatingClasses='RATING_A_'+$(this).attr('data_local_pre_rating') +' GROUPDIS_'+$(this).attr('data_global_rating') +' RATING_B_'+$(this).attr('data_local_post_rating')+' ';
        	    
        	      var ZielBereich='';
        	      var state_of_idea=$(this).attr('data_global_rating');
        	      
        	      switch (state_of_idea) 
            	{        	
            		case 'is_global_threshold':
            			ZielBereich='.CE-StepSlide-Rating-Top';
            			RatingClasses=RatingClasses+' CE-StepSlide-Rating-Disabled_DragFunction';
            			break;
            		case 'is_rework':
            			ZielBereich='.CE-StepSlide-Rating-Middle';
            			break;
            		case 'is_accepted':
            			ZielBereich='.CE-StepSlide-Rating-Right';
            			RatingClasses=RatingClasses+' CE-StepSlide-Rating-Disabled_DragFunction';
            			break;
            		case 'is_reject':
            			ZielBereich='.CE-StepSlide-Rating-Left';
            			RatingClasses=RatingClasses+' CE-StepSlide-Rating-Disabled_DragFunction';
            			break;
            		default:
               	 		ZielBereich='';
                	break;
           		}
           		
           		
           		
           		state_of_idea=$(this).attr('data_local_post_rating');
           		if(ZielBereich=='' || ZielBereich=='.CE-StepSlide-Rating-Middle')
           		{
           		
           			 switch (state_of_idea) 
            		{        	
            		case 'is_postaccepted':
            			ZielBereich='.CE-StepSlide-Rating-Right';
            			break;
            		case 'is_postreject':
            			ZielBereich='.CE-StepSlide-Rating-Left';
            			break;
            		case 'is_not_rated':
            			ZielBereich='.CE-StepSlide-Rating-Middle';
            			break;
            		default:
               	 		ZielBereich='.CE-StepSlide-Rating-Middle';
                	break;
           			}          		
           		}

           		$(idea_html_template_tmp).appendTo(e.find(ZielBereich)).addClass(RatingClasses);
        	    
        	}); 	
        
        },
        _createItemsForRelatedIdeaRatings_global_rating: function()
        {
        	var w=this, e=w.element, o=w.options;
        
        	var IdeaRatings=$('#db_datatables .data_table[DataTableName="Idea_Rating_Participant"] .data_row[data_local_pre_rating="is_local_threshold"][data_SessionID="'+o.ActivRatingSessionID+'"]');
        	
        	if(IdeaRatings.length==0 || IdeaRatings=='' || IdeaRatings==undefined) return false;
        	
        	IdeaRatings.each(function(index)
        	{
        	    var idea_html_template_tmp=w._getHTMLTemplateForIdeaID($(this).attr('data_IdeaID'), $(this).attr('data_DataID'), index);
        	    
        	    var state_of_idea=$(this).attr('data_'+o.RatingModus);

        	    var RatingClasses='RATING_A_'+$(this).attr('data_local_pre_rating') +' GROUPDIS_'+$(this).attr('data_global_rating')+' ';

        	    var ZielBereich='';
        	      
        	      
        	      switch (state_of_idea) 
            	{        	
            		case 'is_not_rated':
            			ZielBereich='.CE-StepSlide-Rating-Middle';
            			break;
                    case 'is_global_threshold':
            			ZielBereich='.CE-StepSlide-Rating-Top';
            			break;
            		case 'is_accepted':
            			ZielBereich='.CE-StepSlide-Rating-Right';
            			break;
            		case 'is_reject':
            			ZielBereich='.CE-StepSlide-Rating-Left';
            			break;
            		default:
               	 		ZielBereich='.CE-StepSlide-Rating-Middle';
                	break;
           		}
	
           		$(idea_html_template_tmp).appendTo(e.find(ZielBereich)).addClass(RatingClasses);
        	    
        	});
    	
        	
        },          
        _initLinkedListAndDragFunction: function()
        {
        	var w=this, e=w.element, o=w.options;
        
        	e.find('.CE-StepSlide-Rating-Left, .CE-StepSlide-Rating-Middle, .CE-StepSlide-Rating-Right, .CE-StepSlide-Rating-Top').sortable(
        	{
        		connectWith: '.CE-StepSlide-Rating-Left, .CE-StepSlide-Rating-Middle, .CE-StepSlide-Rating-Right',
        		receive: function(event, ui)
        		{
        			var State='';
        			if($(this).hasClass('CE-StepSlide-Rating-Left'))
        			{
        				State='left';
        			}
        			else if($(this).hasClass('CE-StepSlide-Rating-Right'))
        			{
        				State='right';
        			}        			
        			else if($(this).hasClass('CE-StepSlide-Rating-Middle'))
        			{
        				State='middle';
        			}
        			else if($(this).hasClass('CE-StepSlide-Rating-Top'))
        			{
        				State='top';
        			}
        			
        			event.stopPropagation();
        			
        			ui.item.css('z-index', o.zIndexForIdeas);
        			o.zIndexForIdeas++;
        			w._saveRatingForIdea(ui.item.attr('IdeaID'), ui.item.attr('IdeaRatingID'), State);
        			w._updateMyView();
        			
        		},
        		helper: function(event, ui)
        		{
        			var tmp_class='';
        			ui.find('span').css('font-size', '10px');
        			
        			if(ui.hasClass('CE-StepSlide-Rating-Idea-NoShortDiscription'))
        			{
        				tmp_class='CE-StepSlide-Rating-IdeaDragHelper-NoShortDiscription';
        			}
        			
        			if(ui.hasClass('CE-StepSlide-Rating-Idea-NoPicture'))
        			{
        				tmp_class=tmp_class+' CE-StepSlide-Rating-IdeaDragHelper-NoPicture';
        			}
        			
        			event.stopPropagation();
        			return '<div class="CE-StepSlide-Rating-IdeaDragHelper '+tmp_class+'" IdeaRatingID="'+ui.attr('IdeaRatingID')+'">'+ui.html()+'</div>';
        		},
        		start: function(event, ui)
        		{
        			ui.helper.css('z-index', o.zIndexForIdeas);
        			ui.helper.find('span').css('font-size', '10px');
        			o.zIndexForIdeas++;  
        			event.stopPropagation();
        			 			
        		}
        		,
        		over: function(event, ui)
        		{
        			if($(this).hasClass('CE-StepSlide-Rating-Left'))
        			{
        				$(this).addClass('CE-StepSlide-Rating-Left-IdeaDragOver');
        			}
        			else if($(this).hasClass('CE-StepSlide-Rating-Right'))
        			{
        				$(this).addClass('CE-StepSlide-Rating-Right-IdeaDragOver');
        			}
        			else if($(this).hasClass('CE-StepSlide-Rating-Middle'))
        			{
        				$(this).addClass('CE-StepSlide-Rating-Middle-IdeaDragOver');
        			}
        			else if($(this).hasClass('CE-StepSlide-Rating-Top'))
        			{
        				$(this).addClass('CE-StepSlide-Rating-Top-IdeaDragOver');
        			}
        			
        			event.stopPropagation();
        		},
        		out: function(event, ui)
        		{
        			
        			$(this).removeClass('CE-StepSlide-Rating-Left-IdeaDragOver');
        			$(this).removeClass('CE-StepSlide-Rating-Right-IdeaDragOver');
        			$(this).removeClass('CE-StepSlide-Rating-Middle-IdeaDragOver');
        			$(this).removeClass('CE-StepSlide-Rating-Top-IdeaDragOver');
        			
        			event.stopPropagation();
        		},
        		cursorAt:
        		{
        			top: 20,
        			left:100
        		},
        		activate: function(event, ui)
        		{
        			event.stopPropagation();
        			//alert(ui.helper.attr('idearatingid'));
        			
        			
        			
        		
        		
        		}, // Prevents sorting if you start on elements matching the selector.
        		cancel: '.CE-StepSlide-Rating-Disabled_DragFunction, .CE-StepSlide-Rating-JUST-TEXT',
        		opacity: 0.7
        	}).disableSelection();
        	
        	
        	
        	
        	e.find('.CE-StepSlide-Rating-Idea').click(function(event)
        	{
				w._moveSelectedIdeaToTopIfAllowd($(this).attr('IdeaRatingID'));      		
        		event.stopPropagation();
        	});    
        },
        _initLinkedBrushFunction: function()
        {
        	var w=this, e=w.element, o=w.options;
        
        	e.find('.CE-StepSlide-Rating-Idea').mouseenter(function()
        	{
        		e.find('.CE-StepSlide-Rating-Mini-Items').removeClass('CE-StepSlide-Rating-Idea-linked-Mini-Item-Highlight');   		
        		
        		e.find('.CE-StepSlide-Rating-Mini-Items[idearatingid="'+$(this).attr('idearatingid')+'"]').addClass('CE-StepSlide-Rating-Idea-linked-Mini-Item-Highlight');
        	}).mouseleave(function()
        	{
        		e.find('.CE-StepSlide-Rating-Mini-Items').removeClass('CE-StepSlide-Rating-Idea-linked-Mini-Item-Highlight');     	
        	});        
        },
        _initMiniRatingVisualizations: function()
        {
        	var w=this, e=w.element, o=w.options;

        	//debug(o.ObjName+'_initMiniRatingVisualizations for Participants('+o.AllParticipantIDs.length+')',false,o.debug_it);

        	
        	for(var i=0; i< o.AllParticipantIDs.length; i++)
        	{
        		var tmp_pid=o.AllParticipantIDs[i];
        		$('<div class="CE-StepSlide-Rating-Mini CE-StepSlide-Rating-Mini-'+i+'" PID="'+i+'"></div>').appendTo(e.find('.CE-StepSlide-Rating-Bottom')).SessionStep_MiniRatingVis(
        		{
        			ParticipantID: tmp_pid,
                	ActivRatingSessionID: o.ActivRatingSessionID,
                	ObjName: 'MiniRatVis()',
                	isParticipantSelf: (tmp_pid==o.ParticipantID && o.is_global!=true),
                	SIGNAL_NAME: o.SIGNAL_NAME,
                	is_global:o.is_global,
                	RatingModus: o.RatingModus
        		});
        		
        		$('<div class="CE-StepSlide-Rating-Mini CE-StepSlide-Rating-Mini-'+i+'" template_PID="'+i+'" style="opacity:0.01"></div>').appendTo(e.find('.CE-StepSlide-Rating-Bottom'));
        	}
        
        },          
        _updateMiniRatingVis_GlobalStateWithReorder: function(Last_Iteration)
        {
        	var w=this, e=w.element, o=w.options;
        
        	var have_change=false;
        	
        	// Abbruchbedingung
        	var MAX_ITERATION=30;
        	var Iteration=0;        	
        	if(Last_Iteration!=undefined)
        	{
        		Iteration=Last_Iteration;        	
        	} 
        	Iteration++;
        	
        	if(Iteration>MAX_ITERATION) return false;
        	var MINIRATINGs=e.find('.CE-StepSlide-Rating-Mini[pid]');
        	var this_threshold_element='';
        	var next_threshold_element='';
        	var Element_A='';
        	var Element_B='';
        	
        	for(var i=0; i<MINIRATINGs.length-1; i++)
        	{

        		if(have_change==false)
        		{
        			Element_A=e.find('.CE-StepSlide-Rating-Mini[pid="'+i+'"]');
        			Element_B=e.find('.CE-StepSlide-Rating-Mini[pid="'+(i+1)+'"]');  
        		
        			//debug(o.ObjName+'_updateMiniRatingVis_GlobalStateWithReorder('+Element_A.attr('pid')+' VS '+Element_B.attr('pid')+')',false,o.debug_it);
        		
        			this_threshold_element=Element_A.find('.RATING_A_is_local_threshold');
        			next_threshold_element=Element_B.find('.RATING_A_is_local_threshold');       	
        	
        			var this_RankNumber=0;
        			var next_RankNumber=0;
        	
					if(this_threshold_element.hasClass('GROUPDIS_is_reject')) this_RankNumber=0;
					if(this_threshold_element.hasClass('GROUPDIS_is_accepted')) this_RankNumber=4;
					if(this_threshold_element.hasClass('GROUPDIS_is_global_threshold')) this_RankNumber=3;
					if(this_threshold_element.hasClass('GROUPDIS_is_not_rated')) this_RankNumber=1;
				
				
					if(next_threshold_element.hasClass('GROUPDIS_is_reject')) next_RankNumber=0;
					if(next_threshold_element.hasClass('GROUPDIS_is_accepted')) next_RankNumber=4;
					if(next_threshold_element.hasClass('GROUPDIS_is_global_threshold')) next_RankNumber=3;
					if(next_threshold_element.hasClass('GROUPDIS_is_not_rated')) next_RankNumber=1;
					
					//debug(o.ObjName+'_updateMiniRatingVis_GlobalStateWithReorder('+i+'/'+Iteration+' if('+this_RankNumber+' < '+next_RankNumber+'))',false,o.debug_it);
       		
        			if(this_RankNumber>next_RankNumber)
        			{
        				have_change=true;
        				break;
        			}
        		}
        	}
        	
        	if(have_change==true)
        	{
        		w._updateMiniRatingVis_Postions(Element_A,Element_B,Iteration);         		
        	}
        
        
        },
        _updateMiniRatingVis_Postions:function(element_A, element_B, Iteration)
        {
        	var w=this, e=w.element, o=w.options;
        	
        	//debug(o.ObjName+'_updateMiniRatingVis_Postions_a('+element_A.attr('pid')+' <-> '+element_B.attr('pid')+') of Index('+Iteration+')',true,o.debug_it);
        	
        	if(element_A==undefined || element_A=='' || element_B==undefined || element_B=='' ) return false;
        	
        	var Left_A=0;
        	var Left_B=0;
        	
        	Left_A=e.find('.CE-StepSlide-Rating-Mini[template_pid="'+element_A.attr('pid')+'"]').position().left;
        	Left_B=e.find('.CE-StepSlide-Rating-Mini[template_pid="'+element_B.attr('pid')+'"]').position().left;
        	
        	//debug(o.ObjName+'_updateMiniRatingVis_Postions_b('+Left_A+' <-> '+Left_B+') of Index('+Iteration+')',true,o.debug_it);
        	
        	if(Left_A==undefined || Left_B==undefined) return false;
        	
        	var tmp_pid=element_A.attr('pid');
        	element_A.attr('pid', element_B.attr('pid'));
        	element_B.attr('pid', tmp_pid);

        	element_A.animate(
        			{
        			 	left: Left_B+'px'
        			}, 500);
        		
        	element_B.animate(
        			{
        			 	left: Left_A+'px'
        			}, 500, function()
        			{	
        				w._updateMiniRatingVis_GlobalStateWithReorder(Iteration);
        			});
        	
        },
        _getCurrentIdea: function()
        {
        	var w=this, e=w.element, o=w.options;
        
        	//debug(o.ObjName+'_getCurrentIdea()',false,o.debug_it);
        	
        	var TheIdeaOnTheTop='';
        	
        	e.find('.CE-StepSlide-Rating-Middle .CE-StepSlide-Rating-Idea').each(function(index)
        	{
        		if(TheIdeaOnTheTop=='')
        		{
        			TheIdeaOnTheTop=$(this);
        		
        		}else 
        		{
        		 	if(TheIdeaOnTheTop.css('z-index')<$(this).css('z-index'))
        			{
        				TheIdeaOnTheTop=$(this);
        			}
        		}	
        	});
        	
        	return TheIdeaOnTheTop;
     
        },
        
        _moveCurrentIdeaToRight: function()
        {
        	var w=this, e=w.element, o=w.options;
        
        	var CurrentIdea=w._getCurrentIdea();
        	
        	if(CurrentIdea!='')
        	{
        		w._showIdeaInArea(CurrentIdea.attr('IdeaRatingID'),'CE-StepSlide-Rating-Right');
        	}
        },
        _moveCurrentIdeaToLeft: function()
        {
        	var w=this, e=w.element, o=w.options;
        
        	var CurrentIdea=w._getCurrentIdea();
        	
        	if(CurrentIdea!='')
        	{
        		w._showIdeaInArea(CurrentIdea.attr('IdeaRatingID'),'CE-StepSlide-Rating-Left');
        	}
        },
        _moveSelectedIdeaToTopIfAllowd: function(IdeaRatingID)
        {
        
        	var w=this, e=w.element, o=w.options;
        	
        	
        	
        	var IDEA=e.find('.CE-StepSlide-Rating-Idea[IdeaRatingID="'+IdeaRatingID+'"]');
        	
        	if(IdeaRatingID=='' || IDEA==undefined || IDEA.hasClass('CE-StepSlide-Rating-Disabled_DragFunction')) return false;
        	
        	
        	// RatingClasses=RatingClasses+' CE-StepSlide-Rating-Disabled_DragFunction';
        	
        	var count_of_ideas_in_the_middle=e.find('.CE-StepSlide-Rating-Middle .CE-StepSlide-Rating-Idea').length;
        	var count_of_ideas_in_the_top=e.find('.CE-StepSlide-Rating-Top .CE-StepSlide-Rating-Idea').length;
        	//var count_of_ideas_in_the_left=e.find('.CE-StepSlide-Rating-Left .CE-StepSlide-Rating-Idea').length;
        	var count_of_ideas_in_the_right=e.find('.CE-StepSlide-Rating-Right .CE-StepSlide-Rating-Idea').length;
        	
        	
        	var parentOfIdea=e.find('.CE-StepSlide-Rating-Idea[IdeaRatingID="'+IdeaRatingID+'"]').parent();
        	
        	if(parentOfIdea.hasClass('CE-StepSlide-Rating-Left') && count_of_ideas_in_the_right==0 && count_of_ideas_in_the_middle==0 && count_of_ideas_in_the_top==0)
        	{
        		w._showIdeaInArea(IdeaRatingID,'CE-StepSlide-Rating-Top');   
        	}else
        	if(parentOfIdea.hasClass('CE-StepSlide-Rating-Right') && count_of_ideas_in_the_middle==0 && count_of_ideas_in_the_top==0)
        	{
        		w._showIdeaInArea(IdeaRatingID,'CE-StepSlide-Rating-Top'); 
        	}else if(parentOfIdea.hasClass('CE-StepSlide-Rating-Middle'))
        	{
        		w._moveIdeaToTheBottomOfStaple(IdeaRatingID);        	
        	}
       		    
        //_moveIdeaToTheBottomOfStaple
        },_moveIdeaToTheBottomOfStaple: function(IdeaRatingID)
        {
        	var w=this, e=w.element, o=w.options;        	
        	
        	var count_of_ideas_in_the_middle=e.find('.CE-StepSlide-Rating-Middle .CE-StepSlide-Rating-Idea').length;
        	if(count_of_ideas_in_the_middle<2) return false;   
        	
        	if(IdeaRatingID=='')
        	{
        		IdeaRatingID=w._getCurrentIdea().attr('idearatingid');

        	}
        	
        	//debug(o.ObjName+'_moveIdeaToTheBottomOfStaple('+IdeaRatingID+')',true,o.debug_it);

        	if(IdeaRatingID==undefined || IdeaRatingID=='') return false;       	
        	
        	var last_index=0;
        	
        	e.find('.CE-StepSlide-Rating-Middle .CE-StepSlide-Rating-Idea').each(function(index)
        	{
        		if(last_index==0 || last_index>$(this).css('z-index'))
        		{
        			last_index=$(this).css('z-index');
        		
        		}
        	});
        	
        	var IdeaItem=e.find('.CE-StepSlide-Rating-Middle .CE-StepSlide-Rating-Idea[idearatingid="'+IdeaRatingID+'"]').first();
        	
        	if(IdeaItem==undefined) return false;
        	
        	var tmp_left=IdeaItem.position().left;
        	var tmp_top=IdeaItem.position().top;
        	
        	var item_width=IdeaItem.width();
        	var item_height=IdeaItem.height();
        	
        	IdeaItem.animate(
        			{
        			 	left: (tmp_left+item_width/2)+'px',
        			 	top: (tmp_top-item_height/2)+'px'
        			}, 300, function()
        			{
        				IdeaItem.css('z-index', --last_index);
        				IdeaItem.animate(
        				{
        			 	left: (tmp_left)+'px',
        			 	top: (tmp_top)+'px'
        				}, 200, function()
        				{
        					IdeaItem.css('left','');
        					IdeaItem.css('top','');
        				});
        			});
        },
        /* ### Besondere Funktion, da sie die Spiellogik auf das Ein- und Ausblenden von Elementen ###*/
        _updateMyView: function()
        {
        	var w=this, e=w.element, o=w.options;
        	
        	if(o.is_waiting_for_pre_signal==true)
        	{
        		w._waiting_forPreSignal();
        		return true;
        	
        	}
        	 	
        	
        	//if(o.Slide_isVisible!=true) return false;
        	
        	//debug(o.ObjName+'UPDATE VIEW ##############'+o.Slide_isVisible+'##############',true, o.debug_it); 
        	
        	var count_of_ideas_in_the_middle=e.find('.CE-StepSlide-Rating-Middle .CE-StepSlide-Rating-Idea').length;
        	var count_of_ideas_in_the_top=e.find('.CE-StepSlide-Rating-Top .CE-StepSlide-Rating-Idea').length;
        	var count_of_ideas_in_the_left=e.find('.CE-StepSlide-Rating-Left .CE-StepSlide-Rating-Idea').length;
        	var count_of_ideas_in_the_right=e.find('.CE-StepSlide-Rating-Right .CE-StepSlide-Rating-Idea').length;
        	
        	
        	w._updateImageSizeOfIdeaElements(); 
        	w._updateShortDescritionOfIdeaElements();  
        	        	
        	// Show or hide Buttons ################################################
        	ButtonLeft=e.find('.CE-StepSlide-Rating-ButtonLeft');
        	ButtonRight=e.find('.CE-StepSlide-Rating-ButtonRight');
        	ButtomBottom=e.find('.CE-StepSlide-Rating-ButtonBottom');
        	
        	BereichTop=e.find('.CE-StepSlide-Rating-Top');
        	BereichTopOrder=e.find('.CE-StepSlide-Rating-Order-Top');
        	
        	if(count_of_ideas_in_the_middle>0)
        	{
        		// Zeige die Buttons
        		if(ButtonLeft.is(':hidden'))
        		{
        			ButtonLeft.show('drop', {direction: 'left'});
        			ButtonRight.show('drop', {direction: 'right'});
        		}
        		
        		// Blende den Topbereich aus
        		if(count_of_ideas_in_the_top==0 && BereichTop.is(':visible'))
				{
					BereichTop.fadeOut();
					BereichTopOrder.fadeOut();
        		}	
 		
        	}
        	else if(count_of_ideas_in_the_middle==0)
        	{
        		// Blende Buttons aus
        		if(ButtonLeft.is(':visible'))
        		{
        			ButtonLeft.hide('drop', {direction: 'left'});
        			ButtonRight.hide('drop', {direction: 'right'});       		
        		}
        		
        		if(BereichTop.is(':hidden'))
				{
					BereichTop.fadeIn();
					BereichTopOrder.fadeIn();
        		}   	
        	}
        	
        	if(count_of_ideas_in_the_middle>1)
        	{
        		// Zeige die Buttons
        		if(ButtomBottom.is(':hidden'))
        		{
        			ButtomBottom.show('drop', {direction: 'bottom'});
        		}
        	}else
        	{
        		if(ButtomBottom.is(':visible'))
        		{
        			ButtomBottom.hide('drop', {direction: 'bottom'});
        		}
        	}
        	
        	if(count_of_ideas_in_the_top==1 && BereichTopOrder.is(':visible') && BereichTop.is(':visible'))
				{
					BereichTopOrder.fadeOut();
					
        		}
        		
        		if(count_of_ideas_in_the_top==0 && BereichTopOrder.is(':hidden') && BereichTop.is(':visible'))
				{
					BereichTopOrder.fadeIn();
					
        		}
        	
        	
        	
        	
        	//  Anweisungstexte in groß anzeigen, wenn noch keine Elemente ################################################
			//  Anweisungstexte in klein anzeigen, wenn schon Elemente ################################################
			
				var TextRight=e.find('.CE-StepSlide-Rating-Mini-Right-Text');
        		var TextLeft=e.find('.CE-StepSlide-Rating-Mini-Left-Text');
        		var OrderRight=e.find('.CE-StepSlide-Rating-Order-Right');
        		var OrderLeft=e.find('.CE-StepSlide-Rating-Order-Left');
        		
        		
        		if(count_of_ideas_in_the_right==0 && count_of_ideas_in_the_middle!=0)
        		{
        			if(TextRight.is(':visible'))
        			{
        				TextRight.fadeOut();
        			}
        			if(OrderRight.is(':hidden'))
        			{
        				OrderRight.fadeIn();
        			}
        			
        		
        		}else
        		{
        			if(TextRight.is(':hidden'))
        			{
        				TextRight.fadeIn();
        			}
        			if(OrderRight.is(':visible'))
        			{
        				OrderRight.fadeOut();
        			}
        		
        		}

        		
        		if(count_of_ideas_in_the_left==0 && count_of_ideas_in_the_middle!=0)
        		{
        			if(TextLeft.is(':visible'))
        			{
        				TextLeft.fadeOut();
        			}
        			if(OrderLeft.is(':hidden'))
        			{
        				OrderLeft.fadeIn();
        			}
        			
        		
        		}else
        		{
        			if(TextLeft.is(':hidden'))
        			{
        				TextLeft.fadeIn();
        			}
        			if(OrderLeft.is(':visible'))
        			{
        				OrderLeft.fadeOut();
        			}
        		
        		}
        	
        	
        	// AUSWAHL des SCHWELLENWERT ELEMENTs ################################################
			var OrderTopRight=e.find('.CE-StepSlide-Rating-Order-TopRight');
			var OrderTopLeft=e.find('.CE-StepSlide-Rating-Order-TopLeft');
			var OrderTopArrowRight=e.find('.CE-StepSlide-Rating-Order-ArrowRight');
			var OrderTopArrowLeft=e.find('.CE-StepSlide-Rating-Order-ArrowLeft');
			//OrderTopArrowLeft.fadeOut();
			
			if(count_of_ideas_in_the_middle==0 && count_of_ideas_in_the_top==0)
			{
				
        			
        		if(count_of_ideas_in_the_right==0 )
        		{
        			if(OrderTopLeft.is(':hidden'))
        			{
        				OrderTopLeft.fadeIn();
        			}
        		
        			if(OrderTopArrowLeft.is(':hidden'))
        			{
        				OrderTopArrowLeft.fadeIn();
        			}
        			
        			if(OrderTopArrowRight.is(':visible'))
        			{
        				OrderTopArrowRight.fadeOut();
        			}
        			
        			if(OrderTopRight.is(':visible'))
        			{
        				OrderTopRight.fadeOut();
        			}
        		
        		}else // Standardfall
        		{
        			if(OrderTopArrowRight.is(':hidden'))
        			{
        				OrderTopArrowRight.fadeIn();
        			}
        			
        			if(OrderTopRight.is(':hidden'))
        			{
        				OrderTopRight.fadeIn();
        			}
        			
        			if(OrderTopLeft.is(':visible'))
        			{
        				OrderTopLeft.fadeOut();
        			}
        			
        			if(OrderTopArrowLeft.is(':visible'))
        			{
        				OrderTopArrowLeft.fadeOut();
        			}
        		
        		}
        			
        		
			}
			
			// Anweisungen und Pfeile ausblenden, wenn Ideen in der Mitte oder SW gewählt ################################################
			if(count_of_ideas_in_the_top>0 || count_of_ideas_in_the_middle>0)
			{
				if(OrderTopArrowRight.is(':visible'))
        			{
        				OrderTopArrowRight.fadeOut();
        			}
        			
        			if(OrderTopRight.is(':visible'))
        			{
        				OrderTopRight.fadeOut();
        			}
        			
        		if(OrderTopLeft.is(':visible'))
        			{
        				OrderTopLeft.fadeOut();
        			}
        			
        		if(OrderTopArrowLeft.is(':visible'))
        			{
        				OrderTopArrowLeft.fadeOut();
        			}
			}
			
			// Nebenbedingung - es darf nur ein Schwellenwertelement geben, deshalb drop Funktionen hinzufügen oder entfernen
			if(count_of_ideas_in_the_top==0)
			{
				
				if(count_of_ideas_in_the_right>0)
				{
					e.find('.CE-StepSlide-Rating-Right').sortable(
        			{
        				connectWith: '.CE-StepSlide-Rating-Left, .CE-StepSlide-Rating-Middle, .CE-StepSlide-Rating-Right, .CE-StepSlide-Rating-Top'
        			}); 
        			
        			e.find('.CE-StepSlide-Rating-Left').sortable(
        			{
        				connectWith: '.CE-StepSlide-Rating-Left, .CE-StepSlide-Rating-Middle, .CE-StepSlide-Rating-Right'
        			}); 
				
				}else 
				{
					e.find('.CE-StepSlide-Rating-Left').sortable(
        			{
        				connectWith: '.CE-StepSlide-Rating-Left, .CE-StepSlide-Rating-Middle, .CE-StepSlide-Rating-Right, .CE-StepSlide-Rating-Top'
        			}); 
				}
			}else
			{
				e.find('.CE-StepSlide-Rating-Left, .CE-StepSlide-Rating-Middle, .CE-StepSlide-Rating-Right, .CE-StepSlide-Rating-Top').sortable(
        		{
        			connectWith: '.CE-StepSlide-Rating-Left, .CE-StepSlide-Rating-Middle, .CE-StepSlide-Rating-Right'
        		});
			}
			
			// WENN ALLES EINSORTIERT und SCHWELLENWERT ELEMENT gewählt
			if(count_of_ideas_in_the_top>0 && count_of_ideas_in_the_middle==0 && o.is_global!=true)
			{
				
				w._sendParticipantStateSignalToDataBase(o.SIGNAL_NAME, false); //true -> force save
			}else 
			if(o.is_global!=true)
			{
				
				w._sendParticipantStateSignalToDataBase(o.SIGNAL_NAME, true); // true -> removeSignal
			}			
			
			var OrderBottomWaiting=e.find('.CE-StepSlide-Rating-Order-BottomWaiting');	
			var OrderBottomNext=e.find('.CE-StepSlide-Rating-Order-BottomNext');	
			var OrderBottomArrowWaiting=e.find('.CE-StepSlide-Rating-Order-ArrowBottomWaiting');
			var OrderBottomArrowNext=e.find('.CE-StepSlide-Rating-Order-ArrowBottomNext');
			var ALL_Partipant_Ready=w._hasAllParticipantsSignal(o.SIGNAL_NAME);
			
			if(count_of_ideas_in_the_top>0 && count_of_ideas_in_the_middle==0 && ALL_Partipant_Ready==false)
			{
			
					if(OrderBottomWaiting.is(':hidden'))
        			{
        				OrderBottomWaiting.fadeIn();
        			}
        			
        			if(OrderBottomArrowWaiting.is(':hidden'))
        			{
        				OrderBottomArrowWaiting.fadeIn();
        			}
        			        			
        			if(OrderBottomArrowNext.is(':visible'))
        			{
        				OrderBottomArrowNext.fadeOut();
        			}
        			if(OrderBottomNext.is(':visible'))
        			{
        				OrderBottomNext.fadeOut();
        			}
        					
        					
        			if(o.CloseRatingIfEveryIdeaIsRated==true)
        			{
        				w._activatedTrigger();
        				w._activateFunctionality();
        			}			
        		
        		
        			debug(o.ObjName+'_sendSingnalToAllParticipants(0)',true,o.debug_it);
        			if(o.is_global==true)
					{
						debug(o.ObjName+'_sendSingnalToAllParticipants(1)',true,true);
						w._sendSingnalToAllParticipants(o.SIGNAL_NAME);
					}
        		
					o.AllowKeyNavigation=false;
					w.hideButton(true, false);
        				
			}else if(count_of_ideas_in_the_top>0 && count_of_ideas_in_the_middle==0 && ALL_Partipant_Ready==true)
			{
					if(OrderBottomNext.is(':hidden'))
        			{
        				OrderBottomNext.fadeIn();
        			}
        			if(OrderBottomArrowNext.is(':hidden'))
        			{
        				OrderBottomArrowNext.fadeIn();
        			}
        			
        			if(OrderBottomWaiting.is(':visible'))
        			{
        				OrderBottomWaiting.fadeOut();
        			}
					if(OrderBottomWaiting.is(':visible'))
        			{
        				OrderBottomWaiting.fadeOut();
        			}
				
        			if(OrderBottomArrowWaiting.is(':visible'))
        			{
        				OrderBottomArrowWaiting.fadeOut();
        			}	
        			
        			if(OrderTopArrowRight.is(':visible'))
        			{
        				OrderTopArrowRight.fadeOut();
        			}
        			
        			/*  ! ... disconnect Draging Functionality ........................................................................................ (Bookmark for Coda)  */ 
        			//disconnect Draging Functionality ###################################
        			if(o.CloseRatingIfEveryIdeaIsRated==true)
        			{
		
        				w._deactivatedTrigger();
        				w._deactivateFunctionality();
        			}
        			
        			
        			
     		
					//w._deactivatedTrigger();
        			o.AllowKeyNavigation=true;
        			w.showButton(true, false);      			
        			
        			
			}else // if(ALL_Partipant_Ready==false) and Participant is not ready
			{
			
					if(OrderBottomWaiting.is(':visible'))
        			{
        				OrderBottomWaiting.fadeOut();
        			}
				
        			if(OrderBottomArrowWaiting.is(':visible'))
        			{
        				OrderBottomArrowWaiting.fadeOut();
        			}
        			if(OrderBottomArrowNext.is(':visible'))
        			{
        				OrderBottomArrowNext.fadeOut();
        			}
        			if(OrderBottomNext.is(':visible'))
        			{
        				OrderBottomNext.fadeOut();
        			}
        			
        		o.AllowKeyNavigation=false;	
        		w.hideButton(true, false);	
        		
        		if(o.CloseRatingIfEveryIdeaIsRated==true)
        			{
        				w._activatedTrigger();
        				w._activateFunctionality();
        			}
        		
        				
			}
			
			// Titelzusatz hinzufügen, wenn nötig
			
			e.find('.CE-StepSlide-Rating-Idea h1 label').text('');			
			e.find('.RATING_A_is_local_threshold h1 label').text('Stellvertreter |');
			e.find('.GROUPDIS_is_global_threshold h1 label').text('Gesamtidee |');
			
			
			
			if(o.is_global==true)
			{
				
				w._updateMiniRatingVis_GlobalStateWithReorder();
			}
		
	
        },
        _updateMyViewWithDelay: function(DelayInMS)
        {
        	var w=this, e=w.element, o=w.options;
        	
        	if(DelayInMS>0)
        	{
        		e.stopTime('TIMER_Update');
        		e.oneTime(DelayInMS, 'TIMER_Update', function()
        		{
        				w._updateMyView();
        		}); 
        	}
        },
        _updateImageSizeOfIdeaElements: function()
        {
        	var w=this, e=w.element, o=w.options;
        
        	//debug(o.ObjName+'_updateImageSizeOfIdeaElements()',false,o.debug_it);
        	e.find('.CE-StepSlide-Rating-Middle .CE-StepSlide-Rating-Idea').each(function(index)
        	{
        		var IMG=$(this).find('img');
        		var img_height=IMG.height();        		
        		
        		if(img_height!=undefined && img_height>0)
        		{
        			
        			var img_width=IMG.width();
        			var img_relation_width_height=parseInt(img_width)/parseInt(img_height);
        			
        			var img_top=IMG.position().top;
        			var img_left=IMG.position().left;
        			var parent_height=IMG.parent().height();
        			var parent_width=IMG.parent().width();
        			
        			//debug(o.ObjName+'_updateImageSizeOfIdeaElements('+index+'-> (h'+img_height+',w'+img_width+')(l'+img_left+',t'+img_top+')(ph'+parent_height+',pw'+parent_width+'))',false,o.debug_it);
        			
        			var new_max_height=parseInt(parent_height)-parseInt(img_top)-10;
        			var new_max_width=parseInt(parent_width)-parseInt(img_left)-10;
        			
        			////debug(o.ObjName+'NewMaxSize(w'+new_max_width+' mit '+max_height_after_new_width+' ODER h'+new_max_height+' mit '+max_width_after_new_height+')',false,o.debug_it);
        			//debug(o.ObjName+'(w'+new_max_width+', h'+new_max_height+')',false,o.debug_it);
        			
        			IMG.css('max-width', new_max_width).css('max-height', new_max_height);        			
        			
        		}	
        	});
        },        
        _updateShortDescritionOfIdeaElements: function()
        {
        
        	var w=this, e=w.element, o=w.options;
        	
        	
        
        	//debug(o.ObjName+'updateShortDescritionOfIdeaElements()',false,o.debug_it);
        	
        	var all_iterations=0;
        	
        	e.find('.CE-StepSlide-Rating-Idea-NoPicture').each(function(index)
        	{
        		
        		// Parent and Element
        		var parent_height=$(this).height();
        		var parent_width=$(this).width();
        		var SPAN=$(this).find('span');
        		
        		SPAN.css('font-size','auto');
        		
        		
        		// Size of the Element
        		var span_top=SPAN.position().top;
        		var span_width=SPAN.width();
        		var span_height=SPAN.height();
        		
        		// FontSize
        		var span_fontsize=parseFloat(SPAN.css('font-size'), 10);
        		
        		// Temp Variables
        		var PUFFER_HEIGHT=-5;
        		var PUFFER_WIDTH=-10;
        		var MAX_INTERATION=200;
        		var iteration=0;
        		var hasAChange=true;
        		var FONT_SIZE_CHANGE=3;
        		
        		// StartBedingung
        		var is_SPAN_too_height=((span_height+span_top+PUFFER_HEIGHT)>=parent_height);
        		var is_SPAN_too_weight=((span_width+PUFFER_WIDTH)>=parent_width);
        		var Start_too_big=false;
        		
        		if(is_SPAN_too_height||is_SPAN_too_weight)
        		{
        			Start_too_big=true;
        		}
        		
        		
        		
				
			while(FONT_SIZE_CHANGE>0) // doppel schleife - zur schnelleren Reduktion
			{
				// FONT_SIZE_CHANGE ....n....3...2....1px für immer genauere, aber schneller Anpassung, aber Ideas*(n-1) zusätzliche durchläufe, auch wenn keine veränderung - als ca. 15 Durchläufe extra?
        		while(hasAChange && span_height!=undefined)
        		{
        			hasAChange=false;

        			span_fontsize=parseFloat(SPAN.css('font-size'), 10);
        			span_height=SPAN.height();
        			span_width=SPAN.width();
        				
        			var is_SPAN_too_height=((span_height+span_top+PUFFER_HEIGHT)>parent_height);
        			//debug(o.ObjName+'updateShortDescrition('+(span_height+span_top+PUFFER_HEIGHT)+'-'+is_SPAN_too_height+'-'+parent_height+')',false,o.debug_it);
        				
        			var is_SPAN_too_weight=((span_width+PUFFER_WIDTH)>parent_width);

        			
        			
        			
        			//debug(o.ObjName+'updateShortDescrition('+index+'-> (h'+span_height+'p['+parent_height+'],w'+span_width+'(p['+parent_width+']) - fontSize('+span_fontsize+') if('+is_SPAN_too_height+'||'+is_SPAN_too_weight+'))',false,o.debug_it);
        				
        			// Wenn es zu gross ist
        			if(is_SPAN_too_height||is_SPAN_too_weight)
        			{
        					SPAN.css('font-size', span_fontsize-FONT_SIZE_CHANGE+'px');
        					// Wenn zu gross gestartet, so lange verkleiner bis es passt
        					if(Start_too_big==true) 
        					{
        						
        						hasAChange=true;
        					}
        			}else
        			{
        					// Wenn zu klein gestartet, so lange vergrößern bis es passt
        					
        					if(Start_too_big==false)  
        					{
        						SPAN.css('font-size', span_fontsize+FONT_SIZE_CHANGE+'px');
        						hasAChange=true;
        					}
        			}	
        			
        			all_iterations++;
        				
        			// Abbruchbedingung 
        			iteration++;
        			if(iteration>=MAX_INTERATION)
        			{
        				hasAChange=false;
        			}
        		}
        		FONT_SIZE_CHANGE--;
        		
        			// Abbruchbedingung 
        			iteration++;
        			if(iteration>=MAX_INTERATION)
        			{
        				hasAChange=false;
        			}	
        	}     		
        	
           });
           
           //debug(o.ObjName+'updateShortDescritionOfIdeaElements('+all_iterations+')',false,o.debug_it);
        }, 
        _updateShortDescritionOfIdeaElements_OLDDDDDDDDDDDDDDDD: function()
        {
        
        	var w=this, e=w.element, o=w.options;
        	
        	
        
        	//debug(o.ObjName+'updateShortDescritionOfIdeaElements()',false,o.debug_it);
        	
        	var all_iterations=0;
        	
        	e.find('.CE-StepSlide-Rating-Idea-NoPicture').each(function(index)
        	{
        		
        		// Parent and Element
        		var parent_height=$(this).height();
        		var parent_width=$(this).width();
        		var SPAN=$(this).find('span');
        		
        		SPAN.css('font-size','auto');
        		
        		
        		// Size of the Element
        		var span_top=SPAN.position().top;
        		var span_width=SPAN.width();
        		var span_height=SPAN.height();
        		
        		// FontSize
        		var span_fontsize=parseFloat(SPAN.css('font-size'), 10);
        		
        		// Temp Variables
        		var PUFFER_HEIGHT=5;
        		var PUFFER_WIDTH=-5;
        		var MAX_INTERATION=200;
        		var iteration=0;
        		var hasAChange=true;
        		var FONT_SIZE_CHANGE=3;
        		
        		// StartBedingung
        		var is_SPAN_too_height=((span_height+span_top+PUFFER_HEIGHT)>=parent_height);
        		var is_SPAN_too_weight=((span_width+PUFFER_WIDTH)>=parent_width);
        		var Start_too_big=false;
        		
        		if(is_SPAN_too_height||is_SPAN_too_weight)
        		{
        			Start_too_big=true;
        		}
        		
        		
        		
				
			while(FONT_SIZE_CHANGE>0) // doppel schleife - zur schnelleren Reduktion
			{
				// FONT_SIZE_CHANGE ....n....3...2....1px für immer genauere, aber schneller Anpassung, aber Ideas*(n-1) zusätzliche durchläufe, auch wenn keine veränderung - als ca. 15 Durchläufe extra?
        		while(hasAChange && span_height!=undefined)
        		{
        			hasAChange=false;

        			span_fontsize=parseFloat(SPAN.css('font-size'), 10);
        			span_height=SPAN.height();
        			span_width=SPAN.width();
        				
        			var is_SPAN_too_height=((span_height+span_top+PUFFER_HEIGHT)>parent_height);
        			//debug(o.ObjName+'updateShortDescrition('+(span_height+span_top+PUFFER_HEIGHT)+'-'+is_SPAN_too_height+'-'+parent_height+')',false,o.debug_it);
        				
        			var is_SPAN_too_weight=((span_width+PUFFER_WIDTH)>parent_width);

        			
        			
        			
        			//debug(o.ObjName+'updateShortDescrition('+index+'-> (h'+span_height+'p['+parent_height+'],w'+span_width+'(p['+parent_width+']) - fontSize('+span_fontsize+') if('+is_SPAN_too_height+'||'+is_SPAN_too_weight+'))',false,o.debug_it);
        				
        			// Wenn es zu gross ist
        			if(is_SPAN_too_height||is_SPAN_too_weight)
        			{
        					SPAN.css('font-size', span_fontsize-FONT_SIZE_CHANGE+'px');
        					// Wenn zu gross gestartet, so lange verkleiner bis es passt
        					if(Start_too_big==true) 
        					{
        						
        						hasAChange=true;
        					}
        			}else
        			{
        					// Wenn zu klein gestartet, so lange vergrößern bis es passt
        					
        					if(Start_too_big==false)  
        					{
        						SPAN.css('font-size', span_fontsize+FONT_SIZE_CHANGE+'px');
        						hasAChange=true;
        					}
        			}	
        			
        			all_iterations++;
        				
        			// Abbruchbedingung 
        			iteration++;
        			if(iteration>=MAX_INTERATION)
        			{
        				hasAChange=false;
        			}
        		}
        		FONT_SIZE_CHANGE--;
        		
        			// Abbruchbedingung 
        			iteration++;
        			if(iteration>=MAX_INTERATION)
        			{
        				hasAChange=false;
        			}	
        	}     		
        	
           });
           
           //debug(o.ObjName+'updateShortDescritionOfIdeaElements('+all_iterations+')',false,o.debug_it);
        }, 
        _showIdeaInArea: function(IdeaRatingID, Bereich)
        {
        	w=this, e=w.element, o=w.options;
        	
        	var VisibleItem=e.find('.CE-StepSlide-Rating-Idea[IdeaRatingID="'+IdeaRatingID+'"]');
        	if(VisibleItem==undefined) return false;
        	
			var ParentOfVisibleItem=VisibleItem.parent();
 			
        	var NextItem=VisibleItem.appendTo(e.find('.'+Bereich));  
        	
        	 
        	VisibleItem=VisibleItem.clone().appendTo(ParentOfVisibleItem);  

        	
				NextItem.css('opacity', '0.01');
				NextItem.find('span').css('font-size','14px');

        		var PosLeftVisElement=VisibleItem.position().left+VisibleItem.parent().position().left;
        		var PosTopVisElement=VisibleItem.position().top+VisibleItem.parent().position().top;
        		
        		var PosLeftNextElement=NextItem.position().left+NextItem.parent().position().left;
        		var PosTopNextElement=NextItem.position().top+NextItem.parent().position().top;
        		
        		//debug(o.ObjName+'MoveAnimateElment('+PosLeftVisElement+','+PosTopVisElement+') to ('+PosLeftNextElement+','+PosTopNextElement+')',true,o.debug_it);
        		var AnimationElement=e.find('.CE-StepSlide-Rating-AnimatedHandle[AnimatedHandelNr="'+VisibleItem.attr('AnimatedHandelNr')+'"]');
        		
        		var tmp_IdeaID=VisibleItem.attr('IdeaID');
        		var tmp_RatingID=VisibleItem.attr('IdeaRatingID');
        		
        		var State='left';
        		if(Bereich=='CE-StepSlide-Rating-Right')
        		{
        			State='right';
        		}else if(Bereich=='CE-StepSlide-Rating-Top')
        		{
        			State='top';        		
        		}
				
				w._saveRatingForIdea(tmp_IdeaID, tmp_RatingID, State);

        		AnimationElement.animate(
        			{
        			 	left: PosLeftVisElement+'px',
        			 	top: PosTopVisElement+'px'
        			}, 50);
        		
        		
        		VisibleItem.animate(
        		{
        			opacity:0
        		}, 100, 
        		function()
        			{
        				$(this).remove();
        				
        			}
        		);
        		
        		AnimationElement.animate(
        		{
        			opacity:1
        		}, 100, 
        		function()
        		{
        			AnimationElement.animate(
        			{
        			 	left: PosLeftNextElement+'px',
        			 	top: PosTopNextElement+'px'
        			}, 300, 
        			function()
        			{
						NextItem.animate({opacity:1}, 100);
						
						//debug(o.ObjName+'Trigger Animation End2',true,o.debug_it);
						
        				AnimationElement.animate({opacity:0}, 100, function()
        				{
        					$(this).css('top', '-500px');
        					$(this).css('left', '-500px');
							//debug(o.ObjName+'TRY TO TRIGGER ANIMATIONEND',true,o.debug_it);
        					$('.CE-StepSlide-Rating').trigger('AnimationEnd');
        					
        					
        				});
        			});
        		});
        		
        		
        	
        		        		
        },
        _saveRatingForIdea: function(IdeaID, IdeaRatingID, State)
        {
        	var w=this, e=w.element, o=w.options;
        	
        	if(IdeaRatingID==undefined || IdeaID==undefined || State==undefined) return false;
        	
        	var value='is_not_rated';
        	
        	var IdeaItem=e.find('.CE-StepSlide-Rating-Idea[IdeaRatingID="'+IdeaRatingID+'"]');     	
        	
        	
        	//local_pre_rating( is_not_rated, is_local_threshold, is_preaccepted, is_prereject) 	local_post_rating 	global_rating
        	switch (o.RatingModus) 
            		{        	
                  		case "local_pre_rating":
                  		
                  			IdeaItem.removeClass('RATING_A_is_prereject').removeClass('RATING_A_is_preaccepted').removeClass('RATING_A_is_local_threshold').removeClass('RATING_A_is_not_rated');
                  			
                			switch (State) // left, right, middle, top
                			{
                			 	case 'left':
                			 		value='is_prereject';
                			 		IdeaItem.addClass('RATING_A_is_prereject');
                				 break;
                			  	case 'right':
                			 		value='is_preaccepted';
                			 		IdeaItem.addClass('RATING_A_is_preaccepted');
                			 	break;
                			 	case 'middle':
                			 		value='is_not_rated';
                			 		IdeaItem.addClass('RATING_A_is_not_rated');
                			 	break;
                			 	case 'top':
                			 		value='is_local_threshold';
                			 		IdeaItem.addClass('RATING_A_is_local_threshold');
                			 	break;
                			}                			            			
                  			break;
                  		case "global_rating":
                  			
                  			IdeaItem.removeClass('GROUPDIS_is_reject').removeClass('GROUPDIS_is_accepted').removeClass('GROUPDIS_is_global_threshold').removeClass('GROUPDIS_is_not_rated').removeClass('GROUPDIS_is_rework');
                  		
                			switch (State) // left, right, middle, top
                			{
                			 	case 'left':
                			 		value='is_reject';
                			 		IdeaItem.addClass('GROUPDIS_is_reject');
                				 break;
                			  	case 'right':
                			 		value='is_accepted';
                			 		IdeaItem.addClass('GROUPDIS_is_accepted');
                			 	break;
                			 	case 'middle':
                			 		value='is_not_rated';
                			 		IdeaItem.addClass('GROUPDIS_is_not_rated');
                			 	break;
                			 	case 'top':
                			 		value='is_global_threshold';
                			 		IdeaItem.addClass('GROUPDIS_is_global_threshold');
                			 	break;
                			}                			            			
                  			break;
                  		case "local_post_rating":
                  		
                  			IdeaItem.removeClass('RATING_B_is_postreject').removeClass('RATING_B_is_postaccepted').removeClass('RATING_B_is_not_rated');
                  		
                			switch (State) // left, right, middle, top
                			{
                			 	case 'left':
                			 		value='is_postreject';
                			 		IdeaItem.addClass('RATING_B_is_postreject');
                				 break;
                			  	case 'right':
                			 		value='is_postaccepted';
                			 		IdeaItem.addClass('RATING_B_is_postaccepted');
                			 	break;
                			 	case 'middle':
                			 		value='is_not_rated';
                			 		IdeaItem.addClass('RATING_B_is_not_rated');
                			 	break;                			 	
                			}                			            			
                  			break;
                  		default:               	 		
                		break;
           			}
        	
        	if(o.is_global!=true)
        	{
        		w._sendDataToDatatables('Idea_Rating_Participant', IdeaRatingID, 'data_'+o.RatingModus, value, 0, 0, true, false, false);
        	}else
        	{
        		w._sendDataToDatatables('Idea_Rating_Participant', IdeaRatingID, 'data_'+o.RatingModus, value, 1, 0, false, false, false);
        		w._updatedAndSaveRelatedRatings(IdeaRatingID, value);
        	}
        	
        },
        _updatedAndSaveRelatedRatings: function(IdeaRatingID, Value)
        {
        	var w=this, e=w.element, o=w.options;
        	
        	
        	
        	var UpdatedThresholdIdeaRating=$('#db_datatables .data_table[DataTableName="Idea_Rating_Participant"] .data_row[data_DataID="'+IdeaRatingID+'"]');
			var RelatedRatingSession=UpdatedThresholdIdeaRating.attr('data_SessionID');
			var RelatedParticipantID=UpdatedThresholdIdeaRating.attr('data_ParticipantID');
			
			//debug(o.ObjName+'_updatedAndSaveRelatedRatings(#####'+RelatedRatingSession+'###########'+RelatedParticipantID+')',false,o.debug_it);
			
			if(RelatedRatingSession==undefined || RelatedParticipantID==undefined) return false;
			
			//1. find related Ideas (same Participant - same Rating Session)
			var RelatedRatings=$('#db_datatables .data_table[DataTableName="Idea_Rating_Participant"] .data_row[data_DataID!="'+IdeaRatingID+'"][data_SessionID="'+RelatedRatingSession+'"][data_ParticipantID="'+RelatedParticipantID+'"]');
			
			//alert(RelatedRatings.length);
			var index_b=0;
			RelatedRatings.each(function(index, value)
			{
				var pre_state=$(this).attr('data_local_pre_rating');
				var global_state='';
				 //is_rework, is_accepted,  is_reject,  is_not_rated
				 
				 
				//Change State of the global Attribute
				switch(Value)
				{
					case 'is_reject':
						if(pre_state=='is_preaccepted')
						{
							global_state='is_rework';
						}
						else if(pre_state=='is_prereject')
						{
							global_state='is_reject';
						}					
					break;
					case 'is_accepted':
						if(pre_state=='is_preaccepted')
						{
							global_state='is_accepted';
						}
						else if(pre_state=='is_prereject')
						{
							global_state='is_rework';
						}					
					break;		
					case 'is_global_threshold':
						if(pre_state=='is_preaccepted')
						{
							global_state='is_accepted';
						}
						else if(pre_state=='is_prereject')
						{
							global_state='is_reject';
						}					
					break;				
					case 'is_not_rated':
						if(pre_state=='is_preaccepted')
						{
							global_state='is_not_rated';
						}
						else if(pre_state=='is_prereject')
						{
							global_state='is_not_rated';
						}					
					break;
					default:
						global_state='i_do_not_know';
					break;
				
					
				}
				
				if(index==RelatedRatings.length-1)
				{
					//submit the Change 
					w._sendDataToDatatables('Idea_Rating_Participant', $(this).attr('data_DataID'), 'data_'+o.RatingModus, global_state, 0, 0, true, false, false);
				
				}else
				{
					w._sendDataToDatatables('Idea_Rating_Participant', $(this).attr('data_DataID'), 'data_'+o.RatingModus, global_state, 1, 0, false, false, false);				
				}			
			});        	       	
        },
        _getHTMLTemplateForIdeaID: function(IdeaID, IdeaRatingID, index)
        {
        	var w=this, e=w.element, o=w.options;
        	
        	//debug(o.ObjName+'_getHTMLTemplateForIdeaID('+IdeaID+')',false,o.debug_it);
        	
        	var Idea=$('#db_datatables .data_table[DataTableName="Idea"] .data_row[data_DataID="'+IdeaID+'"]');	
        	
        	var IdeaTemplateTitle='<h1><label class="titel_zusatz">MYLABEL</label> '+Idea.attr('data_title')+'</h1>';
        	
        	var NoShortDiscriptionClass='';
        	var IdeaTemplateShorDescription='<span>'+Idea.attr('data_shortDiscription')+'</span>';
        	if(Idea.attr('data_shortDiscription')=='')
        	{
        		NoShortDiscriptionClass='CE-StepSlide-Rating-Idea-NoShortDiscription';
        	}
        	
        	var IndexClass='CE-StepSlide-Rating-Idea-Index-'+index;
        	
        	var IdeaTemplateDescription='<p>'+Idea.attr('data_Discription')+'</p>';
        	
        	var IdeaTemplateBild=Idea.attr('data_picture');
        	var NoPictureClass='';
        	if(IdeaTemplateBild!=''&& IdeaTemplateBild!=undefined)
        	{
        		IdeaTemplateBild='<img src="'+IdeaTemplateBild+'"/>';
        	}else
        	{
        		NoPictureClass='CE-StepSlide-Rating-Idea-NoPicture';
        	
        	}
        	
        	
        	
        	var IdeaTemplate='<div class="CE-StepSlide-Rating-Idea '+NoPictureClass+' '+NoShortDiscriptionClass+' '+IndexClass+' '+o.NoVisClass+'" IdeaID="'+IdeaID+'" IdeaRatingID="'+IdeaRatingID+'" style="z-index:'+o.zIndexForIdeas+'" AnimatedHandelNr="'+index+'">'+IdeaTemplateTitle+IdeaTemplateShorDescription+IdeaTemplateDescription+IdeaTemplateBild+'</div>';
        o.zIndexForIdeas++;
        	
        	return IdeaTemplate;
        },
        _setTextForSides: function()
        {
        	var w=this, e=w.element, o=w.options;
        	//debug(o.ObjName+'_setTextForSides()',false,o.debug_it);
        	e.find('.CE-StepSlide-Rating-Mini-Left-Text').html(o.TextLeftSide);
        	e.find('.CE-StepSlide-Rating-Mini-Right-Text').html(o.TextRightSide);
        
        },
        showButton: function(showLeftButtonNot, showRightButtonNot)
        {
        	var w=this, e=w.element, o=w.options;

        	if(showLeftButtonNot!=true && !o.ButtonLeft_isVisible)
        	{ 
        		o.ButtonLeft_isVisible=true;
        		o.ButtonLeft.animate({top: '4px', left: '0px'},'fast');    		
        		o.ButtonLeft.show('drop', {direction: 'left'});
        	} 
        	
        	//debug(o.ObjName+'showButton'+o.ButtonRight_isVisible, false,o.debug_it);
        	
        	if(showRightButtonNot!=true  && !o.ButtonRight_isVisible)
        	{
        		
        		o.ButtonRight_isVisible=true;
        		o.ButtonRight.animate({top: '4px', right: '0px'},'fast');  
        		o.ButtonRight.show('drop', {direction: 'right'});
        	} 
        },_triggerDataLoad: function()
        {
        	var w=this, e=w.element, o=w.options;
        
        
        }
    });



	//########################################################## MIDDLE_POINT_DIV ##################################################
/*  ! ... CE. MIDDLE_POINT_DIV ........................................................................................ (Bookmark for Coda)  */     
	 $.widget( "CE.MIDDLE_POINT_DIV" , {
        options: { },
        _init: function(){
			
			var w=this, e=w.element, o=w.options;
			
			//e.css('background','#10c8ff');
			e.css('width','2px');
			e.css('height','2px');
			
			$(window).resize(function() 
			{	
				w.updatePositions();
  			});
  			
  			w.updatePositions();

        },
        updatePositions:function()
        {
        	var w=this, e=w.element, o=w.options;
        	
        		var position=e.position();
				var top=position.top;
				var left=position.left;
  				
  				e.attr('top',top);
  				e.attr('left',left);
  				
  				$('.MIDDLE_POINT_CONNECTED').trigger('update_position');
        }
    });
	



})( jQuery, window, document );
