// JavaScript Document
$(document).ready(function(){
	var this_val;
	$("input[type=text]:not([readonly=readonly])").focusin(function() {
		this_val = $(this).val();
		if($(this).val() == this_val)
  		$(this).val("");
	});

	$("#search-box").css("height","33px");
	$("#search-btn").click(function(){
	  $(this).hide();
	  $("#search").show(); 
	  $("#search-submit").show();
	 });
	 $("#search-box-02").hover(function(){
	  //$("#search").toggle(); 
	 },function(){
	  $("#search-submit").hide();
	  $("#search").fadeOut("slow");
	  $("#search-btn").show();
	 });
/*HOME ROLL-OVER*/
$(".home-roll-over").hover(function(){
		$(".home-box",this).stop(true,true).fadeIn();
	},function(){
		$(".home-box",this).fadeOut();
	});
/*selected js-多选 js*/
$('#choose-shade li').hover(function(){
		$(".shade-box",this).stop(true,true).fadeIn("fast");
	},function(){
		$(".shade-box",this).fadeOut("fast");
	});
	
$('#choose-shade li').click( function () {
		var shade = $(this).attr("title");
		$('#choose-shade a').removeClass();
		$("a",this).toggleClass('selected-01');
		$("#input_shade").val(shade);
		return false;
	});
	
$('#choose-texture a').click( function () {
		var texture = $(this).attr("title");
		$('#choose-texture a').removeClass();
		$(this).toggleClass('selected-01');
		$("#input_texture").val(texture);
		return false;
	});
	
$('#your-budget a').click( function () {
		var budget = $(this).attr("title");
		$('#your-budget a').removeClass();
		$(this).toggleClass('selected-01');
		$("#input_price").val(budget);
		return false;
		
	});
	
	$('#choose-shade-02 a').click( function () {
		var select_color = $("#input_shade").attr("value");
		var color = $(this).attr("title");
		if ( $(this).hasClass("selected-02") ){
			select_color = select_color.replace(color,"");
			select_color = select_color.replace(',,',',');
			if (color == '')
			{
				$(this).removeClass('selected-02');
				$("#input_shade").val('');
			}else{
				$(this).removeClass('selected-02');
				$("#input_shade").val(select_color);
			}
			return false;
		}else{
			select_color += color +',';
			if (color == '')
			{
				$('#choose-shade-02 a').removeClass('selected-02');
				$(this).addClass('selected-02');
				$("#input_shade").val('LIGHT,MEDIUM,DARK');
			}else{
				if($('#choose-shade-box-all').hasClass('selected-02')){
					$('#choose-shade-box-all').removeClass('selected-02');
					select_color = color +',';
				}
				$(this).addClass('selected-02');
				$("#input_shade").val(select_color);
			}
			return false;
		}
	});
/*	$("#choose-Price").click(function(){
		var price_min = $("#price_min").attr("value");
		var price_max = $("#price_max").attr("value");
		var price = $(this).attr("value");
		var prices= new Array();
		prices=price.split("-");
        if($(this).attr("checked")==true){
			alert('hello');
			if (price_min){
				if (price_min > prices[0]){
					$("#price_min").val(prices[0]);
				}
			}else{
				
				$("#price_min").val(prices[0]);
			}
				if (price_max < prices[1]){
					$("#price_min").val(prices[1]);
				}

        }else{
            if (price_min < prices[0]){
				$("#price_min").val(prices[0]);
			}
            if (price_max > prices[1]){
				$("#price_min").val(prices[1]);
			}
        }
    })
*/	
/*footer join*/
$("#join").hover(function(){
		$("img",this).attr("src","/skin/Urbanfloor/_images/join-btn-on.jpg");
	},function(){
		$("img",this).attr("src","/skin/Urbanfloor/_images/join-btn.jpg");
	});
/*left-nav*/
$("#left-nav a").hover(function(){
		$(this).stop(true,true).animate({height : "183px"},600);
	},function(){
		$(this).animate({height : "31px"},600);
	});
/*.productindex-top*/
//$(window).width();
$(".class-top").css("width",$(window).width());
$(window).resize(function() {
 $(".class-top").css("width",$(window).width());
});
/*product-box-01*/
$(".product-box-01").hover(function(){
		$("a img",this).css("opacity","0.5");
	},function(){
		$("a img",this).css("opacity","1");
	});
/*#productpetails-top-rt ul li*/

$("#product-top-rt ul li").click(function(){
	$(".pd-top-rt-hover").hide();
	$("#product-top-rt ul li").removeAttr("id");
	$(this).attr("id","current-01");
	$(".pd-top-rt-hover",this).show();
	});
$("#product-top-rt ul li").hover(function(){
		$("a img",this).css("opacity","1");
		$(".pd-top-rt-hover",this).fadeIn("fast");
	},function(){
		$("a img",this).css("opacity","0.6");
		if($(this).attr("id") == "current-01"){
			
		}else{
		$(".pd-top-rt-hover",this).hide();
		}
	});
	

/*product-box-01*/
$(".out_bt_images").parent().css("position","relative");
$(".over_bt_images").mouseover(function(){
	$(this).fadeOut("slow");
	$(this).next().fadeIn("fast");
});

$(".out_bt_images").mouseout(function(){
	$(this).fadeOut("slow");
	$(this).prev().fadeIn("fast");
});


$(".over_button").mouseover(function(){
	$(this).attr("src",$(this).next().attr("alt"));
});

$(".over_button").mouseout(function(){
	$(this).attr("src",$(this).next().attr("src"));
});

/*$("#show_bt_images").parent().hover(function(){
	$(this).hide();
	$(this).next().fadeIn("slow");
},function(){
	$(this).next().hide();
	$(this).fadeIn("slow");
});	*/
	
	
	
	
/*expressorder-table color*/
$("#expressorder-conter table tr:even td").css({background : "#f5f6f7"});
$("#expressorder-conter table tr:odd td").css({background : "#e5e5e5"});

/*invoice-table color*/
$("#invoice-table tr:even td").css({background : "#fafafa"});
$("#invoice-table tr:odd td").css({background : "#e5e5e5"});

/*shoppingcart-main*/
$("#shoppingcart-main table tr:even td").css({background : "#f5f6f7"});

/*radio.star*/
$("#messgae-form radio.star").rating({cancel: 'hide', cancelValue: '1'}); 

if($('#productform1')){
 	$('#productform1 :radio.star').rating({cancel: 'Cancel', cancelValue: '9'}); 
}
/*tabs*/
$('#product-tabs').tabs();




});
/*#productpetails-top-rt ul li*/
$(function(){
	var thispage = 1;
    var n_img = 6; //每版放1个图片
	var v_width = 330; //滚动的宽度
	var speed = 800;//速度
	var len = $("#list-4").find("li").length;
	var thispage_count = Math.ceil(len / n_img) ;
	
	$("a#next-01").click(function(){
		if( !$("#list-4").is(":animated") ){  
		 	 if( thispage == thispage_count ){  
			 	$("#list-4").animate({  left : '0px' }, speed);
				thispage = 1;
			}else{
				$("#list-4").animate({ left : '-='+v_width }, speed);
				thispage++;
			}
		}
		return false;
	});
	$("a#prev-01").click(function(){
		if( !$("#list-4").is(":animated") ){ 
		 	 if( thispage == 1 ){ 
			 	$("#list-4").animate({ left : '-='+v_width*(thispage_count-1) }, speed);
				thispage = thispage_count;
			}else{
				$("#list-4").animate({ left : '+='+v_width }, speed);
				thispage--;
			}
		}
		return false;
	});

});
/*product-bottom*/
$(function(){
	var page = 1;
    var n_img = 3; //每版放3个图片
	var v_width = 766; //滚动的宽度
	var speed = 800;//速度
	var len = $("#list-2").find("li").length;
	var page_count = Math.ceil(len / n_img) ;
	$("a#next-02").click(function(){
		if( !$("#list-2").is(":animated") ){ 
		//alert("hello");   
		 	 if( page == page_count ){
				$("#list-2").animate({  left:'0px' }, speed);
				//showImg(page-1);
				page = 1;
			}else{
				
				$("#list-2").animate({ left : '-='+v_width }, speed);
				page++;
			}
		}
		return false;
	});
	$("a#prev-02").click(function(){
		if( !$("#list-2").is(":animated") ){ 
		 	 if( page == 1 ){ 
				$("#list-2").animate({ left : '-='+v_width*(page_count-1) }, speed);
				page = page_count;
			}else{
				$("#list-2").animate({ left : '+='+v_width }, speed);
				page--;
			}
		}
		return false;
	});
});

/*product-bottom*/
$(function(){
	var page = 1;
    var n_img = 3; //每版放3个图片
	var v_width = 766; //滚动的宽度
	var speed = 800;//速度
	var len = $("#list-2-2").find("li").length;
	var page_count = Math.ceil(len / n_img) ;
	$("a#next-02-2").click(function(){
		if( !$("#list-2-2").is(":animated") ){ 
		//alert("hello");   
		 	 if( page == page_count ){
				$("#list-2-2").animate({  left:'0px' }, speed);
				//showImg(page-1);
				page = 1;
			}else{
				$("#list-2-2").animate({ left : '-='+v_width }, speed);
				page++;
			}
		}
		return false;
	});
	$("a#prev-02-2").click(function(){
		if( !$("#list-2-2").is(":animated") ){ 
		 	 if( page == 1 ){ 
				$("#list-2-2").animate({ left : '-='+v_width*(page_count-1) }, speed);
				page = page_count;
			}else{
				$("#list-2-2").animate({ left : '+='+v_width }, speed);
				page--;
			}
		}
		return false;
	});
});


/*product-bottom*/
$(function(){
	var page = 1;
    var n_img = 3; //每版放3个图片
	var v_width = 766; //滚动的宽度
	var speed = 800;//速度
	var len = $("#list-2-3").find("li").length;
	var page_count = Math.ceil(len / n_img) ;
	$("a#next-02-3").click(function(){
		if( !$("#list-2-3").is(":animated") ){ 
		//alert("hello");   
		 	 if( page == page_count ){
				$("#list-2-3").animate({  left:'0px' }, speed);
				//showImg(page-1);
				page = 1;
			}else{
				
				$("#list-2-3").animate({ left : '-='+v_width }, speed);
				page++;
			}
		}
		return false;
	});
	$("a#prev-02-3").click(function(){
		if( !$("#list-2-3").is(":animated") ){ 
		 	 if( page == 1 ){ 
				$("#list-2-3").animate({ left : '-='+v_width*(page_count-1) }, speed);
				page = page_count;
			}else{
				$("#list-2-3").animate({ left : '+='+v_width }, speed);
				page--;
			}
		}
		return false;
	});
});

/*aboutus*/
$(function(){
	var page = 1;
	var index = 0;
    var n_img = 1; //每版放1个图片
	var v_width = 990; //滚动的宽度
	var speed = 800;//速度
	var len = $("#list-3").find("li").length;
	var page_count = Math.ceil(len / n_img) ;
	
	
	$("#aboutus-img-nav li").click(function(){
   		index =   $("#aboutus-img-nav li").index(this);
   		showImg(index);
	}); 
	/*auto*/
	$(window).load(function(){
		 MyTime = setInterval(function(){
		   showImg(index);
		 index++;
		 if(index==len){index=0;}
		 } , 3000);
	});
	$('#aboutus-show').hover(function(){
		 if(MyTime){
		 clearInterval(MyTime);
		 }
	},function(){
		 MyTime = setInterval(function(){
		   showImg(index);
		 index++;
		 if(index==len){index=0;}
		 } , 3000);
	});
	$(".stop").live('click',function(){
		clearInterval(MyTime);
		return false;
		});
	function showImg(i){
		$("#list-3").stop(true,false).animate({left : -v_width*i},speed);
		$("#aboutus-img-nav").find("li .stop").remove();
		$("#aboutus-img-nav").find("li").removeAttr("id");
		$("#aboutus-img-nav").find("li").eq(i).attr("id","current-02").append('<a class="stop" href="#"><img src="/skin/Urbanfloor/_images/stop-icon.jpg" width="10" height="12" alt="stop" /></a>');
		page = i+1;
	}
});

$(function(){
	$("#home-img-upload-bg").width($(window).width()).height($('body').attr('scrollHeight'));
	$("#upload-btn").click(function(){
		$("#home-img-upload").css("opacity","1");
		$("#home-img-upload-bg").show();
	});	
	$("#upload-x").click(function(){
		$("#home-img-upload-bg").hide();
		return false;
	});	
})

$(function(){
	var length = $(".shopping-cart-box-product").length;
	$("#shopping-cart-show ul").width(109*length);
	var thispage = 1;
    var n_img = 3; //每版放1个图片
	var v_width = 327; //滚动的宽度
	var speed = 800;//速度
	var thispage_count = Math.ceil(length / n_img) ;
	$("a#next-04").click(function(){
		if( !$("#list-5").is(":animated") ){  
		 	 if( thispage == thispage_count ){  
			 	$("#list-5").animate({  left : '0px' }, speed);
				thispage = 1;
			}else{
				$("#list-5").animate({ left : '-='+v_width }, speed);
				thispage++;
			}
		}
		return false;
	});
	$("a#prev-04").click(function(){
		if( !$("#list-5").is(":animated") ){ 
		 	 if( thispage == 1 ){ 
			 	$("#list-5").animate({ left : '-='+v_width*(thispage_count-1) }, speed);
				thispage = thispage_count;
			}else{
				$("#list-5").animate({ left : '+='+v_width }, speed);
				thispage--;
			}
		}
		return false;
	});
})



$(document).ready(function(){
    $(".cart-menu-head").hover(function(index) {
			var loading = "<div style='margin:30px; font-size:14px; text-align:center;'><img src='skin/Urbanfloor/_images/loading.gif' /></div>";
			$(".cart-menu-body").html(loading);
			$.ajax({
				type: "POST",
				url: "cart_this.php",
				data: '',
				cache:false,
				error: function() {
				//	alert("System Error !!");
				},
				success: function(cmsg){
					$(".cart-menu-body").html(cmsg);
				}
				
			});
//alert("sss");
			
    },function(){})
	
});




$(document).ready(function(){
	$("#shop_cart_batton").click(function () {
			
			
  	});
});

function ship2sameasbill(flag) {
  if (flag){
		$("#s_firstname").val($("#b_firstname").val());
		$("#s_address").val($("#b_address").val());
		$("#s_lastname").val($("#b_lastname").val());
		$("#s_city").val($("#b_city").val()) ;
		$("#s_state").val($("#b_state").val()) ;
		$("#s_country").val($("#b_country").val()) ;
		$("#s_zipcode").val($("#s_zipcode").val()) ;
		$("#s_phone").val($("#b_phone").val());
		$("#s_zipcode").val($("#b_zipcode").val()) ;
		$("#s_fax").val($("#b_fax").val()) ;
	}
}

$(function(){
	$(".pop-bg").width($(window).width()).height($('body').attr('scrollHeight'));
	$("#product-pop-btn").click(function(){
		$("#product-pop-bg").show();
		return false;
	});	
	$("#close-x").click(function(){
		$("#product-pop-bg").hide();
		return false;
	});	
})


function Calculator(sq_box) {
	sq_box = Number(sq_box);
	//alert(sq_box);
	//sq_box = sq_box.replace("'", "");
	
	var Total_Square_Feet = 0;
	var Waste_Factor = 0;
	var Total_Materials_Required = 0;
	
	var Waste_Factor = Number($("#Waste_Factor").val()); //Waste Factor
	
	var i=1
	for (i=1;i<=5;i++){
		var Length_feet = Number($("#Length_feet_"+i).val());
		var Length_Inches = Number($("#Length_Inches_"+i).val());
		var Width_feet = Number($("#Width_feet_"+i).val());
		var Width_Inches = Number($("#Width_Inches_"+i).val());
		if (Length_feet > 0 || Length_Inches > 0)
		{
			if (Width_feet > 0 || Width_Inches > 0)
			{
				if (Length_feet > 0 && Length_Inches > 0)
				{
					Length_feet  = Length_feet + (Length_Inches*0.083);
				}else if(Length_feet <= 0 && Length_Inches > 0){
					Length_feet  = Length_Inches*0.083;
				}
				if (Width_feet > 0 && Width_Inches > 0)
				{
					Width_feet = Width_feet + (Width_Inches*0.083);
				}else if(Width_feet <= 0 && Width_Inches > 0){
					Width_feet  = Width_Inches*0.083;
				}
				//alert (Length_feet);
				Total_Square_Feet += Length_feet * Width_feet ;
			}else{
				alert('Please enter the width');
			}
		}
	}
	// print out
	if (Total_Square_Feet > 0)
	{
		Total_Square_Feet = Total_Square_Feet.toFixed(2); //
		$("#Total_Square_Feet").html(Total_Square_Feet);
	}
	
	Waste_Factor = (Total_Square_Feet/100) * Waste_Factor;
	
	if(Waste_Factor > 0)
	{
		Total_Materials_Required = Number(Total_Square_Feet) + Number(Waste_Factor);
	}else{
		Total_Materials_Required = Number(Total_Square_Feet);
	}
	
	Waste_Factor = Waste_Factor.toFixed(2); //
	
	$("#Waste_Factor_span").html(Waste_Factor);
//alert (Total_Materials_Required);
	box = Total_Materials_Required / sq_box;
	//Total_Materials_Required = Total_Materials_Required.toFixed(2); //
	box = Math.ceil(box);
	
	$("#Total_Materials_Required").html(box);
	Total_Materials_Required = Math.ceil(Total_Materials_Required);
	var box_show = box + " boxes / "+Total_Materials_Required+" Sq.Ft.";
	
	$("#Total_Materials_Required_main").html(box_show);

}

function Calculator_clean() {
	for (i=1;i<=5;i++){
		$("#Length_feet_"+i).val('0');
		$("#Length_Inches_"+i).val('0');
		$("#Width_feet_"+i).val('0');
		$("#Width_Inches_"+i).val('0');
	}
	$("#Waste_Factor").val('10');
	$("#Total_Square_Feet").html("0");
	$("#Waste_Factor_span").html("0");
	$("#Total_Materials_Required").html("0");
}



