var hourHand = document.getElementById("hour");
var minHand = document.getElementById("min");
var now, minutes, hours, t, hdeg, mdeg;
var ticker, sms, maxLen, email;
var category = 0;

moveHands();

function moveHands(){
	var now = new Date();
	minutes = now.getMinutes();
	hours = now.getHours();
	
	if (hours > 11){
		hours -= 12;
	}
	
	hdeg = (hours * 30) + (minutes / 2);	
	mdeg = minutes * 6;
	
	hourHand.style.webkitTransform = "rotate(" + hdeg + "deg)";
	minHand.style.webkitTransform = "rotate(" + mdeg + "deg)";
	
	hourHand.style.MozTransform = "rotate(" + hdeg + "deg)";
	minHand.style.MozTransform = "rotate(" + mdeg + "deg)";
	
	hourHand.style.msTransform = "rotate(" + hdeg + "deg)";
	minHand.style.msTransform = "rotate(" + mdeg + "deg)";
	
	hourHand.style.oTransform = "rotate(" + hdeg + "deg)";
	minHand.style.oTransform = "rotate(" + mdeg + "deg)";
	
	hourHand.style.transform = "rotate(" + hdeg + "deg)";
	minHand.style.transform = "rotate(" + mdeg + "deg)";
	
	t = setTimeout("moveHands();", 30000);
}

function smsTicker(){
	ticker = document.getElementById("smsLength");
	sms = document.getElementById("sms");
	email = document.getElementById("email");
	maxLen = 140;
	ticker.innerHTML = maxLen;
}

function smsControl(){
	ticker.innerHTML = maxLen - sms.value.length;
}

function unStyle(textBox){
	textBox.value = "";
	textBox.setAttribute("class", "");
}

function movePieces(y, x){
	// Move slides
	var pieces = document.getElementById("portbox");
	pieces.style.left = -(x * 740) + "px";
	pieces.style.top = -(y * 450) + "px"; 
	
	// Gather page elements
	var cat = document.getElementById("categories");
	var artBoxes = cat.getElementsByClassName("artBtns"); bLen = artBoxes.length;
	var artBtns = cat.getElementsByTagName("div"), artLen = artBtns.length;
	var specBtns = artBoxes[y].getElementsByTagName("div");
	
	// Style category buttons and artBtn boxes if necessary
	if(category != y){
		category = y;
		var btns = cat.getElementsByTagName("a");
		for (var i=0; i<bLen; i++){
			btns[i].setAttribute("class", "");
			artBoxes[i].style.height = "0";
			artBoxes[i].style.width = "140px";
			artBoxes[i].style.padding = "0";
		}

		btns[y].setAttribute("class", "selectedCat");
		artBoxes[y].style.height = (Math.ceil(specBtns.length / 5) * 25) + "px";
		artBoxes[y].style.width = "133px";
		artBoxes[y].style.padding = "5px 0 5px 7px";
	}
	
	
	// Reset all square button divs & style new one
	for(var idx=0; idx<artLen; idx++){
		artBtns[idx].setAttribute("class", "");
	}
	specBtns[x].setAttribute("class", "selectedPiece");
		
}
