// JavaScript Document
$(document).ready(function() {
	$("#menu-member").mouseover(function() {
        $(this).addClass('selected');
        $('.submenu1').css('left',$(this).offset().left);
        $('.submenu1').css('top',$(this).offset().top+32);
        setTimeout(function(){
             $('.submenu1').slideDown('fast');
         },200);
      })
	  
	 $('.submenu1').mouseover(function(){
         $("#menu-member").addClass('selected');
     });
	 
	 $("#menu-contacts").mouseover(function() {
        $(this).addClass('selected');
        $('.submenu2').css('left',$(this).offset().left);
        $('.submenu2').css('top',$(this).offset().top+32);
        setTimeout(function(){
             $('.submenu2').slideDown('fast');
         },200);
      })
	  
	 $('.submenu2').mouseover(function(){
         $("#menu-contacts").addClass('selected');
     }); 
   
    $('#main').mouseover(function(){
         $("#menu-member,#menu-contacts").removeClass('selected');
         $('.submenu1,.submenu2').slideUp('fast');
     }); 
	 
	$('#branchRight').click(function(){
		onClickRight();
	});
	
	$('#branchLeft').click(function(){
		onClickLeft();
	}); 
	
	$('#branchUp').click(function(){
		onClickUp();
	});
	
	$('#branchDown').click(function(){
		onClickDown();
	});
	
	$('#treatment_menu01').mouseover(function(){
		 $('#subtreatmentmenu01').slideDown('slow');
	});
	
	$('#subtreatmentmenu01 a').mouseover(function(){
		 $('#subtreatmentmenu01 li').removeClass('selected');
	});
	
	$('#subproduct_menu01 a').mouseover(function(){
		 $('#subproduct_menu01 li').removeClass('selected');
	});
	
	/*$('#treatment_menu02').mouseover(function(){
		 $('#subtreatmentmenu02').slideDown('slow');
	});*/
	
});

function onClickLeft(){
	if (thisBranch >1){
	$('#branchLeft').unbind('click');
	$('#showBranchAnimate').animate({left:'+=198'},900,
	function(){
		thisBranch-=1;
		allBranch+=1;  
		$('#branchLeft').bind('click',onClickLeft,false);
	},false);
	}else{
		$('#branchLeft').unbind('click');
		$('#showBranchAnimate').animate({left:'+=10'},300).animate({left:'-=10'},300,function(){ 
		$('#branchLeft').bind('click',onClickLeft,false);
	},false);
	}
}

function onClickRight(){
	if (allBranch >4){
	$('#branchRight').unbind('click');
	$('#showBranchAnimate').animate({left:'-=198'},900,
	function(){ 
		thisBranch+=1; 
		allBranch-=1; 
		$('#branchRight').bind('click',onClickRight,false);
	},false);
	}else{
		$('#branchRight').unbind('click');
		$('#showBranchAnimate').animate({left:'-=10'},300).animate({left:'+=10'},300,
		function(){ 
		$('#branchRight').bind('click',onClickRight,false);
	},false);
	}
}

function onClickUp(){
	if (thisSubBranch >1){
	$('#branchUp').unbind('click');
	$('#showBranchSubAnimate').animate({top:'+=95'},900,
	function(){
		thisSubBranch-=2;
		allSubBranch+=2;  
		$('#branchUp').bind('click',onClickUp,false);
	},false);
	}else{
		$('#branchUp').unbind('click');
		$('#showBranchSubAnimate').animate({top:'+=10'},300).animate({top:'-=10'},300,function(){ 
		$('#branchUp').bind('click',onClickUp,false);
	},false);
	}
}

function onClickDown(){
	if (allSubBranch >8){
	$('#branchDown').unbind('click');
	$('#showBranchSubAnimate').animate({top:'-=95'},900,
	function(){ 
		thisSubBranch+=2; 
		allSubBranch-=2; 
		$('#branchDown').bind('click',onClickDown,false);
	},false);
	}else{
		$('#branchDown').unbind('click');
		$('#showBranchSubAnimate').animate({top:'-=10'},300).animate({top:'+=10'},300,
		function(){ 
		$('#branchDown').bind('click',onClickDown,false);
	},false);
	}
}

function checklogin(){
	user = $("#username").val();
	pass = $("#password").val();

	//if(user=='' || pass==''){
	//	return ;
	//}
	jQuery.get('check_login.php?user='+user+'&pass='+pass , function(data) {
 		if(data.indexOf('OK')!=-1){
 			window.location.reload();
 		}else{
			alert(data);
 			//$("#loginbox-error-text").html(data)
 			//$("#loginbox-error").show();
 			return;
 		}

 	}); 
	
}


