$(function(){

	pw_display_ad("#pwad_1", 1);	//
	pw_display_ad("#pwad_3", 5);	//TEXTバナー
	pw_display_ad("#pwad_2", 10);	//

	str = location.pathname;
	var pattern = new Array(
							'^/shop/([0-9]+).html',
							'^/watch/([0-9]+).html'
							);
	for (var i=0; i<pattern.length; i++) {
		if (str.match(pattern[i])) {
			pw_acclog(str);
//			alert(pattern[i] + "にmatch");
		}
	}
});
/**
 *
 */
function pw_display_ad(ad_elm, disp_num) {

	if ( jQuery(ad_elm).size() == 0 )
		return;

	$.ajax({
//		locpath = location.pathname;

		dataType: "json",
		data: {
//			"locpath": locpath
			ad_elm: ad_elm, 
			disp_num: disp_num
		},
		cache: false,
		url: "/pw-content/ad/",
		success: function (data) {
			$(ad_elm).empty();
			$.each(data, function(i,item){
//				alert(i + '...' + item);

				if (item.ad_type == 'image') {
					$("<a/>")
							.attr({
								href: item.url,
								alt: item.shop_name,
								title: item.shop_name
								})
							.append("<img src='" + item.banner_src + "' />\n")
							.appendTo(ad_elm);
				} else {
					$("<li />")
						.append(
							$("<a/>")
								.attr({
									href: item.url,
									alt: item.shop_name,
									title: item.shop_name
									})
								.text(item.text_src)
							)
						.appendTo(ad_elm);
				}
			});
        },
		error:function(XHR, status, errorThrown){
//			alert(status);
		}
	});
}
/**
 *
 */
function pw_acclog(pathname) {
	$.ajax({
//		locpath = location.pathname;

		dataType: "json",
		data: {
			locpath: pathname
		},
		cache: false,
		url: "/pw-content/acc/",
		success: function (data) {
//			alert(data);
		},
		error:function(XHR, status, errorThrown){
//			alert(status);
		}
	});
}