$(document).ready(function(){

	$(".left_image:eq(0)").css({ height:'95px' });
	
    $('#topImage').cycle({
		fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
		timeout:         10000,
		startingSlide: '0',
		pager: '#nav'
	});
	
	
	$(".large_dropdown").click(function(){
		var height = parseInt($(this).next().css("height"));
		if (height == 0){
			$(this).next().animate({height:"170px"});
		}
		else{
			$(this).next().animate({height:"0px"});
		}
	});
	$(".large_dropdown_list a").click(function(){
		var selection = $(this).html();									   
		$(this).parent().prev().text(selection);
		document.getElementById("selectedLocation").value = selection;
		$(this).parent().animate({height:"0px"});
	});
	
	$(".small_dropdown").click(function(){
		var height = parseInt($(this).next().css("height"));
		if (height == 0){
			$(this).next().animate({height:"170px"});
		}
		else{
			$(this).next().animate({height:"0px"});
		}
	});
	$(".small_dropdown_list a").click(function(){
		var selection = $(this).html();									   
		$(this).parent().prev().text(selection);
		$(this).parent().animate({height:"0px"});
	});
	
	$(".location_dropdown").click(function(){
		var height = parseInt($(this).next().css("height"));
		var citycount = parseInt(document.getElementById("citycount").value);
		var openheight = citycount * 16;
		if (height == 0){
			$(this).next().animate({height:openheight + "px"});
		}
		else{
			$(this).next().animate({height:"0px"});
		}
	});
	var previousselection;
	$(".location_dropdown_list a").click(function(){
		var selection = $(this).html();									   
		$(this).parent().prev().text(selection);
		$(this).parent().animate({height:"0px"});
		
		var id = $(this).attr("id");
		locationDetails(id);
		
		if (previousselection != null){
			var margintop1 = parseInt($("#"+previousselection).css("margin-top")) + 211;
			//$(".signpost").css({"height":"0px"});
			$("#"+previousselection).css({"height":"0px", marginTop:margintop1 + "px"});
		}
		
		var margintop = parseInt($("#"+selection).css("margin-top")) - 211;
		$("#"+selection).animate({"height":"211px", marginTop:margintop + "px"}, 400);
		previousselection = selection;
	});
	
});

function selectImage(imageNo)
{

	$('#topImage').cycle('stop');
	$('#topImage').cycle({
		fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
		timeout:         10000,
		startingSlide: imageNo,
		pager: '#nav'
	});

}



function viewcontent(itemNo){
	var oldindex = document.getElementById("linkindex").value;
	if (itemNo != oldindex) {
		$(".left_image:eq("+oldindex+")").animate({ height:'0px' },500);
		$(".left_image:eq("+itemNo+")").animate({ height:'95px' },500);
		document.getElementById("linkindex").value = itemNo;
	}
}

function ajaxSetup() {
    var xmlHttp;
    try    {  
        // Firefox, Opera 8.0+, Safari
	    xmlHttp = new XMLHttpRequest();  
    }
    catch (e)    {  
        // Internet Explorer  
	    try{    
		    xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");    
	    }
	    catch (e){    
		    try{      
  			    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  		    }
		    catch (e){
  			    alert("Your browser does not support AJAX!");
  			    return false;
  		    }
	    }
    }
    return xmlHttp;
}
function locationDetails(id)
{
    var xmlHttp = ajaxSetup();
    
    xmlHttp.onreadystatechange=function()
    {
        if(xmlHttp.readyState == 4)   // 4 = Completed
        {
            document.getElementById("locationdetails").innerHTML = xmlHttp.responseText;
        }
    }
    xmlHttp.open("GET","detailsajax.php?id=" + id, true);
    xmlHttp.send(null);
}
function googlemapss(){
    var xmlHttp = ajaxSetup();
	var postcode = document.getElementById("postcode").value;
	var postcode2 = document.getElementById("postcode2").value;

	xmlHttp.onreadystatechange=function()
    {
        if(xmlHttp.readyState == 4)   // 4 = Completed
        {
            document.getElementById("location_map").innerHTML = xmlHttp.responseText;
        }
    }
    xmlHttp.open("GET","map.php?postcode=" + postcode + "&postcode2=" + postcode2, true);
    xmlHttp.send(null);
}
function newsletter(){
    var xmlHttp = ajaxSetup();
	var email = document.getElementById("email").value;

	xmlHttp.onreadystatechange=function()
    {
        if(xmlHttp.readyState == 4)   // 4 = Completed
        {
            document.getElementById("newsletter_input").innerHTML = "Thank you for signing up to our newsletter";
        }
    }
    xmlHttp.open("GET","newsletter.php?email=" + email, true);
    xmlHttp.send(null);
}
