var fx;
window.addEvent('domready', function() {

	fx = new Fx.Slide('f_images',{duration: 1000, wait:true});
	fx.hide();
	//$('f_images').style.height = '400px';	
	
	$('flickrform').addEvent('submit',function(e){
			new Event(e).stop();		
			fx.hide();
			if($('srchtags').value == "")
			{
				return false;
			}
		  var params = $('flickrform').toQueryString();
		  var url = "_search.php?"+params;
	    ajxCall(url);	
	});//end submit.addEvent
	
}); //end window.addEvent (domready)
//=============================================================================
function mod_check(link,desc){
  try{
    Lightbox.show(link,desc);
  }
  catch(err){console.log(err)}
}//end mod_check
//=============================================================================
function ajxCall(url) {
	  fx.hide();
	  new Ajax(url,{
	  		update:'f_images',
	  		//evalScripts: true,
	  		//evalResponse: true,
	  		method:'get',
	  		onComplete: function(){validate();},
  			onRequest:  function(){$('ajaxLoader').effect('opacity',{duration:100}).start(0,100)},
  			onFailure:  function(){validate();}
	  	}).request();//end Ajax Request	
}//end ajxCall
//=============================================================================
function getPages() {
  if($('pageback'))
  {
    $('pageback').addEvent('click',function(e){
        new Event(e).stop();	
				ajxCall(this.href);
    });
  }

  if($('pageforward'))
  {
    $('pageforward').addEvent('click',function(e){
        new Event(e).stop();	
				ajxCall(this.href);
    });
  }
}//end getPages
//=============================================================================
function validate() {
	  var f = $('f_images');
	  if(f.innerHTML == "0") //nothing returned
	  {
			f.style.height = '20px';
			f.innerHTML = 'No Results Returned.  Please Enter Different Tags.';
	  }	 
		else
		{
		  f.style.height = '400px';
		}
			$('ajaxLoader').effect('opacity',{duration:100}).start(100,0);
			
			fx.slideIn();
     	$('f_images').effect('opacity',{duration:1}).start(0,100);
     	
     	
     	$$('#f_images img').each(function(el){
     		var el_fx = new Fx.Styles(el, {duration:200, wait:false});
     		el.setStyle('opacity',0.6);
     		el.addEvents({
     		  'mouseenter':function(e){el_fx.start({'opacity':1})},
     		  'mouseleave':function(e){el_fx.start({'opacity':0.6})}     		
     	  });
     	});
     	
     	
			getPages();
			addSounds();
			
}//end validate
//=============================================================================
function addSounds() {
  //add sound efx
  $$('#f_images a').each(function(element){
  	element.addEvent('click',function(){
		  soundManager.play('beep1');
	  });
  });
}//end addSounds
//=============================================================================

soundManager.url = 'soundmanager2.swf'; // override default SWF url
soundManager.debugMode = false;
soundManager.consoleOnly = true;

soundManager.onload = function() {
  // soundManager is initialised, ready to use. Create a sound for this demo page.
  //soundManager.createSound('aDrumSound','../mpc/audio/AMB_SN13.mp3');
  //soundManager.createSound('aCymbalSound','../mpc/audio/SPLASH_1.mp3');
  soundManager.createSound('beep1','audio/beep_1.mp3');
}//end SM.onload
//=============================================================================
