﻿$(document).ready(function(){
	$(document).pngFix();
	$('#FB, #FB2').click(function(){
		anteaterAddBookmark("FaceBook");
		return false;
	});
	$('#PL, #PL2').click(function(){
		anteaterAddBookmark("Plurk");
		return false;
	});
	$('#TW, #TW2').click(function(){
		anteaterAddBookmark("Twitter");
		return false;
	});
	
	if($('body').attr('id') == 'index'){
		$('.IndexBoxRe > div:last-child').children('b').css({background:'none'});
		fxSlide('#footSlide', 7, 300);
	}
	//extbtn01
	$('.extbtn01').hover(function(){
		$(this).attr('id','extbtn01ov');
	}, function(){
		$(this).attr('id','');
	});
	$('#mityLeft').next().show().hide().slideDown(300, function(){
		if( $(this).children('li').length == 0){
			$(this).remove();
		}
	});
	
	$('#Submenu > a').click(function(){
		if($(this).attr('href') == '#'){
			if($(this).next().children('li') && $(this).next().css('display') == 'none'){
				$(this).next().show();
			} else if($(this).next().children('li')){
				$(this).next().hide();
			}
			return false;
		}
	}).hover(function(){
		$(this).children('b').css({left:'-222px'});
	}, function(){
		$(this).children('b').css({left:'0px'});
	});
});






function fxSlide (targetBox, showAtOnce, animateSpeed){
	var _this = $(targetBox);
	var itemNum = $('.aItem > div', _this).length;
	var itemWidth = $('.aItem > div', _this).outerWidth(true);
	var slideWidth = itemNum * itemWidth;
	var maxId = itemNum - showAtOnce;
	$('.aItem', _this).css({width : slideWidth + "px"});
	var cId = 0;
	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);
		return false;
	});
	$('.aRight > a', _this).click(function () {
		cId ++;
		sliding (cId);
		return false;
	});
	function sliding (){
		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();
		};
		$('.aItem', _this).animate( { marginLeft: - itemWidth * cId + "px" }, {  duration:animateSpeed } );
	};
	sliding(cId);
};



/******************************************************************************************************************************************************************/
var WEB_SITE_HREF    = "";
var WEB_SITE_TITLE   = ""
var FAVORITES		 = "Favorites";
var FACEBOOK  		 = "FaceBook";
var GOOGLE	  		 = "Google";
var PLURK 			 = "Plurk";
var TWITTER 		 = "Twitter";
var ICON_IMAGE_PATH  = "images/anteaterBookmark/";
var FILE_NAME_EXTENSION = ".png";
var bookmarkList	 = 
[
	FAVORITES , 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 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 ) {
		// Gecko (Netscape 6)
		window.sidebar.addPanel( _title, _locationHref, '' );
	} else if( window.external ) {
		// IE
		window.external.AddFavorite( _locationHref, _title );
	} else if( document.layers ) {
		// NS4
		window.alert( 'Please click OK then press Ctrl+D to create a bookmark' );
	} else {
		// Other browsers
		window.alert( 'Please use your browsers\' bookmarking facility to create a bookmark' );
	}
}
/************ jq pngFix **************************************/
(function($){jQuery.fn.pngFix=function(settings){settings=jQuery.extend({blankgif:'blank.gif'},settings);var ie55=(navigator.appName=="Microsoft Internet Explorer"&&parseInt(navigator.appVersion)==4&&navigator.appVersion.indexOf("MSIE 5.5")!=-1);var ie6=(navigator.appName=="Microsoft Internet Explorer"&&parseInt(navigator.appVersion)==4&&navigator.appVersion.indexOf("MSIE 6.0")!=-1);if(jQuery.browser.msie&&(ie55||ie6)){jQuery(this).find("img[src$=.png]").each(function(){jQuery(this).attr('width',jQuery(this).width());jQuery(this).attr('height',jQuery(this).height());var prevStyle='';var strNewHTML='';var imgId=(jQuery(this).attr('id'))?'id="'+jQuery(this).attr('id')+'" ':'';var imgClass=(jQuery(this).attr('class'))?'class="'+jQuery(this).attr('class')+'" ':'';var imgTitle=(jQuery(this).attr('title'))?'title="'+jQuery(this).attr('title')+'" ':'';var imgAlt=(jQuery(this).attr('alt'))?'alt="'+jQuery(this).attr('alt')+'" ':'';var imgAlign=(jQuery(this).attr('align'))?'float:'+jQuery(this).attr('align')+';':'';var imgHand=(jQuery(this).parent().attr('href'))?'cursor:hand;':'';if(this.style.border){prevStyle+='border:'+this.style.border+';';this.style.border=''}if(this.style.padding){prevStyle+='padding:'+this.style.padding+';';this.style.padding=''}if(this.style.margin){prevStyle+='margin:'+this.style.margin+';';this.style.margin=''}var imgStyle=(this.style.cssText);strNewHTML+='<span '+imgId+imgClass+imgTitle+imgAlt;strNewHTML+='style="position:relative;white-space:pre-line;display:inline-block;background:transparent;'+imgAlign+imgHand;strNewHTML+='width:'+jQuery(this).width()+'px;'+'height:'+jQuery(this).height()+'px;';strNewHTML+='filter:progid:DXImageTransform.Microsoft.AlphaImageLoader'+'(src=\''+jQuery(this).attr('src')+'\', sizingMethod=\'scale\');';strNewHTML+=imgStyle+'"></span>';if(prevStyle!=''){strNewHTML='<span style="position:relative;display:inline-block;'+prevStyle+imgHand+'width:'+jQuery(this).width()+'px;'+'height:'+jQuery(this).height()+'px;'+'">'+strNewHTML+'</span>'}jQuery(this).hide();jQuery(this).after(strNewHTML)});jQuery(this).find("*").each(function(){var bgIMG=jQuery(this).css('background-image');if(bgIMG.indexOf(".png")!=-1){var iebg=bgIMG.split('url("')[1].split('")')[0];jQuery(this).css('background-image','none');jQuery(this).get(0).runtimeStyle.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+iebg+"',sizingMethod='scale')"}});jQuery(this).find("input[src$=.png]").each(function(){var bgIMG=jQuery(this).attr('src');jQuery(this).get(0).runtimeStyle.filter='progid:DXImageTransform.Microsoft.AlphaImageLoader'+'(src=\''+bgIMG+'\', sizingMethod=\'scale\');';jQuery(this).attr('src',settings.blankgif)})}return jQuery}})(jQuery);
