//Avoid flash of unformated content 
//Use in combination with the no-js-blink class
$('html').addClass('js');

$(document).ready( function()
{	
	$('.image-replace').jQIR();
	wejWe.imageRollover.init();
	
	$("#SubNavigation li:last").css("border-bottom", "none");
	/* Q&A */
	$("ul.Block-border li:last").css("background", "none");
	/* Map */
	$("ul.Map-photos li:last").css("margin-right", "0");
	/*$(window).resize( function(){
		if( $(window).width() <= 950 ){
			$('#swf').css({ width: 950 });
		}
		else{
			$('#swf').css({ width: '100%' });
		}
	});*/
	
	if( $('#swf').length ){
		$('#swf').css({ background: '#fff' });
		$('#swf #swf-container-size').css({ height: '285px' , width: '635px', background: '#fff', margin: '0px auto 15px auto', display: 'none' });
		$('#swf img').wrap('<a id="swf-switch" href="#"></a>');
		$('#swf #swf-switch').click( function(){
			$('#swf #swf-container-size').css({ display: 'block' });
			$('#swf #swf-switch').css({ display: 'none' });

			var flashvars = {};
			swfobject.embedSWF( "flash/video_wall_tiny.swf", "swf-container", "635", "285", "8.0.0", "", flashvars, {menu: "false",scale:"noscale",wmode:"transparent"}, {id: "swf-container"} );
			
			return false;
		});
	}
});

function FlashOff(){
	
	if( $('#swf').length ){
		$('#swf').css({ background: '#fff' });
		$('#swf #swf-container-size').css({ height: '285px' , width: '635px', background: '#fff', margin: '0px auto 15px auto', display: 'none' });
		$('#swf img').wrap('<a id="swf-switch" href="#"></a>');
		$('#swf #swf-switch').css({ display: 'block' });
		$('#swf #swf-switch').click( function(){
			$('#swf #swf-container-size').css({ display: 'block' });
			$('#swf #swf-switch').css({ display: 'none' });

			var flashvars = {};
			swfobject.embedSWF( "flash/video_wall_tiny.swf", "swf-container", "635", "285", "8.0.0", "", flashvars, {menu: "false",scale:"noscale",wmode:"transparent"}, {id: "swf-container"} );
			
			return false;
		});
	}
}

/*-----------------------------
 image RollOver
-----------------------------*/
wejWe = {};
wejWe.imageRollover =
{
	init: function(){
		
		this.preload();

		$(".rollover").hover(
			function () { $(this).find("img").attr( 'src', wejWe.imageRollover.newimage($(this).find("img").attr('src')) ); },
			function () { $(this).find("img").attr( 'src', wejWe.imageRollover.oldimage($(this).find("img").attr('src')) ); }
		);
	},

	preload: function(){
		$(window).bind('load', function() {
			$('.rollover').each( function( key, elm ) { $('<img>').attr( 'src', wejWe.imageRollover.newimage( $(this).find("img").attr('src') ) ); });
		});
	},

	newimage: function( src ){
		return src.substring( 0, src.search(/(\.[a-z]+)$/) ) + '_OV' + src.match(/(\.[a-z]+)$/)[0];
	},

	oldimage: function( src ){
		return src.replace(/_OV\./, '.');
	}
};

/*-----------------------------
 Page top
-----------------------------*/
var pagelink = new Object();
pagelink.timer = null;
pagelink.pos = 0;

pagelink._scrollToPageTop = function(){

	if(pagelink.pos > 0){
		pagelink.pos = Math.floor(pagelink.pos * 0.5);

		window.scrollTo(0, pagelink.pos);
		pagelink.timer = setTimeout('pagelink._scrollToPageTop();',25);
	}

	else{
		clearTimeout(pagelink.timer);
	}
}

pagelink.scrollToPageTop = function(){
	if(typeof(window.pageYOffset) != 'undefined'){
		pagelink.pos = window.pageYOffset;
	}

	else if(typeof(document.documentElement) != 'undefined' && typeof(document.documentElement.scrollTop) != 'undefined'){
		pagelink.pos = document.documentElement.scrollTop;
	}

	if(pagelink.pos > 0){
		pagelink._scrollToPageTop();
	}

	else{
		window.scrollTo(0, 0);
	}

}

/*-----------------------------
 Page top
-----------------------------*/

$(function(){
  $('.toc li:odd').addClass('list-on');
  $('.toc li:even').addClass('list-off');
});

$(function(){
  $('.infolist li:odd').addClass('list-on');
  $('.infolist li:even').addClass('list-off');
});

