// Ajax
var http = null;

function ajax()
{
	var http = null;
	if(window.XMLHttpRequest)
	{
		try
		{
			http = new XMLHttpRequest();
		}
		catch(e)
		{
			alert(e);
			http = null;
		}
	}
	else
		if(window.ActiveXObject)
		{
			try
			{
				http = new ActiveXObject('Microsoft.XMLHTTP');
			}
			catch(e)
			{
				alert(e);
				http = null;
			}
		}
	return http;
}

var busy = 0;

function ajaxSend( url, arr, callback )
{
	if( !http ) http = ajax();
	if( !http ) return alert( "Error: Cannot open an http connection" );
	if( http.readyState!='4' && http.readyState!='0' && busy ) return false;
	http.open( "POST", url );
	http.onreadystatechange = callback;
	http.setRequestHeader( "Content-Type", "application/x-www-form-urlencoded" );
	// Connected
	vars = "";
	for( i=0; i<arr.length; i++ )
	{
		tmp = arr[i][1];
		tmp = tmp.replace(/%/g, '%25');
		tmp = tmp.replace(/&/g, '%26');
		tmp = tmp.replace(/\+/g, '%2B');
		vars = vars+arr[i][0]+"="+tmp+"&";
	}
	http.send( vars );
	// Sent
	return true;
}
// End


// Fix-es
function fixPages()
{
	e = document.getElementById( "pages" );
	count = e.getElementsByTagName( "a" ).length;
	w = count*41+5;
	e.style.width = w+"px";
}
//End

// FAQ
function questionOperate ( q, el )
{
	ch = el.firstChild.data;
	question = document.getElementById( "question" + q );
	faq = document.getElementById( "faq" + q );
	if ( question.style.display=="" || question.style.display=="none" )
	{
		ch = "- ";
		question.style.display = "block";
		faq.className = "faq faqActive";
	}
	else
	{
		ch = "+ ";
		question.style.display = "none";
		faq.className = "faq";
	}
	el.firstChild.data = ch;
}
// End

// Portfolio
function projectOperate ( el )
{
	if ( el.className=="project" ) el.className = "project projectHover";
	else el.className = "project";
}

////
var galleryInterval = null;

function galleryMove( type )
{	
	cont = document.getElementById( "gallery" );
	if ( !type )
	{
		if ( cont.scrollLeft>0 ) cont.scrollLeft -= 2;
	}
	else
	{
		cont.scrollLeft += 2;
	}
}

function galleryMoveStart( type )
{
	galleryMoveStop();
	galleryInterval = setInterval( "galleryMove( "+type+" )", 8 );
	document.onmouseup = galleryMoveStop;
}

function galleryMoveStop()
{
	clearInterval( galleryInterval );
	galleryInterval = null;
	document.onmouseup = null;
}

function thumb_hover( thumb, type )
{
	if ( type )
	{
		setAlpha( thumb, 100 );
	}
	else
	{
		setAlpha( thumb, 70 );
	}
}

function setAlpha( obj, val )
{
	obj.style.opacity = val/100;
	obj.style.filter = 'alpha(opacity: '+val+')';
}

function fade( id, isIn )
{
	obj = document.getElementById( "mainImg" );
	if ( obj.timeOut )
	{
		clearTimeout( obj.timeOut );
	}
	var val = ( obj.style.opacity ? obj.style.opacity*100 : 0 ) + ( isIn ? 20 : -20 );
	if ( isIn && val>100 ) val = 100;
	else if ( !isIn && val<0 ) val = 0;
	setAlpha( obj, val );
	if ( isIn )
	{
		if ( val<100 ) obj.timeOut = window.setTimeout( 'fade(\''+id+'\',true)', 50 );
	}
	else
	{
		if ( val>0 ) obj.timeOut = window.setTimeout( 'fade(\''+id+'\',false)', 50 );
		else
		{
			obj.src = "/misc/projects/"+id+".jpg";
			fade( id, 1 );
		}
	}
	return false;
}
// End

// IE Fix
var bo_ns_id = 0;

function startIeFix(){
  if(isIE()){
    document.write('<div id="bo_ns_id_' + bo_ns_id + '"><!-- ');
  }
}

function endIeFix(){
  if(isIE()){
    document.write('</div>');
    var theObject = document.getElementById("bo_ns_id_" + bo_ns_id++);
    var theCode = theObject.innerHTML;
    theCode = theCode.substring(4 ,9+theCode.indexOf("</object>"))
    document.write(theCode);
  }
}

function isIE(){
  // only for Win IE 6+
  // But not in Windows 98, Me, NT 4.0, 2000
  var strBrwsr= navigator.userAgent.toLowerCase();
  if(strBrwsr.indexOf("msie") > -1 && strBrwsr.indexOf("mac") < 0){
    if(parseInt(strBrwsr.charAt(strBrwsr.indexOf("msie")+5)) < 6){
      return false;
    }
    if(strBrwsr.indexOf("win98") > -1 ||
       strBrwsr.indexOf("win 9x 4.90") > -1 ||
       strBrwsr.indexOf("winnt4.0") > -1 ||
       strBrwsr.indexOf("windows nt 5.0") > -1)
    {
      return false;
    }
    return true;
  }else{
    return false;
  }
}
// End
