// JavaScript Document
isIE6 = $.browser.msie && $.browser.version < 7 && !window.XMLHttpRequest,
$(document).ready(function(){
	//alert('a');
	//popMap();
	//popArtWorks();
	videoUploadWrap();
	homeContentVideo();
	hallSelect();
	mapPrint();
	cLeftBar2a();
	imgBoxLI();
});

function imgBoxLI(){
	$("a[rel=group1]").fancybox({
			'opacity'		: true,
			'centerOnScroll': true,
			'padding':0,
			'margin':0,
			'overlayColor':'#000',
			'overlayOpacity':0.9,
			'transitionIn'	: 'fade',
			'transitionOut'	: 'fade',
			'titlePosition' : 'over'
		});
}


function cLeftBar2a(){
	$('#cLeftBar > li > a').click(function(){
		$('#cLeftBar  > li > a').removeClass('sel');
		$('#testListsLeft > .sel').removeClass('sel');
		$('#testListsRight > .sel').removeClass('sel');
		$(this).addClass('sel');
		$($(this).attr('href')).addClass('sel');
		$($(this).attr('href')).next('.testListAuthor').addClass('sel');
	});
	
	if($('#cLeftBar > li > a').length >0  && $('#cLeftBar > li > .sel').length==0){
		var url='';
		var id='';
		if(window.location.href) url= window.location.href;
		else if(window.location) url= window.location;
		else if(location.href) url= location.href;
		else if(parent.location.href) url= parent.location.href;
		else if(top.location.href) url= top.location.href;
		else if(document.location.href) url= document.location.href;
		var ua=url.split('#');
		if(ua.length>0 && $('#cLeftBar > li > a[href="#'+ua[1]+'"]').length){
			$('#cLeftBar > li > a[href="#'+ua[1]+'"]').addClass('sel');
			id='#'+ua[1];
			$(id).addClass('sel');
			$(id).next('.testListAuthor').addClass('sel');
		}
		
	}
	

}

function mapPrint(){
	$('#mapPrint > a,#googleMapPrint').click(function(){
		var height=$(this).attr('height');
		var width=$(this).attr('width')
		var x=window.open("","gainover","width="+width+",height="+height+",top=10,left=10"); 
		x.document.write('<style>html,body{ padding:0; margin:0; position:relative; width:100%; height:100%; color:#333333; background:#e9e5da}</style><img src="'+$(this).attr('value')+'" width="'+width+'" height="'+height+'"></img>');
		x.document.write('<script>window.print();</script>')
		x.document.close();    
		return false;	
	});
}

function hallSelect(){
	$('#hallSelect > select').change(function(){
		$('.hallTabData').show();
		$('.hallTab').show();
		$('.hallTitle').show();
		
		var v=$(this).attr('value');
		if(v!=''){
			var ind=0;
			var type=v.substr(0,1);
			var key=v.substr(1);
			if(type=='s') ind=6;
			else if(type=='e') ind=7;
			if(ind>0){
				$('.hallTabData').hide();
				$('.hallTabData').each(function(){
					if($(this).find('td').eq(ind).text()==key)
						$(this).show();
				});
			}
			
			$('.hallTab').each(function(){
				if($(this).find('.hallTabData:visible').length==0){
					$(this).hide();
					$(this).prev('.hallTitle').hide();
				}
			});
				
			
		}
	});
}

function homeContentVideo(){
	if($('#homeContentVideo').is('a')){
		$('body').append('<div id="jsInBody"><div id="jsVideo"></div></div>');
		$('#jsInBody').hide();
		$('#homeContentVideo').attr('href','#jsVideo');
		$("a#homeContentVideo").fancybox({
			'opacity'		: true,
			'centerOnScroll': true,
			'padding':0,
			'margin':0,
			'overlayColor':'#000',
			'overlayOpacity':0.9,
			'transitionIn'	: 'fade',
			'transitionOut'	: 'fade',
			'width': 560,
			'height': 349,
			'onComplete':function(){
				var flashvars = {
					'file':                 $('#homeContentVideo').attr('value'),
					'image':                $('#homeContentVideo').attr('img'),
					'autostart':            'false',
					'shuffle':              'false',
					'linktarget':            '_self',
					'width': 560,
					'height': 349
				};
				var params ={
					'allowfullscreen':      'true',
					'allowscriptaccess':    'always',
					'bgcolor':              '#000000',
					'width': 560,
					'height': 349
				};
				
				var attributes = {};
				swfobject.embedSWF("/js/player.swf", 'jsVideo', "560", "349", "8.0.0", "/js/expressInstall.swf", flashvars, params, attributes);
			}
		});
	}
	
}


function videoUploadWrap(){
	if($('.videoUploadWrap').length>0){
		$('.videoUploadWrap').each(function(){
			var flashvars = {
				'file':                 $(this).attr('value'),
				'image':                $(this).attr('img'),
				'autostart':            'false',
				'shuffle':              'false',
				'linktarget':            '_self'
			};
			var params ={
				'allowfullscreen':      'true',
				'allowscriptaccess':    'always',
				'bgcolor':              '#000000'
			};
			
			var attributes = {};
			swfobject.embedSWF("/js/player.swf", $(this).find('div').attr('id'), "560", "349", "8.0.0", "/js/expressInstall.swf", flashvars, params, attributes);

		});
	}
}



function URLdecode(str) {
     var ret = "";
     for(var i=0;i<str.length;i++) {
         var chr = str.charAt(i);
         if(chr == "+") {
             ret += " ";
         }else if(chr=="%") {
             var asc = str.substring(i+1,i+3);
             if(parseInt("0x"+asc)>0x7f) {
                 ret += decodeURI("%"+ str.substring(i+1,i+9));
                 i += 8;
             }else {
                 ret += String.fromCharCode(parseInt("0x"+asc));
                 i += 2;
             }
         }else {
             ret += chr;
         }
     }
     return ret;
 }
 
