//** Version Note : 2008-03-27 21:21 CH AM ::::::::: Initial Build |
//** This class gives us all our options :)                        |
//** As well as our debug output functions.                        |
//** As this grows, we may add the colour cycle transitions into   |
//** this object, possibly panel toggler too.          						 |
//** P + C 2008 - SAMPLE OAK RECORDS WEB DEVELOPMENT ::::          | 
//** ===============================================================
//*****************************************************************
//VALUES FOR TRANSITIONS__________________________________________*
//Linear,Quad,Cubic,Quart,Quint,Sine,Expo,Circ,Bounce,Back,Elastic*
//================================================================*                                                           
//AND FOR EASES___________________________________________________*
//easeIn,easeOut,easeInOut                                        *  
//N.B ITS VERY EASY TO MESS UP THE COLOUR TRANSITIONS SO PLEASE   *
//make note of original settings. if we use any other transition  *
//than linear, durations etc between colours aren't at the same   *
//rate between colour to colour. so they can stack up quite quick!*
//*****************************************************************

var Sampleoak = ({
	
	options: {
		transitioncol	: 'linear',
		easeIncol			: 'easeInOut',
		transitionpos	: 'Quint',
		easeInpos			: 'easeIn',
		colourdur			: 3100,
		qfcolourdur		:	800,
		reposdur			: 400,
		periodical 		: 3400,
		colours				: [{"fadeto":"#49192B"},{"fadeto":"#8E3557"},{"fadeto":"#83815B"},{"fadeto":"#ACCF4F"},{"fadeto":"#F7F2B1"},{"fadeto":"#959DB0"}],
		basecolour		: {"fadeto":"#959DB0"},
		gotocolour		: {"fadeto":"#83815B"},
		isGo					: false,
		isTrue				: false,
		delay					: 3700,
		number				: 6,
		factor				: 1.35,
		cc1start			: false,
		cc1end				: true,
		cc2start			: false,
		cc2end				: true,
		prime					: false,
		debug2				: false,
		debug					: false,
		debug3				: false,
		dodebug				: false,
		dodet					: false,
		override			: true,
		lastcolour		: 'N',
		protect				: false,
		protectdur		: 4000,
		ccthresh			: 250,
		disablecc			: false,
		cccount				: 0,
		ccerrthresh		:	3
	},
	
	initialize: function(){
		this.disablecc			= this.options.disablecc;
		this.transitioncol 	= this.options.transitioncol;
		this.transitioncol 	= this.options.transitioncol;
		this.transitionpos 	= this.options.transitionpos;
		this.easeInpos			= this.options.easeInpos;
		this.easeIncol 			= this.options.easeIncol;
		this.periodical  		= this.options.periodical;
		this.isGo						= this.options.isGo;
		this.isTrue 				= this.options.isTrue;
		this.colours 				= this.options.colours;
		this.number 				= this.options.number;
		this.colourdur 			= this.options.colourdur;
		this.reposdur 			= this.options.reposdur;
		this.factor					= this.options.factor;
   	this.cc1start				= this.options.cc1start;
   	this.cc2start				= this.options.cc2start;
   	this.cc1end					= this.options.cc1end;
   	this.cc2end					= this.options.cc2end;
   	this.prime					= this.options.prime;
   	this.dodebug				= this.options.dodebug;
   	this.dodet					= this.options.dodet;
   	this.basecolour			= this.options.basecolour;
   	this.override				= this.options.override;
   	this.qfcolourdur		= this.options.qfcolourdur;
   	this.gotocolour			= this.options.gotocolour;
   	this.lastcolour			= this.options.lastcolour;
   	this.ccthresh				= this.options.ccthresh;
   	this.protect				= this.options.protect;
   	this.protectdur			= this.options.protectdur;
   	this.cccount				= this.options.cccount;
   	this.ccerrthresh		= this.options.ccerrthresh;
   	this.delay 					= this.getDelay();
	},
	
	colchangeOk: function(){
		if(this.cccount>0){
			this.cccount = this.cccount - 1;
		}
	},
	
	testForBadConfig: function(){
		this.cccount = this.cccount + 1;
		if(this.cccount == this.ccerrthresh){
			endColChains();
			this.disablecc = true;
			
		}
	},
	
	setOverride:	function(obj){
		if(document.forms['frmControl'].colourcheck.checked){
				this.override = false;
			}else{
				this.override = true;
			}
	},
	
	setDebugCheck: function(obj){
		this.debugcheck = obj;
	},
	
	setDebugElem: function(obj){
		this.debugelem = obj;
	},
	
	setDebug:	function(obj){
		this.debug = obj;
	},	
	
	setDebug3:	function(obj){
		this.debug3 = obj;
	},
	
	setDebug2:	function(obj){
		this.debug2 = obj;
	},
	
	getDelay: function(){
			
			return ((this.colourdur * this.number) * this.factor);
	},
	
	setDelay:	function(){
		this.delay = ((this.colourdur * this.number) * this.factor);
	},
	
	getColTransition: function(){
		
		if(this.transitioncol =='linear'){
			return Fx.Transitions.linear;
		}else{
			return Fx.Transitions[this.transitioncol][this.easeIncol];
		}
	},

	primeCycle: function (){
		
	 if(!this.prime){
	 	this.prime	= true;
		}else{
			this.prime = false;
		}
		this.debugEvent('*event[:::: primeCycle ' + this.prime.toString());			
	},
	
	triggerCycle:	function	(){
		this.debugEvent('*event[:::: triggerCycle ' + this.prime.toString());
		if(this.prime){
			this.isGo=true;
			this.isTrue=true;
			
		}
	},
	
	stopCycle:	function	(){
		this.isGo=false;
		this.isTrue=false;
	},
	
	debugFunction: function (name,mode){
		if(this.dodebug){
			var tempa 		= this.debug2.value.split('\n');
			var bRemoved 	= false; //we may well have 2 of the same functions running at once. we want to be able to see this.
			var tempstring ='';
			
			if(mode==1){
				//add to list mode.
					this.debug2.value = name + '\n' + this.debug2.value;
						
			}else{
				//remove from list mode.
				//create new string containing all entrys except for that which we are removing.
				for(var x=0;x < tempa.length; x++){
						if(tempa[x] == name && !bRemoved){
							bRemoved = true; //skip over only one instance of this.
						}else{
							if(tempa[x].length > 0){
								tempstring = tempa[x] + '\n' + tempstring; //otherwise rebuild up the string.
							}
						}
				}
				this.debug2.value = tempstring;
			}
			
			bRemoved = false;
		}
	},
	
	// Writes debug alerts out to our 'console'...
	debugEvent: function (sval){
		if(this.dodebug){this.debug.value = $time() + '::::' + sval + '\n' + this.debug.value};
	},
	
	debugVar: function(val){
		if(this.dodebug){this.debug3.value = val + '\n' + this.debug3.value};
	},
	
	clearDebug:	function(){
		this.debug.value ='';
	},
	
	clearDebug2:	function(){
		this.debug2.value ='';
	},	
	
	clearDebug3:	function(){
		this.debug3.value ='';
	},
	
	clearDebugs:	function(){
		this.clearDebug3();
		this.clearDebug2();
		this.clearDebug();
	},
	
	toggleDebug: function(){
		if(this.dodebug){
			this.debugelem.innerHTML = 'debug mode : off';
			this.dodebug=false;
			this.debugcheck.checked = false;
		}else{
			this.dodebug=true;
			this.debugelem.innerHTML = 'debug mode : on';
			this.debugcheck.checked = true;
		}
	},
	
	determineCC:	function(){

		if(this.dodet){
				var bOP = false;
				
				this.debugEvent(' cc1 start = ' + this.cc1start.toString() + ' cc1end = ' + this.cc1end.toString());
				this.debugEvent(' cc2 start = ' + this.cc2start.toString() + ' cc2end = ' + this.cc2end.toString());
				
				if(this.cc1start && !this.cc1end){
					this.debugEvent('CC1 RUNNING');
					bOP = true;
				}
				else if(this.cc2start && !this.cc2end){
					this.debugEvent('cc2 running');
					bOP = true;
				}
				
				if(this.cc1start && this.cc2start){
					this.debugEvent('BOTH RUNNING?');
					bOP = true;
				}
				
				if(this.cc1start && this.cc1end){
					this.debugEvent('FUCKUP');
					bOP = true;
				}
				
				if(this.cc2start && this.cc2end){
					this.debugEvent('FUCKUP2');
					bOP = true;
				}
				
				if(!this.cc1start && !this.cc2start && (this.cc1end && this.cc2end)){
					bOP = true;
					this.debugEvent('NONE RUNNING>USE COL CYCL3 1');
				}
				
				if(!bOP){
					this.debugEvent('UMMM SOMETHINGS SERIOUSLY WRONG. ABANDON.');
				}
			}
	}
	
});




