/* siteEffects - StephenEmmer.com. */
/* CopyRight 2009, HID Digital Solutions <http://www.hid.nl>. */
/* Released: Feb, 17h 2009. */

/* Start of siteEffects class. */
var siteEffects = {

	/* Initialise method, called when the dom tree is ready. */
	init: function (oOptions) {

		/* If a play button is available. */
		if ($('play')) {

			/* Retrieve video preview. */
			this.oPreview = $('movieImage');

			/* Retrieve play button. */
			this.oPlay = $('play');

			/* Retrieve title div. */
			this.oTitle = $('title');

		}

		/* If send to friend is available. */
		if ($('stf')) {

			/* Send to friend. */
			this.oStf = $('stf');

			/* Send to friend Inner. */
			this.oStfInner = $('stfInner');

			/* Send to friend Link. */
			this.oStfLink = $('stfLink');

		}

		/* If print is available. */
		if ($('print')) {

			/* Send to friend. */
			this.oPrint = $('print');

			/* Send to friend Inner. */
			this.oPrintInner = $('printInner');

			/* Send to friend Link. */
			this.oPrintLink = $('printLink');

		}

		/* Check if a play button is available. */
		if ($('play')) {

			/* Check if send to a friend is available. */
			if ($('stf')) {

				/* Effects. */
				this.fx = {
					oPlay: this.oPlay.effect('opacity', {duration: 500}).hide(),
					oTitle: this.oTitle.effect('opacity', {duration: 500}).hide(),
					oStfInner: this.oStfInner.effect('opacity', {duration: 1000}).hide(),
					oStfLink: this.oStfLink.effect('opacity', {duration: 1000}).hide(),
					oPrintInner: this.oPrintInner.effect('opacity', {duration: 1000}).hide(),
					oPrintLink: this.oPrintLink.effect('opacity', {duration: 1000}).hide()
				};

			/* If stf is not available. */
			} else {

				/* Effects. */
				this.fx = {
					oPlay: this.oPlay.effect('opacity', {duration: 500}).hide(),
					oTitle: this.oTitle.effect('opacity', {duration: 500}).hide()
				};

			}

		/* If play button is not available. */
		} else {

			/* If sent to a friend is available. */
			if ($('stf')) {

				/* Effects. */
				this.fx = {
					oStfInner: this.oStfInner.effect('opacity', {duration: 1000}).hide(),
					oStfLink: this.oStfLink.effect('opacity', {duration: 1000}).hide(),
					oPrintInner: this.oPrintInner.effect('opacity', {duration: 1000}).hide(),
					oPrintLink: this.oPrintLink.effect('opacity', {duration: 1000}).hide()
				};

			}

		}

		/* Add mouseover for play button. */     
		if ($('play')) {

			/* Mouseover. */
			this.oPreview.addEvent('mouseover', function (oEvent) {
				this.videoMouseOver();
			}.bind(this));

			/* Mouseover. */
			this.oPlay.addEvent('mouseover', function (oEvent) {
				this.videoMouseOver();
			}.bind(this));

			/* Mouseout. */
			this.oPreview.addEvent('mouseout', function (oEvent) {
				this.videoMouseOut();
			}.bind(this));

		}

		/* Add mouseover for send to friend. */
		if ($('stf')) {

			/* Mouseover. */
			this.oStf.addEvent('mouseover', function (oEvent) {
				this.friendMouseOver();
			}.bind(this));

			/* Mouseout. */
			this.oStf.addEvent('mouseout', function (oEvent) {
				this.friendMouseOut();
			}.bind(this));

		}

		/* Add mouseover for print. */
		if ($('print')) {

			/* Mouseover. */
			this.oPrint.addEvent('mouseover', function (oEvent) {
				this.printMouseOver();
			}.bind(this));

			/* Mouseout. */
			this.oPrint.addEvent('mouseout', function (oEvent) {
				this.printMouseOut();
			}.bind(this));

		}

	},

	/* Mouseover play. */
	videoMouseOver: function() {

		/* Start overlay animation (clear to x% transparency). */
		this.fx.oPlay.stop();
		this.fx.oTitle.stop();
		this.fx.oPlay.start(0.8);
		this.fx.oTitle.start(0.8);

	},

	/* Mouseout play. */
	videoMouseOut: function() {

		/* Start overlay animation (x% transparency to clear). */
		this.fx.oPlay.stop();
		this.fx.oTitle.stop();
		this.fx.oPlay.start(0);
		this.fx.oTitle.start(0);

	},

	/* Mouseover send to friend. */
	friendMouseOver: function() {

		/* Start overlay animation (clear to x% transparency). */
		this.fx.oStfInner.stop();
		this.fx.oStfLink.stop();
		this.fx.oStfLink.start(1.0);
		this.fx.oStfInner.start(1.0);

	},

	/* Mouseout send to friend. */
	friendMouseOut: function() {

		/* Start overlay animation (x% transparency to clear). */
		this.fx.oStfInner.stop();
		this.fx.oStfLink.stop();
		this.fx.oStfLink.start(0);
		this.fx.oStfInner.start(0);

	},

	/* Mouseover print. */
	printMouseOver: function() {

		/* Start overlay animation (clear to x% transparency). */
		this.fx.oPrintInner.stop();
		this.fx.oPrintLink.stop();
		this.fx.oPrintLink.start(1.0);
		this.fx.oPrintInner.start(1.0);

	},

	/* Mouseout print. */
	printMouseOut: function() {

		/* Start overlay animation (x% transparency to clear). */
		this.fx.oPrintInner.stop();
		this.fx.oPrintLink.stop();
		this.fx.oPrintLink.start(0);
		this.fx.oPrintInner.start(0);

	}

}


/* Start of siteSearch class. */
var siteSearch = {

   /* Initialise method, called when the dom tree is ready. */
   init: function (oOptions) {

      /* Retrieve video preview. */
      this.oKeywords  = $('sKeywords');

      this.oResults = $('ulResults');
this.oResults.style.height = '422px';
      this.oButSearch = $('butSearch');

      var searchButton = $('sSearchButton');

      /* Create results div. */
      this.oKeywords.addEvent('keyup', function (oEvent) {
         this.searchWebsite();
      }.bind(this));

      searchButton.addEvent('click', function (oEvent) {
      	this.searchWebsite();
      }.bind(this));

      //this.oButSearch.addEvent('click', function(oEvent) {
      	//this.searchWebsite();
      //}.bind(this));
      /* Effects. */
      this.fx = {
         oResults: this.oResults.effect('opacity', {duration: 1000}).hide()
      }

      this.oResults.style.visibility = "hidden";

   },


   searchWebsite: function() {

      // Start searching with 2 or more chars.
      if(this.oKeywords.value.length >= 2) {

			$('ulResults').innerHTML = '';
			this.oResults.setStyle('background', '#000000 url(/images/front/ajax_loader_search.gif) no-repeat center');
      	this.fx.oResults.stop();
			this.fx.oResults.start(0.9);

			var sJsonKeywords = {"sKeywords" : this.oKeywords.value};
			new XHR({onSuccess: this.showSearchResults}).send('/search/get-results/sKeywords/' + this.oKeywords.value, 'answerme=1&q=test');


      } else {
         this.fx.oResults.stop();
         this.fx.oResults.start(0);
      }


   },


   /* Display search results in website (called after search). */
   showSearchResults: function(sResults) {
   	// Create object from JSON string.
   	
$('ulResults').innerHTML = '';

//alert(myJSONObject);
var myObject = eval('{' + sResults + '}');
//alert(myJSONObject.bindings[0]);

var iCounter = 0;
while(myObject[iCounter] != undefined && iCounter < 13) {


var NewLI = document.createElement("LI");

if(myObject[iCounter].sType == 'content') {
	NewLI.innerHTML = '<a href="' + myObject[iCounter].url + '" title="Content page.">' + myObject[iCounter].title + '</a>';
}

if(myObject[iCounter].sType == 'popup') {
	NewLI.innerHTML = '<a href="' + myObject[iCounter].url + '" title="Content popup." rel="hidBox innerhtml 806 375">' + myObject[iCounter].title + '</a>';
}

if (myObject[iCounter].sType == 'news') {
	NewLI.innerHTML = '<a href="' + myObject[iCounter].url + '" title="News message." rel="hidBox innerhtml 806 375">' + myObject[iCounter].title + '</a>';
}

if (myObject[iCounter].sType == 'press') {
	NewLI.innerHTML = '<a href="' + myObject[iCounter].url + '" title="Press release." rel="hidBox innerhtml 806 375">' + myObject[iCounter].title + '</a>';
}

if(myObject[iCounter].sType == 'workGroup') {
	NewLI.innerHTML = '<a href="' + myObject[iCounter].url + '" title="Work category.">' + myObject[iCounter].title + '</a>';
}

if (myObject[iCounter].sType == 'album') {
	NewLI.innerHTML = '<a href="' + myObject[iCounter].url + '" title="Album information." rel="hidBox innerhtml 806 375">' + myObject[iCounter].title + '</a>';
}

if (myObject[iCounter].sType == 'song') {
	NewLI.innerHTML = '<a href="' + myObject[iCounter].url + '" title="Album song." rel="hidBox innerhtml 806 375">' + myObject[iCounter].title + '</a>';
}



$('ulResults').appendChild(NewLI);
	iCounter++;
}

	hidBox.alterAnchors();

if (iCounter == 0) {
	var NewLI = document.createElement("LI");
NewLI.innerHTML = '<a href="#this">No results.</a>';

$('ulResults').appendChild(NewLI);
}

$('ulResults').setStyle('background', '#000000');

		//alert(myJSONObject.bindings[0].method);
   	/*alert(myJSONObject.childNodes.length);*/
   	
   	//alert(oChilds);
   	//alert(oChilds.length);
		//alert(oResults.length);
   	// Retrieve length.
		//var iLength = oResults.length;
		//if (iLength == undefined) {
			//iLength = 1;
		//}
//alert('Lengte: ' + iLength);
		// Walk through elements.
		//for(var i = 1; i <= iLength; i++) {

			//alert(oResults[i].aStructure.title);
		//}
		//}

   }

}

// When the DOM is ready loading.
//window.addEvent('domready', function()) {
   
   //$('play').effect('opacity', {duration: 300}).hide()

//}
/*
// When the DOM is ready loading.
window.addEvent('domready', function() {

   // Retrieve the button div by ID.
   var el = $('sendtofriend');

   // Set fade to 0.01 by default.
   $('sendtofriend').fade(0.01);

   // Mouseover.
   $('sendtofriend').addEvent('mouseover', function(e) {
      e.stop();
      el.fade(1);
   });

   // Mouseout.
   $('sendtofriend').addEvent('mouseout', function(e) {
      e.stop();
      el.fade(0.01);
   });

   // Retrieve play button and explanation div.
   var elMovie       = $('movieImage');
   var elPlay        = $('play');
   var elDescription = $('title');

   // Set fade to 0.01 by default.
   elPlay.fade(0.01);
   elDescription.fade(0.01);

   // Mouseover.
   elMovie.addEvent('mouseover', function(e) {
      e.stop();
      elPlay.fade(1);
      elDescription.fade(1);
   });

   // Mouseover.
   elPlay.addEvent('mouseover', function(e) {
      e.stop();
      elPlay.fade(1);
      elDescription.fade(1);
   });

   // Mouseover.
   elDescription.addEvent('mouseover', function(e) {
      e.stop();
      elPlay.fade(1);
      elDescription.fade(1);
   });

   // Mouseout.
   elMovie.addEvent('mouseout', function(e) {
      e.stop();
      elPlay.fade(0.01);
      elDescription.fade(0.01);
   });

});*/


/* Display search results. */
/*function showSearchResults(sTerms) {

   // Start searching with 2 or more chars.
   if(sTerms.length == 2) {

      // Create div layer.
      var oDiv = document.createElement('div');
      alert(oDiv);
   }

}*/

/* Preload effects when the dom is ready loading. */
window.addEvent('domready', siteEffects.init.bind(siteEffects));

/* Preload search results div when the dom is ready loading. */
window.addEvent('domready', siteSearch.init.bind(siteSearch));
