$(document).ready(function(){
  $("#accordion").accordion({collapsible:true,active:false,animated:false});	

  $.each($(".borderedTable tr"),function(i){
	   if(i % 2==0 && $(this).children("th").length <= 0){
		  $(this).children().css({background:'#f5fff6'});
	   }else if($(this).children("th").length <= 0){
		  $(this).children().css({background:'#ebffe8'});		
	   }
  });

	$(".help").live('mouseover',function(){
		  $("#tooltip").html($(this).attr('title'));
		  $(this).removeAttr('title');
		  $("#tooltip").css({position:'absolute',left:$(this).offset().left+20+'px',top:$(this).offset().top-25+'px'});
		  $("#tooltip").css({display:'block'});
	});
	
	$(".help").live('mouseout',function(){
		$(this).attr('title',$("#tooltip").html());
		$("#tooltip").css({display:'none'});
	});

	
	    var datepickerOpts={
		  dateFormat:$.datepicker.W3C,
		  showOtherMonths:true,
		  changeMonth: true,
		  changeYear: true,
		  yearRange: "-2:+2"
	    };
	
	    $(".expiryDate").datepicker(datepickerOpts);

	  $('#selectAll').live('click',function(){
	    if($(this).is(':checked')){
	      $('table :checkbox').attr('checked','checked');
	      $('table :checkbox').parent('td').parent('tr').addClass('tableRowHighlight');
	    }else{
	      $('table :checkbox').attr('checked','');
	      $('table :checkbox').parent('td').parent('tr').removeClass('tableRowHighlight');	
		}
	  });	  
	
	$('.btn').each(function(){
	var b = $(this);
	var href=b.attr('href');
	var tt = b.text() || b.val();
	if ($(':submit,:button',this)) {
	b = $('<a>').insertAfter(this). addClass(this.className).attr('id',this.id);
	$(this).remove();
	}

   if(href!=""){
	  b.attr("href",href);
   }

	b.text('').css({cursor:'pointer'}). prepend('<i></i>').append($('<span>').
	text(tt).append('<i></i><span></span>'));

	});
	

	$('.submit').live('click',function(){
		 $(this).parents('.containerForm').submit();
	});  
	
	$("#refreshCode").live('click',function(){
	   $.post('ajax/refreshCode.php',function(data){
		  $("#captchaCode").html('<img src="captcha.php?c='+Math.round(Math.random()*1000000)+'" id="captchaImg" style="border:1px solid #999;vertical-align:middle;"/>');
	  });
	
   });
   

	 $(".menu > li").mouseover(function(){
	   $(this).css({background:'#dbffd6'});
    }).mouseout(function(){
	$(this).css({background:'url("images/site/page_background.png")'});
    });

    function idleVisit(){
	   $.post('ajax/idle.php',function(data){
		   var visitTimer=setTimeout(function(){
		      idleVisit();
	      },30000);
	  });
    }

     var visitTimer=setTimeout(function(){
	     idleVisit();
     },30000);
});
