
/**
 * Function used to load editor's pic video
 */
 
 
 
function rate(id,rating,type)
{
	var page = baseurl+'/ajax.php';
	$.post(page, 
	{ 	
		mode : 'rating',
		id:id,
		rating:rating,
		type:type
	},
	function(data)
	{
		if(!data)
			alert("No data");
		else
			$("#rating_container").html(data);
	},'text');
}


function sd_rate(id,rating,type, isRandom)
{
	if (isRandom === undefined ) {
		isRandom = false;
	}
	
	var page = baseurl+'/ajax.php';
	$.post(page, 
	{ 	
		mode : 'rating',
		id:id,
		rating:rating,
		type:type
	},
	function(data)
	{
		
		if(!data) {
			alert("No data");
		} else {
			
			
			
			var vids;
			var xc = 0;
			var compvid;
			
			$(".thumbUp").each(function(index) {
				
				if (typeof $(this).attr('alt') != 'undefined') {
					if (xc == 0) {
						vids = $(this).attr('alt');
						xc++;
					} else {
						vids = vids + ',' + $(this).attr('alt');
					}
				}
				
				
				vids = vids.replace('undefined', '');
				
				if ($(this).attr('rel') != 'selected') {
					//$(this).html('<img src="/images/thumbDown.png" />');
					
					$(this).css('background-color', '#000000');
					$(this).css('border', 'none');
					
					$(this).html('');
					$(this).css('cursor', 'hand');
					$(this).css('cursor', 'pointer');
					
					compvid = $(this).attr('alt');
					
					
					
					
					////SD get round from video
//					var cur_rnd = 0;
//					var page = baseurl+'/ajax.php';
//					$.post(page, 
//					{ 	
//						mode: 'get_round_from_video',
//						vid: id,
//					}, function(data){
//						
//						cur_rnd = parseInt(data);

						var cur_rnd = parseInt($('#rnd').val());
						//alert(cur_rnd);
						if (cur_rnd > 0) {
							
						
					  
						//SD down rate the video that lost
						var page = baseurl+'/ajax.php';
						$.post(page, 
						{ 	
							mode: 'down_rate',
							id: compvid
						}, function(data){
							//data
						});
						
						//SD up rate the video that won
						var page = baseurl+'/ajax.php';
						$.post(page, 
						{ 	
							mode: 'up_rate',
							id: id
						}, function(data){
							//blah
						});
						
					  
						//SD down rate the video that lost
						var page = baseurl+'/ajax.php';
						$.post(page, 
						{ 	
							mode: 'sd_winloss',
							vid: id,
							compid: compvid,
							rnd: cur_rnd
						}, function(data){
							
							
							if (data == 'Guest limit reached') {
								window.location = '/index.php?sd_msg=1';
							}
							
						});
					  
					  } //end if cur_rnd > 0 check
						
					//});
					
					
					
					
				} else {
					//$(this).css('border', '1px solid #0E3647');
					$(this).css('cursor', 'hand');
					$(this).css('cursor', 'pointer');
					
					$('.thumbUp').height(20);
					$('.thumbUp').css('padding-left', '5px');
					$('.thumbUp').css('font-size', '13px');
			
					
					$('.sd_vs_ico').css('z-index', 0);

					$(this).width(100);
					$(this).css('background-color', '#000000');
					$(this).css('border', 'none');
					$(this).html('<span class="thumbUp_txt" style="line-height: 22px !important; color: #2799C9 !important;">Winner !</span>');
					
					//$(this).next('.player_container_sd').css('border', '5px solid #0E3647');
					$(this).next('.player_container_sd').css('z-index', 4);
					
					//$(this).html('<img src="/images/thumbUp.png" style="vertical-align: middle !important;" /><span class="thumbUp_txt" style="line-height: 48px !important; color: #2799C9 !important;">Winner !</span>');
					
					$('#videxplain').hide();
					
					$('#next_txt').html('<div style="padding-top: 0px !important; padding-bottom: 0px !important;"><a id="next-link" style="text-decoration: none !important;display: block !important;font-size: 18px !important;font-weight: bold !important;color: #D6EEF5 !important; line-height: 30px !important;" href="' + window.location.href.replace("#", "") + '">Go to the next matchup <img src="/img/arrow_right_35.png" style="vertical-align: middle !important;"></a></div>');
					
					$('.sd_video_block').css('position', 'relative');
					$('.sd_video_block').css('top', '-13px');
					
					
				}
				
				
			});
			
		
				
	
			
		}
		
	},'text');
	
	return true;
}
