$j = jQuery.noConflict();

(function($){ //$ = jQuery
$(function(){ //jQuery.ready


var $main = $('#mainContents');
var $side = $('#sidebar');


/*gNav*/
$('#gNavList')
	.pageInit({
		'.siteIndex': 		'#gNav01',
		//news
		'.fxnews': 			'#gNav02',
		'.china': 			'#gNav02',
		'.yucasee': 		'#gNav02',
		'.news': 			'#gNav02',
		//report
		'.klugreport': 		'#gNav03',
		'.fxreview': 		'#gNav03',
		'.fxreport': 		'#gNav03',
		'.commodity': 		'#gNav03',
		'.crudeoil': 		'#gNav03',
		'.au': 				'#gNav03',
		'.marubeni': 		'#gNav03',
		//blog(fx)
		'.yamaoka': 		'#gNav04',
		'.mizukami': 		'#gNav04',
		'.nishihara': 		'#gNav04',
		'.kanai': 			'#gNav04',
		'.fxss': 			'#gNav04',
		'.president': 		'#gNav04',
		'.forecast': 		'#gNav04',
		'.takano':          '#gNav04',
		//blog(economy)
		'.klugview': 		'#gNav05',
		'.mitsuhashi': 		'#gNav05',
		'.ogasawara': 		'#gNav05',
		'.masutani': 		'#gNav05',
		'.tomita': 			'#gNav05',
		'.kowloon': 		'#gNav05',
		//chart
		'.fxChartNew': 		'#gNav06',
		'.fxChart': 		'#gNav06',
		'.scChart': 		'#gNav06',
		'.us_stocks': 		'#gNav06',
		'.indexcal': 		'#gNav06',
		'.holiday': 		'#gNav06',
		//tool
		'.seminar': 		'#gNav07',
		'.correlation': 	'#gNav07',
		'.worldclock': 		'#gNav07',
		'.video': 			'#gNav07',
		'.kfi': 			'#gNav07',
		'.kfi': 			'#gNav07',
		//data
		'.interestrate': 	'#gNav08',
		'.member': 			'#gNav08',
		'.book': 			'#gNav08',
		'.glossary': 		'#gNav08',
		'.enquete': 		'#gNav08',
		//compare
		'.com_compare': 	'#gNav09',
		'.swappoint': 		'#gNav09'
	}, function(){
		$(this).addClass('active');
	})
	.chimg({autoActive:true})
	.find('> li')
		.each(function(){
			var $this = $(this);
			var $sub = $this.find('> div');
			var $iframe = $('<iframe scrolling="no" frameborder="0"></iframe>');
			$sub.before($iframe);
			
			$this
				.hover(function(){
					$iframe.show();
					$sub.show();
				}, function(){
					$iframe.hide();
					$sub.hide();
				})
			
		});


/*hdr_fxnewsBox*/
var $hdr_fxnewsBox = $('#hdr_fxnewsBox');
if($hdr_fxnewsBox.length){
	
	window.hdr_fxNews_callback = function(str){
		$hdr_fxnewsBox.html(str);
	};
	
	var $head = $('head');
	
	var insert_hdr_fxnewsBox_js = function(){
		$('#hdr_fxNews_js').remove();
		var $hdr_fxNews_js = $("<script></script>")
			.attr({
				  'type' : 'text/javascript'
				, 'id' : 'hdr_fxNews_js'
				, 'src' : 'http://www.gci-klug.jp/_common/inc/hdr_fxNewsBox.js' + '?' + (new Date()).getTime()
				, 'charset' : 'UTF-8'
			});
		$hdr_fxNews_js.appendTo($head);
	};
	
	insert_hdr_fxnewsBox_js();

	setInterval(function(){
		insert_hdr_fxnewsBox_js();
	}, 1000 * 60 * 5);
	
}


/*ftrNav*/
$('#ftrNav')
	.chimg();


/*answerBtn*/
$('#answerBtn')
	.chimg()
	.css('margin-top', '5px');


/*** tableColor ***/
$('table', $main)
	.filter('.coloredRow, .swappointTbl')
		.stripe();


/*iframe*/
$('ins')
	.find('ins, iframe')
	.andSelf()
		.css('position', 'static');




/*** その他 ***/


//丸紅レポート PDFリンク
$("body.marubeni .entryBody a[href$='.pdf']")
	.addClass('iconLinkPdfBig');


//ランキング 6位～
$('body.newsRanking .oListStyle03 > li')
	.each(function(i, v){
		i = i + 6;
		var num = i < 10 ? "0" + i : i;
		$(this).css("background-image", 'url("../_common/img/icon_num_'+ num +'.gif")');
	});


//為替レート＆時計表示
$("#fxRateIframe")
	.each(function(){
		var width = 218;
		if($("body").is(".siteIndex")){
			width = 268;
		}
		
		var $clock = $('<div id="clock"></div>').css('margin-top', '3px').clock();
		
		$(this)
			.html('<iframe src ="http://rate.fxcm.co.jp/rate/blog.html" width="250" height="270" frameborder="0" scrolling="no" name="fxRateFrame"></iframe>')
			.after($clock)
	});

/*
//リロード停止 2011/07/04
var $body = $('body');
if($body.is('#fxnews-index') || $body.is('.siteIndex')){
	setTimeout(function(){
		location.href = location.href;
	}, 1000 * 60 * 5);
}
*/

}); // END jQuery.ready



/*時計表示*/
$j.fn.clock = function(ts){
	var $this = this;
	
	function dispTime(ts){
		var d = new $.Date(ts);
		$this.html(d.date("/") +" "+ d.h +":"+ d.m);
	}
	dispTime(ts);
	var timer = setInterval(function(){
		dispTime(ts + 1000);
	}, 1000);
	
	return $this;
};





/*カレンダー表示*/
window.loadCalendar = function(path){
	if(!path) return;
	var d = new $.Date();
	//path = path + "?" + d.now();
	$('#sideCalendarContents').load(path, function(){
		var today = d.date();
		$(this).find('#cal-' + today).addClass('today');
	});
};


/*MSIE*/
window.isMSIE = /*@cc_on!@*/false; 



/*overture*/
window.overture = (function(){
	var lines;
	
	var parse = function(){
		if(!window.zSr || window.zSr.length < 7) return false;
		var ret = [], ad = {};
		var zsr = window.zSr;
		for(var i = 6, l = zsr.length; i < l; i++){
			ad = {};
			
			ad.desc = zsr[i++];
			i++;
			ad.url = zsr[i++];
			ad.title = zsr[i++];
			ad.visible_url = zsr[i++];
			
			ret.push(ad);
		}
		return ret;
	};
	
	return {
		  init: function(params){
			if(lines && lines.length) return;
			params = $.extend({
				  source: 'ecnavi_jp_klug_im'
				, type: 'type1'
				, ctxtKeywords: 'fx,外為,外為比較,外為口座開設'
				, ctxtId: ["fin0201", "fin0202", "fin0203", "fin0204", "fin0205"]
				, ctxtUrl: document.URL
				, ref: document.referrer
				, keywordCharEnc: 'utf8'
				, outputCharEnc: 'utf8'
				, gen: 'M'
				, age: '30'
				, maxCount: 6
			}, params);
			ids = params.ctxtId;
			params.ctxtId = $.isArray(ids) ? ids[Math.floor(Math.random() * ids.length)] : ids;
			var src = [
				  'http://im.ecnavi.ov.yahoo.co.jp/js_flat/'
				, $.param(params)
			].join('?');
			document.write(['<script type="text/javascript" src="', src, '"></s', 'cript>'].join(''));
		}
		
		, parse: parse
		
		, write_html: function(options){
			lines = lines || parse();
			var html = [], line;
			$.extend({
				  type: 1
			}, options)
			var limit = options.limit;
			limit = limit ? Math.min(lines.length, limit) : lines.length;
			
			switch(options.type){
				case 'listStyle01':
					html.push('<ol class="listStyle01">');
					for(var i = 0; i < limit; i++){
						line = lines.shift();
						html = html.concat([
							  '<li><a href="', line.url, '" class="a">'
							, ['	<span class="div title"><span class="a">', line.title, '</span><span class="visibleUrl">', line.visible_url, '</span></span>'].join('')
							, ['	<span class="div desc">', line.desc, '</span>'].join('')
							, '</a></li>'
						]);
					}
					html.push('</ol>');
					break;
				case 2:
					html.push('<ul class="float listStyle01">');
					for(var i = 0; i < limit; i++){
						line = lines.shift();
						html = html.concat([
							  '<li><a href="', line.url, '" class="a">'
							, ['	<span class="div title"><span class="a">', line.title, '</span></span>'].join('')
							, ['	<span class="div desc">', line.desc, '</span>'].join('')
							, ['	<span class="div visibleUrl">', line.visible_url, '</span>'].join('')
							, '</a></li>'
						]);
					}
					html.push('</ul>');
					break;
				case 1:
				default:
					html.push('<ol class="noIconList">');
					for(var i = 0; i < limit; i++){
						line = lines.shift();
						html = html.concat([
							  '<li><a href="', line.url, '" class="a">'
							, ['	<span class="div title"><span class="a">', line.title, '</span><span class="visibleUrl">', line.visible_url, '</span></span>'].join('')
							, ['	<span class="div desc">', line.desc, '</span>'].join('')
							, '</a></li>'
						]);
					}
					html.push('</ol>');
					break;
			}
			document.write(html.join("\n"));
		}
	};
	
	
})();



})(jQuery); // END $ = jQuery

