/*     _ _                             _ _     _  __              _ 
      | (_)                           (_) |   | |/ _|            | |
  ___ | |_ __ __ ___  _ __  ____ _   _ _| | __| | |_ ___  _ __ __| |  ___ ___  _ __ ___
 / _ \| | |  |  / _ \| '__ / _  | | | | | |/ _  |  _/ _ \| '__/ _  | / __/ _ \| '_ ` _ \ 
| (_) | | |  | |  __/| |  | (_) | |_| | | | (_) | || (_) | | | (_) || (_| (_) | | | | | |
 \___/|_|_|\___/\___||_|   \__  |\___/|_|_|\____|_| \___/|_|  \____( )___\___/|_| |_| |_|
                           ___| |                                                                
                          |_____|
*/
/****************************
	Configuration
****************************/
var interval = 5000;
var timeToFade = 2000;

var q = new Q();
q.e("pagebkgrnd1");
q.e("pagebkgrnd2");

var s= new Array();
s.push("https://lh5.googleusercontent.com/-ErCMpXlyqkk/RrnMTqBBooI/AAAAAAAAAYA/SspOCJY4XX4/IMG_8141.JPG");
s.push("https://lh5.googleusercontent.com/-BLy0kMhsGHY/RrnNQqBBosI/AAAAAAAAAYk/IQmDmgHSAgI/Water001.JPG");
s.push("https://lh5.googleusercontent.com/-lchlv5P_ViA/RrnMKqBBonI/AAAAAAAAAX4/aqVJoGEO2d0/IMG_9480.JPG");
s.push("https://lh3.googleusercontent.com/-Wk6l5bWFLPo/RrnZoKBBoxI/AAAAAAAAAZU/q4IZeM18OBY/IMG_8835.JPG");
s.push("https://lh5.googleusercontent.com/-t-uhoSgrjlE/RrnZqqBBoyI/AAAAAAAAAZc/fMOS3vp5TBA/IMG_9371.JPG");
s.push("https://lh4.googleusercontent.com/-GUTn72bAPJk/RrnZsaBBozI/AAAAAAAAAZk/qrZtOhCTLNA/IMG_9485.JPG");
s.push("https://lh6.googleusercontent.com/-ZFFRs3I1-ek/RrnZt6BBo0I/AAAAAAAAAZs/CKf6lnqQDao/IMG_6131.JPG");
s.push("https://lh4.googleusercontent.com/-jwCefr9Ol9E/RrnZuaBBo1I/AAAAAAAAAZ0/XL3jvYYmLuo/IMG_6169.JPG");
s.push("https://lh5.googleusercontent.com/-H6yD-GOw73I/RrnZvqBBo2I/AAAAAAAAAZ8/PLLuh6Lxrew/IMG_7036.JPG");
s.push("https://lh6.googleusercontent.com/-WoEPlh8eZGc/RrnZx6BBo3I/AAAAAAAAAaE/wPXF5GLbZuM/IMG_7071.JPG");
s.push("https://lh6.googleusercontent.com/-QK5rbswXQgY/RrnZ06BBo4I/AAAAAAAAAaM/bhWrpoLObEk/IMG_7072.JPG");
s.push("https://lh5.googleusercontent.com/-54CFz3XqFZU/RrnZ2qBBo5I/AAAAAAAAAaU/z1PCA16y52s/IMG_7189.JPG");
s.push("https://lh5.googleusercontent.com/-FHwPPwjU8ug/RrnZlqBBowI/AAAAAAAAAZM/r9hY5fVezlw/IMG_8312.JPG");
s.push("https://lh6.googleusercontent.com/-y4h7cEqpMqA/Ta4KzyUQk8I/AAAAAAAAC1M/6Ae2h_D0GtA/IMG_1975.JPG");
s.push("https://lh3.googleusercontent.com/-ioeNSIxKVzI/Ta4Hy6-tPYI/AAAAAAAAC00/tCTOrB8T-N0/flowers.jpg");
s.push("https://lh6.googleusercontent.com/-eQI-O6q56eQ/RrnZi6BBotI/AAAAAAAAAY0/YHlUcKhxuvY/April_May_07_059.JPG");
s.push("https://lh6.googleusercontent.com/-20eopXrnlVY/Ta4ItlWtrTI/AAAAAAAAC08/hvuB0Cfe36Y/April_May_07_124.JPG");
s.push("https://lh4.googleusercontent.com/-F0dhKYrTIVw/Ta4KjB3VqxI/AAAAAAAAC68/zbYakL3pde4/kr%252520716.JPG");
s.push("https://lh3.googleusercontent.com/-strHA097LjM/RrnMyKBBopI/AAAAAAAAAYM/ibX91nZyi8I/April_May_07_100.JPG");
s.push("https://lh3.googleusercontent.com/-vpGnu6hDeBs/RrnM-KBBoqI/AAAAAAAAAYU/oM0a7ZAgx98/Spring%252520Adastra089-1.JPG");
s.push("https://lh5.googleusercontent.com/-WcOZYjhejpY/RrnZkqBBouI/AAAAAAAAAY8/uwZK_R-tO6I/IMG_9491.JPG");
s.push("https://lh6.googleusercontent.com/-mpnPCvkcv5Q/Rrnc86BBo6I/AAAAAAAAAa4/LB1htyDutY8/07-02-08%252520Snow017.JPG");
s.push("https://lh5.googleusercontent.com/-_iXVXj_fwUA/Ta4JHht4vmI/AAAAAAAAC1A/bsCvjR2w1j8/IMG_1148.jpg");
s.push("https://lh3.googleusercontent.com/-sfVvor8Th2M/Ta4JeQHbYWI/AAAAAAAAC1E/ejknnHjhk3Y/IMG_2204.JPG");
s.push("https://lh3.googleusercontent.com/-74-jE-QtkBU/Ta4IiN0ELDI/AAAAAAAAC04/v6iEoT4uAnQ/SpringHarvest07_072.JPG");

/****************************
	Variables
****************************/
var pic=0;
var stage = 1;
/****************************
	Functions
****************************/
/*-------------------------*/
/*------- Queue -----------*/
function Q(){
var a=[];var b=0;
this.l=function(){return (a.length-b);};
this.z=function(){return (a.length==0);};
this.e=function(d){a.push(d);};
this.d=function(){return (a.length==0)?undefined:a.splice(0,1);};
this.p=function(){return (a.length>0?a[b]:undefined);};
};
/*------- Queue -----------*/
/*-------------------------*/

function changeBackground(eid){
	pic=(pic==s.length)?0:pic;
	var i=s[pic];
	pic++;
	$('#'+eid).css("background-image", 'url('+i+')');
}

function startFading(){
	changeBackground(q.p());
	q.e(q.d());
	changeBackground(q.p());
	q.e(q.d());
	OGfadeTo();
}

function OGfadeTo(){
	if(stage==1){
		q.e(q.d());
		var a=self.setTimeout("fadeOut()",interval);
		stage = 2;
	} else {
		changeBackground(q.p());
		var b=self.setTimeout("fadeIn()",interval);
		stage = 1;
	}
}

function fadeOut(){
	$('#'+q.p()).fadeTo(timeToFade,0);
	var c=self.setTimeout("OGfadeTo()",timeToFade);
}

function fadeIn(){
	$('#'+q.p()).fadeTo(timeToFade,1);
	q.e(q.d());
	var e=self.setTimeout("changeBackground(q.p());",timeToFade);
	var d=self.setTimeout("OGfadeTo()",timeToFade);
}


/*----------------------------*/
/*------- Ajax Img Getter ----*/

/*
function ajaxObject(url, callbackFunction) {
  var that=this;
  this.updating = false;
  this.abort = function() {
    if (that.updating) {
      that.updating=false;
      that.AJAX.abort();
      that.AJAX=null;
    }
  }
  this.update = function(passData,postMethod) {
    if (that.updating) { return false; }
    that.AJAX = null;
    if (window.XMLHttpRequest) {
      that.AJAX=new XMLHttpRequest();
    } else {
      that.AJAX=new ActiveXObject("Microsoft.XMLHTTP");
    }
    if (that.AJAX==null) {
      return false;
    } else {
      that.AJAX.onreadystatechange = function() {
        if (that.AJAX.readyState==4) {
          that.updating=false;
          that.callback(that.AJAX.responseText,that.AJAX.status,that.AJAX.responseXML);
          that.AJAX=null;
        }
      }
      that.updating = new Date();
      if (/post/i.test(postMethod)) {
        var uri=urlCall+'?'+that.updating.getTime();
        that.AJAX.open("POST", uri, true);
        that.AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        that.AJAX.send(passData);
      } else {
        var uri=urlCall+'?'+passData+'&timestamp='+(that.updating.getTime());
        that.AJAX.open("GET", uri, true);
        that.AJAX.send(null);
      }
      return true;
    }
  }
  var urlCall = url;
  this.callback = callbackFunction || function () { };
}


function processData(JSONData) {
   alert(JSONData.data.picture);
}

var ajaxRequest = new ajaxObject('https://graph.facebook.com/me/photos?access_token=AAAAAAITEghMBALHqjS1SnoVbg6OYNpc4PmyMrRfy54IVGatIQm2ZCweFbYsGw51Q8qPvOWDIhJ99GYZCuoQHluA2GtcMaRDjVitPh2WwZDZD');
    ajaxRequest.callback = function (responseText) {
       alert(responseText);
       eval(responseText);
    }
    ajaxRequest.update();
*/

/*------- Ajax Img Getter ----*/
/*----------------------------*/
