var iniSRC = 'http://image.moshimo.com/item_image/';

$().ready(function(){
				   
	$("#gCart").click(openCart);
	$("#gFav").click(addBookmark);
	$("#fav a").click(addBookmark);
	$("#reco a").click(recoMail);
	$("#shopopen").click(openStartShop);
	
	$("#itemOtherImg a img").each(function(){
		$(this).mouseover(photoPreload);
		$(this).click(onClickThumbNail);
	});
	
	$("div#itemwrap table#itemListTable img.listThumb").each(function(){
		$(this).after('<span class="more">詳細</span>');
	});
	
	
/*
	$("#top_beauty_health_table a").each(function(){
		$(this).attr("href", 'search.php?tag=' + encodeURI($(this).html()));
	});
*/

   //$("#shopopen").hover(pointerON,pointerOFF); ホバーの例
   
	$("a[href='#gtop']").each(function(){
		$(this).click(toPageTop);
	});
   
	$("#megahit ul li:last").css("border", "none");
	
	$("#Map area:eq(0)").attr("href", '50778.html');
	$("#Map area:eq(1)").attr("href", '104748.html');
	$("#Map area:eq(2)").attr("href", '111549.html');
	$("#Map area:eq(3)").attr("href", '106731.html');
	
	if($("#reviewPlace").attr("class")){
			getReviews($("#reviewPlace").attr("class"));
	}
	
	if(this.location.href == 'http://bishin-keikaku.net/132506.html'){
		$('<object width="340" height="285"><param name="movie" value="http://www.youtube.com/v/DNc9tW1AF7w&hl=ja_JP&fs=1&color1=0x5d1719&color2=0xcd311b&border=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/DNc9tW1AF7w&hl=ja_JP&fs=1&color1=0x5d1719&color2=0xcd311b&border=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="340" height="285"></embed></object>').insertBefore("#reviewPlace");
	}
	
	$("#category ul li ul").each(function(){
		$(this).hide();
	});

	$("#category ul li").hover(
		function(){ $(this).find("ul").fadeIn(); },
		function(){ $(this).find("ul").fadeOut(0); }
  	);
	
	
/*	$("#category ul li ul li a").each(function(){
		$(this).attr("href", $(this).parent().parent().parent().find("a").attr("href") + '&tag=' + encodeURI($(this).html()));
	});*/
	
	topBanInit();

});

function openCart(){
	window.open('https://www.moshimo.com/cart/view?sid=132541');
	pageTracker._trackEvent("Cart", "Open");
}

function openStartShop(){
	window.open('https://www.moshimo.com/shop/account/regist?parent_id=132541');
	pageTracker._trackEvent("ShopOpen", "click");
}

function addCart(article_id){
	var title=document.title;
	window.open('http://www.moshimo.com/cart/add?shop_id=132541&article_id='+article_id);
	//pageTracker._trackPageview('/addCart/'+ article_id);
	
	pageTracker._trackEvent("Cart", "Add", title, article_id);
}

function addBookmark() {
	var title=document.title;
	var url=location.href;
	if (window.sidebar) {
		window.sidebar.addPanel(title, url,"");
	} else if( document.all ) {
		window.external.AddFavorite( url, title);
	} else if( window.opera && window.print ) {
		return true;
	}
	//pageTracker._trackPageview('/addBookmark/'+ url);
	pageTracker._trackEvent("Bookmark", "Add", title, url);
}

function recoMail(){
	var title=encodeURI(document.title);
	var url=encodeURI(location.href);
	var subject = encodeURI('おすすめ商品')
	location.href='mailto:abc@abc.com?Subject='+subject+'&body='+title+"\n"+url;
	pageTracker._trackEvent("RecoMail", "Send", title, url);
}

function onClickThumbNail(){
	id = parseInt($(this).attr("alt"))+1;
	src = iniSRC + $("#photo").attr("class") + '/' + id + '/l.jpg';
	$("#photo img").attr("src", src);
	
}

function photoPreload(){
	id = parseInt($(this).attr("alt"))+1;
	src = iniSRC + $("#photo").attr("class") + '/' + id + '/l.jpg';
	jQuery('<img />').attr('src', src);
}

function pointerON(){
	$(this).css("cursor","pointer");
}
function pointerOFF(){
	$(this).css("cursor","");
}

function toPageTop(){
	i = $(window).scrollTop();
	var timerID = setInterval(function(){
			i = i-Math.floor(i/5);
			$(window).scrollTop(i);
			if(i<6){
				$().scrollTop(0);
				 clearInterval(timerID); 
			}
		},10);
	return false;
}

function getReviews(id){
	$.post("common/getReviews.php", {"id" : id}, function(data){
						$("#reviewPlace").html(data);					   
					});
}

function topBanInit(){
	
	if($("#topMainBan").size()){
		
		var src = $("#topMainBan img").attr("src");
		$("#topMainBan img").remove();
		$("#topMainBan").css({"background" : 'url('+src+') left top repeat-x',
								"height" : "200px",
								"width" : "745px"});
		
		$("#topMainBan").append('<div> ・<a href="/search.php?q=chanel">シャネル</a><br />'+
  '・<a href="/search.php?q=HERMES">エルメス</a><br />'+
  '・<a href="/search.php?q=%E3%82%B9%E3%82%A4%E3%83%BC%E3%83%84&cat=01">スイーツ</a><br />'+
  '</div>');
	
	
		$("#topMainBan div a").css({"font-size": "14px", "color": "black"});
		$("#topMainBan div").css({"width": "170px", "position": "absolute", "margin": "100px 3px 3px 540px", "color": "white"});
		$("#topMainBan div a").hover(
		  function () {
			$(this).css({"color": "red"});
		  },
		  function () {
			$(this).css({"color": "black"});
		  }
		);
	}
	

}

//

