﻿// JScript File
$(document).ready(function() {

    $('#quote-feed').each(function() {
    
        var $container = $(this);
        $container.empty();
        
        var fadeHeight = $container.height() / 4;
        for (var yPos = 0; yPos < fadeHeight; yPos +=2) {
            $('<div></div>').css({
                opacity: yPos / fadeHeight,
                top: $container.height() - fadeHeight + yPos
             }).addClass('fade-slice').appendTo($container);
        }
        
        
        $.get('Dynamic Content/Site/quotes.xml', function(data) {
        
            $(data).find('quote').each(function() {
            
               var $quoteXML = $(this);
               
               var $summary = $('<div></div>')
                    .addClass('headline')
                    .html('<em>' + $quoteXML.find('saying').text() + '</em>' + '<br />' + $quoteXML.find('coach').text());
            
               //$(container).append($(html));
               $('<div></div>')
                    .append($summary)
                    .appendTo($container);

            });
                   
            var currentQuote = 0, oldQuote = 0;
            var hiddenPosition = $container.height() + 10;
            $('div.headline').eq(currentQuote).css('top', 0);
            var QuoteCount = $('div.headline').length;
            var pause;
           
            var QuoteRotate = function() {
               currentQuote = (oldQuote + 1) % QuoteCount;
               $('div.headline').eq(oldQuote).animate(
                  {top: -hiddenPosition}, 'slow', function() {
                     $(this).css('top', hiddenPosition);
               });
            
               $('div.headline').eq(currentQuote).animate(
                   {top: 0}, 'slow', function() {
                      pause = setTimeout(QuoteRotate, 5000);
               });
                   
               oldQuote = currentQuote;
            };
           
            pause = setTimeout(QuoteRotate, 5000);
        });
    });
   
});

$(document).ready(function() {
			
	// Handles the addition of a new player in fixture details page.
	$('#btnNewPlayer').bind('click', function() {
        	    
        // Make the table visible.
        $("#ctl00_cphContent_tAddPlayers").css('visibility', 'visible');
        	    
		$("#ctl00_cphContent_tAddPlayers").each(function() {
				
		    var iRows = 0;
		    
		    var rows = $(this).find('tbody > tr').get();
		    $.each(rows, function(index, row) {
		        iRows += 1;
		    });
		
		    alert(iRows);
		
			var html =  "<tr>"
            html +=     "<td style='text-align:left;width:45%;'>"
            html +=     "<input style='background:white;' runat='server' type='text' id='txtForeName" + iRows + "' value='Forename' />"
            html +=     "<br />"
            html +=     "<input style='background:white;' runat='server' type='text' id='txtSurname" + iRows + "' value='Surname' />"
            html +=     "</td>"
            html +=     "<td style='width:5%;'><input type='checkbox' checked='checked' id='chkPlayed" + iRows + "' /></td>"
            html +=     "<td style='width:5%;'><select runat='server' id='selGoals" + iRows + "'>"
		    html +=     "<option selected='selected' value='0'>0</option>"
		    html +=     "<option value='1'>1</option>"
		    html +=     "<option value='2'>2</option>"
		    html +=	    "<option value='3'>3</option>"
		    html +=     "<option value='4'>4</option>"
		    html +=     "<option value='5'>5</option>"
		    html +=     "<option value='6'>6</option>"
		    html +=     "<option value='7'>7</option>"
		    html +=     "<option value='8'>8</option>"
		    html +=     "<option value='9'>9</option>"
		    html +=     "<option value='10'>10</option>"
		    html +=     "<option value='11'>11</option>"
		    html +=     "<option value='12'>12</option>"
		    html +=     "<option value='13'>13</option>"
		    html +=     "<option value='14'>14</option>"
		    html +=     "<option value='15'>15</option>"
		    html +=     "<option value='16'>16</option>"
		    html +=     "<option value='17'>17</option>"
		    html +=     "<option value='18'>18</option>"
		    html +=     "<option value='19'>19</option>"
		    html +=     "<option value='20'>20</option>"
		    html +=     "</select></td>"

		    html +=     "<td style='width:5%;'><select runat='server' id='selOwnGoals" + iRows + "'>"
		    html +=     "<option selected='selected' value='0'>0</option>"
		    html +=     "<option value='1'>1</option>"
		    html +=     "<option value='2'>2</option>"
		    html +=     "<option value='3'>3</option>"
		    html +=     "<option value='4'>4</option>"
		    html +=     "<option value='5'>5</option>"
		    html +=     "</select></td>"
		    html +=     "<td style='width:5%;'><input type='checkbox' runat='server' id='txtYCards" + iRows + "' /></td>"
		    html +=     "<td style='width:5%;'><input type='checkbox' runat='server' id='txtRCards" + iRows + "'/></td>"
		    html +=     "<td style='width:5%;'><input type='checkbox' runat='server' id='txtMOM" + iRows + "'/></td>"
            html +=     "</tr>"
     
            $('#ctl00_cphContent_tAddPlayers tr:last').after($(html));
        
     	});
   });
   
   $('#btnSave').bind('click', function() {
          $.ajax({
              type: "POST",
              url: "coaches-corner-fixture-details.aspx/saveFixtureDetails",
              contentType: "application/json; charset=utf-8",
              data: "{}",
              dataType: "json",
              success: AjaxSucceeded,
              error: AjaxFailed
          }); 
    });

    function AjaxSucceeded(result) {
        alert(result.d);
    }
    function AjaxFailed(result) {
       alert(result.status + ' ' + result.statusText);
    }  
   
});
