// page top

$(document).ready(function()
{
      if(navigator.userAgent.search(/Android/) != -1){
          $("html").css("zoom" , $(window).width()/980 );
      }
    var curdir = location.pathname.split("/")[1];
    //$("div.goTop a").click(function(){toAnchor(); });
    $("select#typeselector").change(function(){
        location.href = "/entry/"+this.value+".html";
    });
    
    /* corner on */
    if (curdir){
        var gmRegExp = new RegExp('/'+curdir+'/');
        $('#globalMenu li a').each(function(){
            if (this.href.match(new RegExp('/'+curdir+'/'))){
                $(this.parentNode).addClass('on');
            }
        });
    }
	
	$('input[title]').each(function() {
		if($(this).val() === '') {
			$(this).val($(this).attr('title'));	
		}
		
		$(this).focus(function() {
			if($(this).val() == $(this).attr('title')) {
				$(this).val('').addClass('focused');
			}
		});
		$(this).blur(function() {
			if($(this).val() === '') {
				$(this).val($(this).attr('title')).removeClass('focused');	
			}
		});
	});

	//mouser over handler
	jQuery("a.imgOverEffect").hover(
		function () {
			//jQuery(this).find('img').addClass("overEffect");
			 jQuery(this).find('img').animate({ 
				opacity: 0.7
				}, 200 );
		  },
		  function () {
			jQuery(this).find('img').animate({ 
				opacity: 1
				}, 0 );
		  }
	);
	


    /* comment post */
    $("#commentsubmit").click(function(){
        var err = "";
        var require = {
            'comment_module': 'コーナー名',
            'comment_itemid': 'アイテムID',
            'comment_title': 'タイトル',
            'comment_name' : 'お名前',
            'comment_text' : '本文'
          };
        
        var postvars = {};
        var selector = "";
        var value = "";
        for (var i in require){
            selector = "#"+i;
            value = $.trim($(selector).val());
            if (!value){
                err += require[i]+"を入力してください。\n";
                $(selector).val("");
            }
            else {
                postvars[i] = value;
            }
        }
        if (err){
            alert(err);
            return false;
        }
        else if (confirm("この内容でよろしいですか？") ){
            $.post('/commentpost.php', postvars, function(text){
                if (text == "1"){
                    $("#commentpost").hide();
                    $("#commentcomplete").show();
                    alert("コメントをありがとうございます。\n事務局で承認の後、掲載いたします。");
                }
                else {
                    alert("コメントの登録に失敗しました。\nお手数ですがもう一度クリックしてください。");
                }
            }, 'text');
        }
    });
});




