var socialModule = function(){
	var shortenURL;
	var originalURL = location.href;
	function init(){
		_deploySocialModCode();
	}

	function _deploySocialModCode(){
		// str = location.href.split('staging.').join('www.');
		var twitterSuffix = encodeURI('?share=tw');
		var mailSuffix = encodeURI('?share=ml');
		var currentURL = 'http://' + socialModVars.currentURL;
		socialCodeBlocks = Array();
		var twStr = _check140('メイベリン ニューヨーク | ' + socialModVars.title, '#MaybellineJP ');
		twStr = _cer(twStr);
		twitterCode = _socialModTwitter(twStr + ' #MaybellineJP', currentURL + twitterSuffix, 'horizontal');
		socialCodeBlocks.push(twitterCode);
		
		mixiCode = _socialModMixi('#maybelline', currentURL);
		socialCodeBlocks.push(mixiCode);
		
		greeCode = _socialModGree('maybelline', currentURL);
		socialCodeBlocks.push(greeCode);
		
		facebookCode = _socialModFacebook('#maybelline', currentURL);
		socialCodeBlocks.push(facebookCode);
		
		mailCode = _socialModMail('#mailStrCurrent');
		socialCodeBlocks.push(mailCode);
		
		$('.social_module').html(socialCodeBlocks.join(''));

		
		socialCodeBlocksHead = Array();
		var twStr = _check140('メイベリン ニューヨーク | ' + socialModVars.title, '#MaybellineJP ');
		twStr = _cer(twStr);
		twitterCode = _socialModTwitter(twStr + ' #MaybellineJP', currentURL + twitterSuffix, 'none');
		socialCodeBlocksHead.push(twitterCode);
		
		mixiCode = _socialModMixi('#maybelline', currentURL);
		socialCodeBlocksHead.push(mixiCode);
		
		greeCode = _socialModGree('maybelline', currentURL);
		socialCodeBlocksHead.push(greeCode);
		
		facebookCode = _socialModFacebook('#maybelline', currentURL);
		socialCodeBlocksHead.push(facebookCode);
		
		mailCode = _socialModMail('#mailStrCurrent');
		socialCodeBlocksHead.push(mailCode);
		
		
		$('#social_module_head').html(socialCodeBlocksHead.join(''));
		
		socialCodeBlocksTop = Array();
		siteTopURL = siteRoot;
		
		var twStr = _check140('メイベリン ニューヨークの公式ブランドサイト', '#MaybellineJP ');
		twStr = _cer(twStr);
		twitterCode = _socialModTwitter(twStr + ' #MaybellineJP', siteTopURL + twitterSuffix, 'horizontal');		
		socialCodeBlocksTop.push(twitterCode);
		
		mixiCode = _socialModMixi('#maybelline', siteTopURL);
		socialCodeBlocksTop.push(mixiCode);
		
		greeCode = _socialModGree('maybelline', siteTopURL);
		socialCodeBlocksTop.push(greeCode);
		
		facebookCode = _socialModFacebook('#maybelline', siteTopURL);
		socialCodeBlocksTop.push(facebookCode);
		
		mailCode = _socialModMail('#mailStrTop');
		socialCodeBlocksTop.push(mailCode);
		
		$('#social_module_top').html(socialCodeBlocksTop.join(''));
		
			function _cer(str){
				str = str.split("&").join("&amp;");
				str = str.split("<").join("&lt;");
				str = str.split(">").join("&gt;");
				str = str.split('"').join("&quot;");
				str = str.split("{").join("&#123;");
				str = str.split("}").join("&#125;");
				str = str.split("'").join("&#039;");
				return str;
			}
			
			function _check140(strA, strB){
				var strC = strA + strB;
				if(strC.length >= 100){
					var offset = (strC.length - 100);
					return strA.substring(0, strA.length - (offset + 4)) + '... ';
				}else{
					return strA;
				}
			}
							
			function _socialModTwitter(arg, url, type){
				code = '<div class="twitter"><a href="http://twitter.com/share" class="twitter-share-button" data-text="' + arg + '" data-count="' + type + '" data-lang="ja" data-url="' + url + '">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div>';
				return code;
			}
			
			function _socialModMixi(arg, url){
				//	production
				MIXI_API_KEY = '15f4101d58b0338ac8f5ca5174825ac4b0552672';
				//	staging
				// MIXI_API_KEY = 'dd70eec8770587655a76520c70f194764d6290ad';
				code = '<div class="mixi"><a href="http://mixi.jp/share.pl" class="mixi-check-button" data-key="' + MIXI_API_KEY + '" data-url="' + url + '">mixiチェック</a><script type="text/javascript" src="http://static.mixi.jp/js/share.js"></script></div>';
				return code;
			}
			
			function _socialModFacebook(arg, url){
				code = '<div class="facebook"><iframe src="http://www.facebook.com/plugins/like.php?href=' + url + '&layout=button_count&show_faces=false&width=450&action=like&font&colorscheme=light&height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:21px;" allowTransparency="true"></iframe></div>';
				return code;
			}
			
			function _socialModGree(arg, url){
				code = '<div class="gree"><iframe src="http://share.gree.jp/share?url=' + url + '&type=0&height=20" scrolling="no" frameborder="0" marginwidth="0" marginheight="0" style="border:none; overflow:hidden; width:100px; height:20px;" allowTransparency="true"></iframe></div>';
				return code;
			}
			
			function _socialModMail(selector){
				code = '<div class="mail"><a href="' + $(selector).html() + '">メール</a></div>';
				return code;
			}
	}
	
	return {
		init : init
	}
}();

$(function(){
	socialModule.init();
})
