/*===================================================
*
*	Common Script
*	Site http://www.unitedcinemas.jp
*	Last Update 2007-08-22
*
====================================================*/

/*--------------------------------------------------
[theater select config]
--------------------------------------------------*/
var $theater = {
	1  : "otsu",
	2  : "kanazawa",
	3  : "sapporo",
	4  : "niigata",
	5  : "kishiwada",
	6  : "inazawa",
	7  : "fukuoka",
	8  : "agui",
	9  : "nagasaki",
	10 : "iruma",
	11 : "toshimaen",
	12 : "canalcity",
	13 : "nakama",
	14 : "toyohashi",
	15 : "shinsei",
	16 : "toyosu",
	17 : "maebashi",
	18 : "kamisato",
	19 : "urawa",
	20 : "kasukabe",
	21 : "minamifuruya"
};



/*--------------------------------------------------
move banner
--------------------------------------------------*/
function banner(){

//バナーの設定
	var move_page    = ["top"]; //動くバナーのページのbodyタグのclassを設定
	var no_move_page = [ ];                   //固定バナーのページのbodyタグのclassを設定

	var image_path  = "/image/side/dragontatoo.jpg"; //バナー画像のパス
	var image_alt   = "ドラゴンタトゥー";//バナー画像のalt 
	var image_width = 120;                             //画像の横幅
	var link_url    = "information.php?from=scrl#information_14352";//バナーのリンク先
	var target_win  = "_self";        //ターゲット（_blank or _self）

	var swf = {
		path: "/image/common/banner/move_banner.swf",
		name: "percy",
		ver : '7',
		bgcolor: "#000000",
		height: 250,
		width: image_width
	};
	swf = undefined;	// Flashを使わないときはコメントを外す

	//バナーの設定ここまで。ここからメイン処理

	var is_move = false;
	for(i=0;i<move_page.length;i++){
		if( $("body." + move_page[i]).size() ) is_move = true;
	}

	var is_no_move = false;
	for(i=0;i<no_move_page.length;i++){
		if( $("body." + no_move_page[i]).size() ) is_no_move = true;
	}

	if(is_move == false && is_no_move == false) return;

	var html = '<div id="moveBannerImage">';
	html += '<a hr'+'ef="' + link_url + '" target="'+ target_win +'"><img s'+'rc="' + image_path + '" alt="' + image_alt + '" /><\/a>';
	html += '<\/div>';
	var scrollTop  = document.body.scrollTop  || document.documentElement.scrollTop;
	
	$("#top").append(html).css("position","relative");
	image_width += 20;
	$("#moveBannerImage").css( {
		"position": "absolute",
		"top": "10px",
		"right": "-" + image_width + "px",
		"margin-top": "22px"
		}
	);

// for Flash
if (typeof swf != 'undefined') {
	var so = new SWFObject(swf.path, swf.name, swf.width, swf.height, swf.ver, swf.bgcolor);
	so.useExpressInstall('/fla/expressinstall.swf');
	so.addParam("wmode","transparent");
	so.write("moveBannerImage");
}

	if(is_move) moveBanner();
}

function moveBanner() {
	var targetPos = document.body.scrollTop  || document.documentElement.scrollTop;
	var initPos = $("#moveBannerImage").offset().top;
	if (targetPos != initPos) {
		var movePos = initPos + ( (targetPos - initPos) / 6 );
		if($.browser.msie) movePos += 1;
		$("#moveBannerImage").css("top",movePos + "px");
	}
	setTimeout('moveBanner()',"20");
}

function banner2(){

	var move_page    = [ ]; //動くバナーのページのbodyタグのclassを設定
	var no_move_page = [ ];                   //固定バナーのページのbodyタグのclassを設定

	var image_path  = "/image/side/lifeinaday_slide.jpg"; //バナー画像のパス
	var image_alt   = "「LIFE IN THE DAY」試写会";//バナー画像のalt 
	var image_width = 120;                             //画像の横幅
	var link_url    = "/lifeinaday/index.html?from=topbnr";//バナーのリンク先
	var target_win  = "_self";        //ターゲット（_blank or _self）

	var swf = {
		path: "/image/common/banner/move_banner.swf",
		name: "percy",
		ver : '7',
		bgcolor: "#000000",
		height: 250,
		width: image_width
	};
	swf = undefined;	// Flashを使わないときはコメントを外す

	//バナーの設定ここまで。ここからメイン処理

	var is_move = false;
	for(i=0;i<move_page.length;i++){
		if( $("body." + move_page[i]).size() ) is_move = true;
	}

	var is_no_move = false;
	for(i=0;i<no_move_page.length;i++){
		if( $("body." + no_move_page[i]).size() ) is_no_move = true;
	}

	if(is_move == false && is_no_move == false) return;

	var html = '<div id="moveBannerImage">';
	html += '<a hr'+'ef="' + link_url + '" target="'+ target_win +'"><img s'+'rc="' + image_path + '" alt="' + image_alt + '" /><\/a>';
	html += '<\/div>';
	var scrollTop  = document.body.scrollTop  || document.documentElement.scrollTop;
	
	$("#top").append(html).css("position","relative");
	image_width += 20;
	$("#moveBannerImage").css( {
		"position": "absolute",
		"top": "10px",
		"right": "-" + image_width + "px",
		"margin-top": "22px"
		}
	);

// for Flash
if (typeof swf != 'undefined') {
	var so = new SWFObject(swf.path, swf.name, swf.width, swf.height, swf.ver, swf.bgcolor);
	so.useExpressInstall('/fla/expressinstall.swf');
	so.addParam("wmode","transparent");
	so.write("moveBannerImage");
}

	if(is_move) moveBanner2();
}

function moveBanner2() {
	var targetPos = document.body.scrollTop  || document.documentElement.scrollTop;
	var initPos = $("#moveBannerImage").offset().top;
	if (targetPos != initPos) {
		var movePos = initPos + ( (targetPos - initPos) / 6 );
		if($.browser.msie) movePos += 1;
		$("#moveBannerImage").css("top",movePos + "px");
	}
	setTimeout('moveBanner()',"20");
}

/*--------------------------------------------------
onload function
--------------------------------------------------*/

$(function(){
	//theater jump
	$('#theaterSelect').change(function(){
		tid = this.value;
		location.href = "http://" + document.domain + "/" + $theater[tid] + "/index.html";
	});
	$('#theaterSelectSms').change(function(){
		tid = this.value;
		location.href = "https://" + document.domain + "/sms/form_dearjohn.php?from=" + $theater[tid];
	});

	//film jump
	$('#filmSelect').change(function(){
		fid = this.value;
		if($("body").attr("id") != '') {
			fid += '&from='+ $("body").attr("id");
		}
		location.href = "film.php?movie="+ fid;
	});

	banner()
	banner2()

	//btm hover action
	$("img.hoverFade").hover(function(){
		$(this).fadeTo(150,0.8);
	},
	function(){
		$(this).fadeTo(150,1.0)
	});

	//theater select
	$("#theaterSelect").hover(
		function(){
			$("#nav-one").fadeIn(200);
			$("a.camflash").css("display","none");
			$("a.camflash_list").css("display","none");
		},
		function(){
			$("#nav-one").css("display","none");
			$("a.camflash").css("display","block");
			$("a.camflash_list").css("display","none");
		}
	);
	//font size chance	
	$("img#fontChange").click(function(){
		var image_base = "/image/common/";
		var image_do_big = "btn_textL";
		var image_do_small = "btn_textS";

		if(this.src.indexOf(image_do_small) == -1){
			$(".fontChangeTarget").css("fontSize","114%");
			this.src = image_base + image_do_small + ".gif";
		}else{
			$(".fontChangeTarget").css("fontSize","100%");
			this.src = image_base + image_do_big + ".gif";
		}
	});

	//do print
	$("img#doPrint").click(function(){print();})

	//height adjust
	var show_height = $("div#showManner").height();
	if(navigator.userAgent.indexOf("IE 6") != -1)
		show_height = show_height + 10;
	$("div#calenderBox").css("height",show_height);

	//virtual traking
	$('.tracking').click(function(){
	urchinTracker(this.id);
	});

});

/*--------------------------------------------------
[image Hover]
--------------------------------------------------*/

(function(){
	
	function rollover(){
		var targetClassName = "hoverImg";
		var suffix = "_hover";

		var overReg = new RegExp("^(.+)(\\.[a-z]+)$");
		var outReg = new RegExp("^(.+)" + suffix + "(\\.[a-z]+)$");

		var preload = new Array();
		var images = document.getElementsByTagName("img");


		for (var i = 0, il = images.length; i < il; i++) {
			var classStr = images[i].getAttribute("class") || images[i].className;
			if(!images[i].getAttribute("src").match(outReg)){
				var classNames = classStr.split(/\s+/);
				for(var j = 0, cl = classNames.length; j < cl; j++){
					if(classNames[j] == targetClassName){

						//preload
						preload[i] = new Image();
						preload[i].src = images[i].getAttribute("src").replace(overReg, "$1" + suffix + "$2");

						//mouseover
						images[i].onmouseover = function() {
							this.src = this.getAttribute("src").replace(overReg, "$1" + suffix + "$2");
						}

						//mouseout
						images[i].onmouseout = function() {
							this.src = this.getAttribute("src").replace(outReg, "$1$2");
						}
					}
				}
			}
		}
	}

	function addEvent(elem,event,func){
		if(elem.addEventListener) {
			elem.addEventListener(event, func, false);
		}else if(elem.attachEvent) {
			elem.attachEvent("on" + event, func);
		}
	}
	addEvent(window,"load",rollover);
})();


/*--------------------------------------------------
navigation rollover pulldown
--------------------------------------------------*/
var timeout         = 500;
var closetimer		= 0;
var ddmenuitem      = 0;

function jsddm_open()
{	jsddm_canceltimer();
	jsddm_close();
	ddmenuitem = $(this).find('ul').eq(0).css('visibility', 'visible');}

function jsddm_close()
{	if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');}

function jsddm_timer()
{	closetimer = window.setTimeout(jsddm_close, timeout);}

function jsddm_canceltimer()
{	if(closetimer)
	{	window.clearTimeout(closetimer);
		closetimer = null;}}

$(document).ready(function(){
	$('#gnavi > li').bind('mouseover', jsddm_open);
	$('#gnavi > li').bind('mouseout',  jsddm_timer);
});

document.onclick = jsddm_close;



/*--------------------------------------------------
old function
--------------------------------------------------*/

function openWinX(w, h) {
	if (screen.width < w)
		w = screen.width;
	if (screen.height < h)
		h = screen.height;
	w = w? w: 600;
	h = h? h: 600;

	subWin = window.open("","text", "toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width="+w+",height="+h);
}

function openWinVideo(w, h,url) {
	if (screen.width < w)
		w = screen.width;
	if (screen.height < h)
		h = screen.height;
	w = w? w: 600;
	h = h? h: 600;
	subWin = window.open(url,"text", "toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width="+w+",height="+h);
}


//2009/5/14 send vars to flash(base.swf)
function separator(vURI){
	var thisPage = this.location.href
	a = thisPage.split("/");
	currentAddress = "/"+a[3]+vURI;	
	//alert(currentAddress)
	urchinTracker(currentAddress);
}


/*--------------------------------------------------------------------------*
 *  
 *  heightLine JavaScript Library beta4
 *  
 *  MIT-style license. 
 *  
 *  2007 Kazuma Nishihata 
 *  http://www.webcreativepark.net
 *  
 *--------------------------------------------------------------------------*/
new function(){
	
	function heightLine(){
	
		this.className="heightLine";
		this.parentClassName="heightLineParent"
		reg = new RegExp(this.className+"-([a-zA-Z0-9-_]+)", "i");
		objCN =new Array();
		var objAll = document.getElementsByTagName ? document.getElementsByTagName("*") : document.all;
		for(var i = 0; i < objAll.length; i++) {
			var eltClass = objAll[i].className.split(/\s+/);
			for(var j = 0; j < eltClass.length; j++) {
				if(eltClass[j] == this.className) {
					if(!objCN["main CN"]) objCN["main CN"] = new Array();
					objCN["main CN"].push(objAll[i]);
					break;
				}else if(eltClass[j] == this.parentClassName){
					if(!objCN["parent CN"]) objCN["parent CN"] = new Array();
					objCN["parent CN"].push(objAll[i]);
					break;
				}else if(eltClass[j].match(reg)){
					var OCN = eltClass[j].match(reg)
					if(!objCN[OCN]) objCN[OCN]=new Array();
					objCN[OCN].push(objAll[i]);
					break;
				}
			}
		}
		
		//check font size
		var e = document.createElement("div");
		var s = document.createTextNode("S");
		e.appendChild(s);
		e.style.visibility="hidden"
		e.style.position="absolute"
		e.style.top="0"
		document.body.appendChild(e);
		var defHeight = e.offsetHeight;
		
		changeBoxSize = function(){
			for(var key in objCN){
				if (objCN.hasOwnProperty(key)) {
					//parent type
					if(key == "parent CN"){
						for(var i=0 ; i<objCN[key].length ; i++){
							var max_height=0;
							var CCN = objCN[key][i].childNodes;
							for(var j=0 ; j<CCN.length ; j++){
								if(CCN[j] && CCN[j].nodeType == 1){
									CCN[j].style.height="auto";
									max_height = max_height>CCN[j].offsetHeight?max_height:CCN[j].offsetHeight;
								}
							}
							for(var j=0 ; j<CCN.length ; j++){
								if(CCN[j].style){
									var stylea = CCN[j].currentStyle || document.defaultView.getComputedStyle(CCN[j], '');
									var newheight = max_height;
									if(stylea.paddingTop)newheight -= stylea.paddingTop.replace("px","");
									if(stylea.paddingBottom)newheight -= stylea.paddingBottom.replace("px","");
									if(stylea.borderTopWidth && stylea.borderTopWidth != "medium")newheight-= stylea.borderTopWidth.replace("px","");
									if(stylea.borderBottomWidth && stylea.borderBottomWidth != "medium")newheight-= stylea.borderBottomWidth.replace("px","");
									CCN[j].style.height =newheight+"px";
								}
							}
						}
					}else{
						var max_height=0;
						for(var i=0 ; i<objCN[key].length ; i++){
							objCN[key][i].style.height="auto";
							max_height = max_height>objCN[key][i].offsetHeight?max_height:objCN[key][i].offsetHeight;
						}
						for(var i=0 ; i<objCN[key].length ; i++){
							if(objCN[key][i].style){
								var stylea = objCN[key][i].currentStyle || document.defaultView.getComputedStyle(objCN[key][i], '');
									var newheight = max_height;
									if(stylea.paddingTop)newheight-= stylea.paddingTop.replace("px","");
									if(stylea.paddingBottom)newheight-= stylea.paddingBottom.replace("px","");
									if(stylea.borderTopWidth && stylea.borderTopWidth != "medium")newheight-= stylea.borderTopWidth.replace("px","")
									if(stylea.borderBottomWidth && stylea.borderBottomWidth != "medium")newheight-= stylea.borderBottomWidth.replace("px","");
									objCN[key][i].style.height =newheight+"px";
							}
						}
					}
				}
			}
		}
		
		checkBoxSize = function(){
			if(defHeight != e.offsetHeight){
				changeBoxSize();
				defHeight= e.offsetHeight;
			}
		}
		changeBoxSize();
		setInterval(checkBoxSize,1000)
		window.onresize=changeBoxSize;
	}
	
	function addEvent(elm,listener,fn){
		try{
			elm.addEventListener(listener,fn,false);
		}catch(e){
			elm.attachEvent("on"+listener,fn);
		}
	}
	addEvent(window,"load",heightLine);
}


