jQuery.easing.easeOutQuart = function (x, t, b, c, d) {
   return -c * ((t=t/d-1)*t*t*t - 1) + b;
};

jQuery(document).ready(function(){
   var locat = self.location.href.split('#');
   if(locat[1]){
      //alert(locat[1]);
      if(locat[1]=='liveVidComment'){
         jQuery('#latestNewsContainer').animate({opacity:0},function(){
            jQuery('#latestNewsContainer').css({display:'none'});
            jQuery('#vidCommentsWrapper').slideDown(function(){
                jQuery('.content_area_read_video.liveVidJ').slideUp();
            });
         });
      }
   }


   jQuery('.liveVidJ object').attr({width:615, height:385});
   jQuery('.liveVidJ embed').attr({width:615, height:385});


   jQuery('#latestNewsContainer .pContent p object').attr({width:360, height:225})
   jQuery('#latestNewsContainer .pContent p object embed').attr({width:360, height:225})
   
   jQuery('.imgCont a').fancybox();
   
   jQuery('[name=yourCommentInput]').TextAreaExpander();
   jQuery('[name=yourCommentInput]').css({minHeight:'70px', padding:'3px 5px'});
   jQuery('#theLoginBox .justBg').css({opacity:0.15});
   
   jQuery('#theLoginBox [name=usrName]').focus(function(){
      if(jQuery(this).val()=='email'){
         jQuery(this).val('');
      }
   });
   jQuery('#theLoginBox [name=usrName]').focusout(function(){
      if(jQuery(this).val()==''){
         jQuery(this).val('email');
      }
   });
   jQuery('#theLoginBox [name=passwrd]').focus(function(){
      if(jQuery(this).val()=='password'){
         jQuery(this).val('');
      }
   });
   jQuery('#theLoginBox [name=passwrd]').focusout(function(){
      if(jQuery(this).val()=='' || jQuery(this).val()==' '){
         jQuery(this).val('password');
      }
   });
   
   
   //latest video and live video toggle=====================================================================DISABLED
   jQuery('#tabLateVideo').css({width:'425px'});
   /*
   jQuery('.letestVidJ').css({display:'none'});
   jQuery('#tabLiveVideo').click(function(){
      jQuery('.letestVidJ').css({display:'none'});
      jQuery('.liveVidJ').css({display:'block'});
      jQuery('.tabbedTransform').removeClass('active');
      jQuery(this).addClass('active');
   });
   jQuery('#tabLateVideo').click(function(){      
      jQuery('.liveVidJ').css({display:'none'});
      jQuery('.letestVidJ').css({display:'block'});
      jQuery('.tabbedTransform').removeClass('active');
      jQuery(this).addClass('active');
      if(jQuery('#latestNewsContainer').css('display')=='none'){
         commentAreaClose();
      };
   });
   */
   jQuery('h2.comments .closeThisButton').click(function(){
      commentAreaClose();
   });
   
   jQuery('#vidCommentsWrapper').css({display:'none'});
   jQuery('.liveVidJ a').click(function(){
      jQuery('#latestNewsContainer').animate({opacity:0},function(){
         jQuery('#latestNewsContainer').css({display:'none'});
         jQuery('#vidCommentsWrapper').slideDown(function(){
             jQuery('.content_area_read_video.liveVidJ').slideUp();
         });
      });
   });
   jQuery('#vidCommentsWrapper [name=backToFeed]').click(function(){
      commentAreaClose();
   });
   
   jQuery('.hiddenLatestVids object').attr({width:615, height:385});
   jQuery('.hiddenLatestVids embed').attr({width:615, height:385});
   
   var nItem   = jQuery("#imageSlider ul").find("li").length;
   var ulWidth = ( nItem*130 ) - 0;
   jQuery('#imageSlider ul').css({width:ulWidth+'px'});
   
   jQuery("#imageSlider li:first").attr("id","first");
   jQuery("#imageSlider li:eq("+(nItem-3)+")").attr("id","last");
   jQuery('span#justPref').css({display:'none'});
   
   jQuery('#imageSlider').serialScroll({
      items:'li', 
      prev:'span#justPref',
      next:'span#justNext',
      offset:0, //when scrolling to photo, stop 230 before reaching it (from the left)
      start:0, //as we are centering it, start at the 2nd
      duration:800,
      force:true,
      stop:true,
      lock:false,
      cycle:false, //don't pull back once you reach the end
      jump: false, //click on the images to scroll to them
      step:1,
      easing:'easeOutQuart', //use this easing equation for a funny effect
      onBefore:function(e, elem, $pane, $items, pos){
         jQuery('span#justPref').css({display:'block'});
         jQuery('span#justPref').animate({opacity:1});
         
         jQuery('span#justNext').css({display:'block'});
         jQuery('span#justNext').animate({opacity:1});
         
         target = jQuery(elem).attr("id");
         if(target=='first'){
            jQuery('span#justPref').animate({opacity:0},function(){
               jQuery('span#justPref').css({display:'none'});
            });
         }else if(target=='last'){
            jQuery('span#justNext').animate({opacity:0},function(){
               jQuery('span#justNext').css({display:'none'});
            });
         }
      }
   });   

   jQuery("#liveVideoCommentForm").validate();
   jQuery.each(jQuery.validator.messages, function(i) {
      jQuery.validator.messages[i] = "&nbsp;";
   });
   
});

function showLatestVid(target){
   jQuery('#latestVideoContID .hiddenLatestVids').css({display:'none'});
   jQuery('#latestVideoContID #latestVidHid-'+target).css({display:'block'});
}

function commentAreaClose(){
   jQuery('#vidCommentsWrapper').slideUp(function(){
      jQuery('#latestNewsContainer').css({display:'block',opacity:0}).animate({opacity:1});
      if( jQuery('.liveVidJ').css('display')!='none' ){
         jQuery('.content_area_read_video.liveVidJ').slideDown();
      }
   });
}

function trim12 (str) {
	var	str = str.replace(/^\s\s*/, ''),
		ws = /\s/,
		i = str.length;
	while (ws.test(str.charAt(--i)));
	return str.slice(0, i + 1);
}

