$(function() {
	
	//menu		
		$('#sitenav li.active').corner('cc:#d6e6fc top 5px');
		
		$('#sitenav li').hover(function()
		{
			$(this).corner('cc:#d6e6fc top 5px');
		});
	
	//lang values
	$.username = "Kasutajanimi";
	$.password = "Parool";
	
	//login text change
	$("#login_user")
    .val($.username)
    .focus(function(){
        if ($(this).val() == $.username) {
            $(this).val("");
        }
    })
    .blur(function(){
        if ($(this).val() == "") {
            $(this).val($.username);
        }
    });
	//password text change
	$("#login_pass")
    .val($.password)
    .focus(function(){
        if ($(this).val() == $.password) {
            $(this).val("");
        }
    })
    .blur(function(){
        if ($(this).val() == "") {
            $(this).val($.password);
        }
    });
		
	//corners for ie
	/*if ( $.browser.msie ) {
		$('.ie-corners-one, .ie-corners-two').append('<div class="lt"></div><div class="rt"></div><div class="lb"></div><div class="rb"></div>');
	}
	*/
	//sitenav last corner
	/*$('#sitenav li:last-child a').css({'border' : 'none'});*/
	$('#countdown').countdown({until: serverTime(), compact: true, 
    layout: '{hnn}{sep}{mnn}{sep}{snn}',timezone: +180,serverSync: hetkeAeg,onExpiry: prepCounter});
	
});

function prepCounter() {
	var lopp = serverTime();
	$('#countdown').countdown('change', {until: lopp,serverSync: hetkeAeg});
	transDate();
}

function transDate() { 
    var time = null; 
    $.ajax({url: 'moodulid/tootekataloog/user.AjaxCalls.php?tegevus=getTransDate', 
        async: false, dataType: 'text', 
        success: function(text) { 
            $("#countdown_kuupaev").html(text);
        }, error: function(http, message, exc) { 
            time = new Date(); 
    }}); 
    return time; 
}
function serverTime() { 
    var time = null; 
    $.ajax({url: 'moodulid/tootekataloog/user.AjaxCalls.php?tegevus=getKuni', 
        async: false, dataType: 'text', 
        success: function(text) { 
            time = new Date(text);
        }, error: function(http, message, exc) { 
            time = new Date(); 
    }}); 
    return time; 
}
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; 
}
