<!-- Begin -->

function roll_over(img_name,img_src) {
document[img_name].src=img_src;
}

function stopRKey(evt) { 
  var evt = (evt) ? evt : ((event) ? event : null); 
  var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null); 
  if ((evt.keyCode == 13) && ((node.type=="text") || (node.type="password")))  {return false;} 
} 

$(document).ready(function() {
	$('#a_1').click(function() {
		$('#q_1').slideToggle('slow');	
	});	

	$('#a_1').hover(function() {
		$('#a_1').css({"cursor" : "pointer", "color" : "red"});
	},function() {
		$('#a_1').css({"color" : "#3366ff"});
	}
	);
	
	$('#a_2').click(function() {
		$('#q_2').slideToggle('slow');	
	});	
	$('#a_2').hover(function() {
		$('#a_2').css({"cursor" : "pointer", "color" : "red"});
	},function() {
		$('#a_2').css({"color" : "#3366ff"});
	}
	);
	
	$('#a_3').click(function() {
		$('#q_3').slideToggle('slow');	
	});	
	$('#a_3').hover(function() {
		$('#a_3').css({"cursor" : "pointer", "color" : "red"});
	},function() {
		$('#a_3').css({"color" : "#3366ff"});
	}
	);

	$('#a_4').click(function() {
		$('#q_4').slideToggle('slow');	
	});	
	$('#a_4').hover(function() {
		$('#a_4').css({"cursor" : "pointer", "color" : "red"});
	},function() {
		$('#a_4').css({"color" : "#3366ff"});
	}
	);	
	
	$('#a_5').click(function() {
		$('#q_5').slideToggle('slow');	
	});	
	$('#a_5').hover(function() {
		$('#a_52').css({"cursor" : "pointer", "color" : "red"});
	},function() {
		$('#a_5').css({"color" : "#3366ff"});
	}
	);
	
	$('#a_6').click(function() {
		$('#q_6').slideToggle('slow');	
	});	
	$('#a_6').hover(function() {
		$('#a_6').css({"cursor" : "pointer", "color" : "red"});
	},function() {
		$('#a_6').css({"color" : "#3366ff"});
	}
	);

	$('#a_7').click(function() {
		$('#q_7').slideToggle('slow');	
	});	
	$('#a_7').hover(function() {
		$('#a_7').css({"cursor" : "pointer", "color" : "red"});
	},function() {
		$('#a_7').css({"color" : "#3366ff"});
	}
	);

	$('#a_8').click(function() {
		$('#q_8').slideToggle('slow');	
	});	
	$('#a_8').hover(function() {
		$('#a_8').css({"cursor" : "pointer", "color" : "red"});
	},function() {
		$('#a_8').css({"color" : "#3366ff"});
	}
	);

	$('#a_9').click(function() {
		$('#q_9').slideToggle('slow');	
	});	
	$('#a_9').hover(function() {
		$('#a_9').css({"cursor" : "pointer", "color" : "red"});
	},function() {
		$('#a_9').css({"color" : "#3366ff"});
	}
	);

	$('#a_10').click(function() {
		$('#q_10').slideToggle('slow');	
	});	
	$('#a_10').hover(function() {
		$('#a_10').css({"cursor" : "pointer", "color" : "red"});
	},function() {
		$('#a_10').css({"color" : "#3366ff"});
	}
	);

	$('#a_11').click(function() {
		$('#q_11').slideToggle('slow');	
	});	
	$('#a_11').hover(function() {
		$('#a_11').css({"cursor" : "pointer", "color" : "red"});
	},function() {
		$('#a_11').css({"color" : "#3366ff"});
	}
	);	

	
	$('.titlebar_menu_home').hover(function() {
		$('.titlebar_menu_home').css("background-position"," 0 -30px");
	},function() {
		$('.titlebar_menu_home').css("background-position", "0 0");
	}
	);		

	$('.titlebar_menu_contact').hover(function() {
		$('.titlebar_menu_contact').css("background-position", "-186px -30px");
	},function() {
		$('.titlebar_menu_contact').css("background-position", "-186px 0" );
	}
	);	
	

	$('.titlebar_menu_shopping').hover(function() {
		$('.titlebar_menu_shopping').css("background-position", "-372px -30px");
	},function() {
		$('.titlebar_menu_shopping').css("background-position", "-372px 0" );
	}
	);	
	

	$('.titlebar_menu_story').hover(function() {
		$('.titlebar_menu_story').css("background-position", "-558px -30px");
	},function() {
		$('.titlebar_menu_story').css("background-position", "-558px 0" );
	}
	);	


	$('.titlebar_menu_mypage').hover(function() {
		$('.titlebar_menu_mypage').css("background-position", "-744px -30px");
	},function() {
		$('.titlebar_menu_mypage').css("background-position", "-744px 0" );
	}
	);		
	
	/*setInterval(function(){  
		$('#header_ad').animate({
			width: '+=20px',
			height: '+=20px'
			}, 1000).delay(2000).animate({
			width: '-=20px',
			height: '-=20px'
			},1000).delay(2000);
		},2000);});

*/

		
		
});

$(document).ready(function(){
  $('#submenu li ul').css('display', 'none');  

  $('#submenu li').hoverIntent(function() { 
  $(this)
      .find('ul')
      .stop(true, true)
      .slideDown('slow');
  }, function() {
    $(this)
      .find('ul')
      .stop(true,true)
      .fadeOut('fast');
  });  
 
});


$(document).ready(function(){
  $('a[href=#top]').click(function(){
    $.scrollTo(0,'slow');
    return false;
  });
});

var currentPhoto = 0;

$(document).ready(function(){
 setTimeout(function() {rotatePics(0);}, 5000);
 var numberOfPhotos = $('#photos img').length;

  currentPhoto = currentPhoto % numberOfPhotos;
  var thisPhoto = currentPhoto;
  if(thisPhoto==0)
	thisPhoto=1;
	var txtVal = "<div id='imagecount'>" + thisPhoto.toString() + "/" + numberOfPhotos.toString() + "</div>";	
 $('#imagecount').replaceWith(txtVal);	
 });

function rotatePics(currentPhoto) {
  var numberOfPhotos = $('#photos img').length;

  currentPhoto = currentPhoto % numberOfPhotos;
  var thisPhoto = currentPhoto+2;
  thisPhoto = thisPhoto % (numberOfPhotos+1);
  if(thisPhoto==0)
	thisPhoto=1;
	var txtVal = "<div id='imagecount'>" + thisPhoto.toString() + "/" + numberOfPhotos.toString() + "</div>";	
  $('#photos img').eq(currentPhoto).fadeOut(function() {
	// fade in the next image
	$('#photos img').eq((currentPhoto+1) % numberOfPhotos).fadeIn();

	$('#imagecount').replaceWith(txtVal);

	setTimeout(function() {rotatePics(++currentPhoto);}, 5000);
    });  
}



$(document).ready(function(){

  var numberOfArrPhotos = $('#arrPhotos img.arrGallImg').length; 
  arrangeCurrentPhoto = arrangeCurrentPhoto % numberOfArrPhotos;
  var thisArrPhoto = arrangeCurrentPhoto;  
  if(thisArrPhoto==0)
	thisArrPhoto=1;
	var txtVal = "<span style='margin-bottom:8px;' id='arrimagecount'>" + thisArrPhoto.toString() + "/" + numberOfArrPhotos.toString() + "</span>";	
 	if(numberOfArrPhotos>0)	
		$('#arrimagecount').replaceWith(txtVal);
 
	if(numberOfArrPhotos<=1)
	{
		$('#nextPhoto').hide();
		$('#prevPhoto').hide();
	}
});

var arrangeCurrentPhoto = 0;
function rotateArrPics(arrangeCurrentPhoto) {
  var numberOfArrPhotos = $('#arrPhotos img.arrGallImg').length;

  arrangeCurrentPhoto = arrangeCurrentPhoto % numberOfArrPhotos;
  var thisArrPhoto = arrangeCurrentPhoto+2;
  thisArrPhoto = thisArrPhoto % (numberOfArrPhotos+1);
  if(thisArrPhoto==0)
	thisArrPhoto=1;
	var txtVal = "<span style='margin-bottom:8px;' id='arrimagecount'>" + thisArrPhoto.toString() + "/" + numberOfArrPhotos.toString() + "</span>";	

	// Hide these while the images change
	$('#nextPhoto').hide();
	$('#prevPhoto').hide();
		
	$('#arrPhotos img.arrGallImg').eq(arrangeCurrentPhoto).fadeOut(function() {
	// fade in the next image
	$('#arrPhotos img.arrGallImg').eq((arrangeCurrentPhoto+1) % numberOfArrPhotos).fadeIn();
	if(numberOfArrPhotos>0)
		$('#arrimagecount').replaceWith(txtVal);

	$('#arrPhotos p.arrgalldesc').eq(arrangeCurrentPhoto).hide();
	$('#arrPhotos span.arrprodimgs').eq(arrangeCurrentPhoto).hide();

	$('#arrPhotos p.arrgalldesc').eq((arrangeCurrentPhoto+1) % numberOfArrPhotos).show();	
	$('#arrPhotos span.arrprodimgs').eq((arrangeCurrentPhoto+1) % numberOfArrPhotos).show();

	// reshow these now the images are live
		$('#nextPhoto').show();
		$('#prevPhoto').show();	

    });  
}

function prevArrPics() {
  var numberOfArrPhotos = $('#arrPhotos img.arrGallImg').length;
var safeCurrentPhoto = arrangeCurrentPhoto -1;
  if(safeCurrentPhoto < 0) 
  {
//	arrangeCurrentPhoto = numberOfArrPhotos;
	  safeCurrentPhoto = numberOfArrPhotos-1;
  }
  arrangeCurrentPhoto = arrangeCurrentPhoto % numberOfArrPhotos;
  var thisArrPhoto = safeCurrentPhoto+1;
  if(thisArrPhoto < 0) 
       thisArrPhoto = numberOfArrPhotos-1;  
	   
  thisArrPhoto = thisArrPhoto % (numberOfArrPhotos+1);
  if(thisArrPhoto==0)
	thisArrPhoto=1;
	var txtVal = "<span style='margin-bottom:8px;' id='arrimagecount'>" + thisArrPhoto.toString() + "/" + numberOfArrPhotos.toString() + "</span>";	

	// Hide these while the images change
	$('#nextPhoto').hide();
	$('#prevPhoto').hide();	
	
	$('#arrPhotos img.arrGallImg').eq(arrangeCurrentPhoto).fadeOut(function() {
	// fade in the next image
	$('#arrPhotos img.arrGallImg').eq((safeCurrentPhoto) % numberOfArrPhotos).fadeIn();
	if(numberOfArrPhotos>0)
		$('#arrimagecount').replaceWith(txtVal);

	$('#arrPhotos p.arrgalldesc').eq(arrangeCurrentPhoto).hide();
	$('#arrPhotos span.arrprodimgs').eq(arrangeCurrentPhoto).hide();

	$('#arrPhotos p.arrgalldesc').eq((safeCurrentPhoto) % numberOfArrPhotos).show();	
	$('#arrPhotos span.arrprodimgs').eq((safeCurrentPhoto) % numberOfArrPhotos).show();
	// reshow these now the images are live
		$('#nextPhoto').show();
		$('#prevPhoto').show();	
		
arrangeCurrentPhoto--;
  if(arrangeCurrentPhoto < 0) 
  {
		arrangeCurrentPhoto = numberOfArrPhotos-1;
}	
    }); 

}

$(document).ready(function(){
  $('.error').hide();
  $('input.text-input').css({backgroundColor:"#FFFFFF"});
  $('input.text-input').focus(function(){
    $(this).css({backgroundColor:"#FFDDAA"});
  });
  $('input.text-input').blur(function(){
    $(this).css({backgroundColor:"#FFFFFF"});
  });

  $(".button").click(function() {
		// validate and process form
		// first hide any error messages
    $('.error').hide();
		var id = $("input#prodid").val();
		
	  var name = $("input#name").val();
		if (name == "") {
      $("label#name_error").show();
      $("input#name").focus();
      return false;
    }
		var email = $("input#email").val();
		AtPos = email.indexOf("@")
		StopPos = email.lastIndexOf(".")
		if (AtPos == -1 || StopPos == -1) {
			$("label#email_error").show();
			$("input#email").focus();
			return false;
		}
		if (StopPos < AtPos) {
			$("label#email_error").show();
			$("input#email").focus();
			return false;
		}

		if (StopPos - AtPos == 1) {
			$("label#email_error").show();
			$("input#email").focus();
			return false;
		}
		
		if (email == "") {
			$("label#email_error").show();
			$("input#email").focus();
			return false;
    }

		
		var dataString = $("#mail_form form").serialize();
		//'name='+ name + '&email=' + email + '&phone=' + phone;
		//alert (dataString);return false;
		
		$.ajax({
      type: "POST",
      url: "../../include/process.php",
      data: dataString,
      success: function() {
        $('#mail_form').html("<div id='message'></div>");
        $('#message').html("<h2>Mail Address Submitted!</h2>")
        .append("")
        .hide()
        .fadeIn(1000, function() {
          $('#message').append("<p>ありがとうございました。<img id='checkmark' src='http://images.nailcaviar.com/heart_01.gif' /></p>");
        });
      }
	  
     });
    return false;
	});
});

// Delete gallery photos on button press

$(document).ready(function(){	
	$(".gallerydelete").click(function() {
	var galId = $(".gallerydelete").val();
	var dataString = 'galleryid='+galId;
 
 	  $.ajax({
      type: "POST",
      url: "../db/deletephoto.php",
      data: dataString,
      success: function() {
		$('#galleryinput').html("<td><input type='hidden' name='MAX_FILE_SIZE' value='3000000' /><input name='user_image' type='file'/></td>");	  
        $('.galleryimage').hide();
		 $('.gallerydelete').hide();
      } 
  
  });
  
  });  
  return false;
 }); 

 $(document).ready(function() {
	$("#nextPhoto").click(function() {rotateArrPics(arrangeCurrentPhoto++); return false;	});
	$("#prevPhoto").click(function() {prevArrPics();  return false;	});
});

// Send test mail magazine
$(document).ready(function(){
	$(".testmailmag").click(function() {		
		var dataString = $("#mailmagform form").serialize();

		$.ajax({
		type: "POST",
		url:"sendtestmail.php",
		data: dataString,
		success: function() {
		$('.testmailmag').css({color:"red"});
		}
		});
		return false;
	});	
});


// Send salon mail magazine
$(document).ready(function(){
	$(".salonmailmag").click(function() {		
		var dataString = $("#salonmailmagform form").serialize();
		$('.salonmailmag').hide();
		$.ajax({
		type: "POST",
		url:"sendsalonmails.php",
		data: dataString,
		success: function() {
		$('.salonmailmag').show();
		$('.salonmailmag').css({color:"red"});
		}
		});
		return false;
	});	
});

// Send maillist mail magazine
$(document).ready(function(){
	$(".maillistmag").click(function() {		
		var dataString = $("#listmailmagform form").serialize();
		$(".mailistmag").hide();
		$.ajax({
		type: "POST",
		url:"sendmaillistmail.php",
		data: dataString,
		success: function() {
		$(".mailistmag").show();
		$('.maillistmag').css({color:"red"});
		}
		});
		return false;
	});	
});


// Rotate homepage banners
$(document).ready(function(){
	var numberOfBanners = $('#banners span').length;
	var startBanner = Math.floor(Math.random() * numberOfBanners);
	$('#banners span').eq(startBanner).fadeIn();

	var time = 12000;
	if(startBanner==0)
		time = 51200;
	setTimeout(function() { rotateBanner(startBanner);}, time);
});

function rotateBanner(currentBanner) {
	var numberOfBanners = $('#banners span').length;
	var nxtBanner = Math.floor(Math.random() * numberOfBanners);
	
	currentBanner = currentBanner % numberOfBanners;
	
	while(nxtBanner == currentBanner)
	{
		nxtBanner = Math.floor(Math.random() * numberOfBanners);
	}
  
	$('#banners span').eq(currentBanner).fadeOut(function() {
	// fade in next banner
	$('#banners span').eq(nxtBanner).fadeIn();
  	
	var time = 12000;
	if(nxtBanner==0) // the flash animation is a lot longer
		time = 51200;
		
	setTimeout(function() { rotateBanner(nxtBanner);}, time);
    });  
}

//document.onkeypress = stopRKey; 
