/* Doritos - Main Javascript
=============================================================================================*/

var DORITOS = {};

$(document).ready( function()
{
   new DORITOS.buttons();
  
   $('#phase2out, #phase3out, #globeout, #ratingout').tooltip({ 
    track: true,
    delay: 0, 
    showURL: false, 
    bodyHandler: function() { 
       return $($(this).attr("tooltip")).html();
    } 
    });
});



DORITOS.buttons = function( active, filter )
{
   var that = this;
   active = active||false;
   filter = filter||"img, input:image";
   
   $(filter).each(function(i, val)
   {
      if( $(val).attr('src').match(/_u/) != null )
      {
         $('<img>').attr( 'src', that.over( $(val).attr('src') ) );
         
         $(val).hover (
            function() { $(this).attr( 'src', that.over($(this).attr('src')) ); },
            function() { $(this).attr( 'src', that.reset($(this).attr('src')) ); }
         );
         
         if( active )
         {
            $('<img>').attr( 'src', that.active( $(val).attr('src') ) );
            
            $(val).mousedown (
               function() { $(this).attr( 'src', that.active($(this).attr('src')) ); }
            ).mouseup (
               function() { $(this).attr( 'src', that.over($(this).attr('src')) ); }
            );
         }
      }
   });
};

DORITOS.buttons.prototype =
{
   over:   function( src ) { return src.replace(/(_a\.|_u\.)/, '_o.'); },
   active: function( src ) { return src.replace(/(_o\.|_u\.)/, '_a.'); },
   reset:  function( src ) { return src.replace(/(_o\.|_a\.)/, '_u.'); }
};

DORITOS.pager = 
{
	change: function( that, ajax_url )
	{
		$.ajax({
			type: "GET",
			url: ajax_url,
			dataType: "script",
			success: function( response )
			{
				$('#videonav .inside').html( response );
				$('.pager .num').removeClass('selected');
				$(that).addClass('selected');
			}
		});
		
		return false;
	}
};

DORITOS.uploadvideo = 
{
	hideall: function()
	{
        scroll(0,0);

        DORITOS.uploadvideo.toggle('holder');
        DORITOS.uploadvideo.toggle('videoreg');
    },
    
    toggle: function(id)
    {
        var details = document.getElementById(id).style;

        if(details.visibility == "hidden")
        {
          details.visibility = "visible";
          details.display = "";
        }
        else
        {
          details.visibility = "hidden";
          details.display = "none";
        }
    }

};



