var currentImg 		= 1;
var submenustatus 	= 0;
var text1status 	= 0;
var text2status 	= 0;
var picwinStatus 	= 1;
var hiremenustatus	= 0;
var openWindow				= false;
var navMainBoldLink 		= false;
var lastboldsubelement 		= false;
var lastLivePortfolioItem 	= false;
var firstBoldSubItem 		= false;
var lastLivePagelinkItem	= false;

function loadPortfolio(img, imagecount, a_imgs, textfile){

	ajaxLoadText(textfile);
	hideWin();
	
	// load the image links box?
	if(imagecount > 1){
		
		if(a_imgs){
			
			try{image_array = a_imgs.split('*');}catch(err){}
		
			var html = '<ul>';
			for(i=0;i<imagecount;i++){
				html += '<li id="num_' + i + '" onclick="boldifyPagelink(this)"';
				if(!i){
					html += ' style="font-weight:bold" ';	
				}
				html += '>';
				html += '<a href="javascript:loadPortfolio(\''+image_array[i]+'\', '+imagecount+')">'+(i+1)+'</a></li>';
			}
			html += '</ul>';
			document.getElementById('pagelinks').style.display = 'block';
			document.getElementById('pagelinks').innerHTML = html;
		}
		
	}else{
		
		document.getElementById('pagelinks').innerHTML = '';
		
	}
	
	if(img == 'blank'){
		$('picwindowimg1').fade();
		$('picwindowimg2').fade();
		
		textOff();
		return false;
	}
	
	if(currentImg == 1){
		$('picwindowimg1').fade();
		document.getElementById('picwindowimg2').src = 'images_portfolio/'+img;
		$('picwindowimg2').appear({ duration: 1, from: 0, to: 1 })
		currentImg = 2;
	}else if(currentImg == 2){
		$('picwindowimg2').fade();
		document.getElementById('picwindowimg1').src = 'images_portfolio/'+img;
		$('picwindowimg1').appear({ duration: 1, from: 0, to: 1 })
		currentImg = 1
	}
	
	// Text boxes on
	textOn();
	
}

function navMainBold(div){
	
	if(div){
		try{document.getElementById('link_'+navMainBoldLink).style.fontWeight = 'normal';}catch(err){}
		try{document.getElementById('link_'+div).style.fontWeight = 'bold';}catch(err){}
	}
	document.getElementById('link_design').style.fontWeight = 'bold';
	navMainBoldLink = div;

}

function navHireMainBold(div){

	if(div){
		try{document.getElementById('link_'+navHireMainBoldLink).style.fontWeight = 'normal';}catch(err){}
		try{document.getElementById('link_'+div).style.fontWeight = 'bold';}catch(err){}
	}
	navHireMainBoldLink = div;

}

function navHireBold(div){
	
	if(div){
		try{document.getElementById('link_'+navHireBoldLink).style.fontWeight = 'normal';}catch(err){}
		try{document.getElementById('link_'+div).style.fontWeight = 'bold';}catch(err){}
	}
	navHireBoldLink = div;

}

function boldify(thing){
	try{document.getElementById('link_general').style.fontWeight = 'normal';}catch(err){}
	try{document.getElementById(firstBoldSubItem).style.fontWeight = 'normal';}catch(err){}
	try{lastLivePortfolioItem.style.fontWeight = 'normal';}catch(err){}
	thing.style.fontWeight = 'bold';
	lastLivePortfolioItem = thing;
}
function boldifyPagelink(thing){
	try{document.getElementById('num_0').style.fontWeight = 'normal';}catch(err){}
	try{lastLivePagelinkItem.style.fontWeight = 'normal';}catch(err){}
	thing.style.fontWeight = 'bold';
	lastLivePagelinkItem = thing;
}

// Main nav control
function mainnav(section){

	greyBgnd('off');
	try{document.getElementById('link_design').style.fontWeight = 'bold';}catch(err){}
	try{document.getElementById('link_art').style.fontWeight = 'normal';}catch(err){}
	try{document.getElementById('spgd').style.color = '#666666';}catch(err){}
	try{document.getElementById('link_design').style.color = '#666666';}catch(err){}
	try{document.getElementById('link_art').style.color = '#666666';}catch(err){}
	try{document.getElementById('copyright').style.color = '#999999';}catch(err){}

	try{document.getElementById('sealimg').src = 'images/spgd_seal_mono_1.jpg';}catch(err){}

	try{document.getElementById('contactformtable').style.display = 'block';}catch(err){}
	try{document.getElementById('contactformresponse').style.display = 'none';}catch(err){}
	try{document.getElementById('slides').style.display = 'none';}catch(err){}
	try{document.getElementById('sub_'+lastboldsubelement).style.fontWeight = 'normal';}catch(err){}
	try{lastLivePortfolioItem.style.fontWeight = 'normal';}catch(err){}
	document.forms['contactform'].reset();

	if(section=='design'){
		$('mainmenu').appear({ duration: 1, from: 0, to: 1 })
		$('emailbox').appear({ duration: 1, from: 0, to: 1 })
		$('telbox').appear({ duration: 1, from: 0, to: 1 })
		$('mobile').appear({ duration: 1, from: 0, to: 1 })
		
		loadPortfolio('blank');
		closeSubnav();
		showWin('about')
		textOff();
		closeHireMenu()
		try{document.getElementById('link_design').style.fontWeight = 'bold';}catch(err){}
		try{document.getElementById('link_about').style.fontWeight = 'bold';}catch(err){}
		try{document.getElementById('link_art').style.fontWeight = 'normal';}catch(err){}
		navMainBold('about');
	}
	
	if(section=='art'){
		loadPortfolio('blank');
		try{$('mainmenu').fade({ duration: 1, from: 1, to: 0 })}catch(err){}
		closeSubnav();
		showWin('art')
		textOff();
		closeHireMenu()
		try{document.getElementById('link_design').style.fontWeight = 'normal';}catch(err){}
		try{document.getElementById('link_art').style.fontWeight = 'bold';}catch(err){}
		try{document.getElementById('link_'+navMainBoldLink).style.fontWeight = 'normal';}catch(err){}
	}

	if(section == 'portfolio'){
		closeSubmenus();
		openSubnav();
		navMainBold(section);
		showWin(section);
	}

	if(section=='about'){
		loadPortfolio('blank');
		showWin(section);
		closeSubnav();
		closeHireMenu()
		navMainBold(section);
		textOff();
	}
	
	if(section=='clients'){
		loadPortfolio('blank');
		closeSubnav();
		showWin(section);
		closeHireMenu();
		navMainBold(section);
		textOff();
	}
	
	if(section=='resume'){
		loadPortfolio('blank');
		closeSubnav();
		showWin(section);
		closeHireMenu();
		navMainBold(section);
		textOff();
	}
	
	if(section=='hireme'){
		openHireMenu();
		closeSubnav();
		loadPortfolio('blank');
		showWin('contact');
		navMainBold(section)
		navHireMainBold('contact');
		textOff();
	}
	
	if(section=='contact'){
		loadPortfolio('blank');
		closeSubnav();
		showWin(section);
		navHireMainBold(section);
		closeHireSubmenu()
		textOff();
	}
	
	if(section=='detailedbrief'){
		loadPortfolio('blank');
		closeSubnav();
		showWin(section);
		navHireMainBold(section);
		textOff();
	}
	
	if(section=='tips'){
		loadPortfolio('blank');
		closeSubnav();
		showWin(section);
		navHireMainBold(section);
		textOff();
	}
	
	if(section=='nittygritty'){
		loadPortfolio('blank');
		closeSubnav();
		showWin(section);
		navHireBold(section);
		textOff();
	}
	if(section=='ownership'){
		loadPortfolio('blank');
		closeSubnav();
		showWin(section);
		navHireBold(section);
		textOff();
	}
	if(section=='money'){
		loadPortfolio('blank');
		closeSubnav();
		showWin(section);
		textOff();
		navHireBold(section);
	}
	if(section=='general'){
		loadPortfolio('blank');
		closeSubnav();
		showWin(section);
		textOff();
		navHireBold(section);
		navHireMainBold('sample')
	}
		
}

//-------------------

function showWin(div){

	if(div != openWindow){
		hideWin();
		openWindow = div;
		try{$(div).appear({ duration: 0.2, from: 0, to: 1 });}catch(err){alert('no openWindow')}
	}

}

function hideWin(){
	try{$(openWindow).fade({ duration: 0.2, from: 1, to: 0 });}catch(err){}
	openWindow = false;
}

//-------------------

function greyBgnd(set){
	
	if(set=='off'){
		document.body.style.backgroundColor = '#FFFFFF';
		document.body.style.color = '#666666';
	}else{
		document.body.style.backgroundColor = '#999999';
		document.body.style.color = '#FFFFFF';
		document.a.style.color = '#FFFFFF';
	}
	
}


function openSubmenu(ind){
	try{document.getElementById('sub_'+ind+'_0').style.fontWeight = 'bold';}catch(err){}
	firstBoldSubItem = 'sub_'+ind+'_0';
	try{document.getElementById('sub_'+lastboldsubelement).style.fontWeight = 'normal';}catch(err){}
	lastboldsubelement = ind;
	Effect.BlindDown('subnav_'+ind, { duration: 0.5 });
	closeSubmenus(ind);
}


function closeSubmenus(ind){
	
	for(counter=0; counter<submenucount; counter++){
		
		if(counter != ind){
			try{Effect.BlindUp('subnav_'+counter, { duration: 0.5 });}catch(err){}
		}
		
	}
	
}


function closeSubnav(){
	if(submenustatus == 1){
		$('submenu').fade({ duration: 0.2, from: 1, to: 0 })
		submenustatus = 0;
	}
}


function openSubnav(){
	if(submenustatus == 0){
		$('submenu').appear({ duration: 0.2, from: 0, to: 1 })
		submenustatus = 1;
	}	
}

//-------------------

function closeHireMenu(){
	if(hiremenustatus == 1){
		$('hirememenu').fade({ duration: 0.2, from: 1, to: 0 })
		hiremenustatus = 0;
		closeHireSubmenu()
	}
}


function openHireMenu(){
	if(hiremenustatus == 0){
		$('hirememenu').appear({ duration: 0.2, from: 0, to: 1 })
		hiremenustatus = 1;
	}	
}


function openHireSubmenu(){
	Effect.BlindDown('hiresubnav_0', { duration: 0.5 });
	hiresubnavopen = 1;
}

function closeHireSubmenu(){
	try{Effect.BlindUp('hiresubnav_0', { duration: 0.5 });}catch(err){}
	hiresubnavopen = 0;
}

//-------------------

function showDesignWin(){
	$('design').appear({ duration: 0.2, from: 0, to: 1 })
}

function hideDesignWin(){
	$('design').fade({ duration: 0.2, from: 1, to: 0 })
}

function showClientsWin(){
	$('clients').appear({ duration: 0.2, from: 0, to: 1 })
}

function hideClientsWin(){	
	$('clients').fade({ duration: 0.2, from: 1, to: 0 })
}

function showResumeWin(){
	$('resume').appear({ duration: 0.2, from: 0, to: 1 })
}

function hideResumeWin(){	
	$('resume').fade({ duration: 0.2, from: 1, to: 0 })
}

function showAboutWin(){
	$('about').appear({ duration: 0.2, from: 0, to: 1 })
}

function hideAboutWin(){	
	$('about').fade({ duration: 0.2, from: 1, to: 0 })
}

function showHiremeWin(){
	$('contact').appear({ duration: 0.2, from: 0, to: 1 })
}

function hideHiremeWin(){	
	$('contact').fade({ duration: 0.2, from: 1, to: 0 })
}

function textOn(){
	if(text2status == 0){
		$('text2').appear({ duration: 0.2, from: 0, to: 1 });
		text2status = 1;
	}	
}

function textOff(){
	if(text1status == 1){
		$('text1').fade({ duration: 0.2, from: 1, to: 0 });
		text1status = 0;
	}
	if(text2status == 1){
		$('text2').fade({ duration: 0.2, from: 1, to: 0 });
		text2status = 0;
	}	
}

function openPicwin(){
	
	if(picwinStatus == 0){
		
		$('picwindowimg1').appear({ duration: 0.2, from: 0, to: 1 });
		$('picwindowimg2').appear({ duration: 0.2, from: 0, to: 1 });
		picwinStatus == 1;
	
	}
	
}

function closePicwin(){
	
	if(picwinStatus == 1){
		
		$('picwindowimg1').fade({ duration: 0.2, from: 1, to: 0 });
		$('picwindowimg2').fade({ duration: 0.2, from: 1, to: 0 });
		picwinStatus == 0;
	
	}
	
}


function contactformprocess(){
	
	//ajaxContactFormProcess();
	
	var err = new Array();
	var errstr = '';
	
	var name 	= document.forms['contactform'].name.value;
	var company = document.forms['contactform'].company.value;
	var email 	= document.forms['contactform'].email.value;
	var tel 	= document.forms['contactform'].tel.value;
	var url 	= document.forms['contactform'].url.value;
	var project = document.forms['contactform'].project.value;
	var desc 	= document.forms['contactform'].description.value;
	var budget 	= document.forms['contactform'].budget.value;
	
	if(!name){err.push("Please enter your name");}
	if(!company){err.push("Please enter your company name");}
	if(!email){err.push("Please enter your email address");}
	if(!tel){err.push("Please enter your telephone number");}
	
	if(err.length > 0){
		
		for(i=0; i<err.length; i++){
			errstr += err[i]+"\r\n";
		}
		if(errstr.length){
			alert(errstr);
		}else{
			ajaxContactFormProcess();
		}
		
	}else{
		
		ajaxContactFormProcess();
	
	}
	
}


function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}

function ValidateForm(){
	var emailID=document.frmSample.txtEmail
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email ID")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	return true
 }


function clearForm(oForm) {
    
  var elements = oForm.elements; 
    
  oForm.reset();

  for(i=0; i<elements.length; i++) {
      
  field_type = elements[i].type.toLowerCase();
  
  switch(field_type) {
  
    case "text": 
    case "password": 
    case "textarea":
          case "hidden":   
      
      elements[i].value = ""; 
      break;
        
    case "radio":
    case "checkbox":
        if (elements[i].checked) {
          elements[i].checked = false; 
      }
      break;

    case "select-one":
    case "select-multi":
                elements[i].selectedIndex = -1;
      break;

    default: 
      break;
  }
    }
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}