$(function(){
	$("#datepicker").datepicker({
        inline: true, 
        showOtherMonths: true, 
        selectOtherMonths: true,
        firstDay: 1,
        beforeShowDay: function (date) {
            var dt = date.getFullYear() + '-' + (1 + date.getMonth()) + '-' + date.getDate();
            if (dt == '2010-2-22') return [true, ''];
            if (dt == '2010-3-16') return [true, ''];
            if (dt == '2010-4-15') return [true, ''];
            if (dt == '2010-5-20') return [true, ''];
            if (dt == '2010-6-17') return [true, ''];
            if (dt == '2010-7-15') return [true, ''];
            return [false,''];
        },
         onSelect: function(dateText, inst) {
             var m = inst.selectedMonth + 1;
             if (m < 10) m = '0' + '' + m;
             var url = inst.selectedYear + '-' + m;
             document.location.href = '?p=' + url;             
         }
    });
    
    var eventTime = (nextDateEventAuto) ? nextDateEventAuto : new Date(Date.UTC(2010, 6, 15, 16, 30, 0));//WARNING! GMT TIME and MONTH starts with 0
//    var eventTime = new Date(Date.UTC(2010, 6, 15, 16, 30, 0));//WARNING! GMT TIME and MONTH starts with 0
    
    window.setInterval(function() {
        var now = new Date();
        
        var diff = Math.round((eventTime.getTime() - now.getTime()) / 1000);
        
        if (diff <= 0) {
            //event has been started
//            $('#timeleft').hide();
            $('#timeleft').show();

            $('#tl_days').html('00');
            $('#tl_hours').html('00');
            $('#tl_mins').html('00');
            $('#tl_secs').html('00');
            
        } else {
            $('#timeleft').show();
            
            var days = Math.floor(diff / 86400);
            diff -= days*86400;
            
            var hours = Math.floor(diff / 3600);
            diff -= hours*3600;
            
            var mins = Math.floor(diff / 60);
            diff -= mins*60;

            var secs = Math.floor(diff);
            
            $('#tl_days').html(days);
            $('#tl_hours').html(hours);
            $('#tl_mins').html(mins);
            $('#tl_secs').html(secs);
        }
        
    }, 1000);
})

function refreshCompetitionPage(m,surr) {
	$.get('templates/competitionTable.ajax.php?M='+m+'&CURR='+surr+'&C='+Date(), function(data) {
		if(data != '') {
		  $('#forecastTable').html(data);
		  //alert('Load was performed.');
		}
	});
}

function refreshIqPage(m,surr) {
	$.get('templates/iq_competitionTable.ajax.php?M='+m+'&C='+Date(), function(data) {
		  $('#iqTable').html(data);
		  //alert('Load was performed.');
	});
}

var fistRun = true;
function tunePosition(pos) {
	if(!fistRun) {
		return;
	}

	if(pos > 250) {
		document.getElementById('forecastTable').scrollTop = (pos - 250);   
		yT = pos - 250;
	}
	fistRun = false;
		// alert(pos)
}


///  BUTTONS SCROLL Functions
			var scrolling = 0;	// Controls whether the layer is scrolling or not
			var yT = 5;			// Pixel position the top of the scrolling layer should be set to
			var lT = 5;			// Initial position for the top of the layer
			var yI = 3;		// Increment that the scrolling layer should move at
			var yH = 0;			// Hight of scrollling layer
			var object = null;	// Stores the generic DOM for the scrolling layer to access style properties

		function startScroll(objectID,direction) {
			object = document.getElementById(objectID);
			scrolling = 1;
			scroll(direction);
		}

		function scroll(direction) {
			if (scrolling == 1) {
				if(direction == 1)
				{
					yT = yT + yI;
					object.scrollTop = yT;
					if(object.scrollTop < yT)
					{
					  yT = object.scrollTop;
					  scolling = 0;
					}
			  }
				else
				{
					yT -= yI;
					object.scrollTop = yT;
					if(object.scrollTop > yT)
					{
					  yT = object.scrollTop;
					  scolling = 0;
					}
				}
				code2run = 'scroll('+ direction + ')';
				setTimeout(code2run,0);
			}
			return false;
		}

		function stopScroll() {
			scrolling = 0;
			return false;
		}

		function URB(objectID) {
			var object = document.getElementById(objectID);
			yH = 999999;
			object.scrollTop = yH;
		}

		function URT(objectID,frameName) {
			var object = document.getElementById(objectID);
			object.scrollTop = lT;
		}
/*
 * 
* 		<span onmousedown="startScroll('scrollArea',1); return false;" onmouseup="stopScroll();" onmouseover="window.status='Up'; return true;" href="#" onfocus="if(this.blur)this.blur();">
			<img id="up" src="up_off.gif" height="25" width="25" border="0" vspace="5" />
		</span><br />
		<span onmousedown="URT('scrollArea'); return false;" onmouseover="window.status='Top'; return true;" href="#" onfocus="if(this.blur)this.blur();">
			<img id="top" src="top_off.gif" height="25" width="25" border="0" vspace="5" />
		</span><br /><br />
		<span onmousedown="URB('scrollArea'); return false;" onmouseover="window.status='Bottom'; return true;" href="#" onfocus="if(this.blur)this.blur();">
			<img id="bottom" src="bottom_off.gif" height="25" width="25" border="0" vspace="5" />
		</span><br />
		<span onmousedown="startScroll('scrollArea',0); return false;" onmouseup="stopScroll();" onmouseover="window.status='Down'; return true;" href="#" onfocus="if(this.blur)this.blur();">
			<img id="down" src="down_off.gif" height="25" width="25" border="0" vspace="5" />
		</span>

 * 
 */		
		
// END OF SCROLL Functions




