portTimer = 0;

function portWin(dir,currItem){
portFolio = new Array(7);
portFolio[0] = "tomi";
portFolio[1] = "wiggintonswills";
portFolio[2] = "terristinies";
portFolio[3] = "care";
portFolio[4] = "nfc";
portFolio[5] = "ccc";
portFolio[6] = "comedyhead";

portFolioAddr = new Array(7);
portFolioAddr[0] = "tomi.org.uk";
portFolioAddr[1] = "wiggintonswills.co.uk";
portFolioAddr[2] = "terristinies.co.uk";
portFolioAddr[3] = "vote2009.eu";
portFolioAddr[4] = "nenefamilychurch.org.uk";
portFolioAddr[5] = "clitheroecommunitychurch.co.uk";
portFolioAddr[6] = "comedyhead.co.uk";

portFolioDesc = new Array(7);
portFolioDesc[0] = "On-line Polish Shop in Peterborough";
portFolioDesc[1] = "Will-writer in Norwich";
portFolioDesc[2] = "Peterborough Childminders";
portFolioDesc[3] = "EU Elections Website";
portFolioDesc[4] = "Nene Family Church in Peterborough";
portFolioDesc[5] = "Clitheroe Community Church";
portFolioDesc[6] = "Christian Comedians in Cambridgeshire";

lowestItem = 0;
highestItem = 6;
 if(dir==1){
   currItem++;
   if(currItem>highestItem){
    currItem=0;
   }
 }
 else{
  /* currItem--; */
  if(currItem<lowestItem){
   currItem = highestItem;
  }
 }
 /* alert(dir + "," + currItem); */
 document.getElementById('portWin').src = "images/portfolio/sidebar_" + portFolio[currItem] + ".png";
 document.getElementById('portWin').alt = portFolioDesc;
 /* The next two lines are commented out since altering it to automatic slideshow, rather than manual changing... to reinstate
   these lines a 'previous' and 'next' < > link needs adding */
 /* document.getElementById('next').href = "javascript:portWin(1," + currItem + ");";
 document.getElementById('previous').href = "javascript:portWin(-1," + currItem + ");"; */
 if(currItem!=3 && currItem!=0){
  document.getElementById('portTxt').innerHTML = "<a class=\"portLink\" href=\"http://www." + portFolioAddr[currItem] + "\" target=\"_blank\">" + portFolioDesc[currItem] + "</a>";
 }
 else{
  if(currItem==0){ document.getElementById('portTxt').innerHTML = "On-line Polish Shop in Peterborough"; }
  if(currItem==3){ document.getElementById('portTxt').innerHTML = "2009 EU Elections Website (No longer live)"; } 
 }
 /** document.getElementById('portWin').onclick = "window.open('http://www.wiggintonswills.co.uk');"; **/
 clearTimeout(portTimer);
 portTimer = setTimeout("portWin(" + dir + "," + currItem + ")",5000);
}

function startPortWin(){
  if(portTimer==0){
   portTimer = setTimeout("portWin(1,0)",5000);
  }
}

function portAnimate(start,finish,adjustment,direction){
 clearTimeout(timer);
 speed = 54;
 document.getElementById('portfolioSlider').style.left = (start+adjustment) + "px";
 if((start+adjustment) != finish){
  if(direction==-1){ /* right */
   adjustment = adjustment - speed;
   timer = setTimeout("portAnimate(" + start + "," + finish + "," + adjustment + "," + direction + ")",speed);
  }
  else if(direction==1){ /* left */
    adjustment = adjustment + speed;
    timer = setTimeout("portAnimate(" + start + "," + finish + "," + adjustment + "," + direction + ")",speed);
  }
  else{
   alert('portAnimate: invalid call, aborting');
   clearTimeout(timer);
  }
 }
}

function portMove(y){
CURRENT_ITEMS = 8; /** UPDATE WHEN ADD ITEMS **/  
MAXLENGTH = 540 * CURRENT_ITEMS;
speed = 54;
direction = y;

currentLeftPos = document.getElementById('portfolioSlider').style.left;
currentLeftPos = parseInt(currentLeftPos);
//alert('Current Position: ' + currentLeftPos);
if(y==-1){ /** right **/
  newLeftPos = currentLeftPos - 540;
  if(newLeftPos<(540*(CURRENT_ITEMS-1))*-1){
   document.getElementById('tracker').innerHTML = "<strong>&lt;&lt;&lt;Please Scroll to the Left Now</strong>";
  }
  else{
   document.getElementById('tracker').innerHTML = "&nbsp;";
   portAnimate(currentLeftPos,newLeftPos,0,direction,speed);
  }
}
else if(y==1){ /** left **/
  newLeftPos = currentLeftPos + 540;
  if(newLeftPos>0){
   document.getElementById('tracker').innerHTML = "<strong>Please Scroll to the Right &gt;&gt;&gt;</strong>";
  }
  else{
   document.getElementById('tracker').innerHTML = "&nbsp;"
   portAnimate(currentLeftPos,newLeftPos,0,direction,speed);
  }
}
else{ /** error **/
  alert('Invalid Call to Function');
}
/* document.getElementById('portfolioSlider').style.left = newLeftPos + "px"; */
/*document.getElementById('tracker').innerHTML = "currentLeftPos = " + newLeftPos + "px"; */
}

function squareHover(alt,x){
 if(x==1){
  document.getElementById('tracker').innerHTML = alt;  
 }
 else{
  document.getElementById('tracker').innerHTML = "&nbsp;";
 }
}

function portQuick(x){
 document.getElementById('portfolioSlider').style.left = (-540 * x) + "px";
}

function checkForm(){
/** checks the add_post form **/
post_title = document.forms['addpost'].elements['news_title'].value;
post_narrative = document.forms['addpost'].elements['news_text'].value;
errors = 0;
/* if(post_title.indexOf("'") != -1){ errors++; }
if(post_narrative.indexOf("'") != -1){ errors++; }
*/
if(errors > 0){ alert(errors + " of the 2 boxes have single quotes in them, please rectify and re-try"); }
 else{
  document.forms['addpost'].action = "xadmin.php";
  document.forms['addpost'].submit();
 }
}

function checkFeedback(){
 probs = 0;
 can_continue = 0;
 message_body = document.forms['feedbackform'].elements['Enquiry'].value;
 persons_name = document.forms['feedbackform'].elements['realname'].value;
 persons_email = document.forms['feedbackform'].elements['email'].value;
 persons_telephone = document.forms['feedbackform'].elements['Phone_Number'].value;
 if(persons_name == ""){ probs++; }
 if(persons_email == "" && persons_telephone == ""){ probs++; }
 if(message_body == ""){ probs++; }
 if(message_body.indexOf("<")!=-1 || message_body.indexOf(">")!=-1 || message_body.indexOf("[")!=-1 || message_body.indexOf("]")!=-1){ alert('No use of <, >, [, or ] allowed. Please remove these and resubmit'); probs++; }
 if(probs==0){ document.forms['feedbackform'].submit(); }
  else{ alert('You need to provide your Name, at least one contact method and a valid message.\nPlease complete these and re-send.\nThank you for your understanding.'); }
}

function browserTweaks2(){
 browser = navigator.userAgent;
 /* alert(browser); */
 if(browser.indexOf("Firefox")!=-1){
  firefox = 1;
 }
 else{
  firefox = 0;
 }
 if(firefox == 1){
  /* document.getElementById('portWin').style.width = "306px"; */
 }
 else{
  /* document.getElementById('portWin').style.width = "300px"; */
 }
}

/*var portwincheck = document.getElementById('portWin');
//if(portwincheck != false){
//   timer = setTimeout("",50000);
//   startPortWin();
//} */

function showRSS(str)
{
if (str.length==0)
  {
  document.getElementById("twitterRSS").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("twitterRSS").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","php-bin/rss2/rss2.php?q="+str,true);
xmlhttp.send();
}

browserTweaks2();
showRSS("mOxby Design Twitter");