	$(document).ready(function(){
		if($('ul', '#sp').height()>278) {
			$('ul', '#sp').css({"height":"280px"});
		} else {
			$('ul', '#sp').css({"height":"auto"});
		}
		
		if($('ul', '#vt').height()>278) {
			$('ul', '#vt').css({"height":"280px"});
		} else {
			$('ul', '#vt').css({"height":"auto"});
		}
		
		$('#dropdown li.headlink').hover(
			function() { $('ul', this).show(); },
			function() { $('ul', this).hide(); 
		});
		
		$('#sp li').click(function(){
			if(!C1) C1 = "#FFFFFF";
			if(!C2) C2 = "#CCCCCC";
			$('a', this).blur();
			$('#vt').css({"background-color":C1});
			$('#sp').css({"background-color":C2});
			$('#vt li').attr({'class' : 'inactive'});
			$('#sp li').attr({'class' : 'inactive'});
			$(this).attr({'class' : 'active'});
		        var url = $('a', this).attr('href');
			var el = $(this).parents('li.headlink');
			$('#inside_stage').fadeOut('normal', function() {
				/*if ($.browser.msie) {*/
					$('#name').text($('li.active').text());
					$('#flashcontent').hide();
					$('#imagecontent').html('<div style="overflow:hidden;height:600px;width:900px;top: 50%;left: 50%;display: table-cell; vertical-align: middle;"><img src="'+url+'" border="0" /></div>');
					$('#imagecontent').show();
					if($('li', el).size()==1) { $('#prev, #next').hide(); } else { $('#prev, #next').fadeTo('fast', 0.5); }
					$('#inside_stage').fadeIn('normal');				
				/*} else {
					$.get(url, function(){
						$('#name').text($('li.active').text());
						$('#flashcontent').hide();
						$('#imagecontent').html('<div style="overflow:hidden;height:600px;width:900px;top: 50%;left: 50%;display: table-cell; vertical-align: middle;"><img src="'+url+'" border="0" /></div>');
						$('#imagecontent').show();
						if($('li', el).size()==1) { $('#prev, #next').hide(); } else { $('#prev, #next').fadeTo('fast', 0.5).css('display', 'block'); }
						$('#inside_stage').fadeIn('normal');					
					});
				}*/
			});
			return false;
		});
		
		$('#vt li').click(function(){
			if(!C1) C1 = "#FFFFFF";
			if(!C2) C2 = "#CCCCCC";
			$('a', this).blur();
			$('#sp').css({"background-color":C1});
			$('#vt').css({"background-color":C2});
			$('#sp li').attr({'class' : 'inactive'});
			$('#vt li').attr({'class' : 'inactive'});
			$(this).attr({'class' : 'active'});
		        var url = $('a', this).attr('href');
		        var xml = $('a', this).attr('rel');
			var el = $(this).parents('li.headlink');
			$('#inside_stage').fadeOut('normal', function() {
				var uri = window.location.href
				var regexp =/pano=(\S+)/;
				if(uri.indexOf("pano=")<0) {
					window.location = uri+"&pano="+xml;
				} else {
					window.location = uri.replace(regexp,"pano="+xml);
				}
				if($('li', el).size()==1) { $('#prev, #next').hide(); } else { $('#prev, #next').fadeTo('fast', 0.5).css('display', 'block'); }	
			});
			return false;
		});
	
		$('#prev').click(function() {
			var el = $('li.active').parents('li.headlink');
			var index = $('li', el).index($('.active'));
			if(index<=0) { $('li:last', el).trigger("click"); }
			$('li', el).eq(index-1).trigger("click");
		});
		
		$('#next').click(function() {
			var el = $('li.active').parents('li.headlink');
			var index = $('li', el).index($('.active'));
			if(index+1>=($('li', el).size())) { $('li:first', el).trigger("click"); }
			$('li', el).eq(index+1).trigger("click");
		});
	});
