var scrollEl;
var scrollH;
var scrollV;
var scrollTimer;

function scroll() {
	$(scrollEl).scrollLeft += scrollH;
	$(scrollEl).scrollTop += scrollV;
}

function speedScroll(h, v) {
	scrollH = h;
	scrollV = v;
}

function startScroll(id, h, v) {
	scrollEl = id;
	scrollH = h;
	scrollV = v;
	scrollTimer = setInterval("scroll()", 10);
}

function stopScroll() {
	clearInterval(scrollTimer);
}

function doClick(el) {
	if (!el.click) {
		HTMLElement.prototype.click = function() {
			var evt = this.ownerDocument.createEvent('MouseEvents');
			evt.initMouseEvent('click', true, true, this.ownerDocument.defaultView, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
			this.dispatchEvent(evt);
		}
	}
	el.click();
}

function showExtVideo(el, videoId, title, username, description) {
	var arr = el.id.split(':');
	
	$('lbprev').style.display = 'none';
	$('lbnext').style.display = 'none';
	
	var prevnum = parseInt(arr[1])-1;
	var nextnum = parseInt(arr[1])+1;
	
	try {
		if ($(arr[0] +':' +prevnum).id) {
			$('lbprev').style.display = 'inline';
			prevVidLink = arr[0] +':' +prevnum;
		}
	} catch(e) {  }

	try {
		if ($(arr[0] +':' +nextnum).id) {
			$('lbnext').style.display = 'inline';
			nextVidLink = arr[0] +':' +nextnum;
		}
	} catch(e) {  }	
	
	grayOut(true);
	
	$('lbvidtitle').innerHTML = title;
	$('lbvidauthor').innerHTML = username;
	$('lbviddesc').innerHTML = description;
	
	$('lightbox').style.top = (document.documentElement.scrollTop +20) +'px';
	$('lightbox').style.display = 'block';
	so2 = new SWFObject("http://www.youtube.com/v/" +videoId +"&rel=0", "vidswf2",
		425, 353, "6", "#000000");
	so2.addParam("wmode", "transparent");
	so2.write("lbvidobj");
}

function closeExtVideo() {
	$('lightbox').style.display = 'none';
	grayOut(false);
}

function nextExtVideo() {
	closeExtVideo();
	doClick($(nextVidLink));
}

function prevExtVideo() {
	closeExtVideo();
	doClick($(prevVidLink));
}
