jQuery.noConflict();
     
	 var def_search_text = "search bloops";
	 
     // Use jQuery via jQuery(...)
     jQuery(document).ready(function(){
		 
		setInterval ( "cursorAnimation()", 2000 );

		 // Assignindg Default value      
		jQuery("#keyword").attr('value',def_search_text);	   
		
		// On Mouse click
	    jQuery("#keyword").focus(function () {	
			var kvalue = jQuery(this).attr('value');
			if(kvalue==def_search_text){
				jQuery(this).attr('value',"");
				jQuery(this).focus();		
			}
		});
		
		// On Mouse out
	    jQuery("#keyword").blur(function () {	
			var kvalue = jQuery(this).attr('value');
			if(kvalue==""){
				jQuery(this).attr('value',def_search_text);		
			}
		});
		
		// Submiiting the Search Form		
		jQuery("#seachButton").click(function () {	
			var kvalue = jQuery("#keyword").attr('value');
			
			if(kvalue != def_search_text)	
				jQuery("#form1").submit();
			
		});
     });
	 
function cursorAnimation()
	{
	  jQuery("#keyword").animate(
	  {
		opacity: 0
	  }, "fast", "swing").animate(
	  {
		opacity: 1
	  }, "fast", "swing");
	}
	
	
  function limitChars(textid, limit, infodiv) {
	 var text = jQuery('#'+textid).val(); 
	 var textlength = text.length;
	 if(textlength > limit) {
	 	jQuery('#' + infodiv).html('You cannot write more then '+limit+' characters!');
	  	jQuery('#'+textid).val(text.substr(0,limit));
	  	return false;
	  }else{
	  	jQuery('#' + infodiv).html('You have '+ (limit - textlength) +' characters left.');
	  	return true;
	  }
  }
  
  /*####################################*/
	function FlagVideo(video_id) {
        // Username validation logic			
        var validateUsername = jQuery('.flagged');
		  validateUsername.html('<img src="/images/ajax-loader.gif" height="16" width="16" /> Please wait'); 
		  
		   jQuery.ajax({
					url: '/search/flagvideo/'+ video_id,					
					dataType: "json",					
					success: function (j) {
					  if(j.status == "1"){	
						validateUsername.html('<img src="/images/flag_1.png"/> Flagged');	
					  }else
					  	validateUsername.html('<span class="error">Some error occured!!</span>');		
					}
                 }); 
			//setTimeout(function(){validateUsername.fadeOut("slow");	}, 5000);
		return false;					 
    }
	
 
	/*####################################*/
	function checkUserName(usr) {
        // Username validation logic	
		if(usr.length<4) return 1;
        var validateUsername = jQuery('#validateUsername');
		  validateUsername.html('<img src="/images/ajax-loader.gif" height="16" width="16" /> checking availability...'); 
		  
		   jQuery.ajax({
					url: '/users/ajaxCheckUsername/'+ usr,
					data: 'username=' + usr,
					dataType: "json",
					type: 'post',
					success: function (j) {
						// put the 'msg' field from the $resp array from check_username (php code) in to the validation message
						validateUsername.html(j.msg);	
						document.getElementById('submit_button').disabled = j.ok;						
						
					}
                 }); 
    }
	
	/*###########  Custom Ajax Function #########################*/
	function callAjaxFunc(calltourl,msgDiv) {        
		
        var validateUsername = jQuery(msgDiv);
		  validateUsername.html('<img src="/images/ajax-loader.gif" height="16" width="16" />'); 
		  
		   jQuery.ajax({
					url: calltourl,					
					dataType: "json",
					type: 'get',
					success: function (j) {						
						validateUsername.html(j.msg);
						setTimeout(function(){
								  validateUsername.fadeOut("slow");
						}, 5000);
						
					}
                 }); 
    }
	
//// Automatich check the follow now links and upadte it	
	function checkFollows(userid,username){
		document.write('<div class="profile_follow"><img src="/images/ajax-loader.gif" height="16" width="16" /></div>');
		var htmlvar = '<a href="javascript:void(1)" onclick=\'callAjaxFunc("/users/followUser/'+username+'/'+userid+'",".profile_follow_msg"); this.style.display="none"; return false;\' class="followup">Follow Now</a>';
		jQuery.ajax({
					url: '/users/CheckfollowStatus/'+ userid,					
				 	dataType: "json", 
					type: 'get',
					success: function (j) {	
					   	jQuery('.profile_follow').html('');			
						if(j.status == 0){
							jQuery('.profile_follow').html(htmlvar);	
						}
						
						if(j.status == 1){
							jQuery('.profile_follow_msg').html("<span class='followup'>Your are following "+username+'</span>');	
						}
						
						if(j.status == 2)
								jQuery('.profile_follow_msg').html("<span class='followup'>Follow request had been already sent</span>");	
						
					}
                 }); 
	}
	
	
	
	
	// ########### Get Video Rating for adding the style  ############
	function getStarRating(videoid){
			
			jQuery.ajax({
				type: "GET",
				url: "/rating/getrate/"+videoid,
				data: "do=getrate",
				cache: false,
				async: false,
				dataType: "json",
				success: function(j) {
					// apply star rating to element
					jQuery("#current-rating-"+videoid).css({ width: "" + j.result + "%" });
					if(j.showvoting ==0){
						// remove #ratelinks element to prevent another rate
						jQuery("#ratelinks-"+videoid).remove();
					}
				},
				error: function(result) {
					alert("some error occured, please try again later");
				}
			});
		}
		
		// Load More logic
		function loadMore(userid) {
			
			//More Button
			jQuery('.morevideos').live("click",function() {
				var ID = jQuery('.loadmore').attr("id");
				//alert("/users/loadMoreBloops/"+userid+"/"+ID);
				if(ID !=''){
					
					jQuery("#morevideos-"+ID).html('<td></td><td colspan="2" align="center"><img src="/images/ajax-loader.gif" height="16" width="16" /></td>');
					
					jQuery.ajax({
						type: "GET",
						url: "/users/loadMoreBloops/"+userid+"/"+ID,
						data: "lastmsg="+ ID, 
						cache: false,
						success: function(html){
									jQuery("#updates").hide().append(html).fadeIn();									
									jQuery("#morevideos-"+ID).remove();
								}
					});
				}
				else
				{
				jQuery(".morevideos").remove();				
				}
				return false;
				
			});
		}
		
		
		// Load More video for search
		function loadMorevideo(keyword) {
			
			//More Button
			jQuery('.morevideos').live("click",function() {
				var ID = jQuery('.loadmore').attr("id"); //page ID
				//alert("/search/loadMorevideo/"+id+"/"+ID);
				if(ID !=''){
					
					jQuery("#morevideos-"+ID).html('<td></td><td colspan="2" align="center"><img src="/images/ajax-loader.gif" height="16" width="16" /></td>');
					
					jQuery.ajax({
						type: "GET",
						url: "/search/loadMorevideo/"+keyword+"/"+ID,
						data: "page="+ ID, 
						cache: false,
						success: function(html){									
									
									jQuery("#updates").hide().append(html).fadeIn('slow');
									
									jQuery("#morevideos-"+ID).remove();
								},
						error: function(result) {
								//alert("some error occured, please try again later");
							}		
					});
				}
				else
				{
				jQuery(".morevideos").remove();				
				}
				return false;
				
			});
		}


// Load More video for latest search
		function loadMorelatestvideo() {
			
			//More Button
			jQuery('.morevideos').live("click",function() {
				var ID = jQuery('.loadmore').attr("id"); //page ID
				//alert("/search/loadMorevideo/"+id+"/"+ID);
				if(ID !=''){
					
					jQuery("#morevideos-"+ID).html('<td></td><td colspan="2" align="center"><img src="/images/ajax-loader.gif" height="16" width="16" /></td>');
					
					jQuery.ajax({
						type: "GET",
						url: "/search/loadMorelatestvideo/"+ID,
						data: "page="+ ID, 
						cache: false,
						success: function(html){									
									jQuery("#updates").append(html);
									
									jQuery("#morevideos-"+ID).remove();
								},
						error: function(result) {
								//alert("some error occured, please try again later");
							}		
					});
				}
				else
				{
				jQuery(".morevideos").remove();				
				}
				return false;
				
			});
		}
		
		function loadMostViewed() {
			
			//More Button
			jQuery('.morevideos').live("click",function() {
				var ID = jQuery('.loadmore').attr("id"); //page ID
				//alert("/search/loadMorevideo/"+id+"/"+ID);
				if(ID !=''){
					
					jQuery("#morevideos-"+ID).html('<td></td><td colspan="2" align="center"><img src="/images/ajax-loader.gif" height="16" width="16" /></td>');
					
					jQuery.ajax({
						type: "GET",
						url: "/search/loadMorelatestvideo/"+ID+"/mv",
						data: "page="+ ID, 
						cache: false,
						success: function(html){									
									jQuery("#updates").append(html);
									
									jQuery("#morevideos-"+ID).remove();
								},
						error: function(result) {
								//alert("some error occured, please try again later");
							}		
					});
				}
				else
				{
				jQuery(".morevideos").remove();				
				}
				return false;
				
			});
		}
		
		
		
		// Load More video for toptweet search
		function loadMoretoptweet() {
			
			//More Button
			jQuery('.morevideos').live("click",function() {
				var ID = jQuery('.loadmore').attr("id"); //page ID
				//alert("/search/loadMorevideo/"+id+"/"+ID);
				if(ID !=''){
					
					jQuery("#morevideos-"+ID).html('<td></td><td colspan="2" align="center"><img src="/images/ajax-loader.gif" height="16" width="16" /></td>');
					
					jQuery.ajax({
						type: "GET",
						url: "/search/loadMoretoptweet/"+ID,
						data: "page="+ ID, 
						cache: false,
						success: function(html){									
									jQuery("#updates").hide().append(html).fadeIn('slow');
									
									jQuery("#morevideos-"+ID).remove();
								},
						error: function(result) {
								//alert("some error occured, please try again later");
							}		
					});
				}
				else
				{
				jQuery(".morevideos").remove();				
				}
				return false;
				
			});
		}
