$(window).load(function(){
	$('.colThree').children('img').wrap('<div class="imgDivCol3">');
	
	$('.slideTitle>a').click(function(){
		return false;
	});
	$('.subMenu>li:last').css({border:'0'});
	$('.printBtn>img').click(function(){
		window.print();
	});
	$('.fxIg').each(function(){
		$(this).css({width:$('.cmsImgBox', this).outerWidth(true) + 'px'});
	});
	//var testing = $('.colFour').height();alert(testing);
	$('.naviDiv > div').css({overflow:'visible'});
	$('.naviDiv div ul').addClass('hide');
	$('.naviDiv div').hover(function(){
		$(this).addClass('relative');
		$('ul', this).show();
	}, function(){
		$(this).removeClass('relative');
		$('ul', this).hide();
	});
	$('.naviDiv li>a').hover(function(){
		$(this).css({backgroundPosition:'right top'});
	}, function(){
		$(this).css({backgroundPosition:'left top'});
	});
	$('.subMenu>li>a').hover(function(){
		$(this).css({backgroundPosition:'right top'});
	}, function(){
		$(this).css({backgroundPosition:'left top'});
	});
	$('.xyImg img').hide();
	$('.xyImg').each(function(){$('img', this).eq(0).show()});
	$('.xyBody > a').mouseover(function(){
		var _this = this;//a
		var _thisBox = $(this).parent();//.xyBody
		var _thisWrap = $(this).parent().parent();//box
		$('.xyImg img', _thisWrap).hide().eq($('a', _thisBox).index(_this)).show();
	});
	$('.pageContentTable21 tr:even').css({background:'#efefef'});
	$('.cmsImgBox2').each(function(){
		$(this).css({width:$('img', this).width() +'px'});
	});
});

$.extend($.fn.disableTextSelect = function() {
	return this.each(function(){
		if($.browser.mozilla){//Firefox
			$(this).css('MozUserSelect','none');
		}else if($.browser.msie){//IE
			$(this).bind('selectstart',function(){return false;});
		}else{//Opera, etc.
			$(this).mousedown(function(){return false;});
		}
	});
});

function wbSlide (targetBox, showAtOnce, animateSpeed){
	$(document).ready(function(){
		var _this = $(targetBox);
		var itemNum = $('.wbItem>div', _this).length;
		var itemWidth = $('.wbItem>div', _this).width();
		var slideWidth = itemNum * itemWidth;
		//var maxId = showAtOnce - itemNum;
		var maxId =-( Math.ceil(itemNum / showAtOnce)) + 1;
		var rowSlide = $('.wbPanel').outerWidth(true);
		$('.wbItem', _this).css({width : slideWidth + 100+ "px"});
		var cId = 0;
		$('.wbLeft>img', _this).click(function () {
			cId ++;
			sliding (cId);
		});
		$('.wbRight>img', _this).click(function () {
			cId --;
			sliding (cId);
		});
		function sliding (cId){
			if(cId == maxId) {$('.wbRight>img', _this).hide();};
			if(cId == 0) {$('.wbLeft>img', _this).hide();};
			//var marginNum = itemWidth * cId;
			var marginNum = rowSlide * cId;
			$(".wbItem", _this).animate( { marginLeft: marginNum + "px" }, {duration:animateSpeed} );
			if(cId > maxId) {$('.wbRight>img', _this).show();};
			if(cId < 0) {$('.wbLeft>img', _this).show();}
		};
		if (itemNum <= showAtOnce){
			$('.wbLeft>img', _this).hide();
			$('.wbRight>img', _this).hide();
		} else {
			$('.wbLeft>img', _this).hide();
		};
	});
};

function wbPageSlide (targetBox, animateSpeed){
	$(document).ready(function(){
		var _this = $(targetBox);
		var itemNum = $('.wbPageItem>div', _this).length;
		var itemWidth = $(".wbPageItem>div", _this).outerWidth(true);
		var slideWidth = itemNum * itemWidth;
		var showAtOnce = 1;
		var maxId = showAtOnce - itemNum;
		$('.wbPageItem', _this).css({width : slideWidth  + "px"});
		var cId = 0;
		$('.wbPageLeft>img', _this).click(function () {
			cId ++;
			sliding (cId);
		});
		$('.wbPageRight>img', _this).click(function () {
			cId --;
			sliding (cId);
		});
		$('.wbPagePage>b', _this).click(function () {
			var cThis = $(this);
			var parentThis = $('.wbPagePage>b', _this);
			cId = -($(parentThis).index(cThis));
			sliding (cId);
		});
		function sliding (cId){
			if(cId == maxId) {$('.wbPageRight>img', _this).hide();};
			if(cId == 0) {$('.wbPageLeft>img', _this).hide();};
			var marginNum = itemWidth * cId;
			var newMargin = marginNum + 'px';
			var blockDistance = Math.abs(($('.wbPagePage>b', _this).outerWidth(true)) * (cId));
			$(".wbPageItem", _this).animate( { marginLeft: marginNum + "px" }, {  duration:animateSpeed } );
			if(cId > maxId) {$('.wbPageRight>img', _this).show();};
			if(cId < 0) {$('.wbPageLeft>img', _this).show();}
			$('.wbPageBlock', _this).animate( { left: blockDistance + "px" }, {  duration:animateSpeed } );
		};
		if (itemNum <= showAtOnce){
			$('.wbPageLeft>img', _this).hide();
			$('.wbPageRight>img', _this).hide();
		} else {
			$('.wbPageLeft>img', _this).hide();
		};
		$('.wbPageLeft>img', _this).disableTextSelect();
		$('.wbPageRight>img', _this).disableTextSelect();		
	});
};

function wbTab (eventFunction, tabTarget, contentTarget){
	$(document).ready(function(){
		var indexNum = 0;
		if(eventFunction == 'click') {
			$(tabTarget).click(function(){
				var _this = $(this), _index = $(tabTarget).index(_this);
					if (indexNum != _index){
						runTab(_index);
					};
			});
		} else if (eventFunction == 'mouseover') {
			$(tabTarget).mouseover(function(){
				var _this = $(this), _index = $(tabTarget).index(_this);
					if (indexNum != _index){
						runTab(_index);
					};
			});
		} else {
			alert('event error, please insert "click" or "mouseover"');
		};
		runTab(indexNum);
		function runTab ( runNum ){
			indexNum = runNum;
			//$(tabTarget).css({backgroundColor:'#2e2e2e',  cursor:'pointer'});
			$(contentTarget).hide();
			var tabHead = $(tabTarget).get(runNum);
			var tabBody = $(contentTarget).get(runNum);
			//$(tabHead).css({backgroundColor:'black', cursor:'default'});
			$(tabBody).show().css({opacity:'0.7'});
			$(tabBody).fadeTo(300, 1);
		};
		var timer;
		clearInterval(timer);
		runTimer();
		$('.slideDiv').hover(function(){
		 	stopTimer();
		}, function(){
			runTimer();
		});
		function stopTimer (){
			clearInterval(timer);
		};
		function runTimer (){
			timer = setInterval( function(){
				var maxItemNum = $(tabTarget).length;
				if(indexNum == maxItemNum - 1 ){
					indexNum = 0;
				} else {
					indexNum++;
				};
				runTab(indexNum);
			}, 6000);
		};

	});
};

