//Javascript


 
var cLeftPos = 0;
var temp_temp_holder = "";
var animation_in_progess = false;
var IE6 = false /*@cc_on || @_jscript_version < 5.7 @*/;

function move_hover_bg($itm,sp){
	$itm.parent().css({backgroundPosition : (sp+'px') 	});
	} 




$(document).ready(function(){

cLeftPos =  	parseInt($("#container").css("left"));						   
$(".spacer1")
	.hover(
		function() {

				move_hover_bg($(this),-65);
							 
			} ,
		function() {

				move_hover_bg($(this),0);

						 

			}

		)
	.click(
		   function(){

				cLeftPos = document.body.scrollLeft;
				if(cLeftPos+329 > window.scrollMaxX ){

						cLeftPos = window.scrollMaxX;

					} else cLeftPos += 329;
 			    $("html,body").animate({ // scroll view
									   scrollLeft:	cLeftPos 
									   },

									   1000);
			   }

		   );

$(".spacer2").hover(
 					function() {
							$(this).parent().css({backgroundPosition : '-130px'});
						} ,
						function() {
							$(this).parent().css({backgroundPosition : '0px'});
						}

					)
 		.click(
			   function(){
 				cLeftPos = document.body.scrollLeft;
				if(cLeftPos-329 < 0 ){
						cLeftPos = 0;
					} else cLeftPos -= 329;
				$("html,body").animate({
									   scrollLeft:	cLeftPos 
									   },
									   1000);
			   }
		   );


 

 
		
		
$("img.sliding_img").click(function(event){
									
									
				 
									
				$img_opened = $(this).attr("opened");
					
				if($img_opened != "yes")
				{
					
							
					goTo = $(this).parents(".products").get(0).offsetLeft;
					$("html,body").animate({
									scrollLeft:	goTo 
									 		}, 2000);
					
					$pr_id = $(this).attr("id");
					$big_img = eval("products_property.product_"+$pr_id+".large_pic");
					$med_img = eval("products_property.product_"+$pr_id+".meduim_pic");
					$prod_wrap = $(this).parents(".products").next(".prod_details_wrap_one");
					$prod_pic = $(this).parents(".product_pic_one");
					$prod_det  = $prod_wrap.find(".product_details_one");
					$prod_disc = $prod_wrap.find(".product_desc_one");
					
				
					//console.log($prod_simil);
					$("#layout").css({width:	(parseInt($("#layout").css("width"))+650)+"px" });
					
					if($.browser.msie){
						
							$prod_wrap.animate({
															
											width:	'260px',
											
											left:	'-260px'
															
											});
					
					
					}
					else
					{
								$prod_wrap.animate({
															
											width:	'520px'
															
											});
					}
					
					$prod_det.css({
									  
									display:	'block'
									  
									});
					
					$prod_det.animate({
					
									width:	'260px'
									  
									  });
				
					
					
					$prod_pic.animate({
									  width:	'520px' 
									  });
					
					$(this).animate({
									left: '260px'	
									});
					
					$prod_disc.animate({
									   
									left:	'260px',
									
									opacity:	'1.0'
									   
									   })
					.css({
								   display: 'block'
								   });
					
					$(this).attr("opened", "yes");

				
									
			
//ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss			



	
 
	
		$si = $(this);
		//console.log($si);
		

		


		bigimg = new Image();
	 d = new Date();
	 
		$(bigimg).unbind("load").attr("src",$big_img+"?"+d.getTime()).load(function(){
			
			$(this).css({backgroundColor: "#e8e8e8"});

				$(this).attr("run","even");
				
				//console.log($(this).parents(".sizing"));
				
				$si.parent().css({
								 width:	'520px',
								 position: 'relative'
								 
								 });
				
				
				$si.attr("original", $med_img);
				

				$si.animate({  
							
							width:	'1040px',
							
							left:	'-300px',
							
							height: '1974px',
							
							top:	'-1050px'

							},function(){
									
									//$(this).parent().parent().append($(this).clone().css("display","none").addClass("temp_bg"));
									$(this)
										
										.attr("src",$big_img)
										.css({

											 cursor:	"move",
											 left:	"-306px",
											 top:		'-774px',
											 width:	  '1040px',
											 height:	"1344px"

											 })

										.draggable();
								 
 								});
  							 }).load();
		
		
		
		}// end if($img_opened != "yes")

});

 


$(".close").click(function(){
				  
				  //console.log($(this));
				  
				  $img = $(this).parents(".prod_details_wrap_one").prev(".products").find(".ui-draggable");
					
				  $prod_disc = $(this).parents(".product_desc_one");
				  
					
				  $med_img = $img.attr("original");
 				  
					
				  $img.attr("src", $med_img);
				  
				  $img.animate({
							   
							width:	'260px',
							
							left:	'260px',
							
							height: '504px',
							
							top:	'0px'
							   
							   },700, function(){
								   
								   $img.css({
														
										left: '0px',
											
						   			position: 'relative',
							
										width:	'260px',
										
										height: '504px'
										
									  });
								   
								   $img.parents(".sizing").css({
											
											left: '260px',
														
											 width:	'260px',
											 
											 position: 'absolute'
											 
										 });
								   
								   
								   });

		
				$img.attr("opened", "no");
				
				 
				if($.browser.msie)
				{
						$prod_disc.find(".pr_sizes").css({
																												
																display: 'none'
																												
													});
				}
				
				$prod_disc.animate({
									   
									left:	'0px' 
																		   
									   },1000, function(){
											 
										   $img.parents(".sizing").animate({
												
												left: '0px'
												
												},200, function(){
													
													$prod_disc.css({display: "none"});
													
													$img.parents(".product_pic_one").animate({
																						 					
																		width:	'260px'
																		
																						 }, 1000, function(){
																							 
																							 $prod_disc.parents(".prod_details_wrap_one").css({ display: "none"});
																							 $img.removeClass('ui-draggable');
																							 $img.css({
																									  position: 'absolute',
																									  display:	'block',
																									  cursor: 'url(images/zoom-in.cur), -moz-zoom-in'
																									  })
																							 
																							 $img.parents(".sizing").css({
																											
																											position: ''
																											
																														 });
																							 
																							 $prod_disc.parents(".prod_details_wrap").css({
																																		  
																															display:	'block',
																															position: 'relative',
																															width: '0px'
																																		  
																																		  });
																							 
																							 $prod_disc.parents(".product_details_one").css({
																																		  
																															width:	'0px'																																		  
																																		  });
																							 
																							 
																							 $prod_disc.css({
																																		  
																															display:	'none',
																															opacity:	'0',
																															position:	'absolute',
																															left:	'260px'
																																		  
																																		  });
																							 
																							 if($.browser.msie)
																															{
																																	$prod_disc.find(".pr_sizes").css({
																																																							
																																											display: ''
																																																							
																																								});
																															}
																							 
										 													  //$prod_disc.parents("product_details_one").css({ display: "none"});
										  													 
																							 });
													
													});
										   
										   });
					
				
					setTimeout('$("#layout").css({width:	(parseInt($("#layout").css("width"))-650)+"px" });', 2500);

 });

//$(".close").click(close_handler);


if(window.location.hash.length > 0){
				hsh = window.location.hash;
				$(hsh).click();
				layout_width += 520;
				
			}
$(".layout").css({width:	layout_width+"px"});


$(".print").click(function(event){

						   

						    var cont1 = $(this).parents(".prod_details_wrap_one").html();
							var cont2 = $(this).parents(".prod_details_wrap_one").prev(".products").find(".sliding_img").attr("original");
						//	console.log(cont2);
 						   
						    var a = window.open('','','scrollbars=yes,width=620,height=520');
											a.document.open("text/html");
											a.document.write('<html><head><link rel="stylesheet" href="style.css" media="all" /><script type="text/javascript" src="jquery126.js"></script></head><body style="padding-left:10px;background-image:none;background-color:#FFFFFF;" onload="document.getElementById(\'product_desc_one\').style.left=260;">');
											a.document.write(cont1);
											a.document.write("<div style='float:left; width:260px'><img src='"+cont2+"' style='left:0'/></div>");
											
											a.document.write('</body></html>');
											a.document.close();
											d = a.document;
											 a.print();
											
											
						   
						   });

});// end $(document).ready(function()
			
			



							   


function close_handler(event){
			event.preventDefault();
			$cont_div = $(this).parents(".product_details_one");
			$simil_div = $(this).parents(".product_desc_one").next(".product_similars_one");
			$desc_div = $(this).parents(".product_desc_one");
			$img_div = $(this).parents(".product_details_one").find(".product_pic_one");
			$img_and_desc = $(this).parents(".product_details_one").children("div").not(".product_similars_one");
			$(this).parents(".product_details_one").attr("resized_down","0");
			$detwrap = $(this).parents(".prod_details_wrap_one");
			
			$rb = $(this).parents(".prod_details_wrap_one").prev().find(".overlay_div_reset_btn");
			$rb.click();
			
			$previous_product_id = $pr_pic.attr("cause");
			$previous_product_img = $("#"+$previous_product_id);
			$previous_product_img.animate({left:	"0px"},500);
			$pr_pic.animate({left: "-260px"},500, function(){
									
									$simil_div.animate({
										width:	'0px',
										opacity:	'0'
											}, 1000,  function(){
											 
														$img_and_desc.animate({
														width:	'0px',
														opacity:	'0'}, 1000, function(){
															
																					// Added By Qutaiba  Start
																					$img_div.css({display:"none"});
																					$cont_div.css({display: "none"});
																					$simil_div.css({display: "none"});
																					$detwrap.css({display: "none"});
																					$desc_div.css({display: "none"});
																					
																					// Added By Qutaiba End
																					if($.browser.msie){
																						}
																					$cont_div.animate({
																						opacity:	'0',
																						width:	'0px' 
																					}, 1000, function(){
																					
																								if(parseInt($img_div.parents(".product_details_one").attr("resized_down")) == 0){
															
																									$("#layout").css({width:	(parseInt($("#layout").css("width"))-588)+"px" });
															
																									$img_div.parents(".product_details_one").attr("resized_down","1");
																									if(variation_stack.length >  0){
																											for(j in variation_stack){
																													t = variation_stack[j];
																													$(t).click();
																												}
																												variation_stack.length = 0;
																											}
																									
																									var rand = new Date;
	 

																									window.location.hash = "#"+(rand.getTime());
																									
																									return true;
																										}

 																									})

																						});

																});

														});
			
 			return false; 
					}

function zoom_overlay(event) {
	
		did = event.data.divid;
		 

		$si = $(this).find(".sliding_img");
		

		
		if($(this).attr("run") == "odd"){

		bigimg = new Image();
		$(bigimg).attr("src",event.data.bigPic); 
		$(bigimg).load(function(){
			
			$(this).css({backgroundColor: "#e8e8e8"});

				$(this).attr("run","even");

				$si.animate({  
							
							width:	'1020px',
							
							left:	'-300px',
							
							height: '1974px',
							
							top:	'-1050px'

							},function(){
									
									$(this).parent().parent().append($(this).clone().css("display","none").addClass("temp_bg"));
									$(this)
										
										.attr("src",event.data.bigPic)
										.css({

											 cursor:	"move",
											 left:	"-306px",
											 top:		'-774px',
											 width:	  '1040px',
											 height:	"1344px"

											 })

										.draggable();
								 
									closeDiv = document.createElement("a");

									$(closeDiv)

										.append( $(document.createElement("img")).attr({
																					   src	:	"images/reset.gif",
																					   border:	"0"
																					   }).css({
																						   	 opacity:	"0.7"
																						   }) )

										.attr("href","javascript: void(0)")
										
										.addClass("overlay_div_reset_btn")
										
										.css({position:	'absolute',left: '0',bottom:	'0',zIndex:	16})

										.click(function(){
													$(this).fadeOut();
															/****/
 													$p = $(this).parent().parent();		
 													$p.css({backgroundColor: ""});	
													//$p.find(".temp_bg").css("display","");
 													//$(this).prev().fadeOut();
													//$(this).prev().attr("src",event.data.medPic);
												 	
													$(this).prev().attr("src",event.data.medPic).css({  
							
																			width:	'1020px',
																			
																			left:	'-300px',
																			
																			height: '1974px',
																			
																			top:	'-1050px'

							}).animate({

																left:  "260px",
																top:	'0px',
																width:	'260px',
																heigth:	"504px"

																},function(){
																	 $p.css("display","none").html("");
																	});

													

				

															

															/****/

														});

									$(this).parent().append($(closeDiv));

								});

				
			
							 });
				

			} else {

				

				}

		

		 

			 

	}
	
  
	
function create_overlay_div(idd){
		d = document.createElement("div");
		d.id =  "overlay_div_"+idd;
		$(d).css({
				 	position: "absolute",
					top: "0px",
					left: "0px",
					width: "520px",
					zIndex: "15",
					height: "504px",
					display: "none",
					overflow: "hidden"
				 });
	return d;
	} 
	
function getVariation(arr,idx){
		 for(o in arr){
			 b = arr[o];
							if(b.id == idx){
								return b;
								}
						}
		return false;
							 
	}
var variation_stack = Array();

function switch_variance(e){
		src_image = e.target;
		//$(src_image).parents(".product_details_one").find("a.close").click();
		//imgid = parseInt(src_image.id.substring(4));
		//variation_stack[variation_stack.length]="img.fading_img#p"+imgid;
		var_pr_id = $(src_image).attr("id").substring(4);
		old_var_id = $(src_image).parents(".product_details_one").find(".sliding_img")
			.attr("cause").substring(1);
			
		//old_var_id = "product_"+old_var_id;	
		
		
		$(src_image).parents(".product_details_one").find(".sliding_img")
			.fadeOut("slow");
			
		newImage = document.createElement("img");
		old_object_holder = new Object();
		old_object_holder=eval("getVariation(products_property.product_"+old_var_id+".variations,"+var_pr_id+")");
		newImage.src = old_object_holder.meduim_pic;
		$("#p"+old_var_id).attr({src:	old_object_holder.small_pic,
								alt:	old_object_holder.product_no});
		
		eval("products_property.product_"+old_var_id+".color = '"+old_object_holder.color+"'");
		eval("products_property.product_"+old_var_id+".desc = '"+old_object_holder.desc+"'");
		eval("products_property.product_"+old_var_id+".desc = '"+old_object_holder.desc+"'");
		eval("products_property.product_"+old_var_id+".id = '"+old_object_holder.id+"'");
		eval("products_property.product_"+old_var_id+".large_pic = '"+old_object_holder.large_pic+"'");
		eval("products_property.product_"+old_var_id+".meduim_pic = '"+old_object_holder.meduim_pic+"'");
		eval("products_property.product_"+old_var_id+".price = '"+old_object_holder.price+"'");
		eval("products_property.product_"+old_var_id+".product_no = '"+old_object_holder.product_no+"'");
		eval("products_property.product_"+old_var_id+".sizes = getVariation(products_property.product_"+old_var_id+".variations,"+var_pr_id+").sizes");
		eval("products_property.product_"+old_var_id+".small_pic = '"+old_object_holder.small_pic+"'");
		
		 
		$(newImage).unbind("load").load(function(){
								$pd = $(src_image).parents(".product_details_one");
								$pd.find(".sliding_img").attr("src",$(this).attr("src"));
								$pd.find(".sliding_img").fadeIn("fast",function(){
											$pd.find(".pr_description").html(old_object_holder.desc);
											$pd.find(".pr_color").html(old_object_holder.color);
											$pd.find(".product_no").html(old_object_holder.product_no);
											$pd.find(".product_price").html(old_object_holder.price);	
											var s2_arr = new Array();
											var s3_arr = new Array();
											s3_arr  =  old_object_holder.sizes.split(",");
											for(j in s3_arr){
												s2_arr[s2_arr.length] = parseFloat(s3_arr[j]);
												}
											
											 
											html_s_array = $pd.find(".pr_sizes").get(0);
				
											for(i=1;i<html_s_array.options.length;i++)
											{
												opt = html_s_array.options[i];
											
												if(s2_arr.indexOf(parseFloat(opt.value)) != -1)
													opt.disabled = false;
												else
													opt.disabled = true;
												
											}
											
																							});
								
								
								  }
						);
		/*.attr("src",);
		$(src_image).unbind("load").bind("load",function(){
								  alert("loaded");
								  });*/
		
		
	}

function create_sim_div(o,clickable){
	if (clickable == null){
	   clickable = true;
	 }
 	if(!o.small_pic) 
			return;
		 
	if(o.small_pic == null)
		return;
		
		newd = document.createElement("div");
		small_img = document.createElement("img");
		small_img.src = o.small_pic;
		
		$(small_img)
			.hide()
			.css({
						 	cursor:	"default",
							height:	"84px",
							width:	 "65px"
						 })
			.attr({alt:	o.desc,
				  border:	"0",
				  title:	o.desc,
				  id:	"var_"+o.id
				  })
			.load(function(){
						   	$(this).fadeIn("slow");
						   }).unbind("click");
		 if(clickable)
			$(small_img).css({cursor: "pointer",
											 display:	"block"})
								.bind("click",switch_variance);
		
		
		
		$(newd)
			.css({
						float:	"left",
						clear:	"both" 
					 
					})
			.append(small_img);
		
		return $(newd);
	}
	
	
if(!Array.indexOf){
    Array.prototype.indexOf = function(obj, start){
        for(var i=(start||0); i<this.length; i++){
            if(this[i]==obj){
                return i;
            }
        }
    return -1;
	}
}



