/**
*
* Optima calass
* オプティマ
* jquery , jquery.pingfix に依存
*
**/

//constructor
var Optima = function() {};


//OptimaClass
Optima.prototype = {

	//IE6以下かの判定フラグ
	isIE6:($.browser.msie && $.browser.version < 7)? true : false,
	//MacのOperaかの判定フラグ
	isMacOpera:(navigator.userAgent.indexOf("Mac")!=-1 && $.browser.opera)? true : false,
	//ページの初期設定
	init:function(){
		this.pngfix();
		$("#wrapper")
			.before($("<p class='printitem' id='print_h'><img src='../images/print_h.jpg' width='222' height='32' /></p>"))
			.after($("<p class='printitem' id='print_b'>Copyright (c) 2010 Optima.Co.,Ltd. All rights reserved.</p>"));
		
	},
	//トップページの初期設定
	initTop:function(){
		$("#print_h").html("<img src='./images/print_h.jpg' width='222' height='32' />");
		if(this.isMacOpera) return;
		imgs = $("#navi img").not(".selected");
		this.preloadImages(imgs);
		this.setOverAction(imgs);
	},
	//２階層目独自の初期設定
	initSec:function(){
		navis = $("#navi img").not(".selected");
		this.preloadImages(navis);
		this.setOverAction(navis);

		sidenavis = $("#sidenavi ul img").not(".selected");
		this.setNaviHeight();
		this.preloadImages(sidenavis);
		this.setOverAction(sidenavis);
		this.setScroll();
		//set rollover image
		var filename = location.href.split("/").pop().split("?").shift().split("#").shift();
		if(filename == "") filename = "index.php";
		if(filename == "faq_fukuri.php") filename = "faq.php";
		if(filename == "faq_work.php") filename = "faq.php";
		var $selectimg = $("#sidenavi ul a[href$="+filename+"] img");
		if($selectimg.size()==0)	return;
			$selectimg
				.unbind("mouseover")
				.unbind("mouseout")
				.attr("src",$selectimg.attr("src").replace(/^(.+)(\.[a-z]+)$/, "$1_over$2"));

	},
	//InterneExplorer var6.x以下への透過画像の表示設定
    pngfix:function(){
    	$("img.png").pngfix();
    },
	//画像のプリロード
   	preloadImages:function(imgs){
		$(imgs).each(function(){
			var preload = new Image;
			var img = $("img",this);
			preload.src = this.src.replace(/^(.+)(\.[a-z]+)$/, "$1_over$2");
		})
	},
	//画像のロールオーバー、アウトのイベントを設定する。
	setOverAction:function(imgs){
		$(imgs)
			.bind("mouseover",function(){
				this.src = this.src.replace(/^(.+)(\.[a-z]+)$/, "$1_over$2");
			})
			.bind("mouseout",function(){
				this.src = this.src.replace(/^(.+)_over(\.[a-z]+)$/, "$1$2");
			})
			.pngfix({mouseover:true,overimagePath:"_over"});
	},
	//サイドバーナビゲーションの高さを設定する。
	setNaviHeight:function(){
		setTimeout(function(){
			var height = $("#content_bg_b").height()-30;
			$("#sidenavi_bg_b").css("height",height);		
		},1000);
	},
	
	//「△この画面の上へ」のリンククリック時のスクロールをセット。
    setScroll:function(){
	    $('#pagetoplink')
	    	.bind("click",function(){$('html,body').animate({ scrollTop: 0 },500);});
	    $('#pagetoplink a').attr("href","javascript:");
    },
	//採用情報-フォトアルバムページで、画像の周りの薄紫色の枠の高さを制御
    initRecruitPhoto:function(){
    	var $boxs = $(".photo_box");
    	$boxs.each(function(){
    		optima.initRecruitPhotoSetHeight($(this));
		});
    },
    initRecruitPhotoSetHeight:function($box){
    	var max_height = 0;
		var buffer = [];
		$("p",$box).each(function(i){
			$p = $(this);
			var height = $p.height();
			if(max_height < height) max_height = height;
			buffer.push($p);
			if(buffer.length == 3){
				for(i=0;i<3;i++){
					buffer[i].height(max_height);
				}
				max_height = 0;
				buffer = [];
			}
		});
		for(i=0;i<buffer.length;i++){
			buffer[i].height(max_height);
		}
		max_height = 0;
		buffer = [];

		max_height = 0;
		$("img",$box).each(function(i){
			$img = $(this);
			var height = $img.height();
			if(max_height < height) max_height = height;
			buffer.push($img);
			if(buffer.length == 3){
				for(i=0;i<3;i++){
					offset = max_height - buffer[i].height();
					offset+=10;
					buffer[i].css("marginBottom",offset+"px");
				}
				max_height = 0;
				buffer = [];
			}
		});
		for(i=0;i<buffer.length;i++){
			offset = max_height - buffer[i].height();
			offset+=10;
			buffer[i].css("marginBottom",offset+"px");
		}
		max_height = 0;
		buffer = [];
    },
	//採用情報-よくある質問ページの初期設定(タブナビゲーションのロールオーバー)
    initRecruitFaq:function(selectNo){
       var imgs = $("a img",$("#faqnavi"));
 	   this.setOverAction(imgs);
    },
	//会社概要-事業所・関連会社ページでプリントアイコンクリック時の画面制御
    com_group_print:function(id){
		
		var bodyBG = $("body").css("backgroundImage");
		$("body").css("backgroundImage","none");
		$("#wrapper").hide();
		$("#foot_bg").hide();
		$("#print"+id).show();
		
		print();
		
		$("body").css("backgroundImage",bodyBG);
		$("#wrapper").show();
		$("#foot_bg").show();
		$("#print"+id).hide();

    },
    //インデックスページのBoxの高さを調整
    initIndexBox:function(){
		setTimeout(function(){
			$(".link_box").each(function(){
				var maxheight = 0;
				$("div",$(this)).each(function(){
					var height = $(this).height();
					if(maxheight<height) maxheight = height;					
				}).height(maxheight);                        
			});
		},1000);
    },
    //画像のポップアップをセット
    initPopupImage:function(){
		$('a.lightbox').lightBox({
			overlayBgColor: '#000',
			overlayOpacity: 0.3,
			imageBtnClose: '../images/lightbox-btn-close.gif',
			imageLoading: '../images/loading.gif'
		});
    }
    
};