var isIE6 = /MSIE\s[56]/.test(window.navigator.userAgent);
var px = 'px';

var rollover = function(img, over)
{
	img.src = over;
}

var rollout = function(img, out)
{
	img.src = out;
}

var swapPng24Image = function(elementId, spacerImage)
{
	if (!spacerImage)
		spacerImage = "images/spacer.png";
	
	if (mediaInspector)
		if (mediaInspector.isPrinting)
			return;
			
	if (isIE6)
	{
		var element = document.getElementById(elementId);
		if (element)
		{
			//alert("cur = (" + element.width  + "x" + element.height + ")");
			element.style.width = element.width + px;
			element.style.height = element.height + px;
			element.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + element.src + "', sizingMethod='scale')";					
			element.src = spacerImage;
		}
	}
};

var $addHandler = function(elem, e, func)
{
	if(elem.addEventListener)
	{
		elem.addEventListener(e,func,false)
	}
	else if(elem.attachEvent)
	{
		elem.attachEvent("on"+e,func)
	}
};

/*

Media Inspector Class

*/
MediaInspector = function()
{
	this.isPrinting = false;
	this.init();
};

MediaInspector.prototype = {
	init : function()
	{
		try
		{
		  var mediaType = document.getElementById('mediaInspector');
		  if (mediaType.currentStyle) {
		    zIndex = mediaType.currentStyle['zIndex'];
		  } else if (window.getComputedStyle) {
		    zIndex = window.getComputedStyle(mediaType, '').getPropertyValue("z-index");
		  }
		  
		  switch (parseInt(zIndex)) 
		  {
		    case 101:
		    default:
		      // @media normal
			  	this.isPrinting = false;
		      break;
		    case 102:
		    	// @media print
			  	this.isPrinting = true;
		      break;
			}
		}
		catch(e) {}
	}
}

/*

Project Scroller Class

*/
ProjectsScroller = function(elemId, count, width, margin, speed)
{
	if (!count)
		count = 0;
		
	if (!width)
		width = 135;
		
	if (!margin)
		margin = 80;
		
	if (!speed)
		speed = 30;
	
	this.projectElementId = elemId;
	this.projectElement = null;
	this.projectItems = count;
	this._itemWidth = width;
	this._itemMargin = 80;
	this.scrollInterval = null;
	this.speed = speed;
	
	this._direction = 1;
	this._listWidth = 0;
	
	this._init();
}

ProjectsScroller.prototype = {					
	start : function(direction)
	{
		if (this.scrollInterval)
			clearInterval(this.scrollInterval);
			
		// get client width
		this.clientWidth = get_clientWidth();
		
		this._direction = direction;
		this.scrollInterval = setInterval(createObjectCallback(this, this._scrollProjects), 80);
	},
	
	stop : function()
	{
		clearInterval(this.scrollInterval);
		this.scrollInterval = null;
	},

	_scrollProjects : function()
	{
		if (this.projectElement)
		{
			left = parseInt(this.projectElement.style.left);
			if (isNaN(left)) left = 0;
			
			if (this.clientWidth > this._listWidth)
			{
			    this.stop();
			    return;
			}
			else if (this._direction > 0)
			{
				if (left >= 0) 
				{
					this.stop();
					this.projectElement.style.left = "0px";	
					return;
				}
			}
			else
			{
				minLeft = ((this._listWidth - this.clientWidth) * -1) - 15;
				if (left <= minLeft) 
				{
					this.stop();
					this.projectElement.style.left = minLeft + px;	
					return;
				}
			}
			
			left = left + (this._direction * this.speed);
			this.projectElement.style.left = left + px;	
		}
	},
	
	_init : function()
	{
		this.projectElement = document.getElementById(this.projectElementId);
		
		if (this.projectItems == 0)
		{
			var items  = this.projectElement.getElementsByTagName('LI');
			if (items)
				this.projectItems = items.length;
		}
		
		this._listWidth = this.projectItems * this._itemWidth + (this.projectItems - 1) * this._itemMargin;
	}
}

function createObjectCallback(obj, fn)
{
	return function() { fn.apply(obj, arguments); };
}

function get_clientWidth()
{
	if(navigator.userAgent.indexOf(" MSIE ")>-1)
	{
	    if (document.compatMode == "BackCompat")
	        return document.body.clientWidth;
	    else
		    return document.documentElement.clientWidth;
	}
	else if (navigator.userAgent.indexOf(" Safari/")>-1)
	{
		return window.innerWidth;
	}
	else if (navigator.userAgent.indexOf("Opera/")>-1)
	{
		return Math.min(window.innerWidth, document.body.clientWidth);
	}
	else (navigator.userAgent.indexOf(" Firefox/")>-1)
	{
		return Math.min(window.innerWidth, document.documentElement.clientWidth);
	}
}



/*

Google Analytics

*/
try {
	var pageTracker = _gat._getTracker("UA-15200768-1");
	pageTracker._trackPageview();
} catch(err) {}
