$(document).ready(function(){
var CreatePageRecommend=function(a){
			$.ajax({
				url: "/shoplists/page_recommend/"+$('#ShopTypeName').val()+'/PageRecommend:'+a,
				cache: false,
				type: "GET",
				dataType: "html",
				beforeSend: function(){
					var position = $("#store01").offset().top * 0.9;
						$("body,html").scrollTop(position);
						$(".loadingRecommend").show();
				},
				success: function(text){
					$('#store01').html(text);
					$('.loadingRecommend').hide();
					LoadEventPageRecommend();
				}
			});	
};

		var LoadEventPageRecommend=function(){
			$('#PageRcm a').click(function(){
				CreatePageRecommend($(this).text());
				return false;
			});
			$('#PageRcm2 a').click(function(){
				CreatePageRecommend($(this).text());
				return false;
			});
		};
		
		
		LoadEventPageRecommend();
		
		
		
		//----------------------------------New shop-------------------
		
		
		var CreatePageNew=function(a){
			$.ajax({
				url: "/shoplists/page_new/"+$('#ShopTypeName').val()+'/PageNew:'+a,
				cache: false,
				type: "GET",
				dataType: "html",
				beforeSend: function(){
					var position = $("#store02").offset().top * 0.9;
						$("body,html").scrollTop(position);
						$(".loadingRecommend").show();
				},
				success: function(text){
					$('#store02').html(text);
					$('.loadingRecommend').hide();
					LoadEventPageNew();
				}
			});	
		};

		var LoadEventPageNew=function(){
			$('#PageNewShop a').click(function(){
				CreatePageNew($(this).text());
				return false;
			});
			$('#PageNewShop2 a').click(function(){
				CreatePageNew($(this).text());
				return false;
			});
		};
		
		
		LoadEventPageNew();
		
		
				//----------------------------------Product-------------------
		
		
		var CreatePageProduct=function(a){
			var ShopName;
			if($.browser.msie){
				ShopName=encodeURI($('#ShopTypeName').val());	
			}else{
				ShopName=$('#ShopTypeName').val();
			}
			
			$.ajax({
				url: "/shoplists/page_product/"+ShopName+'/PageProduct:'+a,
				cache: false,
				type: "GET",
				dataType: "html",
				beforeSend: function(){
					var position = $(".box-cat-me1").offset().top * 0.5;
						$("body,html").scrollTop(position);
						$(".loading").show();
				},
				success: function(text){
				
					$('.box-cat-me1').html(text);
					$('.loading').hide();
					LoadEventPageProduct();
				}
			});	
		};

		var LoadEventPageProduct=function(){
			$('#PageProduct a').click(function(){
				CreatePageProduct($(this).text());
				return false;
			});
			$('#PageProduct2 a').click(function(){
				CreatePageProduct($(this).text());
				return false;
			});
			
		};

		LoadEventPageProduct();
		
				//----------------------------------Product2-------------------
		
		var CreatePageProduct2=function(a){
			var ShopName;
			if($.browser.msie){
				id=encodeURI($('#id').val());	
				title=encodeURI($('#title').val());	
			}else{
				id=$('#id').val();
				title=$('#title').val();
			}
			$.ajax({
				url: '/shoplists/page_product2/id:'+id+'/title:'+title+'/PageProduct:'+a,
				cache: false,
				type: "GET",
				dataType: "html",
				error: function(){
					alert("Error : shoplist.js line 135");	
				},
				beforeSend: function(){
					var position = $(".box-cat-me2").offset().top * 0.5;
						$("body,html").scrollTop(position);
						$(".loading").show();
				},
				success: function(text){
					
					$(".box-cat-me2").html(text);
					$('.loading').hide();
					LoadEventPageProduct2();
				}
			});	
		};

		var LoadEventPageProduct2=function(){
			
			$(".pageidproduct").click(function(){
			var page = 1;
			var urlText = $(this).attr("href");
			var url = urlText.split("PageProduct:");
			
				page = parseInt(url[1]);
                CreatePageProduct2(page);
				return false;
			});

			
		};

		LoadEventPageProduct2();
		
		
			//----------------------------------Product Subcat-------------------
		
		var CreatePageSubcat=function(a){
			
			var id;
			var title;
			if($.browser.msie){
				id=encodeURI($('#id').val());	
				title=encodeURI($('#title').val());	
			}else{
				id=$('#id').val();	
				title=$('#title').val();	
			}
			$.ajax({
				url: '/shoplists/subcat_product/id:'+id+'/title:'+title+'/pageSubcat:'+a,
				cache: false,
				type: "GET",
				dataType: "html",
				error: function(){
					alert("Error : shoplist.js line 135");	
				},
				beforeSend: function(){
					var position = $(".subcat").offset().top * 0.5;
						$("body,html").scrollTop(position);
						$(".loading").show();
					},
				success: function(text){
					
					$(".subcat").html(text);
					$('.loading').hide();
					LoadEventPageSubcat();
				}
			});	
		};

		var LoadEventPageSubcat=function(){
			
			$(".pagesubcat").click(function(){
			var page = 1;
			var urlText = $(this).attr("href");
			var url = urlText.split("pageSubcat:");
			    page = parseInt(url[1]);
                CreatePageSubcat(page);
				return false;
			});

		};

		LoadEventPageSubcat();
		
		//----------------------------------Shop Recommend -------------------
        var CreateShopRecommend=function(a){
			$.ajax({
				url: "/shoplists/recommend_page/"+$('#ShopTypeName').val()+'/PageRecommend:'+a,
				cache: false,
				type: "GET",
				dataType: "html",
				beforeSend: function(){
					var position = $("#box-cat-me").offset().top * 0.5;
						$("body,html").scrollTop(position);
						$(".loading").show();
					},
				error: function(){
						alert("Javascript ERROR !");
					},
				success: function(text){
					$('#box-cat-me').html(text);
					$('.loading').hide();
					LoadEventShopRecommend();
				}
			});	
        };

		var LoadEventShopRecommend=function(){
			
			$(".pageid").click(function(){
			var page = 1;
			var urlText = $(this).attr("href");
			var url = urlText.split("PageRecommend:");
			
				page = parseInt(url[1]);
                CreateShopRecommend(page);
				return false;
			});

		};
		
		
		LoadEventShopRecommend();
		
		
		//----------------------------------Shop Recommend -------------------
        var CreateNewShop=function(a){
			$.ajax({
				url: "/shoplists/newshop_page/"+$('#ShopTypeName').val()+'/PageNew:'+a,
				cache: false,
				type: "GET",
				dataType: "html",
				beforeSend: function(){
					var position = $("#box-cat-me").offset().top * 0.5;
						$("body,html").scrollTop(position);
						$(".loading").show();
					},
				error: function(){
						alert("Javascript ERROR !");
					},
				success: function(text){
					$('#box-cat-me').html(text);
					$('.loading').hide();
					LoadEventNewShop();
				}
			});	
        };

		var LoadEventNewShop=function(){
			
			$(".pageidshop").click(function(){
			var page = 1;
			var urlText = $(this).attr("href");
			var url = urlText.split("PageNew:");
			
				page = parseInt(url[1]);
                CreateNewShop(page);
				return false;
			});

		};
		
		
		LoadEventNewShop();
});