$(function(){
	
	//応急処置
/*
	$('img.imgover').each(function(){
		overObj = $(this).attr("src");
		if(overObj.match(/_o.png$/)){
			overedObj = overObj.replace("_o.png",".png");
			$(this).attr('src', overedObj);
		}
	});
*/

	jQuery(window).bind("beforeunload", function(){
		$('img.imgover').each(function(){
			overObj = $(this).attr("src");
			if(overObj.match(/_o.png$/)){
				overedObj = overObj.replace("_o.png",".png");
				$(this).attr('src', overedObj);
			}
		});
	});

	//rollover
	$('img.imgover').hover(
		function(){
			overObj = $(this).attr("src");
			if(overObj.match(/_o.png$/)){
				overedObj = overObj.replace("_o.png",".png");
			}
			else{
				overedObj = overObj.replace(".png","_o.png");
			}
			$(this).attr('src', overedObj);
		}
	);
	
	//search keyword	
	var self = $('.inputGroup input');
	var targetLabel = $('.inputGroup').find('label');
	var resetWordBtn = $('.inputGroup').find('.reset_word');
	//検索窓focus
	self.focus(function(){
		targetLabel.addClass('focus');
	});
	//検索窓入力中
	self.keyup(function(e){
		if(self.val()==""){
			resetWordBtn.hide();
			targetLabel.removeClass('hasText').addClass('focus');
		} else {
			resetWordBtn.show();
			targetLabel.addClass('hasText').removeClass('focus');
		}
		if(e.keyCode == 27){//escキー
			self.val("");
			resetWordBtn.hide();
			self.blur();
		}
	});
	//検索窓からfocusを外す
	self.blur(function(){
		if(self.val() == "") {
		targetLabel.removeClass('hasText').removeClass('focus');
		}
	});	
	//resetキーワード処理
	resetWordBtn.click(function(){
		self.val("");
		resetWordBtn.hide();
		self.focus();
	});
	
	
	function resetSearchArea(){
		self.val("");
		resetWordBtn.hide();
		self.focus();	
	}


});


function bindPlayAct(){
	$("a.clickPlayBtn").bind('click',function(){
		var vid = $(this).attr("vid");
    var title = $(this).html();
	
		var flg = false;
		if($(this).attr('dflg')){
			flg = true;
		}

    $.ajax({
      type: "POST",
      url: "/video/onload/"+vid,
      beforeSend :function(){        
				$('#videoBox').show();
      },
      success: function(sig){
        $.ajax({
          type: "POST",
          url: "/video/changeList/"+vid,
          beforeSend :function(){
            $('table.chapter_nav').html('');
            $('table.chapter_nav_bottom').html('');
            $('table.chapter_nav_top_bottom').html('');
          },
          success: function(val){
            $('table.chapter_nav').html(val);
            $('table.chapter_nav_bottom').html(val);
            $('table.chapter_nav_top_bottom').html(val);
						$("a.clickPlayBtn").unbind('click');
						bindPlayAct();
          }
        });
				
				if(!flg){
	        $('h3.moviesubchapter').html(title);
				}

        var attributes = {
          id: "externalPlayer",
          name: "externalPlayer"
        };

        var flashvars = {s:sig};
        var params = ($.browser.msie)? {wmode: "transparent",allowFullScreen: "true"} : {allowFullScreen: "true"};
        swfobject.embedSWF("/swf/DWPlayer.swf", "externalPlayer", "856", "480", "9.0.0", "DWPlayer.swf",flashvars, params, attributes);
      }
    });
  });
}



