        var position;
        function init(){
            resizeBrowser();
            jQuery.event.add(window, "load", resizeBrowser);
            jQuery.event.add(window, "resize", resizeBrowser);
            $(window).bind('scroll', function(){position=getScrollY();});
            $('#photoList').css("vertical-align","top");
        }

        function getScrollY() {
              var scrOfX = 0, scrOfY = 0;
              if( typeof( window.pageYOffset ) == 'number' ) {
                //Netscape compliant
                scrOfY = window.pageYOffset;
                scrOfX = window.pageXOffset;
              } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
                //DOM compliant
                scrOfY = document.body.scrollTop;
                scrOfX = document.body.scrollLeft;
              } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
                //IE6 standards compliant mode
                scrOfY = document.documentElement.scrollTop;
                scrOfX = document.documentElement.scrollLeft;
              }
              return scrOfY;
            }

        function resizeBrowser(){
            var win= $(window);
			$('.imgContent').css('width',1024);
			$('.btnNext').css("left",990);
			$('#footer table').css("width",974);
            if(win.width()>1024){
                $('.imgContent').css('width',win.width()-45);
                $('.btnNext').css("left",win.width()-77);
                $('#footer table').css("width",win.width()-50);
            }
        }

        function showBox(){
            var options = {};
            $(".ContectForm").show("clip",options,800);
        }

        function Slide(){
           var arr=new Array();
           var num=0;
           var timer;
           function initSlide(){
               i=0;
               $(".imgContent").each(function(){
                   arr[i]=this;
                   i++;
               });
			   if($(arr[0]).height()>0){
				   $('.btnNext').css("top", $(arr[0]).height()*0.7);
				   $('.btnPrevious').css("top", $(arr[0]).height()*0.7);
			   }else{
					$(arr[0]).load(function(){
						$('.btnNext').css("top", $(this).height()*0.7);
				        $('.btnPrevious').css("top", $(this).height()*0.7);
					});
			   }
           }
           function slideRun(old){
               if(arguments.length>1) thisImg=arr[arguments[1]];
               else thisImg=arr[num];
			   var oldHeight=$('.imgContent').parent().height();
               $(old).fadeOut(500,function(){
                   $('.imgContent').parent().css("height",oldHeight);
                   window.scrollTo(0,position);
                   $(thisImg).fadeIn(500,function(){
						$('.btnNext').css("top", $(thisImg).height()*0.7);
						$('.btnPrevious').css("top", $(thisImg).height()*0.7);
						$('.imgContent').parent().css("height",0);
				   });
                   window.scrollTo(0,position);
               });
               timer=setTimeout(function(){  if(num+1<=arr.length-1)num++;
		       else num=0;
                       slideRun(thisImg);},8000);
           }

           function goTo(next){
               clearTimeout(timer);
               slideRun(arr[num],next);
               num=next;
           }
           initSlide();
           if(arr.length>1){
               timer=setTimeout(function(){ slideRun(arr[0],num+1);},8000);
           }else{
            $('.btnPrevious').remove();
            $('.btnNext').remove();
           }
           $('.btnPrevious').die();
           $('.btnPrevious').live("click",function(){
               next=0;
               if(num-1<0)next=arr.length-1;
               else next=num-1;
               goTo(next);
               return false;
           });
           $('.btnNext').die();
           $('.btnNext').live("click",function(){
               next=0;
                if(num+1<=arr.length-1)next=num+1;
		else next=0;
               goTo(next);
               return false;
           });
           
        }
		
        function changeProductListOnContactUs(){
            var id=$('#catalog_list').val();
            $.ajax({
                    url:"Function/getProductListOnContact.php?id="+id,
                    type:'get',
                    async: false,
                    dataType:'html',
                    success:function(msg){
                                     $('#product_list_Contact').html("<option value=''>Select a Product</option>"+msg);
                    }
            });
        }

        function getCatalog(id)
	{
                document.getElementById("product_list").innerHTML="";
                document.getElementById("Catalog").innerHTML="";
                if (window.XMLHttpRequest)
		  {// code for IE7+, Firefox, Chrome, Opera, Safari
		  xmlhttp=new XMLHttpRequest();
		  }
		else
		  {// code for IE6, IE5
		  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		  }
                var currentCatalogID=document.getElementById("catalog_ID").value;
		xmlhttp.open("GET","Function/getCatalog.php?CategoryID="+id+"&currentID="+currentCatalogID,false);
		xmlhttp.send();
		document.getElementById("Catalog").innerHTML=xmlhttp.responseText;
				
		return false;
	}
	
	function getSubCategory(id)
	{
		document.getElementById("Catalog").innerHTML="";
                if (window.XMLHttpRequest)
		  {// code for IE7+, Firefox, Chrome, Opera, Safari
		  xmlhttp=new XMLHttpRequest();
		  }
		else
		  {// code for IE6, IE5
		  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		  }
                
		xmlhttp.open("GET","Function/getSubCategory.php?CategoryID="+id,false);
		xmlhttp.send();
		document.getElementById("SubCategory").innerHTML=xmlhttp.responseText;
				
		return false;
	}

        function getProductList(id){
            if (window.XMLHttpRequest)
		  {// code for IE7+, Firefox, Chrome, Opera, Safari
		  xmlhttp=new XMLHttpRequest();
		  }
		else
		  {// code for IE6, IE5
		  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		  }
                var currentProductID=document.getElementById("product_ID").value;
		xmlhttp.open("GET","Function/getasahi_scissors.php?ProductID="+id+"&currentID="+currentProductID,false);
		xmlhttp.send();
		document.getElementById("product_list").innerHTML=xmlhttp.responseText;

		return false;
        }
	
	function getIDtoContent(){
		var pid=getURLParam("pid");
		var cid=getURLParam("cid");
		if(cid.length>0){
			getMainContent("Category",cid);
		}else{
                    getMainContent("Category",2);
                }
	}
	
	function getURLParam(strParamName){
	  var strReturn = "";
	  var strHref = window.location.href;
	  if ( strHref.indexOf("?") > -1 ){
		var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
		var aQueryString = strQueryString.split("&");
		for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
		  if ( 
	aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1 ){
			var aParam = aQueryString[iParam].split("=");
			strReturn = aParam[1];
			break;
		  }
		}
	  }
	  return unescape(strReturn);
	}
	
	function getMainContent(CType, id)
	{
                if (window.XMLHttpRequest)
		  {// code for IE7+, Firefox, Chrome, Opera, Safari
		  xmlhttp=new XMLHttpRequest();
		  }
		else
		  {// code for IE6, IE5
		  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		  }
		if(arguments.length>=3){
			var pid=arguments[2];
			xmlhttp.open("GET","Function/getContent.php?Type="+CType+"&ID="+id+"&pid="+pid,false);
		}else{
			xmlhttp.open("GET","Function/getContent.php?Type="+CType+"&ID="+id,false);
		}
		
		xmlhttp.send();
		document.getElementById("MainContent").innerHTML=xmlhttp.responseText;
		
		return false;
	}
	
	function clearCatalog()
	{
		document.getElementById("Catalog").innerHTML = "<b>&nbsp;</b>";
                document.getElementById("product_list").innerHTML="";
	}
	
	function addProduct(id)
	{
		if (window.XMLHttpRequest)
		  {// code for IE7+, Firefox, Chrome, Opera, Safari
		  xmlhttp=new XMLHttpRequest();
		  }
		else
		  {// code for IE6, IE5
		  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		  }
		  
		 ProductID = id;
		 QTY = "";
		 Name = "";
		 Size = "";
                 Price="";
                 Color="";

				 
		 if(document.getElementById("QTY_" + id)!=null)
		 	QTY = document.getElementById("QTY_" + id).value;
		 if(document.getElementById("Name_" + id)!=null)
		 	Name = document.getElementById("Name_" + id).value;
		 if(document.getElementById("Size_" + id)!=null)
		 	Size = document.getElementById("Size_" + id).value;
                 if(document.getElementById("Price_" + id)!=null)
		 	Price = document.getElementById("Price_" + id).value;
                  if(document.getElementById("Color_" + id)!=null)
		 	Color = document.getElementById("Color_" + id).value;


		if(isInteger(QTY))
		{
			xmlhttp.open("GET","Function/addCart.php?ProductID="+ProductID+"&QTY="+QTY +"&ProductName="+Name+"&Size="+Size+"&Price="+Price+"&Color="+Color ,false);
			xmlhttp.send();	
			
			//alert(xmlhttp.responseText);
			
			getCart();
                        checkOut();
		}
		else
		{
			alert("Please enter a number on QTY");
		}
		return false;
	}
	
	function removeItem(index)
	{
		if (window.XMLHttpRequest)
		  {// code for IE7+, Firefox, Chrome, Opera, Safari
		  xmlhttp=new XMLHttpRequest();
		  }
		else
		  {// code for IE6, IE5
		  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		  }
		  
		xmlhttp.open("GET","Function/removeCart.php?Index="+index ,false);
		xmlhttp.send();	
		
		alert(xmlhttp.responseText);
		
		getCart();
		checkOut();
		
		return false;
	}
	
	function isValidEmail(str) 
	{
		return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
	}

	function sentCS()
	{
		
		var Message = document.getElementById("Message").value;
		var EMail = document.getElementById("E-Mail").value;
                var catalog = document.getElementById("catalog_list").value;
                var product = document.getElementById("product_list_Contact").value;
		var url = "Function/sendMail.php";
		if((Message != "") && (EMail != "")&&(catalog != "") && (product != ""))
		{
			if(isValidEmail(EMail))
			{
				var postStr = "EMail="+ EMail +"&Message="+ Message+"&catalog="+catalog+"&product="+product;
                                 $.ajax({
                                        url:"Function/sendMail.php",
                                        data:postStr,
                                        type:'post',
                                        dataType:'html',
                                        success:function(msg){
                                            alert(msg);
                                            location.href="index.php";
                                      }
                                });
				
			}
			else
				alert("Invalid E-Mail Format!!");
		}
		else
			alert("Please Enter ALl Fields.");
	}
	
	function getCart()
	{
		if (window.XMLHttpRequest)
		  {// code for IE7+, Firefox, Chrome, Opera, Safari
		  xmlhttp=new XMLHttpRequest();
		  }
		else
		  {// code for IE6, IE5
		  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		  }

		xmlhttp.open("GET","Function/getCart.php",false);
		xmlhttp.send();
		document.getElementById("Cart").innerHTML=xmlhttp.responseText;
	}
	
	function checkOut()
	{
		if (window.XMLHttpRequest)
		  {// code for IE7+, Firefox, Chrome, Opera, Safari
		  xmlhttp=new XMLHttpRequest();
		  }
		else
		  {// code for IE6, IE5
		  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		  }
		
		xmlhttp.open("GET","Function/CheckOut.php",false);
		xmlhttp.send();
		document.getElementById("ContectForm").innerHTML=xmlhttp.responseText;
                window.scrollTo(0,parseInt($("body").css("height")));
                $('#CustomerName').focus();
	}
	
	function checkInfo()
	{
		var CustomerName = document.getElementById("CustomerName").value;
                var LastName = document.getElementById("LastName").value;
                var Occupation = document.getElementById("Occupation").value;
                var company = document.getElementById("Company").value;
                var zip = document.getElementById("zipCode").value;
                var city = document.getElementById("city").value;
                var country = document.getElementById("country").value;
				 var comments = document.getElementById("comments").value;
		var Address1 =  document.getElementById("Address1").value; 
		//var Address2 =  document.getElementById("Address2").value; 
		var Phone = document.getElementById("Phone").value; 
		var EMail = document.getElementById("EMail").value; 
		
		if((CustomerName != "") && (Address1 != "") && (Phone != "") && (EMail != "")&& (LastName != "")&& (Occupation != "")&& (company != "")&& (zip != "")&& (city != "")&& (country != ""))
		{
			if(!isValidEmail(EMail))
			{
				alert("Invalid E-mail address format !");
				return false;
			}
		}
		else
		{
			alert("Please enter all informations !");
			return false;
		}
                 $.ajax({
                        url:"Function/confirmCheckOut.php",
                        type:'post',
                        data:"CustomerName="+CustomerName+"&Address1="+Address1+"&Phone="+Phone+"&EMail="+EMail+"&LastName="+LastName+"&Occupation="+Occupation+"&company="+company+"&zipCode="+zip+"&city="+city+"&country="+country+"&comments="+comments,
                        dataType:'html',
                        success:function(msg){
                               $('#order_output').html(msg);
                               getCart();
                        }
                });
                return false;
	}

        function sendOrder(){
            var CustomerName = document.getElementById("CustomerName").value;
                var LastName = document.getElementById("LastName").value;
                var Occupation = document.getElementById("Occupation").value;
                var company = document.getElementById("company").value;
                var zip = document.getElementById("zipCode").value;
                var city = document.getElementById("city").value;
                var country = document.getElementById("country").value;
				var comments = document.getElementById("comments").value;
		var Address1 =  document.getElementById("Address1").value;
		//var Address2 =  document.getElementById("Address2").value;
		var Phone = document.getElementById("Phone").value;
		var EMail = document.getElementById("EMail").value;
		
		
                var data="CustomerName="+CustomerName+"&Address1="+Address1+"&Phone="+Phone+"&EMail="+EMail+"&LastName="+LastName+"&Occupation="+Occupation+"&company="+company+"&zipCode="+zip+"&city="+city+"&country="+country+"&comments="+comments;
            $.ajax({
                    url:"Function/SubmitOrder.php",
                    type:'post',
                    data:data,
                    dataType:'html',
                    success:function(msg){
                           $('#order_output').html(msg);
                           getCart();
                    }
            });
            return false;
        }
	
	function isInteger(val)
	{
		if(val==null)
		{
			return false;
		}
		if (val.length==0)
		{
			return false;
		}
		for (var i = 0; i < val.length; i++) 
		{
			var ch = val.charAt(i)
			if (i == 0 && ch == "-")
			{
				continue;
			}
			if (ch < "0" || ch > "9")
			{
				return false;
			}
		}
		return true;
	}
	
