var http = false;
var lastgroup = false;

if(navigator.appName == "Microsoft Internet Explorer") {
  http = new ActiveXObject("Microsoft.XMLHTTP");
} else {
  http = new XMLHttpRequest();
}


$(document).ready(function(){
						   
	$("#searchoptions").hover(function() {
 		$(this).css('cursor','pointer');
 		}, function() {
 		$(this).css('cursor','auto');
	});
	$("#searchoptions").click(function() {
		productFinder();
	});
	
	
});

function clearSearch(){
	if(document.termsform.termsfield.value == 'SEARCH'){
		document.termsform.termsfield.value = '';
	}
}

function resetSearch(){
	if(document.termsform.termsfield.value == ''){
		document.termsform.termsfield.value = 'SEARCH';	
	}
}

function allChecked(selector){	

	var result = true;
	var count = 0
  $('input[type=checkbox]').each(function() { 
		
		if(this.id.indexOf(selector) == 0){
			
			if(count==1){
				
				if(this.checked == true){
					result = false;	
				}else{
					result = true;
				}
				var first = this.id;

			}
			count++;
		}
										  
		if(this.id.indexOf(selector) == 0){
        	this.checked = result;
		}
		if(!result){
			document.getElementById(selector+"_0").checked=false;
		}
		
	}); 	

}

$('#prodFinderInner').click(function() {
									
  $('#prodFinderInner').fadeOut('slow', function() {
    // Animation complete.
  });
});

function productFinder(){

	$('#prodFinder').fadeIn('slow', function() {

     });
      $('#prodFinderInner').slideDown('slow', function() {

     });
	  
	  $('#searchoptions').fadeOut('fast', function() {

     });
	
	$('#whiteout').fadeIn('fast', function() {

     })

	  menusClose();
}

function resetFinder(){
	$('input[type=checkbox]').each(function() { 
        this.checked = false; 
	}); 	
	resetFinderCookies();
}

function resetFinderCookies(){
	http.open("GET", "ajax/resetfinder.php");
	http.onreadystatechange=function() {
	  if(http.readyState == 4) {
	    //alert(http.responseText);
	  }
	}
	http.send(null);
}

function submitFinder(){
	closeFinder()
	document.finderform.submit();	
}

function closeFinder(){

      $('#prodFinderInner').slideUp('slow', function() {

      });
	
	$('#searchoptions').fadeIn('fast', function() {

     });
	$('#whiteout').fadeOut('fast', function() {

     });
	$('#prodFinder').fadeOut('slow', function() {

     });
}

function showfinishes(group){

		if(lastgroup){
			$('#group_'+lastgroup).slideUp('slow', function() {

      		});
		}
		
	  $('#group_'+group).slideDown('slow', function() {

      });
	lastgroup = group;
}


function over(obj) {
   obj.style.border = '1px solid #a49b8a';
}

function out(obj){
	obj.style.border = '1px solid #f6f2ec';
}

function emailaddress(){
	a = 'info'; 
	b = 'holbein.co.uk'; 
	c = '@';
	document.write('<a href="mailto:'+a+c+b+'">'+a+c+b+'</a>')	;
}
function no(){}

function show(id){
	obj = document.getElementById(id).style.display;
	if(document.getElementById(id).style.display == 'block'){
		document.getElementById(id).style.display = 'none';
	}else{
		$('#'+id).click(function() {
      $('#book').fadeIn('slow', function() {
        // Animation complete
      });
    });
	}
}


function linkto(url){
	document.location.href = url;
}


function deleteconfirm(del){ 
	if (
		confirm("Are you sure you wish to permanently delete this item?\n\nOK = Yes - Cancel = No")){ 
		window.location=del;
	}
} 



function showsubs2(){
	document.getElementById('submenu').style.display = 'none';
	//document.getElementById('submenu2').style.display = 'block';
	
	$('#submenu').slideDown('fast', function() {
        // Animation complete
      });
    
	
	if(prodmenuopen){
		document.getElementById(prodmenuopen).style.display = 'none';
	}
}



function hidesubs(){
	menusClose();
	if(prodmenuopen){
		document.getElementById(prodmenuopen).style.display = 'none';
	}
}


function loadimage(img, obj){
	document.getElementById('imageloader').src = img;
	document.getElementById(obj).src = 'images/photos/thumbs/';
}



var prodmenuopen = '';


function showProductMenu(id, position){
	
	if(prodmenuopen){
		document.getElementById(prodmenuopen).style.display = 'none';
	}
	
	document.getElementById(id).style.top = ((position*22)+60)+'px';

	var idopen = '#'+id;
	$(idopen).fadeIn('fast', function() {
        // Animation complete
      });
	prodmenuopen = id;
}

function menusClose(){
	document.getElementById('submenu').style.display = 'none';
}
