// JavaScript Document

/*-------------
ポップアップ各種
--------------*/
function popup600(url){
	window.open("" + url +"", "_blank", "width=615, menubar=no, toolbar=no, scrollbars=yes, resizable=yes ");
}

function popup665(url){

	window.open("" + url +"", "_blank", "width=680, height=680 menubar=no, toolbar=no, scrollbars=yes, resizable=yes ");
}

function popup450(url){

	window.open("" + url +"", "_blank", "width=465, menubar=no, toolbar=no, scrollbars=yes, resizable=yes ");
}

function popup(url){

	window.open("" + url +"", "wind", "menubar=no, toolbar=no, scrollbars=yes, resizable=yes");
}

function popupFull(url){

	window.open("" + url +"", "Test", "fullscreen=yes");
}

$(function(){
	
	/*-------------
	ポップアップ起動
	--------------*/
	$("a.popup_blank").attr({target:"_blank"});
	
	
	
	$("a.popup_full").each(function(){
		var myURL=($(this).attr("href"));
		$(this).click(function(){
			popupFull(myURL);
			return false;
		});
	});
	
	$("a.popup_665").each(function(){
		var myURL=($(this).attr("href"));
		$(this).click(function(){
			popup600(myURL);
			return false;
		});
	});
	
	$("a.popup_600").each(function(){
		var myURL=($(this).attr("href"));
		$(this).click(function(){
			popup600(myURL);
			return false;
		});
	});
	
	$("a.popup_450").each(function(){
		var myURL=($(this).attr("href"));
		$(this).click(function(){
			popup600(myURL);
			return false;
		});
	});
	
	/*-------------
	左カラム
	--------------*/
	$("div:first","div#container div#left_column").addClass("first");
	
	
	/*-------------
	検索のフォーム
	--------------*/
	$("#global_header input#fn_search_box,#footer_nav input#fn_search_box").val("サイト全体検索").css("color","#CCC").one("focus",function(){
			$(this).val("").css("color","#000");
		}).blur(function(){
			if($(this).val()==""){
			$(this).val("サイト全体検索").css("color","#CCC").one("focus",function(){
			$(this).val("").css("color","#000");
		})
		}
	})
	
	
	
	/*-------------
	main_menuプルダウン
	--------------*/
	
	$("li.products,li.service","ul#main_menu_list").hover(
		function () {
			$(this).find("ul").show();
		},
		function () {
			$(this).find("ul").hide();
		}
	);
	
	/*-------------
	ブランクアイコン付与
	--------------*/
	
	/*関連ページ 
	$("div.related_page_list a").each(function(){
		var myTaerget=$(this).attr("target");
		var myHref=$(this).attr("href");
		if(myBlankTaerget=="_blank"){
			$(this).find("strong").wrapInner("<span class='iconBlank'></span>");
		}
	});*/
	
	$("#right_column a span.iconBlank,#footer_nav a span.iconBlank,.home #important_news_area a span.iconBlank,#Recipe a span.iconBlank,ul#main_menu_list li a span.iconBlank").each(function(){
		$(this).append("<img src='/jp/common/img/icon_blank.gif' alt='' />");
	});
	
	
	/*-------------
	imageBorder
	--------------*/
	$("div.product_related_page_box div.related_page_list ul li a").hover(
		function () {
			$(this).find("img").addClass("borderHover");
		},
		function () {
			$(this).find("img").removeClass("borderHover");
		}
	);
	
	/*-------------
	発見ランキングToggle
	--------------*/
	$('div.ranking_btn').click(function(){
		$(this).next().slideToggle('fast');
	});
	$('div.ranking_close').click(function(){
		$(this).parent().slideToggle('fast');
	});
	
	/*-------------
	flatHeight
	--------------*/
	($.browser.safari ? $(window).load : $).call($(window), function () {
		/**
		* 【使い方】
		*
		* 1.親要素のclassに flatHeight-（1行の子要素数） を指定する。
		*   設定可能な親要素はdivとulのみ。
		*   例）<ul class="clearfix flatHeight-4">
		* 
		* 2.全子要素の高さを揃えたい場合は、
		*   親要素のclassに flatHeightParent を指定する。
		*   例）<ul class="clearfix flatHeightParent">
		*
		* 3.孫要素の高さを揃えたい場合は、
		*   親要素のclassに flatHeight-（1行の子要素数）C（孫要素のindex（0～）） を指定する。
		*   例）<ul class="clearfix flatHeight-4C1">
		*         <li>
		*           <div>                   </div>
		*           <div>このdivの高さが揃う</div>
		*           <div>                   </div>
		*
		* setFlatHeightElements()を実行することで要素リストが作成される。
		* ページがロードされた時、または、動的に作成された要素の高さを揃えたい場合に実行する。
		* 
		*/
		setFlatHeightElements();
	});
	
});

/**
 * キーワードで探す submit
 */
function submitKeywordSearch() {
	var keywordBox = $('div.product_serch_keyword_serch_box');
	var str = $('div.boxL input', keywordBox).val();
	if (str != '') {
		if (IS_KEYWORD_SEARCH) {
			// 現在のページがキーワード検索ページの場合
			createKeywordSearchResult(0);
	return false;
		} else {
			// 現在のページがキーワード検索ページではない場合
			// page_id=0を持ってキーワード検索ページへ遷移。
			str = encodeURIComponent(str);
			window.location.href = '/jp/products/search/?page=0#' + str;
			//createKeywordSearchResult(0, true);
	return false;
		}
	} else {
		alert('キーワードを入力してください。')
	}
	return false;
}
