
(function($){

	$(document).ready(function(){

		// rollover.
		$('#header img.over, #gnav img.over').each(function(){
			// preload image.
			var img = new Image();
			img.src = this.src.replace(/^(.+)(\.[a-z]+)$/, '$1_on$2');
			$(this)
				// store the image sources.
				.data('image', {
					defaultSrc: this.src,
					hoverSrc: img.src
				})
				.hover(
					function(){
						this.src = $(this).data('image').hoverSrc;
					},
					function(){
						this.src = $(this).data('image').defaultSrc;
					}
				);
		});

		// status current.
		$('#header img.on, #gnav img.on').each(function(){
			this.src = this.src.replace(/^(.+)(\.[a-z]+)$/, '$1_on$2');
		});


		$('#aside div.contact a, #contact a').click(function(){
			window.open(this.href, 'winvisit', 'status=no,toolbar=no,location=no,menubar=no,scrollbars=yes,resizable=yes,width=750,height=650');return false;
		});

		$('#main div.about a, #about a').click(function(){
			window.open(this.href, 'winvisit', 'menubar=yes,toolbar=no,location=yes,status=yes,scrollbars=no,resizable=no,width=780,height=650');return false;
		});

		$('#main div.fair0515 a, #fair0515 a').click(function(){
			window.open(this.href, 'winvisit', 'menubar=yes,toolbar=no,location=yes,status=yes,scrollbars=yes,resizable=yes,width=980,height=800');return false;
		});
		
		
		$('#other div.other_20 a, #other_20 a').click(function(){
			window.open(this.href, 'winvisit', 'menubar=0,toolbar=no,location=0,status=0,scrollbars=0,resizable=0,width=700,height=600');return false;
		});

		$('#main div.fair_sp a, #fair_sp a').click(function(){
			window.open(this.href, 'winvisit', 'menubar=yes,toolbar=no,location=yes,status=yes,scrollbars=yes,resizable=yes,width=700,height=800');return false;
		});

		$('#main div.fair_20 a, #fair_20 a').click(function(){
			window.open(this.href, 'winvisit', 'menubar=0,toolbar=no,location=0,status=0,scrollbars=0,resizable=0,width=700,height=600');return false;
		});

		$('#main div.autumn a, #autumn a').click(function(){
			window.open(this.href, 'winvisit', 'menubar=yes,toolbar=no,location=yes,status=yes,scrollbars=yes,resizable=yes,width=980,height=800');return false;
		});
		
		$('#main div.ic a, #ic a').click(function(){
			window.open(this.href, 'winvisit', 'menubar=yes,toolbar=no,location=yes,status=yes,scrollbars=yes,resizable=yes,width=774,height=700');return false;
		});
		
		$('#other div.other_fair a, #other_fair a').click(function(){
			window.open(this.href, 'winvisit', 'menubar=yes,toolbar=no,location=yes,status=yes,scrollbars=yes,resizable=yes,width=700,height=800');return false;
		});

			// popup (width: 700px)
		$("#topics a.popup, #content a.popup, #search a.popup").click(function(i){
			this.src = window.open(this.href,'_blank','status=no, toolbar=no, location=no, menubar=no, scrollbars=yes, resizable=no, width=717,');return false;
		});

		// popup2 (width: 700px)
		$("#topics a.popup2, #content a.popup2, #search a.popup2").click(function(i){
			this.src = window.open(this.href,'_blank','status=no, toolbar=no, location=no, menubar=no, scrollbars=yes, resizable=no, width=717,height=700');return false;
		});

		// show party report.
		$('#aside div.report ul a[rel=view]')
			.colorbox({
				iframe: true,
				width: 660,
				height: 553,
				opacity: 0.6,
				overlayClose:false
			},
			// load completed.
			function(){
				// for ie...
				if ($.browser.msie) {
					var iframe = $('#cboxIframe').get(0);
					if (iframe.readyState !== 'complete') {
						// wait for ready.
						setTimeout(arguments.callee, 100);
						return;
					}
					setIframeClose(iframe.contentWindow.document);
				}
				// other browser.
				else {
					$('#cboxIframe')
						.bind('load.colorbox', function(){
							setIframeClose(this.contentWindow.document);
						})
						.trigger('load.colorbox')
					;
				}
			})
		;

	});

	function setIframeClose(context)
	{
		$('p.close a', context).bind('click.close', function(){
			$(this).unbind('click.close');
			$.fn.colorbox.close();
			return false;
		});
	}

	$(window).load(function(){

		if ($.browser.msie && $.browser.version < 7) {
			// set parent heights for colorbox.
			$('html, body').css('height', '100%');
		}

	});

})(jQuery);

