/*




<?php
    $GLOBALS['base_vars']['EN_BLOG_URL'] = 'http://en.j-cast.com/';
    $GLOBALS['base_vars']['EN_BLOG_SITE_PATH'] = '/home/httpd/webmaster-bus/NEWS/EN/';
    $GLOBALS['base_vars']['JP_BLOG_URL'] = 'http://www.j-cast.com/';
    $GLOBALS['base_vars']['JP_BLOG_SITE_PATH'] = '/home/httpd/webmaster-bus/NEWS/JP/';
    $GLOBALS['base_vars']['CN_BLOG_URL'] = 'http://cn.j-cast.com/';
    $GLOBALS['base_vars']['CN_BLOG_SITE_PATH'] = '/home/httpd/webmaster-bus/NEWS/CN/';
    $GLOBALS['base_vars']['TV_BLOG_URL'] = 'http://www.j-cast.com/tv/';
    $GLOBALS['base_vars']['TV_BLOG_SITE_PATH'] = '/home/httpd/webmaster-bus/NEWS/JP/tv/';
    $GLOBALS['base_vars']['MB_BLOG_URL'] = 'http://www.j-cast.com/m/';
    $GLOBALS['base_vars']['MB_BLOG_SITE_PATH'] = '/home/httpd/webmaster-bus/NEWS/JP/m/';
    $GLOBALS['base_vars']['MONO_BLOG_SITE_PATH'] = '/home/httpd/webmaster-bus/NEWS/JP/mono/';
    $GLOBALS['base_vars']['MONO_BLOG_URL'] = 'http://www.j-cast.com/mono/';
    $GLOBALS['base_vars']['KAISHA_BLOG_SITE_PATH'] = '/home/httpd/webmaster-bus/NEWS/JP/kaisha/';
    $GLOBALS['base_vars']['KAISHA_BLOG_URL'] = 'http://www.j-cast.com/kaisha/';
    $GLOBALS['base_vars']['JAPAN_BLOG_SITE_PATH'] = '/home/httpd/webmaster-bus/NEWS/JP/japan/';
    $GLOBALS['base_vars']['JAPAN_BLOG_URL'] = 'http://www.j-cast.com/japan/';
    $GLOBALS['base_vars']['SSL_BLOG_URL'] = 'https://ssl.j-cast.com';
    $GLOBALS['base_vars']['SSL_BLOG_SITE_PATH'] = '/home/httpd/webmaster-bus/NEWS/JP/';
    $GLOBALS['base_vars']['HONBAN'] = '1';
    $GLOBALS['base_vars']['COMMON_INC_DIR'] = '/home/httpd/webmaster-bus/NEWS/JP/include/common/';
    $GLOBALS['base_vars']['CUR_BLOG_ID'] = '12';

    // current access url & site
    if (isset($_SERVER['REQUEST_URI']) && $_SERVER['REQUEST_URI']) {
        $GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
    } else {
        $GLOBALS['REQUEST_URI'] = null;
    }
    if (preg_match("/(tv|mono|kaisha|other|motto|japan|skytree)/", $GLOBALS['REQUEST_URI'], $regs)) {
        $GLOBALS['REQUEST_SITE'] = $regs[1];
    } else {
        $GLOBALS['REQUEST_SITE'] = 'news';
    }
    if ($GLOBALS['REQUEST_SITE'] == 'other') {
        $GLOBALS['REQUEST_SITE'] = 'mono';
    }
    $GLOBALS['CUR_PAGE_TYPE'] = 'entry';

    //HTTP or HTTP
    if (isset($_SERVER['HTTPS'])) {
        $GLOBALS['base_vars']['IS_SSL'] = 1;
    } else {
        $GLOBALS['base_vars']['IS_SSL'] = 0;
    }

    // Load common functions
    $INC_DIR = '/home/httpd/webmaster-bus/NEWS/JP/' . 'include/common/';
    require_once($INC_DIR . 'common_funcs.php');
    require_once($INC_DIR . 'print_ad.php');
    require_once($INC_DIR . 'ad/pc_overture.php');

    // Web page is built for PC or Mobile ?
    $page_device_type = 'pc';
    $cur_blog_id = '12';
    // jcast_page.php からロードされる場合
    if (empty($page_device_type)) {
        $page_device_type = $this->pageDeviceType;
    }
    if (empty($cur_blog_id)) {
        $cur_blog_id = $this->curBlogId;
    }

    // PCページへきたモバイル端末およびモバイル用クローラーはモバイルページへ転送
   if ($page_device_type=='pc' && (isMobile() OR isCrawler('mobile'))) {
        $url = getSelfURL();
        $host = 'www.j-cast.com';
        // 互換性のため。旧版で有効
        $relative_url = '/weather/';
        // 新版で有効
        if (isset($this->curBlogRelativeUrl)) {
            $relative_url = $this->curBlogRelativeUrl;
        }
        $pat = '/(^.+' . $host . ')(' . preg_replace("/\//", "\/", $relative_url) . ')(m\/)*(.*$)/';
        if (preg_match($pat, $url, $regs)) {
            $redirect_url = sprintf("%s%sm/%s", $regs[1], $regs[2], $regs[4]);
            header("Location: $redirect_url");
            exit(0);
        }
    }


    if ($page_device_type=='mobile') {
        if (isMobile()) {
            if (!isMobileTargetTerminal() && !isCrawler('mobile')) {

            }
        } else {
            // 携帯以外の端末(PC, iPhone... etc..) には基本的に非表示。
            $showMobilePage = false;
            if (isCrawler('mobile')) {
                // モバイル用クローラー
                $showMobilePage = true;
            }
            if (!empty($_SERVER['REMOTE_ADDR']) && preg_match("/(192\.168|124\.32\.51\.90)/", $_SERVER['REMOTE_ADDR'])) {
                // 自社からのアクセス
                $showMobilePage = true;
            }
            // PCページへ転送
            if (!$showMobilePage) {
                if (preg_match("/(.*)\/m\/(.*)/", getSelfURL(), $regs)) {
                    $redirect_url = sprintf("%s/%s", $regs[1], $regs[2]);
                    header("Location: $redirect_url");
                    exit;
                }
            }
        }
    }

    if ($page_device_type=='mobile') {
        // LOAD AD SETTING FOR MOBILE
        $MB_AD_DIR = $GLOBALS["base_vars"]["JP_BLOG_SITE_PATH"] . "include/common/ad/";
        require_once($MB_AD_DIR . 'mb_overture_hs.php');
        require_once($MB_AD_DIR . 'mb_advantage.php');
        require_once($MB_AD_DIR . 'mb_opast.php');
        require_once($MB_AD_DIR . 'mb_micro_ad.php');


        $GLOBALS['ad']['impactPageId'] = mt_rand();

        // PUT ONLY MAIN CONTENTS FOR GOO CRAWLERS
        // ex) gooMobileADcrawler/0.2.2 , WakameCrawler/0.02(+http://help.goo.ne.jp/door/crawler.html)
        if (preg_match("/(gooMobileADcrawler|WakameCrawler)/", $_SERVER['HTTP_USER_AGENT'])) {
          $GLOBALS['ad']['IS_GOO_CRAWLER'] = true;
        } else {
          $GLOBALS['ad']['IS_GOO_CRAWLER'] = false;
        }
    }



    // PHP設定など
    ini_set('default_charset', 'UTF-8');
    if ($page_device_type=='pc') {
        // PC Site, Set the encoding and put header
        if (!defined('HEADER_SENT')) {
          ini_set('mbstring.internal_encoding', 'UTF-8');
          ini_set('mbstring.script_encoding', 'UTF-8');
          ini_set('mbstring.http_output', 'UTF-8');
          header('Content-Type: text/html; charset=UTF-8');
          define('HEADER_SENT', true);
        }
    } else {
        ini_set('mbstring.language', 'Japanese');
        ini_set('mbstring.internal_encoding', 'SJIS');
        ini_set('mbstring.script_encoding', 'auto');
        ini_set('mbstring.http_output', 'SJIS');
        ini_set('default_socket_timeout', 30);
    }

?>
*/


/** J-CASTニュース 全国・地域・地点ページ 天気表示
 * 
 * @author	nagnao@j-cast.com
 * @version	1.1
 * @date	2009-5-1
 * 
 */



$(function()
{
	// Weather Map View がドキュメント中に存在した場合、Weather Map View Controller オブジェクトを生成
	
	if ( $( 'div.container_weather_mapView' ).length>0 )
	{
		// create MapViewController
		weatherMapViewController			= new WeatherMapController();
		// set area (e.g. Hokkaido, Tokyo, etc...)
		weatherMapViewController.kindsOfMap	= $( 'div.container_weather_mapView' ).get(0).id.replace(/weather_mapView_/,'');
		// create IconBehavior
		$( 'li.weather_mapView_point_icons' )	.each	(function(){ this.behavior = new UIWeatherIcon ( this ); });
	}
	
	// set cookie
	if ( $( 'div.container_weather_detailView' ).length>0 )
	{
		var id	= $( 'div.container_weather_detailView' ).get(0).id;
		id		= id.substr( id.length-4, 4 )
		$.cookie ( 'weather', id, { expires:30, path:'/' } );
	}
	
	// adjutst balloon message position
	var balloonMessage			= $( '#weather_koalaView_balloon span:first' );
	var CENTER_OF_BALLOON		= 33;
	var balloonMessageHeight	= balloonMessage.height();
	var balloonMessageTop		= CENTER_OF_BALLOON - balloonMessageHeight * 0.5;
	balloonMessage	.css( 'top', balloonMessageTop )
					.animate({'opacity':1}, {duration:200});
	
});


/* Utility
 *
 */
function trace ( message )
{
	/*
	if ( window.console )	window.console.log( message );
	//else					$( '#watcher' ).append( message+'<br />' );
	else					$( '#watcher' ).html( message );
	*/
}
function iterator ( obj )
{
	/*
	var str	= '';
	for (var i in obj) {
		str	+= ( i+':  '+obj[i]+'\n' );
	}
	trace( str );
	*/
}


/* Extend
 *
 */
Array.prototype.indexOfValue	= function ( value )
{
	for ( var i=0; i<this.length; i++ ) {
		if ( value==this[i] )	return i;
	}
	return -1;
}


/* WeatherMapView を操作するルートクラス
	
	properties:::
	ANIME_SPEED						--	モーション継続時間
	ROOT_PATH						--	ルートのパス
	kindsOfMap						--	地図の種類（全国、各地方）
	view							--	UIViewManager （表示管理クラス）のインスタンス
	dayController, kindsController	--	タブスライダ操作クラスのインスタンス
	
 */
function WeatherMapController ()
{
	// static
	this.ANIME_SPEED		= 500;
	this.ROOT_PATH			= 'http://www.j-cast.com/';
	//this.ROOT_PATH			= ( String(document.location).indexOf('/weather/district/')==-1 ) ? '../' : '../../../';
	
	// kind of map (e.g. all, kanto-koshin, etc...)
	this.kindsOfMap			= '';
	
	// flag
	this.isLaunched			= false;
	
	// create objects
	// View
	this.view				= new UIViewManager ();
	// Controller: Day
	var initObj				= {	jqSelf	: $('#container_weather_mapView_controller_day'),
								owner	: this,
								view	: this.view,
								kinds	: 'day',
								src		: this.ROOT_PATH+'images/weather/ui/slidetab.png',
								width	: 199,
								height	: 27,
								offsetH	: 2,
								offsetV	: 2 };
	this.dayController		= new UISlideTabManager ( initObj );
	// Controller: Kinds (Weatehr & Rainfall Probability or Temperature)
	initObj.jqSelf			= $('#container_weather_mapView_controller_kinds');
	initObj.kinds			= 'kinds';
	this.kindsController	= new UISlideTabManager ( initObj );
	
	// default view (today or tomorrow) #container_weather_mapView_switching
	var container	= $('#container_weather_mapView_switching');
	this.isDefaultTomorrow = ( container.attr('class').indexOf('weather_mapView_switching_default_tomorrow') !== -1 );
	//alert('this.isDefaultTomorrow:  '+this.isDefaultTomorrow);
	////
	/*
	2009.5.7 nagano@j-cast.com
	this.isDefaultTomorrow	= false;
	try { if ( IS_DEFAULT_TOMORROW ) this.isDefaultTomorrow	= true; } catch(e) {};
	*/
}


/* スライダ管理クラスコンストラクタ
		画像の読み込みを行う
		画像読み込み完了後、初期化を行う
	
	properties:::
	SLIDE_INTERVAL		--	スライダタブボタン間の間隔
	jqSelf				--	自身の jQuery オブジェクト
	view				--	ビュークラス（地図の表示を行う）のインスタンス
	kinds				--	自身のスライダタブの種類（日 or 種類）
	jqButtons			--	配下のボタンの jQuery オブジェクト
	buttons				--	各ボタンクラスのインスタンスを格納する配列
	buttonValues		--	各ボタンの値を格納する配列
	buttonsLeft			--	各ボタンのY座標を格納する配列
	buttonCurrent		--	現在選択されているボタン
	width, height		--	自身のサイズ
	offsetH, offsetV	--	自身のオフセットサイズ（下地とボタン矩形の差）
	parts				--	グラフィックを構成する各 Image オブジェクトを格納
	zIndex				--	Z座標
	slider				--	スライダ管理クラスのインスタンス
	
 */
function UISlideTabManager ( initObj )
{
	this.SLIDE_INTERVAL	= 1;
	
	// initialize
	this.jqSelf			= initObj.jqSelf;
	this.view			= initObj.view;
	this.kinds			= initObj.kinds;
	
	// buttons
	this.jqButtons		= $( 'a', this.jqSelf );
	this.buttons		= new Array();
	this.buttonValues	= new Array();
	this.buttonsLeft	= new Array();
	this.buttonCurrent	= '';
	
	// figule data
	this.width			= initObj.width;
	this.height			= initObj.height;
	this.offsetH		= initObj.offsetH;
	this.offsetV		= initObj.offsetV;
	
	// prepare value
	this.parts			= new Object();
	this.zIndex			= Number( this.jqSelf.css( 'z-index' ) );
	this.slider;
	
	// load parts images
	var parts			= new Array( 'left', 'center', 'right', 'bg_left', 'bg_center', 'bg_right' );
	for ( var i=0; i<parts.length; i++ ) {
		var symbol					= parts[i];
		this.parts[ symbol ]		= new Image ();
		this.parts[ symbol ].src	= initObj.src.replace( /.png/, '_'+symbol+'.png' );
	}
	var self = this;
	this.timerID		= setInterval ( function() { self._partsLoadObserver(); }, 100 );
}
/* スライダ管理クラスプロトタイプ

	methods:::
	
	_partsLoadObserver()	--	画像の読み込みを監視し、読み込み終了後、初期化を行う
								Image.onload() を使用の場合、IE7 で同期に問題があるため、interval で監視
	
	_initialize()			--	初期化
								各種パーツの生成
								ビューに最初の値定義メッセージを送り、アプリ起動のきっかけとなる
	
	_createSlideGraphic()	--	スライダ、及び背景グラフィックの生成
	_TAG_COMPATIBILITY		--	上のための補助的な定数を格納
	
	_createButtons()		--	ボタンの生成、及び初期化
								ここで初期に選択されているボタンを定義しているが、
								「日」スライドタブであり、かつデフォルト表示が「明日」の場合、「今日」ではなく「明日」とする
	
	sendValue()				--	ボタンやスライダ等のUIパーツから値を受け、
								View に値と移動方向を、
								UIパーツ各種に値を送信する
								また、初期化時にも呼び、アプリ起動のきっかけとなる
	
 */
UISlideTabManager.prototype	= {
	
	_partsLoadObserver	: function ( img )
		{
			// checking load status
			var isLoaded	= true;
			for ( var i in this.parts ) { if ( ! this.parts[i].complete ) isLoaded = false; };
			// initialize
			if ( isLoaded ) {
				clearInterval( this.timerID );
				this._initialize();
			}
		},
		
	
	_initialize			: function ()
		{
			// create background
			this._createSlideGraphic( 'bg' );
			// create slide
			this._createSlideGraphic( 'slider' );
			
			// create button
			this._createButtons();
			
			// create slider behavior
			var slider	= $( '.ui_slidetab_slider', this.jqSelf );
			var initObj	= {	node			: slider.get(0),
							width			: this.sliderWidth,
							top				: this.offsetV,
							left			: this.offsetH,
							buttonValues	: this.buttonValues,
							buttonsLeft		: this.buttonsLeft,
							manager			: this }
			this.slider	= new UISlideTabSlider ( initObj );
			
			// launch view
			this.sendValue();
			this.jqSelf.css( 'visibility', 'visible' );
		},
	
	
	_createSlideGraphic	: function ( kinds )
		{
			// compatibility
			var elm			= this._TAG_COMPATIBILITY[ kinds ];
			var imgLeft		= this.parts[ this._TAG_COMPATIBILITY[ kinds ].LEFT ];
			var imgCenter	= this.parts[ this._TAG_COMPATIBILITY[ kinds ].CENTER ];
			var imgRight	= this.parts[ this._TAG_COMPATIBILITY[ kinds ].RIGHT ];
			switch ( kinds ) {
				case 'slider':
					this.sliderWidth	= Math.round ( (this.width-this.offsetH*2) / this.jqButtons.length ) - this.SLIDE_INTERVAL*(this.jqButtons.length-1);
					this.sliderHeight	= this.height - this.offsetV*2;
					var centerWidth		= this.sliderWidth - imgLeft.width - imgRight.width;
					break;
				case 'bg':
					var centerWidth		= this.width - imgLeft.width - imgRight.width;
					break;
			}
			// html
			var html		= '<'+elm.OPEN_TAG+' style="z-index:'+(this.zIndex+elm.Z_INDEX)+';">';
			html			+= '<img galleryImg="false" src="'+imgLeft.src+'" width="'+imgLeft.width+'" height="'+imgLeft.height+'" class="ui_slidetab_part_left" />';
			html			+= '<img galleryImg="false" src="'+imgCenter.src+'" width="'+centerWidth+'" height="'+imgCenter.height+'" style="left:'+imgLeft.width+'px;" class="ui_slidetab_part_center" />';
			html			+= '<img galleryImg="false" src="'+imgRight.src+'" width="'+imgRight.width+'" height="'+imgRight.height+'" class="ui_slidetab_part_right" />';
			html			+= '</'+elm.CLOSE_TAG+'>';
			// create
			this.jqSelf.prepend( html );
		},
	_TAG_COMPATIBILITY	:
		{		slider:
			{	LEFT		: 'left',		CENTER		: 'center',			RIGHT		: 'right',				Z_INDEX		: 200,
				OPEN_TAG	: 'a class="ui_slidetab_slider"',				CLOSE_TAG	: 'a' },
				bg:
			{	LEFT		: 'bg_left',	CENTER		: 'bg_center',		RIGHT		: 'bg_right',			Z_INDEX		: 100,
				OPEN_TAG	: 'div class="ui_slidetab_bg"',					CLOSE_TAG	: 'div' }
		},
		
	
	_createButtons		: function ()
		{
			// buttons setup
			var initObj			= new Object ({	owner	: this,
												zIndex	: this.zIndex+300,
												width	: this.sliderWidth,
												height	: this.height });
			var left			= ( this.width - this.offsetH*2 - this.sliderWidth - this.jqButtons.length*this.SLIDE_INTERVAL ) / (this.jqButtons.length-1);
			for ( var i=0; i<this.jqButtons.length; i++ ) {
				initObj.node	= this.jqButtons[i];
				initObj.order	= i;
				initObj.left	= this.offsetH + Math.round( left*i ) + i*this.SLIDE_INTERVAL;
				this.buttons[i]	= new UISlideTabButton ( initObj );
				this.buttonValues	.push ( this.buttons[i].value );
				this.buttonsLeft	.push ( initObj.left );
			}
			
			// deafult value
			// 2009.5.7 nagano@j-cast.com
			//var value	= 0;
			//try { if ( this.kinds=='day' && IS_DEFAULT_TOMORROW ) value	= 1; } catch(e) {};
			
			var value = ( this.kinds=='day' && weatherMapViewController.isDefaultTomorrow ) ? 1 : 0;
			this.buttonCurrent	= this.buttonValues[value];
			
		},
	
	
	sendValue			: function ( value )
		{
			// define value
			var posNew			= this.buttonValues.indexOfValue( value );
			var posCur			= this.buttonValues.indexOfValue( this.buttonCurrent );
			this.buttonCurrent	= ( value ) ? value : this.buttonCurrent;
			// direction
			switch ( true ) {
				case ( value==undefined )	: var direction	= 'static';	break;
				case ( posNew > posCur )	: var direction	= 'right';	break;
				case ( posNew < posCur )	: var direction	= 'left';	break;
				default						: var direction	= 'static';	break;
			}
			// message:
			// message change view
			this.view			.changeView ( this.kinds, this.buttonCurrent, direction );
			// message change button
			for ( var i=0; i<this.buttons.length; i++ ) {
				this.buttons[i]	.changeView ( this.buttonCurrent );
			}
			// message change slider
			this.slider			.changeView ( this.buttonCurrent );
		}
	
}


/* スライドタブ スライダクラス コンストラクタ
	
	properties:::
	self			--	対象の DOM
	jqSelf			--	対象の jQueryオブジェクト
	manager			--	親階層にあたる、管理クラス
	current			--	スライダの指し示すボタンの値
	eventCapture	--	マウスイベントを取得するための HTMLElement
	origLoc			--	原点座標
	buttonValues	--	UISlideTabManager に同じ
	buttonsLeft		--	UISlideTabManager に同じ
	width			--	自身の横幅
	
 */
function UISlideTabSlider ( initObj )
{
	this.self			= initObj.node;
	this.jqSelf			= $( this.self );
	this.manager		= initObj.manager;
	this.current;
	this.eventCapture;
	this.origLoc		= { top: initObj.top, left: initObj.left };
	//this.buttons		= initObj.buttons;
	this.buttonValues	= initObj.buttonValues;
	this.buttonsLeft	= initObj.buttonsLeft;
	this.width			= initObj.width;
	// substance
	this.self.behavior	= this;
	this.jqSelf.css({	'width'		: this.width,
						'top'		: this.origLoc.top,
						'left'		: this.origLoc.left });
	// create event capture
	this.jqSelf.parent().append( '<div class="eventCapture" style="width:'+this.jqSelf.width()+'px; height:'+this.jqSelf.height()+'px; top:'+this.origLoc.top+'px; left:'+this.origLoc.left+'px;"></div>' );
	this.eventCapture	= $( '.eventCapture', this.jqSelf.parent() );
	this.eventCapture.get(0).owner	= this;
	//
	this.eventCapture.draggable({	axis		: 'x',
									containment	: this.jqSelf.parent(),
									drag		: function(e,ui){this.owner._dragging(e,ui)},
									stop		: function(e,ui){this.owner._stopDragging(e,ui)} });
}
/* スライドタブ スライダクラス プロトタイプ
	
	methods:::
	
	changeView()	--	選択されたボタンが変更された際に呼ばれる
						スライダの選択しているボタンと異なる場合、移動を行う
	
	move()			--	選択されたボタン位置への移動を実行
	
	_dragging()		--	ドラッグ中に呼ばれる
						実際には自身ではなく、eventCapture がドラッグされているため、位置の追随を行う
						また、ボタン領域をまたぐと、自身の選択ボタンの更新と、管理クラスに選択したボタンの値を送信し、
						ライブでビューの切り換えを行う
	
	_stopDragging()	--	ドラッグ終了時に呼ばれる
	
 */
UISlideTabSlider.prototype	= {
	
	//weatherMapViewController.isLaunched
	
	changeView	: function( current )
	{
		if ( this.current != current ) {
			var duration = ( this.current==undefined ) ? 1 : weatherMapViewController.ANIME_SPEED*0.65; // 2009.5.7 nagano@j-cast.com
			this.current	= current;
			this.move( duration );
		}
	},
	
	
	move	: function( duration )
	{
		var left	= this.buttonsLeft[ this.buttonValues.indexOfValue(this.current) ];
		this.jqSelf			.animate(	{	'left': this.buttonsLeft[ this.buttonValues.indexOfValue(this.current) ] },
										duration );
										/*weatherMapViewController.ANIME_SPEED*0.65 );*/ // 2009.5.7 nagano@j-cast.com
		this.eventCapture	.css	(		'left', left );
	},
	
	
	_dragging	: function(e,ui)
	{
		try {
			var dragX	= Number( this.eventCapture.css('left').slice(0,-2) );
			this.jqSelf.css( 'left', dragX );
			for ( var i=0; i<this.buttonsLeft.length; i++ ) {
				if ( this.buttonsLeft[i]-this.width*0.5 < dragX && dragX < this.buttonsLeft[i]+this.width*0.5 ) {
					if ( this.buttonValues[i] != this.current ) {
						this.current	= this.buttonValues[i];
						this.manager.sendValue( this.buttonValues[i] );
					}
				}
			}
		} catch(e) {
		}
	},
	
	
	_stopDragging	: function(e,ui)
	{
		this.move();
	}
	
}


/* スライドタブボタンクラス コンストラクタ
	
	properties:::
	self			--	対象の DOM
	jqSelf			--	対象の jQueryオブジェクト
	owner			--	上位階層にあたる自身の所有者
	width, height	--	矩形情報
	value			--	自身のボタンの値
	_isVisible		--	表示されているか
	animeParam		--	モーション情報
	DURATION		--	モーションの継続時間
	images			--	自身の標準時とハイライト時のグラフィックを格納
	
 */
function UISlideTabButton ( initObj )
{
	// Class Value
	this.self			= initObj.node;
	this.jqSelf			= $( this.self );
	this.owner			= initObj.owner;
	this.width			= initObj.width;
	this.height			= initObj.height;
	this.value			= this.jqSelf.attr( 'href' ).replace( /#/, "" );
	this._isVisible;
	var imgWidth		= $( 'img', this.jqSelf ).width();
	var imgHeight		= $( 'img', this.jqSelf ).height();
	// anime
	this.animeParam		= new this.ANIME_PARAM ();
	this.DURATION		= ( $.browser.msie ) ? 1 : weatherMapViewController.ANIME_SPEED*0.6;
	// Tag Value
	this.self.behavior	= this;
	
	//
	this.jqSelf	.css		({	'left'		: Math.round( initObj.left + (this.width-imgWidth)*0.5 )+'px',
								'top'		: Math.round( (this.height-imgHeight)*0.5 )+'px',
								'z-index'	: initObj.zIndex
							})
				.bind		(	'click', function(e){this.behavior._click()} )
				.removeAttr	(	'href' );
	
	// image
	this.images			= {	normal		: $( 'img.ui_slidetab_button_n',	this.jqSelf ),
							highlight	: $( 'img.ui_slidetab_button_hl',	this.jqSelf ) };
}
/* スライドタブボタンクラス プロトタイプ
	
	methods:::
	ANIME_PARAM()	--	モーション情報を生成
						IE における透過処理がままならないので、分岐を行っている
	
	changeView()	--	選択されたボタンが変更された際に呼ばれる
						自身の表示状態の変更を行う
	
	_click()		--	クリック時に呼ばれる
						管理クラスに自身のボタンの値を送る
	
 */
UISlideTabButton.prototype	= {
	
	ANIME_PARAM				: function()
		{
			this.IN					= {	CSS		: {	visibility	: 'visible' },
										ANIMATE	: { left		: '+=0px' } };
			this.OUT				= {	CSS		: {	visibility	: 'visible' },
										ANIMATE	: { left		: '+=0px' } };
			if ( !$.browser.msie ) {
				this.IN.CSS.opacity			= 0;
				this.IN.ANIMATE.opacity		= 1;
				this.OUT.CSS.opacity		= 1;
				this.OUT.ANIMATE.opacity	= 0;
			}
		},
	
	
	changeView	: function( current )
	{
		if ( current==this.value ) {
			if ( this._isVisible==undefined || this._isVisible==false ) {
				if ( this.images.normal.queue().length==0 ) {
					this.images.normal		.css		(	this.animeParam.OUT.CSS );
					this.images.highlight	.css		(	this.animeParam.IN.CSS );
				} else {
					this.images.normal		.stop		();
					this.images.highlight	.stop		();
				}
				this.images.normal			.animate	(	this.animeParam.OUT.ANIMATE,
															{	duration	: this.DURATION,
																complete	: function(){$(this).css('visibility','hidden');} });
				this.images.highlight		.animate	(	this.animeParam.IN.ANIMATE,
															{	duration	: this.DURATION });
				this._isVisible	= true;
			}
		} else {
			if ( this._isVisible==undefined || this._isVisible==true ) {
				if ( this.images.normal.queue().length==0 ) {
					this.images.normal		.css		(	this.animeParam.IN.CSS );
					this.images.highlight	.css		(	this.animeParam.OUT.CSS );
				} else {
					this.images.normal		.stop		();
					this.images.highlight	.stop		();
				}
				this.images.normal			.animate	(	this.animeParam.IN.ANIMATE,
															{	duration	: this.DURATION });
				this.images.highlight		.animate	(	this.animeParam.OUT.ANIMATE,
															{	duration	: this.DURATION,
																complete	: function(){$(this).css('visibility','hidden');} });
				this._isVisible	= false;
			}
		}
	},
	
	
	_click	: function()
	{
		this.owner.sendValue( this.value );
	}
}


/* ビュー管理クラス コンストラクタ
	
	properties:::
	composition		--	選択されている日・種類のビュー
	VIEW_SELECTOR	--	配下のビュー（今日・明日・あさって、天気・気温の各ビュー）の jQuery セレクタ
	PREFIX			--	配下のビューの id 名の接頭辞
	INFIX			--	配下のビューの id 名の接中辞
	jqViews			--	配下のビューの jQuery オブジェクト
	views			--	配下のビューの表示情報などを格納
	
	methods:::
	changeView()	--	スライドタブ管理クラス（コントローラ）から呼ばれ、
						ビューの切り換えを行う
						composition の値の更新と、
						配下のビューに切換えをメッセージする
	
 */
function UIViewManager ()
{
	this.composition	= {	day		: '',
							kinds	: '' };
	this.VIEW_SELECTOR	= 'div.container_weather_mapView_switching';
	this.PREFIX			= 'container_weather_mapView_switching_';
	this.INFIX			= '_';
	//
	this.jqViews		= $( this.VIEW_SELECTOR );
	this.views			= new Array();
	
	for ( var i=0; i<this.jqViews.length; i++ ) {
		this.views[i]	= new UIView ( this.jqViews[i] );
		
		this.jqViews[i].isVisible		= false;
		this.jqViews[i].animeSpeed		= 700;
		this.jqViews[i].animeDistance	= { left: 540, right: -540, static: 0 };
	}
	this.jqViews	.bind ( 'onChangeView', function( e, kinds, direction ){ this.behavior._changeView( kinds, direction ) } );
	
	// change view
	this.changeView		= function( kinds, value, direction )
	{
		this.composition[kinds]	= value;
		this.jqViews	.trigger	( "onChangeView", [ this.PREFIX+this.composition.day+this.INFIX+this.composition.kinds, direction ] );
	}
}


/* ビュークラス コンストラクタ
	
	properties:::
	self			--	対象の DOM
	jqSelf			--	対象の jQueryオブジェクト
	animeParam		--	モーション情報
	
 */
function UIView ( node )
{
	this.self			= node;
	this.jqSelf			= $( node );
	this.self.behavior	= this;
	// anime
	this.animeParam		= {	right	: new this.ANIME_PARAM ( 'right' ),
							left	: new this.ANIME_PARAM ( 'left' ),
							static	: new this.ANIME_PARAM ( 'static' ) }
}
/* ビュークラス プロトタイプ
	
	properties:::
	_isVisible		--	表示されているか
	
	
	methods:::
	
	ANIME_PARAM		--	モーション情報の生成
	
	_changeView		--	ビュー管理クラスで onChangeView イベントとバインドされたメソッド
						表示の切り換えを行う
						引数が DOM の id と一致する場合し、非表示の場合、フェードイン
						不一致で表示されている場合、フェードアウトを行う
	
 */
UIView.prototype	= {
	// static
	ANIME_PARAM				: function( val )
		{
			this.ANIME_MOVE			= 540,
			this.IN					= {	CSS		: {	visibility	: 'visible',
													left		: 0 },
										ANIMATE	: {	left		: 0 } };
			this.OUT				= {	CSS		: {	visibility	: 'visible',
													left		: 0 },
										ANIMATE	: {	left		: 0 } };
			this.IN.CSS.left		+=  this.ANIME_MOVE*(val=='left') - this.ANIME_MOVE*(val=='right');
			this.OUT.ANIMATE.left	+= -this.ANIME_MOVE*(val=='left') + this.ANIME_MOVE*(val=='right');
			if ( !$.browser.msie ) {
				this.IN.CSS.opacity			= 0;
				this.IN.ANIMATE.opacity		= 1;
				this.OUT.CSS.opacity		= 1;
				this.OUT.ANIMATE.opacity	= 0;
			}
		},
		
	// initial
	_isVisible				: false,
	
	_changeView		: function ( kinds, direction )
		{
			/*
			2009.5.7 nagano@j-cast.com
			// specific case
			var isTodayWeatherAndDefaultTomorrow	=	(	(! weatherMapViewController.isLaunched)
														&&	this.self.id=='container_weather_mapView_switching_today_weather'
														&&	weatherMapViewController.isDefaultTomorrow );
			var isTomorrowWeatherAndDefaultTomorrow	=	(	(! weatherMapViewController.isLaunched)
														&&	this.self.id=='container_weather_mapView_switching_tomorrow_weather'
														&&	weatherMapViewController.isDefaultTomorrow );
			if ( isTodayWeatherAndDefaultTomorrow || isTomorrowWeatherAndDefaultTomorrow ) {
				direction							= 'right';
			}
			*/
			if ( this.self.id==kinds ) {
				// fade in
				if ( ! this.isVisible ) {
					//if ( weatherMapViewController.isDefaultTomorrow || weatherMapViewController.isLaunched ) { // 2009.5.7 nagano@j-cast.com
					if ( weatherMapViewController.isLaunched ) {
						if ( weatherMapViewController.isLaunched==false ) weatherMapViewController.isLaunched = true;
						if ( this.jqSelf.queue().length==0 )	this.jqSelf	.css		(	this.animeParam[direction].IN.CSS );
						else									this.jqSelf	.stop		();
						this.jqSelf		.animate	( this.animeParam[direction].IN.ANIMATE, weatherMapViewController.ANIME_SPEED );
					} else {
						weatherMapViewController.isLaunched = true;
					}
					this.isVisible	= true;
				}
			} else {
				// fade out
				//if ( this.isVisible || isTodayWeatherAndDefaultTomorrow ) {// 2009.5.7 nagano@j-cast.com
				if ( this.isVisible ) {
					if ( this.jqSelf.queue().length==0 )	this.jqSelf	.css		(	this.animeParam[direction].OUT.CSS );
					else									this.jqSelf	.stop		();
					this.jqSelf		.animate	( this.animeParam[direction].OUT.ANIMATE, weatherMapViewController.ANIME_SPEED );
					this.isVisible	= false;
				}
			}
		}
	
}


/* アイコンクラス コンストラクタ
	
	properties:::
	areaCode		--	自身の示す地域コード
	animeParam		--	モーション情報
	highlight		--	自身がホバーされた際にハイライトする要素を格納
	duration		--	モーションの持続時間
						IE の場合はモーションを行わないため、最小の持続時間とする
	
 */
function UIWeatherIcon ( node )
{
	this.self		= node;
	this.jqSelf		= $( node );
	this.areaCode	= this.self.id.slice( this.self.id.length-4, this.self.id.length );
	// anime
	this.animeParam	= new this.ANIME_PARAM ();
	this.highlight	= new Array();
	this.duration	= weatherMapViewController.ANIME_SPEED*0.3;
	// create hover image
	var	html		= '<img galleryImg="false" class="weather_mapView_point_icon_rectangle" src="'+weatherMapViewController.ROOT_PATH+'images/weather/ui/highlight.png" />';
	html			+= '<img galleryImg="false" class="eventCapture" src="'+weatherMapViewController.ROOT_PATH+'images/weather/ui/spacer.gif" />';
	html			+= '<img galleryImg="false" class="weather_mapView_point_icon_point" src="'+weatherMapViewController.ROOT_PATH+'images/weather/ui/point.png" />';
	html			+= '<img galleryImg="false" class="weather_mapView_point_icon_point weather_mapView_point_icon_point_highlight" src="'+weatherMapViewController.ROOT_PATH+'images/weather/ui/point_hl.png" />';
	//weather_mapView_point_icon_point_highlight
	$( 'a', this.self )	.append ( html );
	this.highlight.push( $( 'img.weather_mapView_point_icon_rectangle', this.self ) );
	this.highlight.push( $( 'img.weather_mapView_point_icon_point_highlight', this.self ) );
	// create map highlight
	var map			= (weatherMapViewController.kindsOfMap=='all') ? 'district' : 'todofuken';
	var path		= weatherMapViewController.kindsOfMap;
	var targetName	= WEATHER_AREADATA_POINTS[this.areaCode][map];
	if ( $( '#weather_mapView_highlight_area_'+targetName ).length==0 ) {
		var	html	= '<img galleryImg="false" id="weather_mapView_highlight_area_'+targetName+'" class="weather_mapView_point_icon_rectangle" src="'+weatherMapViewController.ROOT_PATH+'images/weather/highlight/'+path+'/'+targetName+'.gif" />';
		$( '#container_weather_mapView_highlight_area' ).append ( html );
	}
	this.highlight.push( $( '#weather_mapView_highlight_area_'+targetName ) );
	// mouse event
	this.jqSelf	.bind( 'mouseover',	function(e){this.behavior._mouseover( e )} )
				.bind( 'mouseout',	function(e){this.behavior._mouseout( e )} );
}
/* アイコンクラス プロトタイプ	
	
	methods:::
	ANIME_PARAM				--	モーション情報の生成
	_mouseover, _mouseout	--	自身がホバーされた際にハイライトする要素を格納
	
 */
UIWeatherIcon.prototype	= {
	
	ANIME_PARAM				: function()
		{
			this.IN					= {	CSS		: {	visibility	: 'visible' },
										ANIMATE	: { left		: '+=0px' } };
			this.OUT				= {	CSS		: {	visibility	: 'visible' },
										ANIMATE	: { left		: '+=0px' } };
			if ( !$.browser.msie ) {
				this.IN.CSS		.opacity	= this.OUT.ANIMATE	.opacity	= 0;
				this.IN.ANIMATE	.opacity	= this.OUT.CSS		.opacity	= 1;
			}
		},
	
	_mouseover				: function(e)
		{
			this.isHover	= true;
			for ( var i=0; i<this.highlight.length; i++ ) {
				if ( $.browser.msie ) {
						this.highlight[i]	.css( 'visibility', 'visible' );
				} else {
					if ( this.highlight[i].queue().length==0 )	this.highlight[i]	.css		(	this.animeParam.IN.CSS );
					else										this.highlight[i]	.stop		();
																this.highlight[i]	.animate	(	this.animeParam.IN.ANIMATE,
																									{ 	duration	: this.duration } );
				}
			}
		},
	
	_mouseout				: function(e)
		{
			this.isHover	= false;
			for ( var i=0; i<this.highlight.length; i++ ) {
				if ( $.browser.msie ) {
						this.highlight[i]	.css( 'visibility', 'hidden' );
				} else {
					if ( this.highlight[i].queue().length==0 )	this.highlight[i]	.css		(	this.animeParam.OUT.CSS );
					else										this.highlight[i]	.stop		();
																this.highlight[i]	.animate	(	this.animeParam.OUT.ANIMATE,
																									{	duration	: this.duration,
																										complete	: function(){$(this).css('visibility','hidden');} });
				}
			}
		}
		
}


