$(function(){
	
	//sitenav border
	$('#sitenav li:first-child').css('border' , 'none');
	
	//form submit
	$('#price_bet .button2').click(function() {
		$('#price_bet').submit();
	});
	
	//slider functions
	$('.content_column2 .slider_arrows .slide_left').click(function(){
		$('#slider1').data('AnythingSlider').goBack();      // go Back one slide
	});
	$('.content_column2 .slider_arrows .slide_right').click(function(){
		$('#slider1').data('AnythingSlider').goForward();      // go forward one slide
	});
	$('.content_column3 .slider_arrows .slide_left').click(function(){
		$('#slider2').data('AnythingSlider').goBack();      // go Back one slide
	});
	$('.content_column3 .slider_arrows .slide_right').click(function(){
		$('#slider2').data('AnythingSlider').goForward();      // go forward one slide
	});
	
		
	//ie only
	if($.browser.msie && $.browser.version < 9){
		$('.button1, .button2')
			.append('<span class="lt"></span><span class="rt"></span><span class="lb"></span><span class="rb"></span>')
			.css('position' ,'relative');
	}

$('.white_box').find('div.product1').each(function(){
          id = $(this).attr('id');
        //timer
	newTime = new Date($('#timestamp_'+id).text());
	$('#time_'+id).countdown({
		until: newTime,
	      layout: $('#timerLayout_'+id).html(),
          /*timezone: +180,*/
          serverSync: hetkeAeg,
		format: 'dHMS'
	});
       });
       
 $('#content').find('div.product2').each(function(){
          id = $(this).attr('id');
        //timer
	newTime = new Date($('#timestamp_'+id).text());
	$('#time_'+id).countdown({
		until: newTime,
	      layout: $('#timerLayout_'+id).html(),
          /*timezone: +180,*/
          serverSync: hetkeAeg,
		format: 'dHMS'
	});
       });


       $('#slider2 li').find('div.sp_product').each(function(){
           id = $(this).attr('id');
        //timer
	newTime = new Date($('#timestamp_'+id).text());
	$('#time_'+id).countdown({
		until: newTime,
	    layout: $('#timerLayout_'+id).html(),
          /*timezone: +180,*/
          serverSync: hetkeAeg,
		format: 'dHMS'
	});
       });
       
       //timer
	newTime = new Date($('#timestamp').text());
	$('#time').countdown({
		until: newTime,
        onExpiry: showEnded,
	    layout: $('#timerLayout').html(),
          /*timezone: +180,*/
          serverSync: hetkeAeg,
		format: 'dHMS'
	});

     
	
	//textbox values
	/*swap_val = [];
	$(".input").each(function(i){
		swap_val[i] = $(this).val();
		$(this).focusin(function(){
			if ($(this).val() == swap_val[i]) {
				$(this).val("");
			}
		}).focusout(function(){
			if ($.trim($(this).val()) == "") {
				$(this).val(swap_val[i]);
			}
		});
		*/

});

function showEnded()
{
    $('#lisaautopakkuja').remove();
     $('.pr_content4 .red').text($('#loppenud_translate').text());
}

function hetkeAeg() { 
    var time = null; 
    $.ajax({url: 'moodulid/tootekataloog/user.AjaxCalls.php?tegevus=getAlates', 
        async: false, dataType: 'text', 
        success: function(text) { 
            time = new Date(text); 
        }, error: function(http, message, exc) { 
            time = new Date(); 
    }}); 
   return time; 
}

