/* Javascript Document */
/* Author: Nichole Shannon */
/* Date: 03/2009 */
/* Description: OnReadyState Functions  */

/* jQuery Readystate objects: while this is a good way of loading 
   these objects not all of them are used on every page. It would be better to modularly 
   load some objects, function or widgets only on the pages they are used.
*/
$jquery(document).ready(function(){
	/* SET Ajaxify Default Override */
	$jquery.AjaxifyDefaults.animateOut = true;
	$jquery.AjaxifyDefaults.animateIn = true;
	$jquery.AjaxifyDefaults.method = 'GET'; 
	$jquery.AjaxifyDefaults.loading_img = "/images/loading_big.gif";
	$jquery.AjaxifyDefaults.title = false;
	$jquery.AjaxifyDefaults.forms = false;
	$jquery.AjaxifyDefaults.cache = false;
	/* onSuccess function required to reinitialize AJAX eneble links within AJAX content results */
	$jquery.AjaxifyDefaults.onSuccess = function(op){
	  //init_search_results();
	  /*It is necessary to unbind all previous ajaxify bindings 
	   *or else ajax events will be appended to existing events 
	   */
	$jquery('.modal_ajax').unbind('click', $jquery.ajaxify);
	$jquery('.modal_ajax_p').unbind('click', $jquery.ajaxify);	  
    $jquery('.modal_ajax').ajaxify({
      animateOut:{opacity:'0'},
      animateOutSpeed:300,
      animateIn:{opacity:'1'},
      animateInSpeed:300,
      title:'DTS Title Search Results',
      onStart:function(options){
        $jquery("#mmgs_search_results").hide();
        $jquery("#mmgs_search_detail").show();
        $jquery(".musicNGamesSearch div.back").show();
        $jquery(".musicNGamesSearch div.next_previous").show();
      },
      onComplete:function(options){
        //$jquery('#contentResults.detail tr:odd').addClass('oddRow'); 
        //$jquery('#trailerResults.detail tr:even').addClass('evenRow'); 
      }
  });

  $jquery('.modal_ajax_p').ajaxify({
      animateOut: { opacity: '0' },
      animateOutSpeed: 300,
      animateIn: { opacity: '1' },
      animateInSpeed: 300,
      title: 'DTS Title Search Results',
      onStart: function(options) {
          $jquery("#mmgs_search_results").show();
          $jquery("#mmgs_search_detail").hide();
          $jquery(".musicNGamesSearch div.back").hide();
          $jquery(".musicNGamesSearch div.next_previous").hide();
      },
      onComplete: function(options) {
          //$jquery('#contentResults.detail tr:odd').addClass('oddRow'); 
          //$jquery('#trailerResults.detail tr:even').addClass('evenRow'); 
      }
  });   
	};
	$jquery.AjaxifyDefaults.onComplete = function(op){};
	$jquery('.modal_ajax').ajaxify({
        animateOut:{opacity:'0'},
        animateOutSpeed:300,
        animateIn:{opacity:'1'},
        animateInSpeed:300,
        title:'DTS Title Search Results',
        onStart:function(options){
          $jquery("#mmgs_search_results").hide();
          $jquery("#mmgs_search_detail").show();
          $jquery(".musicNGamesSearch div.back").show();
          $jquery(".musicNGamesSearch div.next_previous").show();
        },
        onComplete:function(options){
          //$jquery('#contentResults.detail tr:odd').addClass('oddRow'); 
	        //$jquery('#trailerResults.detail tr:even').addClass('evenRow'); 
        }
    });
    $jquery('.modal_ajax_p').ajaxify({
        animateOut: { opacity: '0' },
        animateOutSpeed: 300,
        animateIn: { opacity: '1' },
        animateInSpeed: 300,
        title: 'DTS Title Search Results',
        onStart: function(options) {
            $jquery("#mmgs_search_results").show();
            $jquery("#mmgs_search_detail").hide();
            $jquery(".musicNGamesSearch div.back").hide();
            $jquery(".musicNGamesSearch div.next_previous").hide();
        },
        onComplete: function(options) {
            //$jquery('#contentResults.detail tr:odd').addClass('oddRow'); 
            //$jquery('#trailerResults.detail tr:even').addClass('evenRow'); 
        }
    });     
    
	/* Set up new defaults for main navigaton drop downs */
  $jquery('ul.sf-menu').superfish({
    pathClass:  'current', 
    pathLevels: 3,
    delay:800,
    animation:{opacity:'show'},
    speed:'fast',
    autoArrows:false,
    dropShadows:false
  });
   
});
/* END of Ready state */

/*ReadyState Enable Functions */
/* Funtion for MMG Flash enabled search page. 
  The search function is Flash with calls out to JS functions. 
  filterSearch(technology,provider,releaseDate,media) and  keywordSearch(keyword)
*/
function mmgSearch(){
    this.resultsCont = "#mmgs_search_results";
    this.detailCont = "#mmgs_search_detail";
    this.nextCont = ".musicNGamesSearch div.next_previous";
    this.backCont = ".musicNGamesSearch div.back";
    this.linkParams = "";
    /* DEFAULT SEARCH REQUEST go to: */
    /* This should be set to the real query location: it can be an absolute of fully qualified URL */
    this.searchURL = '/MMG/Search_Results.aspx';
}
mmgSearch.prototype  = {
  toggle_containers : function(){
    $jquery(this.nextCont).hide();
    $jquery(this.backCont).hide();
    $jquery(this.detailCont).empty();
    $jquery(this.detailCont).hide();
    $jquery(this.resultsCont).show();
  },
  initLinks : function(){
     $jquery('.modal_ajax').ajaxify({
        animateOut:{opacity:'0'},
        animateOutSpeed:300,
        animateIn:{opacity:'1'},
        animateInSpeed:300,
        title:'DTS Title Search Results',
        onStart:function(options){
          $jquery(MMGSEARCH.resultsCont).hide();
          $jquery(MMGSEARCH.detailCont).show();
          $jquery(MMGSEARCH.backCont).show();
          $jquery(MMGSEARCH.nextCont).show();
        },
        onComplete:function(options){ /* DO NOTHING */ }
    });
    $jquery('.modal_ajax_p').ajaxify({
        animateOut: { opacity: '0' },
        animateOutSpeed: 300,
        animateIn: { opacity: '1' },
        animateInSpeed: 300,
        title: 'DTS Title Search Results',
        onStart: function(options) {
            $jquery(MMGSEARCH.resultsCont).show();
            $jquery(MMGSEARCH.detailCont).hide();
            $jquery(MMGSEARCH.backCont).hide();
            $jquery(MMGSEARCH.nextCont).hide();
        },
        onComplete: function(options) { /* DO NOTHING */ }
    });     
  },
  getResults : function(){
    var a = arguments;
    //alert([ a[0],a[1],a[2],a[3] ]);
    /* Prepare all AJAX enable links */
    if(a.length == 4){
       jQuery.get(this.searchURL , {
                  at:a[0],
                  pr: a[1],
                  y: a[2],
                  f: a[3]
              },
              function(data,textStatus) {
                  $jquery("#mmgs_search_results").html(data);
                  MMGSEARCH.initLinks();
              },"html"
        );
    }
    else if(a.length == 1){
      jQuery.get(this.searchURL , {
                  q:a[0]
              },
              function(data,textStatus) {
                   $jquery("#mmgs_search_results").html(data);
                    MMGSEARCH.initLinks();
              },"html"
        );
    }
    else {
        jQuery.get(this.searchURL, {
            q: ''
        },
              function(data, textStatus) {
                  $jquery("#mmgs_search_results").html(data);
                  MMGSEARCH.initLinks();
              }, "html"
        );
    }
  }
};
MMGSEARCH = new mmgSearch();


/* *********************************************************
  Music, Movies and Games FLASH enable search functions.
  Basically these simply pass search params to an AJAXed search 
********************************************************** */
function keywordSearch(k){
    if(k == ""){
			MMGSEARCH.getResults();
		}
		else{
			MMGSEARCH.getResults(k);
		}
    if($jquery(MMGSEARCH.resultsCont).css("display")=='none'){
      MMGSEARCH.toggle_containers();
    }
}

function filterSearch(t,p,rd,m){
    MMGSEARCH.getResults(t,p,rd,m);
    if($jquery(MMGSEARCH.resultsCont).css("display")=='none'){
      MMGSEARCH.toggle_containers();
    }     
}
    

    




