﻿/*
$(document).pngFix();ie6 png fix
$(this).lightBox();jq lightbox
$(this).fxFile(70);input type="file"
$(this).fxSlide(5, 300, 'v');slide can be vertical'v' or horizontal'h'
$(this).fxCss(target); clone target's css
$(this).mousewheel(function(e, delta){}); mousewheel event
$(this).bgiframe();
getUrlVars()["id"];
getAjaxVars(e)["me"];
--------jq effect
$(this).effect('blind');
blind bounce clip drop explode fade fold highlight pulsate scale shake slide transfer puff
--------jq easing 
$(this).animate({left:''}, 500, 'easeInQuad', callback);
easeInQuad	easeOutQuad	easeInOutQuad	easeInCubic	easeOutCubic	easeInOutCubic	easeInQuart	easeOutQuart	easeInOutQuart	easeInQuint	easeOutQuint	easeInOutQuint	easeInSine	easeOutSine	easeInOutSine	easeInExpo	easeOutExpo	easeInOutExpo	easeInCirc	easeOutCirc	easeInOutCirc	easeInElastic	easeOutElastic	easeInOutElastic	easeInBack	easeOutBack	easeInOutBack	easeInBounce	easeOutBounce	easeInOutBounce
--------share
anteaterAddBookmark("FaceBook");
anteaterAddBookmark("Twitter");
anteaterAddBookmark("Plurk");
--------outside event
clickoutside, dblclickoutside, focusoutside, bluroutside, mousemoveoutside, mousedownoutside, mouseupoutside, mouseoveroutside, mouseoutoutside, keydownoutside, keypressoutside, keyupoutside, changeoutside, selectoutside, submitoutside
--------own selector
$.extend($.expr[':'], {  
    over100pixels: function(a) {  
        return $(a).height() > 100;  
    }  
}); 
*/

//index only
var winHeight;
var indexCheckTime = 100;
var maxWait = 5000;
var maxTry = maxWait/indexCheckTime;
var indexTried = 0;

$(document).ready(function(){
	disableSelection(document.body);
	$(document).bind("contextmenu", function(e) {
		e.preventDefault();
	});
	if( $.browser.version == '6.0' && $.browser.msie ){ 
		$('#BG').bgiframe();
		$(document).pngFix();
	};
	if(document.getElementById('indexBG')){ //index js
		winHeight = $(document).height()/1.1;
		$('#indexNewsBG, #indexNewsBG2').css({opacity:0.8});
		$('#newsBox').mouseleave(function(){
			$(this).animate({width:'0px'}, 200);
		});
		$('#newsBox2').mouseleave(function(){
			$(this).animate({width:'0px'}, 200);
		});
		$('#indexMenu > div').each(function(i){
			$(this).css({top: $(this).position().top - winHeight + 'px'});
		});
		$('#indexMenuDot').css({overflow:'visible'});
		var indexBGmax = $('#indexBG > div').length - 1;
		var indexTimer;
		var indexImgNum = $('#indexBG > div').length;
		var indeximgDone=0;
		$('#indexBG > div').each(function(i){
			//var img = new Image().src= window.location.href + $(this).css('background-image').replace('url(','').replace(')','');
			var _thisImg = $('<img />');
			_thisImg.appendTo('#preloader');
			_thisImg.attr('src', $(this).css('background-image').replace('url(','').replace(')','').replace('"','').replace('"','')).load(function(){
				indeximgDone++;
			});			
		});
		indexTimer = setInterval(function(){
			//document.title = indeximgDone + '/';
			if(indeximgDone == indexImgNum || indexTried >maxTry){
				clearInterval(indexTimer);
				$('#indexBG > div').show();
				setInterval(function(){
					$('#indexBG > div').eq(indexBGmax).fadeOut(1500, function(){$(this).show().prependTo('#indexBG')});
				}, 5000);
				$('#indexMenu > div').each(function(i){
					$(this).delay(i*200).animate({top:'+='+winHeight}, 1000, 'easeOutExpo')/*.children('p').children('a').css({opacity:0.7})*/;
				});
				$('#indexHead').delay(200*($('#indexMenu > div').length)+ 1000).animate({width:'100%'}, 500, function(){
					$('#indexFoot').animate({height:'51px'}, 500);
				});
				$('#indexMenu > div').hover(function(){
					$(this).css({overflow:'visible', zIndex:5}).children('div').css({zIndex:6});
				}, function(){
					$(this).css({overflow:'hidden', zIndex:1}).children('div').css({zIndex:1});
				});
			} else {
				indexTried++;
			};
		}, indexCheckTime);
	}//index end

	if(document.getElementById('pageMenu')){
		$('#pageMenu > div').hover(function(){
			$(this).children('p').show();
		}, function(){
			$(this).children('p').hide();
		});
	}
	if( document.getElementById('hotSlide2') ){
		$('#hotSlide2').fxSlide2(4, 500, 'v');
		$('#hotSlideImg2 > div').eq(0).addClass('ON');
	}
	if( document.getElementById('flashFun') ){
		swfobject.embedSWF('swf/map.swf', 'flashFun', '591', '547', '10.0.0', 'js/expressinstall.swf', {}, {'allowfullscreen':'true', 'allowScriptAccess':'always', 'wmode':'opaque'}, {'id':'flashFun', 'name':'flashFun'});
	}
	if( document.getElementById('flashFun2') ){
		swfobject.embedSWF('swf/map2.swf', 'flashFun2', '591', '547', '10.0.0', 'js/expressinstall.swf', {}, {'allowfullscreen':'true', 'allowScriptAccess':'always', 'wmode':'opaque'}, {'id':'flashFun2', 'name':'flashFun2'});
	}
	/*if( document.getElementById('newSlistli2')){
		$('#newSlistli2 a').lightBox();
	}*/
	
	if( document.getElementById('memberInputFC') ){
		$('#memberInputFC input.clinPut').each(function(){
			$(this).val($(this).attr('svalue'));
		}).focus(function(){
			if($(this).val() == $(this).attr('svalue') ){
				$(this).val('');
			}
		}).blur(function(){
			if($(this).val() == ''){
				$(this).val($(this).attr('svalue'));
			}
		});
		
		$('#memberInputFC input.clinPut2').each(function(){
			$(this).val($(this).attr('svalue'));
		}).focus(function(){
			if( $(this).attr('svalue') != '' || $(this).attr('svalue') != null){
				$(this).next().show().focus().prev().hide();
			}
		}).blur(function(){
			if($(this).val() == ''){
				$(this).hide().prev().show();
			}
		});
	}
	
});

$(window).load(function(){
	if( document.getElementById('hotSlide2') ){
		$('#hotSlide2').fxSlide2(4, 500, 'v');
		$('#hotSlideImg2 > div').each(function(i){
			hotImgManager(this);
		});
		$('#hotCaseImg2 > div').each(function(){
			hotImgManager(this);
		});
	}
});

function hotImgManager(DOM){
	if($(DOM).children('img').width() > $(DOM).width()){
		$(DOM).children('img').css({left: - (($(DOM).children('img').width() - $(DOM).width())/2) + 'px'});
	};
	if($(DOM).height() > $(DOM).children('img').height()  ){
		$(DOM).children('img').css({top: ($(DOM).height()- $(DOM).children('img').height() )/2  + 'px'});
	}
}

function disableSelection(target){
	if (typeof target.onselectstart!="undefined") //IE route
		target.onselectstart=function(){return false}
	else if (typeof target.style.MozUserSelect!="undefined") //Firefox route
		target.style.MozUserSelect="none"
	else //All other route (ie: Opera)
		target.onmousedown=function(){return false}
	target.style.cursor = "default"
}
function iFocus(DOM, STR){
	if($(DOM).val() == STR || $(DOM).val() == ''){
		$(DOM).val('');
	} else {
	
	}
}
function iFocus2(DOM, STR){
	if($(DOM).val() == STR || $(DOM).val() == ''){
		$(DOM).val('').attr('type', 'password');
	} else {
	}
}
function knowExpand(DOM){
	if( $(DOM).next().css('display') == 'none'){
		$(DOM).text('CLOSE').next().show();
	} else {
		$(DOM).text('OPEN').next().hide();
	}
}
function knowImgClose(DOM){
	$('#pageBody>div').hide().eq(0).show();
}
function knowImg(DOM, NUM){
	$('#pageBody>div').hide().eq(1+NUM).show();
}
function hotTab2(DOM, NUM){
	$(DOM).parent().children('a').removeClass().eq(NUM).addClass('ON');
	$('#hotBox2 > div').hide().eq(NUM).show().css({height:'auto'});
}
function hotSlide2(DOM, NUM){
	$('#hotSlideImg2 > div').removeClass();
	$(DOM).parent().addClass('ON');
	$('#hotCaseImg2 > div').hide().eq(NUM).show();
}
function newsOpen(){
	$('#newsBox').animate({width:'491px'}, 700);
}
function newsOpen2(){
	$('#newsBox2').animate({width:'491px'}, 700);
}
var newFontSize;
function fontSize(DOM, SIZE){
	switch(SIZE){
		case 1:
			newFontSize = 12;
			break;
		case 2:
			newFontSize = 15;
			break;
		case 3:
			newFontSize = 18;
			break;
	}
	$('#pageTiBar, #pageBody').css({fontSize:newFontSize + 'px'});
}

jQuery.fn.extend({
	fxSlide2: function (showAtOnce, animateSpeed, fxDirect, SORT){
		$(this).each(function(){
			if (!fxDirect) {
				alert('fxSlide error (showAtOnce『1,2,3』, animateSpeed『10,100,1000』, fxDirect『"h" or "v"』)');
			};
			var _this = $(this);
			var itemNum = $('.aItem > div', _this).length;
			
			var maxId = itemNum - showAtOnce;
			var itemWidth;
			var cId = 0;
			
			if(fxDirect == 'h'){
				itemWidth = $('.aItem > div', _this).outerWidth(true);
				$('.aItem', _this).css({width : itemWidth * itemWidth + 10 + "px"});
			} else if(fxDirect == 'v') {
				itemWidth = $('.aItem > div', _this).outerHeight(true);
				$('.aItem', _this).css({height : itemWidth * itemWidth + 10 + "px"});
			};
			var slideWidth = itemNum * itemWidth;
			
			if (itemNum <= showAtOnce){
				$('.aLeft > a', _this).remove();
				$('.aRight > a', _this).remove();
			} else {
				/*_this.mousewheel(function(e, delta){
					if(delta > 0){
						cId--;
					} else if (delta < 0){
						cId++;
					};
					sliding (cId);
					return false;
				});*/
			};
			$('.aLeft > a', _this).click(function () {
				cId --;
				sliding (cId);
				$(this).blur();
				return false;
			});
			$('.aRight > a', _this).click(function () {
				cId ++;
				sliding (cId);
				$(this).blur();
				return false;
			});
			function sliding (SID, NUM){
				if(cId >= maxId && maxId > 0) {
					$('.aRight > a', _this).hide();
					$('.aLeft > a', _this).show();
					cId = maxId;
				} else if(cId <= 0) {
					$('.aRight > a', _this).show();
					$('.aLeft > a', _this).hide();
					cId = 0;
				} else {
					$('.aRight > a, .aLeft > a', _this).show();
				};
				if (fxDirect == 'h') $('.aItem', _this).stop().animate( { marginLeft: - itemWidth * cId + "px" }, animateSpeed);
				if (fxDirect == 'v') $('.aItem', _this).stop().animate( { marginTop: - itemWidth * cId + "px" }, animateSpeed);
				if( NUM != 1){
					$('.aItem > div', _this).eq(cId).children('div').each(function(i){
						$(this).css({position:'relative', top:'150px', left:'150px', opacity:0}).delay(i*50).animate({left:'0px', top:'0px', opacity:1}, 500, function(){$(this).css({position:'static'});});
					});
				}
				$('#indexPage > a').removeClass().eq(cId).addClass('on');
				if( SORT == 'campwork'){
					$('.aNum i').text( (cId*10 + 1) + ' - ' + ((cId+1)*10) );
				};
				
			};
			sliding(cId, 1);
			$('#indexPage > a').click(function(){
				cId = $('#indexPage > a').index(this);
				sliding();
				return false;
			});
		});
	}, 	fxSlide3: function (showAtOnce, animateSpeed, fxDirect){
		$(this).each(function(){
			if (!fxDirect) {
				alert('fxSlide error (showAtOnce『1,2,3』, animateSpeed『10,100,1000』, fxDirect『"h" or "v"』)');
			};
			var _this = $(this);
			var itemNum = $('.aItem > div', _this).length;
			
			var maxId = itemNum - showAtOnce;
			var itemWidth;
			var cId = 0;
			
			if(fxDirect == 'h'){
				itemWidth = $('.aItem > div', _this).outerWidth(true);
				$('.aItem', _this).css({width : itemWidth * itemWidth + 10 + "px"});
			} else if(fxDirect == 'v') {
				itemWidth = $('.aItem > div', _this).outerHeight(true);
				$('.aItem', _this).css({height : itemWidth * itemWidth + 10 + "px"});
			};
			var slideWidth = itemNum * itemWidth;
			
			if (itemNum <= showAtOnce){
				$('.aLeft > a', _this).remove();
				$('.aRight > a', _this).remove();
			} else {
				/*_this.mousewheel(function(e, delta){
					if(delta > 0){
						cId--;
					} else if (delta < 0){
						cId++;
					};
					sliding (cId);
					return false;
				});*/
			};
			$('.aLeft > a', _this).click(function () {
				cId --;
				sliding (cId);
				$(this).blur();
				return false;
			});
			$('.aRight > a', _this).click(function () {
				cId ++;
				sliding (cId);
				$(this).blur();
				return false;
			});
			function sliding (SID, NUM){
				if(cId >= maxId && maxId > 0) {
					$('.aRight > a', _this).hide();
					$('.aLeft > a', _this).show();
					cId = maxId;
				} else if(cId <= 0) {
					$('.aRight > a', _this).show();
					$('.aLeft > a', _this).hide();
					cId = 0;
				} else {
					$('.aRight > a, .aLeft > a', _this).show();
				};
				if (fxDirect == 'h') $('.aItem', _this).stop().animate( { marginLeft: - itemWidth * cId + "px" }, animateSpeed);
				if (fxDirect == 'v') $('.aItem', _this).stop().animate( { marginTop: - itemWidth * cId + "px" }, animateSpeed);
				$('#indexPage > a').removeClass().eq(cId).addClass('on');
			};
			sliding(cId, 1);
			$('#indexPage > a').click(function(){
				cId = $('#indexPage > a').index(this);
				sliding();
				return false;
			});
		});
	}
});

function fxCirSlide(DOM) {
	var _this = $(DOM);
	//var _thisAR = $('.htmlArray', _this);
    var maxDivision = $('.tvcfCenter > div', _this).length;
	var cHigher = 100;//current target higher X axis
	var smallCwidth = 200;
	var bigCwidth = 300;
    var radiusX = 200;
    var radiusY = 80;
    var cPI = Math.PI * 2 / 4;
    var xPI = Math.PI * 2 / maxDivision;
    var dId = 0;
	var cArray = new Array();
    $('.tvcfCenter > div', _this).each(function(i) {
        var seta = xPI * i + cPI;
        var tY = Math.floor((Math.sin(seta)) * radiusY);
        var tX = Math.floor((Math.cos(seta)) * radiusX);
        var opa = Math.floor((tY + (radiusY + (radiusY*0.1))) / (radiusY*2) * 1000) / 1000;
		var cObj;
        if (i != 0) {
			cObj = {
				ty: tY,
				tx: tX,
				wid: smallCwidth,
				zin:Math.floor(tY),
				opa:opa,
				ord:i
			};/*
            $('<b ty="' + tY + '" tx="' + tX + '" wid="' + smallCwidth + '" zin="' + Math.floor(tY) + '" opa="' + opa + '"></b>').appendTo(_thisAR);*/
            $(this).css({ zIndex: Math.floor(tY), top: tY + 'px', left: tX + 'px' });
            $('img', this).css({ width: smallCwidth + 'px' });
            $('a', this).css({ left: -(smallCwidth/ 2) + 'px', opacity: opa });
        } else {
			cObj = {
				ty: tY-cHigher,
				tx: tX,
				wid: bigCwidth,
				zin:Math.floor(tY),
				opa:opa,
				ord:i
			};/*
            $('<b ty="' + (tY - 100) + '" tx="' + tX + '" wid="' + bigCwidth + '" zin="' + Math.floor(tY) + '" opa="' + opa + '"></b>').appendTo(_thisAR);**/
            //$(this).css({zIndex:Math.floor(tY), top:tY - 100 +'px', left:tX+'px', width:'222px'});
            $(this).css({ zIndex: Math.floor(tY), top: tY - 100 + 'px', left: tX + 'px' });
            $('img', this).css({ width: bigCwidth + 'px' });
            $('a', this).css({ width: -(bigCwidth/2) + '0px', opacity: opa });
        };
		cArray.push(cObj);
    });
	$('.aNum i', _this).text( cArray[0].ord + 1 + ' / '+ maxDivision);
    $('.aLeft', _this).click(function() {
        //$('.htmlArray b:last-child').prependTo(_thisAR);
		cArray.unshift( cArray.pop() );
        run3D();
        $(this).blur();
        return false;
    });
    $('.aRight', _this).click(function() {
        //$('.htmlArray b:first-child').appendTo(_thisAR);
		cArray.push( cArray.shift() );
        run3D();
        $(this).blur();
        return false;
    });
    $(_this).mousewheel(function(e, delta) {
        if (delta > 0) {
            //$('b:last-child', _thisAR).prependTo(_thisAR);
			cArray.unshift( cArray.pop() );
        } else {
            //$('b:first-child', _thisAR).appendTo(_thisAR);
			cArray.push( cArray.shift() );
        };
        run3D();
        return false;
    });
    function run3D() {
        $('.tvcfCenter > div', _this).each(function(j) {/*
            $(this).stop().animate({
                top: $('.htmlArray b').eq(j).attr('ty') + 'px',
                left: $('.htmlArray b').eq(j).attr('tx') + 'px'
            }, 300).css({ zIndex: $('b', _thisAR).eq(j).attr('zin') });
            $('img', this).stop().animate({ width: $('b', _thisAR).eq(j).attr('wid') + 'px' }, 200);
            $('a', this).stop().animate({ left: -($('b', _thisAR).eq(j).attr('wid') / 2) + 'px', opacity: $('b', _thisAR).eq(j).attr('opa') }, 200);*/
            $(this).stop().animate({
                top: cArray[j].ty + 'px',
                left: cArray[j].tx + 'px'
            }, 300).css({ zIndex: cArray[j].zin });
            $('img', this).stop().animate({ width: cArray[j].wid + 'px' }, 200);
            $('a', this).stop().animate({ left: -( cArray[j].wid / 2) + 'px', opacity: cArray[j].opa }, 200);
        });
		$('.aNum i', _this).text( cArray[0].ord + 1 + ' / '+ maxDivision);
    };
	
};

var WEB_SITE_HREF="";
var WEB_SITE_TITLE="";
var FAVORITES="Favorites";
var FACEBOOK="FaceBook";
var GOOGLE="Google";
var PLURK="Plurk";
var SINA="Sina";
var TWITTER="Twitter";
var QQ="QQ";
var HAPPY="Happy";
var SO="So";
var REN = "Ren";
var ICON_IMAGE_PATH="images/anteaterBookmark/";
var FILE_NAME_EXTENSION=".png";
var bookmarkList=[FAVORITES,SINA,QQ,HAPPY,SO,REN,FACEBOOK,GOOGLE,PLURK,TWITTER];
function getBookmarkList(){return bookmarkList;}
function getBookmarkListIcon(){var _array=bookmarkList.concat();for(var i=0;i<_array.length;i++){_array[i]=ICON_IMAGE_PATH+_array[i]+FILE_NAME_EXTENSION;};return _array;};
function anteaterAddBookmark(pType,DOM){
	var _locationHref=(WEB_SITE_HREF=="")?window.location.href:WEB_SITE_HREF;
	_locationHref=encodeURIComponent(_locationHref);var _title=(WEB_SITE_TITLE=="")?document.title:WEB_SITE_TITLE;
	_title=encodeURIComponent(_title);var _href;
	switch(pType){
	case FAVORITES:
		anteaterAddFavorites();
		return;
		break;
	case SINA:
		_href="http://v.t.sina.com.cn/share/share.php?url="+_locationHref+"&title="+_title;
		break;
	case QQ:
		_href="http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url="+_locationHref+"&title="+_title;
		break;
	case HAPPY:
		_href="http://www.kaixin001.com/repaste/share.php??rurl="+_locationHref+"&rtitle="+_title;
		break;
	case SO:
		_href="http://t.sohu.com/third/post.jsp?url="+_locationHref+"&title="+_title;
		break;
	case REN:
		_href = "http://share.renren.com/share/buttonshare.do?link="+_locationHref+"&title="+_title;
		break;
		
	case FACEBOOK:
		_href="http://www.facebook.com/sharer.php?u="+_locationHref+"&title="+_title;
		break;
	case GOOGLE:
		_href="http://www.google.com/bookmarks/mark?op=add&bkmk="+_locationHref+"&title="+_title;
		break;
	case PLURK:
		_href="http://www.plurk.com/?qualifier=shares&status=".concat(_locationHref).concat(' ').concat('(').concat(_title).concat(')');
		break;
	case TWITTER:
		_href="http://twitter.com/home/?status="+_title+" "+_locationHref;
		break;
	};
	window.open(_href,"_blank");return false;
};
function anteaterAddFavorites(){var _title=(WEB_SITE_TITLE=="")?document.title:WEB_SITE_TITLE;var _locationHref=(WEB_SITE_HREF=="")?window.location.href:WEB_SITE_HREF;if(window.sidebar&&window.sidebar.addPanel){window.sidebar.addPanel(_title,_locationHref,'');}else if(window.external){window.external.AddFavorite(_locationHref,_title);}else if(document.layers){window.alert('Please click OK then press Ctrl+D to create a bookmark');}else{window.alert('Please use your browsers\' bookmarking facility to create a bookmark');}};
(function($,c,b){$.map("click dblclick mousemove mousedown mouseup mouseover mouseout change select submit keydown keypress keyup".split(" "),function(d){a(d)});a("focusin","focus"+b);a("focusout","blur"+b);$.addOutsideEvent=a;function a(g,e){e=e||g+b;var d=$(),h=g+"."+e+"-special-event";$.event.special[e]={setup:function(){d=d.add(this);if(d.length===1){$(c).bind(h,f)}},teardown:function(){d=d.not(this);if(d.length===0){$(c).unbind(h)}},add:function(i){var j=i.handler;i.handler=function(l,k){l.target=k;j.apply(this,arguments)}}};function f(i){$(d).each(function(){var j=$(this);if(this!==i.target&&!j.has(i.target).length){j.triggerHandler(e,[i.target])}})}}})(jQuery,document,"outside");
