
var bookmark = {};

bookmark.product = {
	"lipstick01":	[ "Essence Stay Rouge",					"エッセンスステイルージュ" ],
	"lipstick02":	[ "BU Rouge",							"ブライトアップルージュ" ],
	"lipstick03":	[ "BU Rouge (Long Keep)",				"ブライトアップルージュ （ロングキープ）" ],
	"lipstick04":	[ "BU Rouge (Creamy Liquid)",			"ブライトアップルージュ （クリーミィリキッド）" ],
	"eyeshadow01":	[ "Eyes Appeal Shadow",					"アイズアピールシャドウ" ],
	"eyeshadow02":	[ "PG Eyes",							"パーフェクトグラデアイズ" ],
	"eyeshadow03":	[ "3D Glossy Eyes",						"3Dグロッシーアイズ" ],
	"eyeshadow04":	[ "Magical Gradation Eyes",				"マジカルグラデアイズ" ],
	"eyeshadow05":	[ "Wide Gradation Eyes",				"ワイドグラデーションアイズ" ],
	"mascara01":	[ "3D Mascara",							"3Dグラマラスマスカラ" ],
	"mascara02":	[ "3D Wide Lash Mascara",				"3Dワイドラッシュマスカラ" ],
	"mascara03":	[ "Mascara Base",						"マスカラベース" ],
	"eyebrow01":	[ "Smooth Touch Eye Brow",				"スムースタッチアイブロウ" ],
	"cheek01":		[ "Beauty Sharp Designer",				"ビューティシャープデザイナー" ],
	"cheek02":		[ "Smile Up Ceeks",						"スマイルアップチークス" ],
	"nail01":		[ "Gloss Up Nail Color",				"グロスアップネイルカラー " ],
	"nail02":		[ "Gel Mode Top Coat N",				"ジェルモードトップコートN" ],
	"nail03":		[ "Top %26 Base Coat",					"トップ＆ベースコート" ],
	"nail04":		[ "Nail Care Oil",						"ネイルケアオイル" ],
	"foundation01":	[ "Silky Lasting Pact UV",				"シルキィラスティング パクトUV" ],
	"foundation02":	[ "Silky Lasting Gel Foundation UV",	"シルキィラスティングジェルファンデーションUV" ],
	"foundation03":	[ "Fast Beauty Foundation UV",			"ファストビューティ ファンデーションUV" ],
	"foundation04":	[ "Silk F Pact n",						"シルキィフィット パクトn" ],
	"foundation05":	[ "Silk F Liquid",						"シルキィフィット リクイド" ],
	"foundation06":	[ "Silk F Pact UV(Long Keep)",			"シルキィフィット パクトＵＶ（ロングキープ）" ],
	"foundation07":	[ "Silk F Liquid UV(Long Keep)",		"シルキィフィット リクイドＵＶ（ロングキープ）" ],
	"base01":		[ "Silky Lasting Base UV",				"シルキィラスティング　ベースUV" ],
	"base02":		[ "Cover Base UV",						"UVカバーベース" ],
	"base03":		[ "Moist Pack Base",					"モイストパックベース" ],
	"base04":		[ "Full Keep Base UV",					"フルキープベースＵＶ" ],
	"base05":		[ "Clear Cover Base UV50",				"クリアカバーベースＵＶ50" ],
	"powder01":		[ "Face Powder(Lucent)",				"ルーセントグロウフィニッシュＵＶ" ],
	"powder02":		[ "Face Powder(Cover)",					"カバークリアフィニッシュＵＶ" ]
}

bookmark.open = function(){
	
	var head = document.getElementsByTagName('head')[0];
	var print_style = document.createElement('link');
	
	print_style.rel = 'stylesheet';
	print_style.type = 'text/css';
	print_style.media = 'print';
	print_style.href = '/coffretdor/common/style/bookmark_print.css?' + new Date().getTime();
	
	head.appendChild(print_style);
	
	bookmark.resize(true);
	
}

bookmark.close = function(){
	
	var head = document.getElementsByTagName('head')[0];
	var links = head.getElementsByTagName('link');
	
	head.removeChild(links[links.length-1]);
	
	$('#bookmark').animate({ height:'0px' }, 500, function(){})
	
}

bookmark.resize = function(move){
	
	var h;
	var item_length = bookmark.item_length;
	
	if( item_length == 0 ) h = 100;
	else if( 7 < item_length ) h = 354;
	else h = 200;
	
	bookmark.height = h;
	
	if(move) $('#bookmark').animate({ height:bookmark.height+'px' }, 500, function(){});
	
}

bookmark.add = function(){
	
	var _product = bookmark.where;
	var products = $.cookie('products');
	
	if(products == undefined || products == "") {
		
		$.cookie( 'products', _product, { expires:365, path:'/' } );
		
	}else{
		
		var productsArray = products.split(',');
		
		if(productsArray.length > 14) return;
		
		for(i=0; i<productsArray.length; i++) if(_product == productsArray[i]) return;
		
		$.cookie( 'products', products + "," + _product, { expires:365, path:'/'} );
		
		
	}
	
	document.getElementById('bookmark_btn_gard').style.display = 'block';
	
	$(document.getElementById('addedAlert')).fadeIn('200',function(){
		
		$(this).fadeOut(2000, function(){
			this.style.display = 'none';
			document.getElementById('bookmark_btn_gard').style.display = 'none';
		});
		
	})
	
	bookmark.update();
	
}

bookmark.getList = function(){
	return $.cookie('products');
}

$(function(){
bookmark.where = (function(){
	
	var place = (document.body.className+'').split(' ');
	var permit = [ 'lipstick', 'lipgloss', 'eyeshadow', 'mascara', 'eyeliner', 'eyebrow', 'cheek', 'nail', 'foundation', 'base', 'powder', 'others' ];
	
	for(i=0; i<place.length; i++){
	
		for(j=0; j<permit.length; j++){
			
			if( place[i].slice(0,-2) == permit[j] ) return place[i];
		}
	}
	
})()
})

bookmark.get = function(_product){
	
	if($.cookie('products') == undefined || $.cookie('products') == "" || $.cookie('products') == null) return false;
	
	var products = $.cookie('products');
	var array = products.split(",");
	var bool = false;
	for(var i = 0; i < array.length; i++){
		if(_product == array[i]){
			bool = true;
			break;
		}
	}
	return bool;
}

bookmark.del = function(_product){
	var products = $.cookie('products');
	var array = products.split(",");	
	for(var i = 0; i < array.length; i++){
		var val = array[i];
		if(val == _product){
			array.splice(i, 1);
		}
	}
	$.cookie('products', array.toString(), {expires: 365, path:'/'});
	$.cookie(_product, null);
}

bookmark.update = function(){
	
	var products = $.cookie('products');
	
	if( products == undefined || products == "" ) {
		
		document.getElementById('bookmark_tab_number').src = '/coffretdor/bookmark/images/number_00.gif';
		
		document.getElementById('bookmark_print_gard').style.display = 'block';
		document.getElementById('bookmark_alert').style.display = 'block';
		
		bookmark.item_length = 0;
		
	}else{
	
		var displayArray = products.split(',');
		var lists = document.getElementById('bookmark').getElementsByTagName('li');
		var mail = '';
		
		document.getElementById('bookmark_tab_number').src = '/coffretdor/bookmark/images/number_' + ( (displayArray.length < 10) ? '0' + displayArray.length : displayArray.length ) + '.gif';
		
		document.getElementById('bookmark_print_gard').style.display = 'none';
		document.getElementById('bookmark_alert').style.display = 'none';
		
		for(i=0; i<displayArray.length; i++) {
			
			mail += bookmark.product[displayArray[i]][0] + '%0D%0A';
//			mail += encodeURIComponent( bookmark.product[displayArray[i]][1], Encoding.GetEncoding("Shift-JIS")) + '%0D%0A';
			
			$('#bookmark li.' + displayArray[i])[0].style.display = 'block';
			
		}
		
		for(i=0,j=0; i<lists.length; i++){
			
			if(lists[i].style.display == 'block'){
				
				lists[i].style.display = 'block';
				lists[i].style.paddingRight = '11px';
				if(j==6) lists[i].style.paddingRight = '116px';
				
				j++;
				
			}
			
		}
		document.getElementById('bookmark_mail').getElementsByTagName('a')[0].href = "mailto:?body=" + mail;
		
		bookmark.item_length = displayArray.length;
		
	}
	
	bookmark.resize($('#bookmark').height()!=0);
	
}

bookmark.mousemove = function(event){
	
	var target;
	
	var p = function(e) {
		
		var obj = new Object();
		
		if(e) {
			obj.x = e.pageX;
			obj.y = e.pageY;
		} else {
			obj.x = event.x + document.body.scrollLeft;
			obj.y = event.y + document.body.scrollTop;
		}
	
		return obj;
		
	}(event)
	
	if( bookmark.get( bookmark.where ) ){
		target = document.getElementById('alreadyAlert');
	}else if(bookmark.item_length > 14){
		target = document.getElementById('limitAlert');
	}else return;
	
	$(target).stop();
	
	target.style.display = 'block';
	target.style.opacity = 1;
	target.style.filter = 'alpha(opacity=100)';
	target.style.left = ( p.x - 55 ) + 'px';
	target.style.top = ( p.y - 50 ) + 'px';
	
}

bookmark.mouseout = function(event){
	
	var target;
	
	if( bookmark.get( bookmark.where ) ){
		target = document.getElementById('alreadyAlert');
	}else if(bookmark.item_length > 14){
		target = document.getElementById('limitAlert');
	}else return;
	
	$(target).fadeOut(1500, function(){ this.style.display = 'none'; });
	
}

bookmark.init = function(){
	
	bookmark.height = 80;
	
	var tab = document.createElement('div');
	var tab_img = new Image();
	var number_img = new Image();
	
	tab.id = "bookmark_tab";
	tab_img.src = "/coffretdor/bookmark/images/btn_03.gif";
	tab_img.className = "imgover slider";
	
	number_img.src = "/coffretdor/bookmark/images/number_00.gif";
	number_img.id = "bookmark_tab_number";
	
	$(tab).toggle(function(){ bookmark.open(); },function(){ bookmark.close(); });
	
	tab.appendChild(tab_img);
	tab.appendChild(number_img);
	
	document.getElementById('gnav').appendChild(tab);
	
	if(-1 < document.body.className.indexOf('detail')){
		
		var btn = document.createElement('div');
		var btn_img = new Image();
		var limit = new Image();
		var already = new Image();
		var added = document.createElement('div');
		var added_img = new Image();
		
		var btn_gard = document.createElement('div');
		
		btn_gard.id = 'bookmark_btn_gard';
		
		btn.id = "bookmark_btn";
		btn_img.src = "/coffretdor/bookmark/images/btn_04.gif";
		btn_img.className = "imgover";
		
		$(btn_img)
			.bind('click', bookmark.add)
			.bind('mousemove', bookmark.mousemove)
			.bind('mouseout', bookmark.mouseout);
		
		limit.id = 'limitAlert';
		limit.src = "/coffretdor/bookmark/images/alert_01.gif";
		
		already.id = 'alreadyAlert';
		already.src = "/coffretdor/bookmark/images/alert_02.gif";
		
		added.id = 'addedAlert';
		added_img.src = "/coffretdor/bookmark/images/alert_03.gif";
		
		btn.appendChild(btn_img);
		added.appendChild(added_img);
		
		btn.appendChild(btn_gard);
		btn.appendChild(added);
		
		document.getElementById('shareArea').appendChild(btn);
		document.body.appendChild(limit);
		document.body.appendChild(already);
		
	}
	
	$.get(
		'/coffretdor/bookmark/item_list.html?' + new Date().getTime(),
		{ encodeURIComponent:false },
		function(data){
			
			document.getElementById('bookmark').innerHTML = data.match( new RegExp('<!-- bookmark include -->([\\s\\S]*)<!-- /bookmark include -->', 'i') )[0];
			
			var print_gard = document.createElement('div');
			print_gard.id = 'bookmark_print_gard';
			document.getElementById('bookmark_inner').appendChild(print_gard);
			
			bookmark.update();
			
			istRollOver.setRollOver('#bookmark');
			istRollOver.setRollOver('#bookmark_tab');
			istRollOver.setRollOver('#bookmark_btn');
			
			$('#bookmark_print').click(function(){ window.print(); });
			
			$('#bookmark .delete img').click(function(){
				
				var name = $(this).parent().parent().attr('class');
				
				bookmark.del(name);
				$('#bookmark ul li.'+name)[0].style.display = 'none';
				
				bookmark.update();
				
			});
			
		}
	)

}

bookmark.height = 0;
bookmark.item_length = 0;

$(function(){ bookmark.init() });

/**
 * Cookie plugin
 *
 * Copyright © 2006 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */

/**
 * Create a cookie with the given name and value and other optional parameters.
 *
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Set the value of a cookie.
 * @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
 * @desc Create a cookie with all available options.
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Create a session cookie.
 * @example $.cookie('the_cookie', null);
 * @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain
 *       used when the cookie was set.
 *
 * @param String name The name of the cookie.
 * @param String value The value of the cookie.
 * @param Object options An object literal containing key/value pairs to provide optional cookie attributes.
 * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
 *                             If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
 *                             If set to null or omitted, the cookie will be a session cookie and will not be retained
 *                             when the the browser exits.
 * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).
 * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
 * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will
 *                        require a secure protocol (like HTTPS).
 * @type undefined
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */

/**
 * Get the value of a cookie with the given name.
 *
 * @example $.cookie('the_cookie');
 * @desc Get the value of a cookie.
 *
 * @param String name The name of the cookie.
 * @return The value of the cookie.
 * @type String
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */

(function($){
$.cookie = function(name, value, options){
    if (typeof value != 'undefined') {
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString();
        }
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else {
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = $.trim(cookies[i]);
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};
})(jQuery);

