/**
 * Flash
 * 
 */
var hexDecReference = "0123456789ABCDEF";

function flashElement(startColor, endColor, element) {
	changeBgColor(element, startColor);
	slideColor(startColor, endColor, element);
}
	
function slideColor(currentColor, endColor, element) {	
	if (currentColor != endColor) {
		var nextColor = getNextColor(currentColor, endColor, 12);
		changeBgColor(element, nextColor);
		
		setTimeout(function() { 
					slideColor(nextColor, endColor, element); 
				}, 10);
	}
}

function changeBgColor(element, color) {
	if (element != undefined) {
		element.style.backgroundColor = '#' + color;
	}
}
	
function dec2Hex(dec) {
	var hex = hexDecReference.substr(dec&15, 1);
	while (dec > 15) {
		dec >>= 4;
		hex = hexDecReference.substr(dec&15, 1) + hex;
	}
	
	return (hex.length == 1) ? "0" + hex : hex;
}

function hex2Dec(hex) {
	return parseInt(hex, 16);
}

function numPush(number) {
	number = parseFloat(number);
	return (number >= 0) ? Math.ceil(number) : Math.floor(number);	
}

function getNextColor(startHex, endHex) {
	var startR = hex2Dec(startHex.substr(0, 2));
	var startG = hex2Dec(startHex.substr(2, 2));
	var startB = hex2Dec(startHex.substr(4, 2));
	
	var endR   = hex2Dec(endHex.substr(0, 2));
	var endG   = hex2Dec(endHex.substr(2, 2));
	var endB   = hex2Dec(endHex.substr(4, 2));
	
	var nextR  = startR + numPush((endR - startR) / 22);
	var nextG  = startG + numPush((endG - startG) / 22);
	var nextB  = startB + numPush((endB - startB) / 22);
	
	return dec2Hex(nextR) + dec2Hex(nextG) + dec2Hex(nextB);
}