var lastHash='';
var waitingAsyncProcessCount =0;
highlightingClip = false;

function getHashData() {
		if (location.href.indexOf("#") > -1) {
			var hashArr = location.href.split('#');
			return hashArr[1];
		} else {
			return "";
		}
}

function setHash(val, replace) {
	if (val == '') {
		window.location.hash = '_';
		return;
	}
	if (replace != undefined && replace) {
		if (location.href.indexOf("#") > -1) {
			location.replace(location.href.substring(0, location.href.indexOf("#")) + "#" + val);
		} else {
			location.replace(location.href  + "#" + val);
		} 
	} else {
		if (location.href.indexOf("#") > -1) {
			location.href = location.href.substring(0, location.href.indexOf("#")) + "#" + val;
		} else {
			location.href = location.href  + "#" + val;
		}
	}
}		
	


function handleURLHash() {
	
	if (waitingAsyncProcessCount != 0 || highlightingClip) { return; }
	var hashData = getHashData();
	if (hashData != lastHash) {

		lastHash = hashData;
		
		if (typeof(handleSearchHash) !== 'undefined' && handleSearchHash(hashData)) {
			return;
		}
		
		var found = hashData.match(/(?:c(\d+))/);
		if (found) {
			clipId = found[1];
			if (clipId !=  currentClipId) {
				showClip(clipId);
			}
		} 
	}
}

function pollHash() {
	
	handleURLHash();
}

$(document).ready(function() {			

});
