var w, h;
function GetDimensions()
{
	if(window.innerHeight) //Standards-based browsers
	{
		h = window.innerHeight;
		w = window.innerWidth;
	} else if(document.documentElement.clientHeight) //IE in Standards Mode
	{
		h = document.documentElement.clientHeight;
		w = document.documentElement.clientWidth;
	} else if(document.body.clientHeight) //IE in Quirks Mode
	{
		h = document.body.clientHeight;
		w = document.body.clientWidth;
	} else {
	}
	PosGlobalElements(w,h);
	return w;
}
var photoNum = 8;
var panMargin = 30;
function PosGlobalElements(w,h) 
{
	var container = document.getElementById("container");
	var arrows = document.getElementById("arrows");
	var contact = document.getElementById("contactPan");
	var portfolio = document.getElementById("portfolioPan");
	var news = document.getElementById("newsPan");
	var about = document.getElementById("aboutPan");
	if (h < 628) 
	{
		container.style.margin = "-230px 0 0 0";
		arrows.style.display = "none";
	} else {
		container.style.top = "50%";
		container.style.margin = "-250px 0 0 0";
	}
	portfolio.style.width = (560+2) * photoNum + "px";
	container.style.width = (contact.offsetWidth + panMargin) + (portfolio.offsetWidth + panMargin) + (news.offsetWidth + panMargin) + (about.offsetWidth + panMargin) + "px";
}
var opacity = 75;
function SetOpacity()
{
	obj = document.getElementById("arrows");
	obj.style.filter = "alpha(opacity:"+opacity+")";
	obj.style.KHTMLOpacity = opacity/100;
	obj.style.MozOpacity = opacity/100;
	obj.style.opacity = opacity/100;
}
var timer = 0;
var scr;
var dx = 0;
function scrollRight(amt,yeah)
{
	container = document.getElementById("container");
	scr = yeah;
	if (scr) {
		if (container.offsetLeft+container.offsetWidth > w) {
			clearTimeout(timer);
			dx = amt;
			container.style.left = container.offsetLeft + amt + "px";
			timer = setTimeout("scrollRight(dx,"+true+")",20);
		} else {
			clearTimeout(timer);
		return;
		}
	} else {
		clearTimeout(timer);
		return;
	}
}
function scrollLeft(amt,yeah)
{
	container = document.getElementById("container");
	scr = yeah;
	if (scr) {
		if (container.offsetLeft < 0) {
			clearTimeout(timer);
			dx = amt;
			container.style.left = container.offsetLeft + amt + "px";
			timer = setTimeout("scrollLeft(dx,"+true+")",20);
		} else {
			container.style.left = 0 + "px";
		}
	} else {
		clearTimeout(timer);
		return;
	}
}


var allowScroll = false;
function ScrollContent()
{
	if (allowScroll)
	{
		scroller = document.getElementById("scrubber");
		text = document.getElementById("newsHolder");
		mask = document.getElementById("newMask");
		if (scroller.offsetTop > 0 && (scroller.offsetTop + scroller.offsetHeight) < mask.offsetHeight)
		{
			amount = (text.offsetHeight - mask.offsetHeight) / (mask.offsetHeight - scroller.offsetHeight);
			absolute = Math.abs(mask.offsetTop - (scroller.offsetTop+58));
			text.style.top = absolute * -1 * amount + "px";
		}
	}
	
}
var scrub = "scrubber";
var obj = null;
var dy = 0;
function Grab(evt)
{
	var evt = (evt) ? evt: ((window.event) ? window.event : null);
	var target = (evt.target) ? evt.target.id : ((evt.srcElement) ? evt.srcElement.id : null);
	var drag = false;
	if(scrub == target)
	{
		drag = true;
	}
	if (drag)
	{
		obj = document.getElementById(target)
		dy = evt.screenY - obj.offsetTop;
		
		document.onmousemove = Drag;
		document.onmouseup = LetGo;
		allowScroll = true;
	}
}
function Drag(evt)
{
	scroller = document.getElementById("scrubber");
	text = document.getElementById("newsHolder");
	mask = document.getElementById("newMask");
	document.body.focus();
	if ((scroller.offsetTop+scroller.offsetHeight) > mask.offsetHeight) 
	{
		bottom = mask.offsetHeight - scroller.offsetHeight;
		end = mask.offsetHeight - text.offsetHeight;
		scroller.style.top = bottom + "px";
		LetGo(evt);
		text.style.top = end + "px";
	}
	if (scroller.offsetTop < 0) 
	{
		scroller.style.top = "0px";
		LetGo(evt);
		text.style.top = "0px";
	}
	if (obj == null)
	{
		return;
	}
	var evt = (evt) ? evt: ((window.event) ? window.event : null);
	obj.style.top = evt.screenY - dy + "px";
}
function LetGo(evt) 
{
	obj = null;
	document.onmousemove = null;
	document.onmouseup = null;
	allowScroll = false;
}
function CancelSelect() 
{
	var h = document.getElementById('container');
	h.onselectstart = function (){return false;}
	h.onmousedown = function (){return false;}
}
function EnableSelect() 
{
	var h = document.getElementById('container');
	h.onselectstart = function (){return true;}
	h.onmousedown = function (){return true;}
}

function changePage(el)
{
	e = document.getElementById(el);
	container = document.getElementById("container");
	newLeft = 0;
	a = container.offsetWidth - e.offsetLeft;
	b = w - a;
	c = a - container.offsetWidth;
	if (b > 20)
	{
		container.style.left = c + "px";
		container.style.left = container.offsetLeft + b + "px";
		
	} else {
		container.style.left = (e.offsetLeft*-1)+20 + "px";
	}
	
}



window.onload = function() {
	GetDimensions();
	SetOpacity();
	document.getElementById("right").onmouseover = function() {scrollRight(-15,true);}
	document.getElementById("right").onmouseout = function() {scrollRight(0,false);}
	document.getElementById("left").onmouseover = function() {scrollLeft(15,true);}
	document.getElementById("left").onmouseout = function() {scrollLeft(0,false);}
	document.onmousedown = Grab;
	document.getElementById("scrubber").onmousedown = CancelSelect;
	document.getElementById("container").onmouseup = EnableSelect;
	document.getElementById("scrubber").onmouseup = EnableSelect;
}
window.onresize = GetDimensions;
