$('document').ready(function(){



//Videos Suggest Form
$('#suggest-video-form').submit(function(){

  var sLink  = $('#sugg-video-link').val();
  var nTrail = $('#sugg-video-trail').val();
  if (sLink!='http://www.youtube.com/watch?v=' && sLink!='') {
    $('#sugg-video-link').val('Sending.....');
    var sRet = $.get('/ajax/trails-videos.php',
                     {t:nTrail,v:sLink},
                      function(oData){
                        // if wwe get back the word true then add the link to the list of others
                        // but flag it as pending approval
                        if (oData!='false') {
                          var oDataTitle = oData.substring(0,40) ;
                          var aLink = sLink.split("v=")
                          var href = aLink[1]

                          var sNewLink = '<li><a href="'+sLink+'" class="dont-embed smaller" title="'+oData+'" rel="trailvideo" id="'+href+'">'+oDataTitle+'</a></li>' ;
                          $('#video-list ul').append(sNewLink) ;

                          //Change the Big Video to the Uploaded One
                          $('#'+href).flash(
                               { width: 580, height: 387 },
                               { version: 8 },
                               function(htmlOptions) {

                                                      htmlOptions.src = "http://youtube.com/v/" + href;
                                                      $('#mainvideo').css("display","block")
                                                      //now remove our
                                                      $('#mainvideo').empty();
                                                      $('#mainvideo').append($.fn.flash.transform(htmlOptions));
                               });

                        }else{
                          $.prompt('There was a problem, your video was not stored OR It may have been previously uploaded and is awaiting approval' ,{prefix:'tb',useiframe:true});
                        }
                        $('#sugg-video-link').val('http://www.youtube.com/watch?v=');

                      });
  }else {
    $.prompt('You didn\'t put in a valid YouTube link' ,{prefix:'tb',useiframe:true});
  }

  return false;
});



/** Trails Page Video Toggles **/
  $('a[rel="trailvideo"]').live("click",function(){
    var nWidth  = 580; //480;
    var nHeight = 387; //295;

    $(this).flash(
      { width: nWidth, height: nHeight },
      { version: 8 },
      function(htmlOptions) {
        aLink = $(this).attr('href').split("v=")
        href = aLink[1]
        htmlOptions.src = "http://youtube.com/v/" + href;
        $('#mainvideo').css("display","block")
        //now remove our
        $('#mainvideo').empty();
        $('#mainvideo').append($.fn.flash.transform(htmlOptions));
       }
     );
   return false;
  });


}); //end document.ready