/**
* Controllo Website Development Application
* (c) Copyright 2007 Adam Doeler.
* http://www.adamdoeler.com
* http://www.releod.com
* 
* Short Description:
* - Place all homemade recipes in this file
*
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
* 
* @copyright:       (c) Copyright 2007 Adam Doeler.
* @link:            http://www.adamdoeler.com
* @package:         controllo
* @subpackage:      controllo.web.javascripts
* @since:           version 0.1
* @version:         JAVASCRIPT
* @license          http://www.opensource.org/licenses/mit-license.php The MIT License
* 
**/

/**
* Sort items in the admin area 
*/
function filter_sortby(args) {
  // before we do anything ensure the queue has been cleared
  // this prevents jerky behaviour when users click on items rapidly
  var queue = Effect.Queues.get( 'sortbyscope' );
  queue.each( function( e ) { e.cancel() } );
  
  // define the flash id
  var sort_flash_for = $('sort_flash_for');
  
  // ensure the element exists
  if( sort_flash_for ) {
    sort_flash_for.style.display = 'block';
    
    innerHTML = '<div class="loading_request">';
    innerHTML = innerHTML + '<img src="../images/common/spinner.gif" alt="Loading.."/>';
    innerHTML = innerHTML + '<p>Please wait while your request loads...</p>';
    innerHTML = innerHTML + '</div>';
    
    sort_flash_for.innerHTML = innerHTML;
    
    // ensure the innerHTML will be shown right-away [no delay]
    new Effect.Opacity( sort_flash_for, {duration: 0, from: 0, to: 1, queue: {position: 'end', scope: 'sortbyscope', limit: 3} });
    
    // call the url to show the flash for this request
    new Ajax.Updater( sort_flash_for, '/' + args.name + '/filter_sortby?' + args.sortby, {onSuccess:sort_flash_on_success} );
  }
  
  // function to do the complete effects for the flash element
  function sort_flash_on_success() {
	  // fade-out the flash message
	  new Effect.Opacity( sort_flash_for, {delay:0.5, duration:2, from:1, to:0, queue: {position: 'end', scope: 'sortbyscope', limit: 3}, afterFinish:sort_flash_after_finish} );
	}
	
	// function to slide up the flash after it has been displayed
	function sort_flash_after_finish() {
	  // slide up to recover the height generated by the flash message
	  new Effect.SlideUp( sort_flash_for, {queue: {position: 'end', scope: 'sortbyscope', limit: 3} } );
  }
}

function shop_add(args) {
  // create a new instance of the ppShopBox class
  // this will create the html divs, call the url via ajax
  // present the user with a status report
  var myShopBox = new ppShopBox(args);
}

function initPlayerPopUp(args) {
  // function fires when page loads
  
  // ensure we can access the html elements
  if( !document.getElementsByClassName ){ return; }
  
  // find all the tags with player_track className
  var aHrefs = document.getElementsByClassName("player_track");
  
  for(a = 0; a != aHrefs.length; a++) {
    // loop through the links and assign scripts on players
    
    // set the url for the new window
    aHrefs[a].playerURL = aHrefs[a].href;
    
    aHrefs[a].onclick = function() {
      // function fires when link is clicked
      
      // set the window name
      window.name = "foxjawsParent";
      
      // create the new popup window attribtues
      var sAttributes = new String("location=no,scrollbars=no,menubar=no,resizable=no,status=no,toolbar=no,height=190,width=370,top=150,left=150");
      
      // open the new window
      window.open(this.playerURL, "playerWindow", sAttributes, false);
      
      // return false to prevent the href from being called
      return false;
    }
  }
}
Event.observe(window, 'load', initPlayerPopUp, false);