// All code in this file © Sean Schricker 
//function $(id){
//	return document.getElementById(id);
//}
function doPic(theA){
	$("#bigPhoto")[0].src=theA.href;
	return false;
}


trace=('console' in window)?console.log:function(){};

steps=10
var timeOutHandle
function changeColor(){
	if(clr.length){
		var thisClr=clr.shift();
		document.body.style.backgroundColor='rgb('
			+ (thisClr[0]) +","
			+ (thisClr[1]) +","
			+ (thisClr[2]) +")"
		/*
		negStyle='rgb('
			+ Math.abs(255-thisClr[0]) +","
			+ Math.abs(255-thisClr[1]) +","
			+ Math.abs(255-thisClr[2]) +")"
		//$('neg').style.backgroundColor=negStyle;
		document.styleSheets[0].cssRules[1].style.color=negStyle
		document.styleSheets[0].cssRules[1].style.borderColor=negStyle
		*/
		//trace(document.styleSheets[0].cssRules[0].cssText)
	}else{
		clearInterval(timeOutHandle)
	}
}
function toColorNOTINUSE(newColor){
	if(typeof newColor == 'string'){
		newColor=[
			parseInt(newColor.substr(1,2),16),
			parseInt(newColor.substr(3,2),16),
			parseInt(newColor.substr(5,2),16)
		]
	}
	
	timeOutHandle=setInterval(changeColor,10);
//	trace(timeOutHandle)
	return newColor
}
var hashPattern=/^#(\w\w)(\w\w)(\w\w)$/
var rgbPattern=	/^rgb\(\s*(\w{1,3}),\s*(\w{1,3}),\s*(\w{1,3})\)$/
function makeRgbArrayOfColor(_c){
	if(hashPattern.test(_c)){
		return [
			parseInt(_c.substr(1,2),16),
			parseInt(_c.substr(3,2),16),
			parseInt(_c.substr(5,2),16)
		];
	}else if(rgbPattern.test(_c)){
		return [
			+RegExp.$1,
			+RegExp.$2,
			+RegExp.$3
		];
	}else{
		return [0,0,0];
	}
}

function addColors(C){
	if(clr.length){
//		trace('from clr[0]')
		oldColor=clr[0];
		clr=[oldColor];
	}else{
//		trace('from body')
//		trace(document.body.style.backgroundColor)
		oldColor=( document.body.style.backgroundColor)?document.body.style.backgroundColor:_nc;
	}
		trace(oldColor)
	oldColor=makeRgbArrayOfColor(oldColor);
	newColor=makeRgbArrayOfColor(C);
	document.cookie='scheme='+C;
//		trace(oldColor)
	var shouldBeBlack=(newColor[0] + newColor[1] + newColor[2] >= 555)
	$('#whiteStyle')[0].disabled= shouldBeBlack;
	$('#blackStyle')[0].disabled=!shouldBeBlack;

	if(/MSIE (5\.5)|[6]/.test(navigator.userAgent) && navigator.platform == "Win32"){
		$('#logo')[0].outerHTML='<img src="/images/logo-{0}.png" border="0" id="logo" />'.format( (shouldBeBlack?'b':'w') );
	}else{
		$('#logo')[0].src='/images/logo-{0}.png'.format( (shouldBeBlack?'b':'w') );
	}

	var delta=[];
	for(var i=0;i<=2;i++){
		//CorF=( newColor[i]-oldColor[i]>0 )?'floor':'ceil';
		delta[i]=(newColor[i]-oldColor[i])/steps
	}

	for(var i=0;i<=steps;i++){
		 clr.push(
			/*
			"rgb("
			+ Math.round(oldColor[0]+(delta[0]*i)) + ","
			+ Math.round(oldColor[1]+(delta[1]*i)) + ","
			+ Math.round(oldColor[2]+(delta[2]*i)) + ")"
			*/
			[
			Math.round(oldColor[0]+(delta[0]*i)) ,
			Math.round(oldColor[1]+(delta[1]*i)) ,
			Math.round(oldColor[2]+(delta[2]*i))
			]
		 )
	}
//	clr.push(C)
trace(clr)
	timeOutHandle=setInterval(changeColor,10);
}
window.onload=function(){
//	addColors('#FFFFFF')
}


var clr=[];

String.prototype.format=function(){
	var ar=arguments;
	return this.replace(/\{\d+\}/g,function(w){return ar[+w.replace(/[}{]/g,'')]});
}

if(/scheme=(#\w{6}|rgb\([^\)]+\))/.test(document.cookie)){
	_nc=RegExp.$1
	document.write('<style>body{background-color:'+_nc+'}</style>');
	setTimeout(function(){
		var newColor=makeRgbArrayOfColor(_nc);
		var shouldBeBlack=(newColor[0] + newColor[1] + newColor[2] >= 555)
		$('#whiteStyle')[0].disabled= shouldBeBlack;
		$('#blackStyle')[0].disabled=!shouldBeBlack;
		$('#logo')[0].src='/images/logo-{0}.png'.format( (shouldBeBlack?'b':'w') );

	if(0)if(/MSIE (5\.5)|[6]/.test(navigator.userAgent) && navigator.platform == "Win32"){
		$('#logo')[0].outerHTML='<img src="/images/logo-{0}.png" border="0" id="logo" />'.format( (shouldBeBlack?'b':'w') );
	}else{
		$('#logo')[0].src='/images/logo-{0}.png'.format( (shouldBeBlack?'b':'w') );
	}


		},20)
}







