//Written by Nathan Faubion: http://n-son.com
//Use this or edit how you want, just give me
//some credit!

var urlobj;

function jsScroller (o, w, h) {
	var self = this;
	var list = o.getElementsByTagName("div");
	for (var i = 0; i < list.length; i++) {
		if (list[i].className.indexOf("Scroller-Container") > -1) {
			o = list[i];
		}
	}

	//Private methods
	this._setPos = function (x, y) {
		if (x < this.viewableWidth - this.totalWidth)
			x = this.viewableWidth - this.totalWidth;
		if (x > 0) x = 0;
		if (y < this.viewableHeight - this.totalHeight)
			y = this.viewableHeight - this.totalHeight;
		if (y > 0) y = 0;
		this._x = x;
		this._y = y;
		with (o.style) {
			left = this._x +"px";
			top  = this._y +"px";
		}
	};

	//Public Methods
	this.reset = function () {
		this.content = o;
		this.totalHeight = o.offsetHeight;
		this.totalWidth	 = o.offsetWidth;
		this._x = 0;
		this._y = 0;
		with (o.style) {
			left = "0px";
			top  = "0px";
		}
	};
	this.scrollBy = function (x, y) {
		this._setPos(this._x + x, this._y + y);
	};
	this.scrollTo = function (x, y) {
		this._setPos(-x, -y);
	};
	this.stopScroll = function () {
		if (this.scrollTimer) window.clearInterval(this.scrollTimer);
	};
	this.startScroll = function (x, y) {
		this.stopScroll();
		this.scrollTimer = window.setInterval(
			function(){ self.scrollBy(x, y); }, 40
		);
	};
	this.swapContent = function (c, w, h) {
		o = c;
		var list = o.getElementsByTagName("div");
		for (var i = 0; i < list.length; i++) {
			if (list[i].className.indexOf("Scroller-Container") > -1) {
				o = list[i];
			}
		}
		if (w) this.viewableWidth  = w;
		if (h) this.viewableHeight = h;
		this.reset();
	};

	//variables
	this.content = o;
	this.viewableWidth  = w;
	this.viewableHeight = h;
	this.totalWidth	 = o.offsetWidth;
	this.totalHeight = o.offsetHeight;
	this.scrollTimer = null;
	this.reset();
};

function ScrollLeft(img, scroller, stop) {
  if (stop) {
    scroller.stopScroll();
    img.src = './img/slider_arrow_left.gif';
  } else {
    scroller.startScroll(5, 0);
    img.src = './img/slider_arrow_left_hover.gif';
  }
}

function ScrollRight(img, scroller, stop) {
  if (stop) {
    scroller.stopScroll();
    img.src = './img/slider_arrow_right.gif';
  } else {
    scroller.startScroll(-5, 0);
    img.src = './img/slider_arrow_right_hover.gif';
  }
}

function ShowPicture(filename, width, height) {
  pic = document.getElementById('portfolio_picture');
  info = document.getElementById('portfolio_pictureinfo');
  content = document.getElementById('portfolio_content');
  if (filename == '') {
    pic.style.display = 'none';
    info.style.display = 'block';
    content.style.width = '500px';
  } else {
    pic.src = '';
    pic.style.display = 'block';
    info.style.display = 'none';
    content.style.width = width+'px';
    pic.width = width;
    pic.height = height;
    pic.src = './img/pic/'+filename;
  }
}


function BrowseServer(obj) {
  urlobj = obj;
  OpenServerBrowser(
          '/lib/fckeditor/editor/filemanager/browser/default/browser.html?Type=Image&Connector=connectors/php/connector.php',
          screen.width * 0.7,
          screen.height * 0.7 ) ;
}

function OpenServerBrowser( url, width, height ) {
  var iLeft = (screen.width  - width) / 2 ;
  var iTop  = (screen.height - height) / 2 ;
  var sOptions = "toolbar=no,status=no,resizable=yes,dependent=yes" ;
  sOptions += ",width=" + width ;
  sOptions += ",height=" + height ;
  sOptions += ",left=" + iLeft ;
  sOptions += ",top=" + iTop ;
  var oWindow = window.open( url, "BrowseWindow", sOptions ) ;
}

function SetUrl( url, width, height, alt ) {
  document.getElementById(urlobj).value = url ;
  oWindow = null;
}

function WriteEmail(user, dom, dotwhat) {
  document.write('<a href="');
  document.write('ma');
  document.write('il' + 'to:' + user + '@' + dom + dotwhat + '">');
  document.write(user + '@' + dom + dotwhat);
  document.write('</a>');
}

function ToggleElement(id) {
  obj = document.getElementById(id);
  if (obj.style.display == 'block')
    obj.style.display = 'none';
  else
    obj.style.display = 'block';
}