$(document).ready(function(){
	// パンくず
	$("#breadCrumb").jBreadCrumb({endElementsToLeaveOpen:'2'});

	// カテゴリツリー
	if ($("#treeview").size() > 0) {
		$("#treeview").treeview({
			persist: "location",
			collapsed: true
		});
		// 中カテゴリクリックによる小カテゴリopen
		$('.folder').click(function() {
			$(this).next().show();
			$(this).parent().find('div').removeClass('expandable-hitarea');
			$(this).parent().find('div').addClass('collapsable-hitarea');
		});
		// 中カテゴリクリックによる小カテゴリopen（サーバー応答後）
		var openCategory = $('#open_category').val();
		if (openCategory != '') {
			$("#" + openCategory).show();
			$("#" + openCategory).parent().find('div').removeClass('expandable-hitarea');
			$("#" + openCategory).parent().find('div').addClass('collapsable-hitarea');
		}
	}

	// ホットスポット角丸
	if ($(".hsContents").size() > 0) {
		$(".hsContents").corner("");
	}

	// 外部リンクをwindow.openで実現
	$(".outsideLink").click(function () { 
		window.open($(this).attr('href')); 
		return false;
	});

	$('#contentsMatchBackGround').fadeIn();

	$('.mover')
	.mouseover(function(){
		$(this).css({opacity: 0.6});
	})
	.mouseout(function(){
		$(this).css({opacity: 1.0});
	});

	// フォーカスが当たった場合の入力フィールド強調
	$(":input:text").focus(function(){
		$(this).addClass("userInputFieldMover");
	});

	// フォーカスが外れた場合の入力フィールド強調解除
	$(":input:text").blur(function(){
		$(this).removeClass("userInputFieldMover");
	});

	// お気に入りに追加＆解除
	$('img[id^="favoriteButton"]').each(function() {
		var pointID = $(this)[0].id;
		pointID = pointID.replace("favoriteButton", "");
		$(this).bind("click", function(){
			$.get("/ajax/favoritepointid/", {point_id:pointID}, function(returnData){
				if (returnData == 'regist') {
					// 追加したので、解除ボタンに切替
					$('#favoriteButton' + pointID).attr('src', "/image/point/btn_favoriteRemove.gif");
				} else if (returnData == 'delete') {
					// 解除したので、追加ボタンに切替
					$('#favoriteButton' + pointID).attr('src', "/image/point/btn_favoriteAppend.gif");
				}
			});
		});
	});

	// マイページお気に入り解除
	$('img[id^="favoriteDelete"]').each(function() {
		var pointID = $(this)[0].id;
		pointID = pointID.replace("favoriteDelete", "");
		$(this).bind("click", function(){
			$.get("/ajax/favoritepointid/", {point_id:pointID}, function(returnData){
				if (returnData == 'regist') {
					// 追加はありえないはず
				} else if (returnData == 'delete') {
					// 解除したので、隠す
					$('#favoriteDelete' + pointID).closest("div[class='favoriteContainer']").hide();
				}
			});
		});
	});

	// 懸賞情報お気に入りに追加＆解除
	$('img[id^="favoritePresent"]').each(function() {
		var presentID = $(this)[0].id;
		presentID = presentID.replace("favoritePresent_", "");
		$(this).bind("click", function(){
			$.get("/ajax/favoritepresentid/", {id:presentID}, function(returnData){
				if (returnData == 'regist') {
					// 追加したので、解除ボタンに切替
					$('#favoritePresent_' + presentID).attr('src', "/image/point/btn_favoriteRemove.gif");
				} else if (returnData == 'delete') {
					// 解除したので、追加ボタンに切替
					$('#favoritePresent_' + presentID).attr('src', "/image/point/btn_favoriteAppend.gif");
				}
			});
		});
	});

	// 応募方法絞り込み
	$('#methodPulldown').change(function () { 
		location.href = $("#viewSequence").attr('href').replace('/new/', '/method/') + $('option:selected', this).val();
	});
	// 応募条件絞り込み
	$('#requiredPulldown').change(function () { 
		location.href = $("#viewSequence").attr('href').replace('/new/', '/required/') + $('option:selected', this).val();
	});
	// 抽選方法絞り込み
	$('#drawingPulldown').change(function () { 
		location.href = $("#viewSequence").attr('href').replace('/new/', '/drawing/') + $('option:selected', this).val();
	});

	$("#breadCrumb").show();
});

