﻿(function($){
	 $(document).ready(function(){
		//show submenu
		(function(){
			var as = $('#navigator>ul>li>a'),items = $('#navigator>ul>li'),nIndex = items.index($('#navigator>ul>li.current')),subItems = $('#submenu_inner ul'),timer = null;
			as.each(function(i){
				$(this).bind('mouseover',function(){
					$('#submenu_inner').show();
					$('#main').css('padding-top',0)
					items.removeClass('current').eq(i).addClass('current').end().find('span').removeClass('show').eq(i).addClass('show');
					var spanWidth = $(this).parent().find('span').width();
					var off = $(this).parent().find('span').offset();
					//document.title = (off.left+spanWidth/2) + ':' + off.top;
					subItems.hide().eq(i).show();
				});
			});
			
			function hideSubmenu(){
				timer = setTimeout(function(){
					$('#submenu_inner').hide();
					$('#main').css('padding-top',30);
					items.removeClass().eq(nIndex).addClass('current').end().find('span').removeClass('show')/* .eq(nIndex).addClass('show') */;
					subItems.hide().eq(nIndex).show()
				},100);
			}
			$('#header').bind('mouseout',hideSubmenu);
			$('#header_search').bind('mouseover',hideSubmenu);
			
			$('#header').bind('mouseover',function(){
				if(timer) clearTimeout(timer);
			})
			$()
		})();
		
		
		//set footer to center
		(function(){
			var pWidth = $('#footer_inner p').width(), ulWidth = $('#footer_inner ul').width();
			$('#footer_inner').width(pWidth+ulWidth);
		})();
		
		//index_search
		$("#tx_indexedsearch").submit(function(){
			if($('#tx_indexedsearch_sword').val() == SEARCH_TEXT){return false;}else{return true;}
		});
		$('#tx_indexedsearch_sword').focus(function(){
			if($(this).val() == SEARCH_TEXT){$(this).val('');}
		}).blur(function(){
			if($(this).val() == ''){$(this).val(SEARCH_TEXT);}
		});
		
		/* (function(){
			$('<div id="footer_width"><p>&nbsp;</p></div>').appendTo($('body'));
		})(); */
		
		//set footer position
		/* var setFooterPos = function(){
			var browserHeight = document.documentElement.clientHeight;
			$('#footer').css('top',browserHeight-25);
		}
		setFooterPos();
		$(window).resize(function(){setFooterPos()}); */
	});
	
	/*$(window).bind('load',function(){
		//flash has loaded
		(function(){
			var timer = null, flashHasLoaed = false;
			setInterval(function(){
				if(flashHasLoaed) return;
				if(document.getElementById('flash')..PercentLoaded()==100){
					setTimeout(function(){
						$('#main').slideDown('nomarl',function(){flashHasLoaed = true;})
					},500);
				}
			},500);
		})();
	}) */
	
	$(window).bind('load',function(){
		//set layout width
		/* var setLayoutWidth = function(){
			var browserHeight = document.documentElement.clientHeight,mainHeight = $('#main')[0].offsetHeight,$layout = $('#layout');
			var contnetHeight = mainHeight + 365 + 65 + 6 , cHeight = browserHeight - contnetHeight;
			cHeight > 0 ? $('#main').height(mainHeight + cHeight - 30) : $layout.height(browserHeight - cHeight);
		}
		setLayoutWidth();
		$(window).resize(function(){setLayoutWidth()}); */
		
		//content slide
		(function(){
			//var oHeight = $('#main')[0].offsetHeight + 365 + 65 + 6;
			var oHeight = 850;
			//var browserHeight = document.documentElement.clientHeight
			$('#banner').height(oHeight);
			$('#banner>div').height(oHeight);
			$('#wrapper').css({'top':oHeight-65,'visibility':'visible'})/* .animate({'top':365},function(){
				$('#submenu').show();
			}); */
			setTimeout(function(){
				$('#wrapper').animate({'top':365},1000,function(){
					$('#submenu').show();
				});
			},2000);
			
			//var bannerWidht = $('#banner img').width();
			//$('#banner img').css({'margin-left':-bannerWidht/2,'left':'50%'});
		})();

		//img hover
		(function(){
			var transformImg = function(obj){
				var src = obj.attr('src');
				obj.attr('src',obj.attr('srd')).attr('srd',src);
			};
			$('.imgBox img').hover(function(){transformImg($(this));},function(){transformImg($(this));});
		})();

	});
})(jQuery)
