var ah=0;
var objName='';
/****** INITIALIZATION of Overlay Object to Center Middle ******/
function initCenterMiddle(){
	jQuery.event.add(window, "load", centerMiddle);
	jQuery.event.add(window, "resize", centerMiddle);
	jQuery.event.add(window, "scroll", centerMiddle);
}
function centerMiddle(){
	var visibleHeight = document.documentElement.clientHeight;
	var hiddenHeight = $(document).scrollTop();
	var h = hiddenHeight + (visibleHeight / 2);
	var nh = h - (ah / 2);
	$(objName).css('margin-top',nh);
}

/****** INITIALIZATION of Home Banner ******/
function initHomeBanner(){
			$('#slides').slides({
				width: 920,
				height: 401,
				preload: true,
				preloadImage: '/media/images/loading.gif',
				play: 4000,
				pause: 2500,
				hoverPause: true
			});
			
}
/****** INITIALIZATION of Tooltip ******/
function initTooltip(){
	//toolbox 1
	$('.popularpicks_img1').mouseenter(function(){
			$('.tooltip_box1').show();
			$('.bg_tooltip_tail1').show();
			$('.tooltip_btn1').show();
	});
	$('.popularpicks_img1').mouseleave(function(){
			$('.tooltip_box1').hide();
			$('.bg_tooltip_tail1').hide();
			$('.tooltip_btn1').hide();									
	});
	$('.tooltip_box1').mouseenter(function(){
		
			$('.tooltip_box1').show();
			$('.bg_tooltip_tail1').show();
			$('.tooltip_btn1').show();									
	});
	$('.tooltip_box1').mouseleave(function(){
			$('.tooltip_box1').hide();
			$('.bg_tooltip_tail1').hide();
			$('.tooltip_btn1').hide();									
	});
	$('.bg_tooltip_tail1').mouseenter(function(){
		
			$('.tooltip_box1').show();
			$('.bg_tooltip_tail1').show();
			$('.tooltip_btn1').show();									
	});
	$('.bg_tooltip_tail1').mouseleave(function(){
			$('.tooltip_box1').hide();
			$('.bg_tooltip_tail1').hide();
			$('.tooltip_btn1').hide();									
	});
	$('.tooltip_btn1').mouseenter(function(){
		
			$('.tooltip_box1').show();
			$('.bg_tooltip_tail1').show();
			$('.tooltip_btn1').show();									
	});
	$('.tooltip_btn1').mouseleave(function(){
			$('.tooltip_box1').hide();
			$('.bg_tooltip_tail1').hide();
			$('.tooltip_btn1').hide();									
	});
	
	//toolbox 2
	$('.popularpicks_img2').mouseenter(function(){
			$('.tooltip_box2').show();
			$('.bg_tooltip_tail2').show();
			$('.tooltip_btn2').show();
	});
	$('.popularpicks_img2').mouseleave(function(){
			$('.tooltip_box2').hide();
			$('.bg_tooltip_tail2').hide();
			$('.tooltip_btn2').hide();									
	});
	$('.tooltip_box2').mouseenter(function(){
		
			$('.tooltip_box2').show();
			$('.bg_tooltip_tail2').show();
			$('.tooltip_btn2').show();									
	});
	$('.tooltip_box2').mouseleave(function(){
			$('.tooltip_box2').hide();
			$('.bg_tooltip_tail2').hide();
			$('.tooltip_btn2').hide();									
	});
	$('.bg_tooltip_tail2').mouseenter(function(){
		
			$('.tooltip_box2').show();
			$('.bg_tooltip_tail2').show();
			$('.tooltip_btn2').show();									
	});
	$('.bg_tooltip_tail2').mouseleave(function(){
			$('.tooltip_box2').hide();
			$('.bg_tooltip_tail2').hide();
			$('.tooltip_btn2').hide();									
	});
	$('.tooltip_btn2').mouseenter(function(){
		
			$('.tooltip_box2').show();
			$('.bg_tooltip_tail2').show();
			$('.tooltip_btn2').show();									
	});
	$('.tooltip_btn2').mouseleave(function(){
			$('.tooltip_box2').hide();
			$('.bg_tooltip_tail2').hide();
			$('.tooltip_btn2').hide();									
	});
	
	//toolbox 3
	$('.popularpicks_img3').mouseenter(function(){
			$('.tooltip_box3').show();
			$('.bg_tooltip_tail3').show();
			$('.tooltip_btn3').show();
	});
	$('.popularpicks_img3').mouseleave(function(){
			$('.tooltip_box3').hide();
			$('.bg_tooltip_tail3').hide();
			$('.tooltip_btn3').hide();									
	});
	$('.tooltip_box3').mouseenter(function(){
		
			$('.tooltip_box3').show();
			$('.bg_tooltip_tail3').show();
			$('.tooltip_btn3').show();									
	});
	$('.tooltip_box3').mouseleave(function(){
			$('.tooltip_box3').hide();
			$('.bg_tooltip_tail3').hide();
			$('.tooltip_btn3').hide();									
	});
	$('.bg_tooltip_tail3').mouseenter(function(){
		
			$('.tooltip_box3').show();
			$('.bg_tooltip_tail3').show();
			$('.tooltip_btn3').show();									
	});
	$('.bg_tooltip_tail3').mouseleave(function(){
			$('.tooltip_box3').hide();
			$('.bg_tooltip_tail3').hide();
			$('.tooltip_btn3').hide();									
	});
	$('.tooltip_btn3').mouseenter(function(){
		
			$('.tooltip_box3').show();
			$('.bg_tooltip_tail3').show();
			$('.tooltip_btn3').show();									
	});
	$('.tooltip_btn3').mouseleave(function(){
			$('.tooltip_box3').hide();
			$('.bg_tooltip_tail3').hide();
			$('.tooltip_btn3').hide();									
	});
	
	//toolbox 4
	$('.popularpicks_img4').mouseenter(function(){
			$('.tooltip_box4').show();
			$('.bg_tooltip_tail4').show();
			$('.tooltip_btn4').show();
	});
	$('.popularpicks_img4').mouseleave(function(){
			$('.tooltip_box4').hide();
			$('.bg_tooltip_tail4').hide();
			$('.tooltip_btn4').hide();									
	});
	$('.tooltip_box4').mouseenter(function(){
		
			$('.tooltip_box4').show();
			$('.bg_tooltip_tail4').show();
			$('.tooltip_btn4').show();									
	});
	$('.tooltip_box4').mouseleave(function(){
			$('.tooltip_box4').hide();
			$('.bg_tooltip_tail4').hide();
			$('.tooltip_btn4').hide();									
	});
	$('.bg_tooltip_tail4').mouseenter(function(){
		
			$('.tooltip_box4').show();
			$('.bg_tooltip_tail4').show();
			$('.tooltip_btn4').show();									
	});
	$('.bg_tooltip_tail4').mouseleave(function(){
			$('.tooltip_box4').hide();
			$('.bg_tooltip_tail4').hide();
			$('.tooltip_btn4').hide();									
	});
	$('.tooltip_btn4').mouseenter(function(){
		
			$('.tooltip_box4').show();
			$('.bg_tooltip_tail4').show();
			$('.tooltip_btn4').show();									
	});
	$('.tooltip_btn4').mouseleave(function(){
			$('.tooltip_box4').hide();
			$('.bg_tooltip_tail4').hide();
			$('.tooltip_btn4').hide();									
	});
	
}

/***** General Overlay ******/
function showOverlay(overlay,obj){ //pass in the overlay class name and the obj class on top
		$(overlay).css('height',document.documentElement.scrollHeight);
		$(overlay).fadeIn("slow",function() {
			ah = $(obj).height();
			objName = obj;
			centerMiddle();
			$(objName).show();
			/*$('body').css('overflow','hidden');*/
			initCenterMiddle();
		});
	}                                             

function hideOverlay(overlay,obj){
		$(obj).hide();
		$(overlay).fadeOut("slow");
		/*$('body').css('overflow','');*/
	}

/***** General change object container on overlay ******/
function showNextObj(obj1,obj2){ //pass in the two obj class name
		
			$(obj1).hide();
			ah = $(obj2).height();
			objName = obj2;
			centerMiddle();
			$(objName).show();
			initCenterMiddle();
		
	}                                             

function hideNextObj(obj1,obj2){
	
		$(obj2).hide();
		ah = $(obj1).height();
		objName = obj1;
		centerMiddle();
		$(objName).show();
		initCenterMiddle();
		
	}
	
/***** Show NOT AVAILABLE after detected the height of menu item box ******/
function notAvailableHeight(){
	$('.not_available').css('height',$('.itembox_postlogin').height()-parseInt($('.not_available').css('padding-top'),10)-parseInt($('.not_available').css('padding-bottom'),10));
	$('.not_available').show();
}

/***** Set timer for payment process ******/
function paymentProcess(current_obj,next_obj){
	timeout=0;
	timeout=setTimeout(function()
        { 
		  //showNextObj(current_obj,next_obj);
		  location.replace("payment-summary-postlogin.html");
		 //alert('d');
		}, 500);
}

/***** Set timer for sending feedback process ******/
function sendingProcess(current_obj,next_obj){
	timeout=0;
	timeout=setTimeout(function()
        { 
		  //showNextObj(current_obj,next_obj);
		  location.replace("feedback2.html");
		 //alert('d');
		}, 1000);
}

/****CLEAR INPUT FIELD****/
function clearText(field,defaultValue){
    if (field.value == defaultValue) field.value = '';
    
}
function putText(field,defaultValue){
	if (field.value == '') field.value = defaultValue;
}

/****FAKE PASSWORD FIELD****/
function pwdFocus() {

      //alert('test');
      //var Value=document.getElementById("Header:loginForm:fakepassword").value;
      //alert(Value);
      //var Value2=document.getElementById("Header:loginForm:password").value;
      //alert(Value2);
      document.getElementById("Header:loginForm:fakepassword").style.display="none";
      document.getElementById("Header:loginForm:password").style.display="";
      document.getElementById("Header:loginForm:password").focus();
      //alert('done');

}

function pwdBlur() {

      //alert('testblur');
      //var Value=document.getElementById("Header:loginForm:fakepassword").value;
      //alert(Value);

      if (document.getElementById("Header:loginForm:password").value == '') {
            document.getElementById("Header:loginForm:password").style.display="none";
            document.getElementById("Header:loginForm:fakepassword").style.display="";
      }

}

/****FAKE PASSWORD FIELD FOR HEADER IN IFRAME****/
function pwdFocusNew() {

      //alert('test');
      //var Value=document.getElementById("Header:loginForm:fakepassword").value;
      //alert(Value);
      //var Value2=document.getElementById("Header:loginForm:password").value;
      //alert(Value2);
      document.getElementById("loginForm:fakepassword").style.display="none";
      document.getElementById("loginForm:password").style.display="";
      document.getElementById("loginForm:password").focus();
      
      //alert('done');

}

function pwdBlurNew() {

      //alert('testblur');
      //var Value=document.getElementById("Header:loginForm:fakepassword").value;
      //alert(Value);

      if (document.getElementById("loginForm:password").value == '') {
            document.getElementById("loginForm:password").style.display="none";
            document.getElementById("loginForm:fakepassword").style.display="";
      }

}

/***** SHOW TOOLTIP ADD IN MENU PAGE *****/
function showTooltipAdd(div_id) {
	$(div_id).css('display','block');
	
	$(div_id).mouseleave(function(){
			$(div_id).css('display','none');
	});
	
	$('.tooltip_add').mouseleave(function(){
			$(div_id).css('display','none');
	});
}
