// JavaScript Document
var akd = {
	qqOnline : function() {
		var qqOnline = $('div#qqOnline');
		var showHandler = $('div#showHandler');
		var contactList = $('div#contactList');
		var currentTop = 0;
		$(contactList).hide();
		$(showHandler).hover(
			function(){
				$(this).removeClass('showHandler');
				$(this).addClass('showHandlerHover');
			},
			function(){
				$(this).removeClass('showHandlerHover');
				$(this).addClass('showHandler');
		});
		$(showHandler).toggle(
			function(){
				$(qqOnline).animate({top:currentTop,right:0,width:195},
									500,
									function(){
										$(contactList).fadeIn(500);
									});
			},
			function(){
				$(contactList).fadeOut(500,
									   function(){
										   $(qqOnline).animate({top:currentTop,right:0,width:15},500);
									});
		});
		$(window).scroll(function(){
			currentTop = (document.body.scrollTop+document.documentElement.scrollTop)+'px';
			$(qqOnline).css('top',currentTop);
		});
	},
	akdNavbar : function() {
		var navbar = $('div#nb');
		var navbarMenu = $(navbar).children('ul.navbar_menu').children('li.navbar_menu');
		var listHeight = 0;
		var navid = "";
		$(navbarMenu).each(function(){

				var navlist = $(this).children('div.navList')
				var ul =$(navlist).children('ul');
				var li = $(ul).children('li');
				var liLength = li.length;
				var liHeight = 30;
				var listHeight = liHeight * liLength;
				$(ul).css('height',listHeight+"px");
				$(this).hover(function(){
								if($(this).attr('id') != "logo") {
									navid = $(this).attr('id');
									$(this).attr('id',navid+"Hover");
								}
								$(navlist).slideDown(200,
													function(){
														$(li).fadeIn(200);
								});
							},function(){
								if($(this).attr('id') != "logo")
								{
									$(this).attr('id',navid);
								}
								$(li).fadeOut(200,
											  function(){
												  $(navlist).slideUp(200);
						})
				});
		});
	},
	textMoveToLeft : function(obj,s,w){
		move = setInterval(function(){
								currentLeft = parseInt($(obj).css('left'));
								if(currentLeft >= -(w))
								{
									currentLeft -= 1;
									$(obj).css('left',currentLeft+'px');
								}
								else
								{
									
									$(obj).css('left',s+'px');
								}
									},10);
	},
	stopMove : function(m) {
		clearInterval(m);
	},
	akdAnnouncement : function(){
		var announ = $('div#announText');
		var announText = $(announ).children('p');
		var announLi = $(announText).children('a');
		var textWidth = 0;
		var currentLeft = 0;
		$(announLi).each(function(index){
			var fontSize = parseInt($(this).css('font-size'));
			var stringLength = parseInt($(this).text().length);
			textWidth += fontSize * stringLength;
		});
		var startLeft = windowsWidth = 745;
		$(announText).css('left',startLeft+'px');
		akd.textMoveToLeft(announText,startLeft,textWidth);
		$(announLi).hover(function(){
				akd.stopMove(move);			
			},function(){
				akd.textMoveToLeft(announText,startLeft,textWidth);
		});
	},
	akdMain : function(imgs,img){
		var akdImgs = $(imgs);
		var akdWindow = $('div#akdMainWindows')
		var akdImg = $(img);	
		var preIndex = 0;
		$(akdImg).eq(0).fadeIn(500,
							   function(){
								   $(this).children('div.business').children('p.bTitle').fadeIn(500,
												function(){
													$(this).siblings('p.bDetails').fadeIn(500);
												});										
		});
		
		var akdMenu = $('div.akdMenu');
		$(akdMenu).eq(0).animate({bottom:10},200);
		if(typeof(akdMenu))
		{
			var scrollPic = setInterval(function(){
											$(akdImg).eq(preIndex).hide();
											$(akdImg).eq(preIndex).children('div.business').children().hide();
											$(akdImg).eq(preIndex).children('div.business').hide();
											$(akdMenu).eq(preIndex).animate({bottom:0},200);
											if(preIndex < 2) {
												preIndex++;
											} else {
												preIndex = 0;
											}
											$(akdImg).eq(preIndex).children('div.business').show();
											$(akdImg).eq(preIndex).fadeIn(500,
							   												function(){
								   												$(this).children('div.business').children('p.bTitle').fadeIn(500,
																					function(){
																								$(this).siblings('p.bDetails').fadeIn(500);
																					});										
																			});
											$(akdMenu).eq(preIndex).animate({bottom:10},200);
										},4000);
		$(akdMenu).each(function(index){
			$(this).hover(function(){
					clearInterval(scrollPic);
					if(preIndex != index)
					{
						$(akdImg).eq(preIndex).hide();
						$(akdImg).eq(preIndex).children('div.business').children().hide();
						$(akdImg).eq(preIndex).children('div.business').hide();
						$(akdMenu).eq(preIndex).animate({bottom:0},200);
						$(akdImg).eq(index).children('div.business').show();
						$(akdImg).eq(index).fadeIn(
									500,
									function(){
										$(this).children('div.business').children('p.bTitle').fadeIn(
												500,
												function(){
													$(this).siblings('p.bDetails').fadeIn(500);
												});
						});
						preIndex = index;
					}
					$(this).animate({bottom:10},200);
					
					
				},function(){
					scrollPic = setInterval(function(){
											$(akdImg).eq(preIndex).hide();
											$(akdImg).eq(preIndex).children('div.business').children().hide();
											$(akdImg).eq(preIndex).children('div.business').hide();
											$(akdMenu).eq(preIndex).animate({bottom:0},200);
											if(preIndex < 2) {
												preIndex++;
											} else {
												preIndex = 0;
											}
											$(akdImg).eq(preIndex).children('div.business').show();
											$(akdImg).eq(preIndex).fadeIn(500,
							   												function(){
								   												$(this).children('div.business').children('p.bTitle').fadeIn(500,
																					function(){
																								$(this).siblings('p.bDetails').fadeIn(500);
																					});										
																			});
											$(akdMenu).eq(preIndex).animate({bottom:10},200);
										},4000);
			});
		});
		}
	},
	akdFeedback : function(){
		var team = $('div#team');
		var imagesList = $('div.imagesList');
		var imagesLi = $(imagesList).find('li');
		var scrollWindow = $('div#scrollWindow');
		var currentIndex = 0;
		var windowWidth = -450;
		var scrollLeft = 0;
		$(imagesLi).eq(currentIndex).addClass('current');
		var change = setInterval(function(){									
								 	$(imagesLi).eq(currentIndex).removeClass('current');
									if(currentIndex < ($(imagesLi).length-1)) {
										currentIndex++;
									}
									else {
										currentIndex = 0;
									}
									$(imagesLi).eq(currentIndex).addClass('current');
									scrollLeft = currentIndex*windowWidth;
									$(scrollWindow).animate({left:scrollLeft},1000);
								},5000);
		$(imagesLi).each(function(i){
			$(this).hover(function(){
							clearInterval(change);
							scrollLeft = i * windowWidth;
							$(scrollWindow).animate({left:scrollLeft},500);
							if(currentIndex != i){
								$(imagesLi).eq(currentIndex).removeClass('current')
								$(this).addClass('current');
								currentIndex = i;
							}
						},function(){
							change = setInterval(function(){
									$(imagesLi).eq(currentIndex).removeClass('current');
									if(currentIndex < ($(imagesLi).length-1)) {
										currentIndex++;
									}
									else {
										currentIndex = 0;
									}
									$(imagesLi).eq(currentIndex).addClass('current');
									scrollLeft = currentIndex*windowWidth;
									$(scrollWindow).animate({left:scrollLeft},1000);
									
								},5000);
						});
		});
	},
	newsCenter : function() {
		var newsList = $('div#ncContent ul li');
		var currentIndex = preIndex = 0;
		showNews = setInterval(function(){
								if(preIndex != currentIndex)
								{
									$(newsList).eq(preIndex).hide();
								}
								$(newsList).eq(currentIndex).fadeIn(500);
								preIndex = currentIndex;
								if(currentIndex < newsList.length-1)
								{
									currentIndex++;
								}
								else 
								{
									currentIndex = 0;
								}
							},3000);
	},
	akdOtherInfo : function() {
		var infoOption = $('div#infoOption ul li.infoOption');
		var optionLink = $(infoOption).children('a');
		var infoDetails = $('div#infoDetails div.infoDetails');
		var infoFrame = $('div#infoDetails');
		var currentIndex = 0;
		$(optionLink).each(function(){
			$(this).click(function(event){
				event.preventDefault();
			});
		});
		$('div.icon').pngFix();
		$(infoDetails).hide();
		$(infoDetails).eq(0).fadeIn('slow');
		$(infoOption).each(function(indexOp){
			$(this).click(function(){
				$(infoOption).each(function(){
					if($(this).attr('id'))
					{
						$(this).removeClass('current_f');
						$(this).children('a').css('color','#069');
					}
					else
					{
						$(this).removeClass('current');
						$(this).children('a').css('color','#069');
					}
				});
				if($(this).attr('id'))
				{
					$(this).addClass('current_f');
					$(this).children('a').css('color','#990');
				}
				else
				{
					$(this).addClass('current');
					$(this).children('a').css('color','#990');
				}
				$(infoDetails).each(function(indexDe){
					if(indexDe == indexOp)
					{
						$(this).fadeIn('slow');
						currentIndex = indexDe;
					}
					else
					{
						$(this).hide();
					}
				});
			});
		});
	},
	akdShowNewsletter : function(o) {
		$(o).each(function(i){
			$(this).hover(function(){
						akd.akdCreateFloatWindow(this);
						$(this).find('div.floatWindow').fadeIn(500);
					},
					function(){
						$(this).find('div.floatWindow').fadeOut(200,function(){
																		$(this).find('div.hiddenSpace').remove();
																	});
		});
	});
	},
	akdCreateFloatWindow : function(doc) {
		var hiddenSpace = document.createElement("div");
		$(hiddenSpace).addClass("hiddenSpace");
		$(hiddenSpace).appendTo(doc);
		var floatWin = document.createElement("div");
		$(floatWin).addClass("floatWindow");
		$(floatWin).appendTo(hiddenSpace);
	},
	limitTextLength : function(ele,l,alink) {
		var length = $(ele).text().length;
		var p = $(ele).children('p');
		var theEleTextLength = 0;
		if(length > l)
		{
			$(p).each(function(index){
				theEleTextLength = $(this).text().length;
				if(l > theEleTextLength)
				{
					l -= theEleTextLength;
				}
				else
				{
					var text = $(this).text().substring(0,l);
					text += '......';
					$(this).text(text);
					if(parseInt(alink) != 0){
						$(this).append('<a href="'+alink+'">[详细信息]</a>');
					}
					return true;
				}
			});
		}
	},
	akdFooter : function() {
		var footer = $('div#footer');
		var fnavbar = $(footer).find('div#footerNavbar');
		var fnavbarLi = $(fnavbar).find('li');
		var fnavbarLiA = $(fnavbarLi).children('a');
		var ci = 0;
		var isOpen = false;
		var footerNavSublist = $(footer).find('div.footerNavSublist');
		
		$(fnavbarLiA).each(function(){
			if($(this).attr("id") == "link"){
				$(this).click(function(event){
					event.preventDefault();
				});
			}
		});
		$(fnavbarLi).each(function(i){
			$(this).hover(function(){
							$(this).addClass('hover');
						},function(){
							$(this).removeClass('hover');
			});
		});
		$(fnavbarLi).children('a#link').click(function(event){
												if(!isOpen){
													$(footerNavSublist).slideDown(400);
													isOpen = true;
												}else{
													$(footerNavSublist).slideUp(200);
													isOpen = false;
												}
											});
	}
}