function trace() {
	var debug = document.getElementById('debug');
	if (!debug) {
		var debug = document.createElement('div');
		debug.setAttribute('id', 'debug');
		document.body.appendChild(debug);
		/*
		debug.onclick = function() {
			if (this.closed) {
				this.style.height = '200px';
				this.closed = false;
			} else {
				this.style.height = '2px';
				this.closed = true;
			}
		}
		*/
	}
	if (debug) {
		var o = '';
		o = 'arguments.length = ' + arguments.length + '<br />';
//		o += arguments;
		for (var i=0; i<arguments.length; i++) {
			o += '<div style="margin-left: 16px;">';
			o += arguments[i];
			for (j in arguments[i]) {
				o += '<div style="margin-left: 16px;">';
				o += '<b>' + j +'</b>&nbsp;=&nbsp;' + String(arguments[i][j]).split('<').join('&lt;').split('>').join('&gt;').split('\"').join('&raquo;');
				o += '</div>';
			}				
			o += '</div>';
		}
		debug.innerHTML = o;
	}
}
/* get dimension */
function getDimension(obj) {
	var pobj = obj;
	obj.x = 0;
	obj.y = 0;
	obj._x = obj.offsetLeft;
	obj._y = obj.offsetTop;
	obj._width = obj.offsetWidth;
	obj._height = obj.offsetHeight;
	if(pobj.offsetParent){
		while (pobj) {
//			alert(pobj.className + ' - ' + pobj.offsetTop);
//			 pobj.style.background = 'red'
			obj.x += pobj.offsetLeft;
			obj.y += pobj.offsetTop;
			pobj = pobj.offsetParent;
		}
	}
	return {x: obj.x, y: obj.y, _x: obj._x, _y: obj._y, _width: obj._width, _height: obj._height};
}
/* /get dimension */



/* get mouse */
function getMouse(e) {
	e = e || window.event;
	return {x: (e.pageX || e.clientX + document.documentElement.scrollLeft), y: (e.pageY || e.clientY + document.documentElement.scrollTop)};
}
/* /get mouse */



/* :hover */
function hover(obj) {
	obj.onmouseover = function() {
		this.className += ' hover';
	}
	obj.onmouseout = function() {
		this.className = this.className.split('hover').join('');
	}
}
/* /:hover */


/* */
function scrollobjDirect(obj, x, y) {
		obj.style.left = String(Math.round(x)) + 'px';
	obj.style.top = String(Math.round(y)) + 'px';
}

function scrollobj(obj, hspace, vspace) {
	var outer = obj.parentNode;
	outer.inner = obj;
	outer.hspace = hspace;
	outer.vspace = vspace;
	outer.onmousemove = function(e) {
	getDimension(this.inner);
		getDimension(this);
	//	trace(getDimension(this))	
scrollobjDirect(this.inner, Math.min(0, Math.max(this._width-this.inner._width, (this._width-this.inner._width)*(getMouse(e).x-this.x-this.hspace)/(this._width-2*this.hspace))), Math.min(0, Math.max(this._height-this.inner._height, (this._height-this.inner._height)*(getMouse(e).y-this.y-this.vspace)/(this._height-2*this.vspace))));
	}
}
/* / */

$(document).ready(function(){

	if(dataobj=document.getElementById("reference-list-inner")) scrollobj(dataobj, 10, 10);
	
		

	
	$("div.left-menu-holder li a").hover(
		function(){
			$(this).animate({width: 140}, {"duration": 100, "easing": "swing" });
		} // This should set the opacity to 100% on hover
		,function(){
			$(this).animate({width: 20}, {"duration": 200, "easing": "swing" });
	});

	$('div.content-holder.news a.archive-btn').click(function(){
		$('div.content-holder.news div.entry-list').show(300)
	}
)

	$('div.content-holder.news div.entry-list').hover(function(){
		$('div.content-holder.news div.entry-list').show()
	}, function(){
		$('div.content-holder.news div.entry-list').hide(300)
	})
	
	doMatrix = function(matrix){

		var matrix = matrix.split('');

		for(i = 0; i < 15; i++){
			$('div.matrix').append('<div class="matrix-item">'+matrix[i]+'</div>');
		}

		$('.matrix-item').each(function(){
			$(this).mouseover(function(){
				$(this).toggleClass('over');
			});
			$(this).mouseout(function(){
				$(this).toggleClass('out');
			});
		
		});

	}
	
    var contactFormOptions = { 
        clearForm: false,        // clear all form fields after successful submit 
        dataType:  'json', 
		beforeSubmit: function(data, $form, opts){
				$('div.message', opts).empty().html('Progress....').show()
		},
        success:   function(data, $form, opts){ 
				$('div.message', opts).empty().html(data.message).show();
				if(data.success == true){
					opts.clearForm();
				} else {
					$('div.message', opts).addClass('error')
				}
		} 
    }; 
 

 
    $('#contact-form').ajaxForm(contactFormOptions); 

	$('#slideshow-holder')
	.cycle({ 
    	fx:    'fade', 
	    pager:  '.nav', 
	    timeout: 0, 
	    speed: 'fast',
   	 	next:   '.next', 
   		prev:   '.prev' 	});

});
