/* config */
$(function() {
    var preLoad = new Object();
    $('img.Over').each(function(){
        var imgSrc = this.src;
        var fType = imgSrc.substring(imgSrc.lastIndexOf('.'));
        var imgName = imgSrc.substr(0, imgSrc.lastIndexOf('.'));
        var imgOver = imgName + '_o' + fType;
        preLoad[this.src] = new Image();
        preLoad[this.src].src = imgOver;
        $(this).hover(
            function (){
                this.src = imgOver;
            },
            function (){
                this.src = imgSrc;
            }
        );
    });

    $('a[href^="http"]').not('a[href^="http://www.backlog.jp/"],a[href^="https://www.backlog.jp/"]').click(function(){
        window.open(this.href, '');
        return false;
    });

    if ($.browser.msie && $.browser.version < 7) {
        $('#balloon img').attr('src','img/txt_siteid_vol1_8.png');
    }

    $('#detail dl dt:first,#detail dl dd:first,').css('border-top','0');
    $('#detail dl.First > dt').append('<span>:</span>');
    $('#detail dd ul dl dt').prepend('[');
    $('#detail dd ul dl dt').append(':');
    $('#detail dd ul dl dd').append(']');

      // リクエストフォーム用 - ここから
      var notify = function(message, options) {
	      if (!message || message.length == 0) {
		      return;
	      }
	      var notifyMessage = $("<div>");
	      notifyMessage.css({
		                        "position": "absolute",
		                        "top": ($(window).scrollTop()+250) + "px",
		                        "left": "0px",
		                        "width": "100%",
		                        "fontSize": "1.5em",
 		                        "text-align": "center",
		                        "color": "#fff",
		                        "background": "#81B419",
		                        "padding": "10px 0",
		                        "margin": "0",
		                        "opacity": 0.9,
		                        "z-index": 9999,
		                        "display": "none"
	                        });
	      notifyMessage.text(message);
	      $("body").append(notifyMessage);
	      setTimeout(function() {
		                 notifyMessage.fadeIn(200);
	                 }, 0);
	      setTimeout(function() {
		                 notifyMessage.fadeOut(200, function() {
			                                       $(this).remove();
                                                   $.each(["name","mail","company","pc","message"],function(index, value){
                                                              $('#'+value).val("").removeAttr('disabled');
                                                          });
		                                       });
	                 }, 3000);
      };
      $('#requestBtn').click(function(){
                                 setTimeout(function() {
                                                var requireParams = ["name","mail","pc"];
                                                var checked = 0;
                                                $.each(requireParams, function(index, value){
                                                           var input = $('#'+value);
                                                           if (!input.val()) {
                                                               input.focus();
                                                               input.css({ "background-color": '#FFCCCC' });
                                                               setTimeout(function() {
                                                                              input.css({"background-color": 'none'});
                                                                          },500);
                                                               return false;
                                                           }
                                                           checked++;
                                                           return true;
                                                       });
                                                if (checked != requireParams.length) {
                                                    console.debug(checked + " != " + requireParams.length);
                                                    return;
                                                }
                                                var formData = $('#requestForm').serialize();
                                                $.each(["name","mail","company","pc","message"],function(index, value){
                                                           $('#'+value).attr('disabled','disabled');
                                                       });
                                                $.post(
                                                    "/subversionworkshop/request",
                                                    formData,
                                                    function(data) {
                                                        if (data.result == 'ok') {
                                                            notify("参加申込みを受け付けました！");
                                                        }
                                                    }, "json"
                                                );
                                            },0);
                  });
});
