$(document).ready(function(){ 

	if(jQuery().datepicker) {
	   $(".datepick").datepicker({dateFormat: "yy-mm-dd"});
	}
	if(jQuery().clockpick) {
	  //$(".clockpick").clockpick();
	  $(".clockpick").clockpick({military:true,minutedivisions:12});
	}
	
	if(jQuery().tablesorter) {
		$(".sorttable table").tablesorter();
	}
	if(jQuery().validate) {
		$(".validate").validate();
	}	
	
	
	$("input:radio, input:checkbox").addClass('radio');
	$(".zebra tr:nth-child(odd)").css("background","#cccccc");
	
	
	$(".hovertable tr, .contentbody table tr").live("mouseenter",function(){
		$(this).addClass('hover');
	}).live("mouseleave",function(){
		$(this).removeClass('hover');
	});  
	
	$(".sup").hover(function(){
		$('.sub', this).show();
	},function(){
		$('.sub', this).hide('fast');
	});

$(".supper").live("mouseenter",function(){
	if($('.subbar', this).css("display")!='none')return false;
	$('.subbar').hide();
	$(".subbar", this).slideDown('fast');
}).live("mouseleave",function(){
	$(".subbar").slideUp('fast');
});  
  



$("#loading").live("ajaxSend", function(){
   $(this).show();
 }).live("ajaxComplete", function(){
   $(this).hide();
});
  

$(".button").live("click",function(){
	$(this).addClass("selected"); 
});

$(".confirm, .delete").live("click",function(){
	return confirm(' \n Before you click OK be sure you do right action! \n\n\n Note: This may take a some troubles \n\n\n');
});


  
$(".onhover").live("mouseenter",function(){
	$(".onhover").removeClass('hover');
	$(this).addClass('hover');
}).live("mouseleave",function(){
	$(".onhover").removeClass('hover');});


$(".closewin, .winclose").live("click",function(){
	$(this).closest('.window').fadeOut('fast'); return false;//	winclose(this);
});


///////////////////////////////////////////// form field default text from field title  
$(".def_text").bind("focus",function(){
	 if ($(this).val() == $(this).attr('title')){
            $(this).removeClass("defaultTextActive"); $(this).val("");
        }
}).bind("blur",function(){
	 if ($(this).val() == ""){
            $(this).addClass("defaultTextActive");
            $(this).val($(this).attr('title'));
        }
}); $(".def_text").blur();

$("form").bind("submit",function(){
	 if ($('.def_text', this).val() == $('.def_text', this).attr('title')){
            $('.def_text', this).val("");
        }
});
/////////////////////////////////////////////
  
$(".tdig").bind("focusout", function(){
	var vall = $(this).val(); vall = Math.round(vall);
	if(vall=='0'){vall=''; }
	
	if((vall>=1 && vall<=10) || vall==''){
		$(this).val(vall).removeClass('alertbrd');return false;
	}else{ $(this).val('').addClass('alertbrd'); }
});

$(".hdig").bind("focusout", function(){
	var vall = $(this).val(); vall = Math.round(vall);
	if(vall=='0'){vall=''; }
	
	if((vall>=1 && vall<=100) || vall==''){
		$(this).val(vall).removeClass('alertbrd');return false;
	}else{ $(this).val('').addClass('alertbrd'); }
});

$(".showtip").bind("mouseenter",function(){
	$(".tipcontent", this).fadeIn('fast');
}).bind("mouseleave",function(){
	$(".tipcontent", this).hide();
});

$(".ctextarea").bind("focus",function(){
	$(".ctextarea").removeClass('grovetextarea');
	$(this).addClass('grovetextarea');
}).bind("focusout",function(){
	$(".ctextarea").removeClass('grovetextarea');
});
	
	
$(".tabs li").bind("click",function(){
	//alert('ssss');
	var toid = $(this).attr('toid');
	var et = $("#"+toid).css("display");
	
	if(et=='block'){ return false; }
	$(".tabs li").removeClass('selected');
	$(".tabb").hide();
	
	$(this).addClass('selected');
	$("#"+toid).show();
	
}); showfirsttab();

	
$(".fastselect").live("mouseenter",function(){
	$('.'+$(this).attr('subclass'), this).show('fast');
}).live("mouseleave",function(){
	$('.'+$(this).attr('subclass'), this).hide('fast');
});	
	
$(".hvr").live("mouseenter",function(){
	if($(this).attr('hvr')){ $(this).css('background-image','url(images/'+$(this).attr('hvr')+'.png)') }
}).live("mouseleave",function(){
	if($(this).attr('nrml')){ $(this).css('background-image','url(images/'+$(this).attr('nrml')+'.png)') }
});
	
$(".fromto").live("click",function(){
	var frm = $(this).attr('from');
	var to = $(this).attr('to');
	fast_load(frm, to);
});



	
});


  
function tabber( id, clas ){
	$('.'+clas).hide();
	$('#'+id).show();
}
  

  function togling( id ){
    
	var et = $("#"+id).css("display");
	if(et=='none'){
		$('#'+id).slideDown('fast');
	}else{
		$('#'+id).slideUp('fast');
	}
  }
  
function sliding( id ){
$('#'+id).toggle(400);
}
  
function dinload( id, get, post){
	///id - loading container id
	if(id==''){return false;}
	var d = new Date();
	var dcontrol = d.getHours();
	
	$("#loading").bind("ajaxSend", function(){
	   $("#"+id).hide();
	}).bind("ajaxComplete", function(){
	   $("#"+id).show();
	});
	
	$("#"+id).load("dinload.php"+get,{val: post, control: dcontrol });

}
	
function show_first(id){
	$("#"+id).show();
}

/////////
function winclose(thiss){
	$(thiss).closest('.window').fadeOut('fast');
}


/////// calendar selector
function calendar_selector(get, post){
	var year = $('#phpcalendary').val();
	var month = $('#phpcalendarm').val();
	var post = year+month;
	dinload('phpcalendarcontainer', get, post);
//	alert(get);
	
}

function fast_load(from, to){
	var stat = $("#"+to+' #fromtoidenter').attr('current');
	if(stat==from)return false;
	
	$("#"+to).html('').hide();
	var tt = $('#'+from).html();
	$("#"+to).html(tt).show().prepend("<span id='fromtoidenter' class='hide' current='"+from+"'></span>");
}

function showfirsttab(){
	$('.tabs li').each(function(index){
	   var toid = $(this).attr('toid');
	   var et = $("#"+toid).css("display");
	   if(et=='block'){ return false; }
//	   alert(toid);
	});
	
	$('.tabs li').each(function(index){
	   var toid = $(this).attr('toid');
	   $(this).click(); return false;
	});
	return false;
}	

