// JavaScript Document


$().ready(function() {
			$('.searchBox').click(
				function() {
					if (this.value == this.defaultValue) {
					this.value = '';
					}
				}
			);
			
			$('.searchBox').blur(
				function() {
					if (this.value == '') {
					this.value = this.defaultValue;
					}
				}
			);
			
			$("#searchStr").autocomplete("/ac.php", {
				width: 320,
				max: 30, 
				highlight: false,
				scroll: true,
				scrollHeight: 400,
				formatItem: function(data, i, n, value) {
					return "<img align='left' style='width:30px;height:30px;' src='" + data[2] + "'/>" + value.split(".")[0] + "<br /><em>" + data[3] +"</em>";
				},
				formatResult: function(data, value) {
					return value.split(".")[0];
				}
				/*width: 185,
				scroll: false,
				selectFirst: false*/
			});
			
			$("#searchStr").result(function(event, data, formatted) {
				if (data)
				window.location = "/?_a=viewCat&catId="+data[4]+"#"+data[1];
			});
				
				
			/* animate the scrolling */
			var id = window.location.hash.slice(1);
			if(id!=0) {
				$('html,body').animate({scrollTop: $('#id_'+ id).offset().top}, 2500);
			}
			
			
			/* quickquote */
			
			function onCatChange(){
				var selected = $("#Cat option:selected");			
				$("#Prod").load("/ajax.php?action=getProds&val="+selected.val());
			}
			
			function quickQuote(){ 
				var selected = $("#Prod option:selected");			
				window.location = "http://www.blinds4udirect.co.uk/prod_" + selected.val() + ".html?width=" + $("#width").val() + "&drop=" + $("#drop").val() + "";
			}
		
			/* Quick Quote Builder */
			$("#Cat").load("/ajax.php?action=getCats");
			
			var selected = $("#Cat option:selected");			
			$("#Prod").load("/ajax.php?action=getProds&val=4");
			
			$("#Cat").change(onCatChange); 
			$("#quickQuoteSubmit").click(quickQuote); 
			
			  $.extend({  
			 getUrlVars: function(){  
			   var vars = [], hash;  
			   var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');  
			   for(var i = 0; i < hashes.length; i++)  
			   {  
				 hash = hashes[i].split('=');  
				 vars.push(hash[0]);  
				 vars[hash[0]] = hash[1];  
			   }  
			   return vars;  
			 },  
			 getUrlVar: function(name){  
			   return $.getUrlVars()[name];  
			 }  
		   });  
			
			
		
							
});	

