$(document).ready(function(){

// alert($.cookies.get('RDC_COLOURS_DARK'));

 if($.cookies.get('RDC_COLOURS_DARK') != null) {
	$("#accessStylePicker").css({ "background-color" :  $.cookies.get('RDC_COLOURS_DARK') });
	$(".search_button").css({ "background-color" :  $.cookies.get('RDC_COLOURS_DARK') });
	$("#menu1 li.selected").css({ "background-color" : $.cookies.get('RDC_COLOURS_DARK') });
	$("a_zList li a:hover").css({ "background-color" :  $.cookies.get('RDC_COLOURS_DARK') });
	$(".section_footer").css({ "background-color" :  $.cookies.get('RDC_COLOURS_LIGHT') });
	$(".widget_links").css({ "color" :  $.cookies.get('RDC_COLOURS_DARK') });
	$(".headers").css({ "background-image" :  $.cookies.get('RDC_IMG_SMALL') });
	$(".headers_large").css({ "background-image" :  $.cookies.get('RDC_IMG_SMALL') });
	$(".headers_large2").css({ "background-image" :  $.cookies.get('RDC_IMG_SMALL') });
	$(".headers_page_nav").css({ "background-image" :  $.cookies.get('RDC_IMG_SMALL') });
 }
//-------------------------------------------------------------------------------------------------------------------------

//homepage colours

$("#green").click(function() { 
   var options = { path: "", expires: 10 };
	$.cookies.set('RDC_COLOURS_DARK', '#528C2F', options);
	$.cookies.set('RDC_COLOURS_LIGHT', '#639142', options);
	$.cookies.set('RDC_IMG_SMALL', 'url(images/small_leaf_green.gif)', options);
	$("#accessStylePicker").css({ "background-color" :  $.cookies.get('RDC_COLOURS_DARK') });
$(".search_button").css({ "background-color" :  $.cookies.get('RDC_COLOURS_DARK') });
$("#menu1 li.selected").css({ "background-color" : $.cookies.get('RDC_COLOURS_DARK') });
$("a_zList li a:hover").css({ "background-color" :  $.cookies.get('RDC_COLOURS_DARK') });
$(".section_footer").css({ "background-color" :  $.cookies.get('RDC_COLOURS_LIGHT') });
$(".widget_links").css({ "color" :  $.cookies.get('RDC_COLOURS_DARK') });
$(".headers").css({ "background-image" :  $.cookies.get('RDC_IMG_SMALL') });
$(".headers_large").css({ "background-image" :  $.cookies.get('RDC_IMG_SMALL') });
$(".headers_large2").css({ "background-image" :  $.cookies.get('RDC_IMG_SMALL') });
$(".headers_page_nav").css({ "background-image" :  $.cookies.get('RDC_IMG_SMALL') });
    return false;
});


$("#blue").click(function() { 
   var options = { path: "", expires: 10 };
	$.cookies.set('RDC_COLOURS_DARK', '#00699B', options);
	$.cookies.set('RDC_COLOURS_LIGHT', '#007CB9', options);
	$.cookies.set('RDC_IMG_SMALL', 'url(images/small_leaf_blue.gif)', options);
	$("#accessStylePicker").css({ "background-color" :  $.cookies.get('RDC_COLOURS_DARK') });
$(".search_button").css({ "background-color" :  $.cookies.get('RDC_COLOURS_DARK') });
$("#menu1 li.selected").css({ "background-color" : $.cookies.get('RDC_COLOURS_DARK') });
$("a_zList li a:hover").css({ "background-color" :  $.cookies.get('RDC_COLOURS_DARK') });
$(".section_footer").css({ "background-color" :  $.cookies.get('RDC_COLOURS_LIGHT') });
$(".widget_links").css({ "color" :  $.cookies.get('RDC_COLOURS_DARK') });
$(".headers").css({ "background-image" :  $.cookies.get('RDC_IMG_SMALL') });
$(".headers_large").css({ "background-image" :  $.cookies.get('RDC_IMG_SMALL') });
$(".headers_large2").css({ "background-image" :  $.cookies.get('RDC_IMG_SMALL') });
$(".headers_page_nav").css({ "background-image" :  $.cookies.get('RDC_IMG_SMALL') });
    return false;
});

$("#purple").click(function() { 
   var options = { path: "", expires: 10 };
	$.cookies.set('RDC_COLOURS_DARK', '#9F0050', options);
	$.cookies.set('RDC_COLOURS_LIGHT', '#D7006B', options);
	$.cookies.set('RDC_IMG_SMALL', 'url(images/small_leaf_purple.gif)', options);
	$("#accessStylePicker").css({ "background-color" :  $.cookies.get('RDC_COLOURS_DARK') });
$(".search_button").css({ "background-color" :  $.cookies.get('RDC_COLOURS_DARK') });
$("#menu1 li.selected").css({ "background-color" : $.cookies.get('RDC_COLOURS_DARK') });
$("a_zList li a:hover").css({ "background-color" :  $.cookies.get('RDC_COLOURS_DARK') });
$(".section_footer").css({ "background-color" :  $.cookies.get('RDC_COLOURS_LIGHT') });
$(".widget_links").css({ "color" :  $.cookies.get('RDC_COLOURS_DARK') });
$(".headers").css({ "background-image" :  $.cookies.get('RDC_IMG_SMALL') });
$(".headers_large").css({ "background-image" :  $.cookies.get('RDC_IMG_SMALL') });
$(".headers_large2").css({ "background-image" :  $.cookies.get('RDC_IMG_SMALL') });
$(".headers_page_nav").css({ "background-image" :  $.cookies.get('RDC_IMG_SMALL') });
    return false;
});


$("#red").click(function() { 
   var options = { path: "", expires: 10 };
	$.cookies.set('RDC_COLOURS_DARK', '#CE0000', options);
	$.cookies.set('RDC_COLOURS_LIGHT', '#FF1A1A', options);
	$.cookies.set('RDC_IMG_SMALL', 'url(images/small_leaf_red.gif)', options);
	$("#accessStylePicker").css({ "background-color" :  $.cookies.get('RDC_COLOURS_DARK') });
$(".search_button").css({ "background-color" :  $.cookies.get('RDC_COLOURS_DARK') });
$("#menu1 li.selected").css({ "background-color" : $.cookies.get('RDC_COLOURS_DARK') });
$("a_zList li a:hover").css({ "background-color" :  $.cookies.get('RDC_COLOURS_DARK') });
$(".section_footer").css({ "background-color" :  $.cookies.get('RDC_COLOURS_LIGHT') });
$(".widget_links").css({ "color" :  $.cookies.get('RDC_COLOURS_DARK') });
$(".headers").css({ "background-image" :  $.cookies.get('RDC_IMG_SMALL') });
$(".headers_large").css({ "background-image" :  $.cookies.get('RDC_IMG_SMALL') });
$(".headers_large2").css({ "background-image" :  $.cookies.get('RDC_IMG_SMALL') });
$(".headers_page_nav").css({ "background-image" :  $.cookies.get('RDC_IMG_SMALL') });
    return false;
});

$("#orange").click(function() { 
   var options = { path: "", expires: 10 };
	$.cookies.set('RDC_COLOURS_DARK', '#BA500C', options);
	$.cookies.set('RDC_COLOURS_LIGHT', '#EA660F', options);
	$.cookies.set('RDC_IMG_SMALL', 'url(images/small_leaf_orange.gif)', options);
$("#accessStylePicker").css({ "background-color" :  $.cookies.get('RDC_COLOURS_DARK') });
$(".search_button").css({ "background-color" :  $.cookies.get('RDC_COLOURS_DARK') });
$("#menu1 li.selected").css({ "background-color" : $.cookies.get('RDC_COLOURS_DARK') });
$("a_zList li a:hover").css({ "background-color" :  $.cookies.get('RDC_COLOURS_DARK') });
$(".section_footer").css({ "background-color" :  $.cookies.get('RDC_COLOURS_LIGHT') });
$(".widget_links").css({ "color" :  $.cookies.get('RDC_COLOURS_DARK') });
$(".headers").css({ "background-image" :  $.cookies.get('RDC_IMG_SMALL') });
$(".headers_large").css({ "background-image" :  $.cookies.get('RDC_IMG_SMALL') });
$(".headers_large2").css({ "background-image" :  $.cookies.get('RDC_IMG_SMALL') });
$(".headers_page_nav").css({ "background-image" :  $.cookies.get('RDC_IMG_SMALL') });
    return false;
});

//-------------------------------------------------------------------------------------------------------------------------

$("#tooltip_move").simpletip({ 
	// Configuration properties  
	 fixed: true, 
	 content: "Drag & Drop me no a new position on the page",
	 position: ["0", "-20"] 
});


//-------------------------------------------------------------------------------------------------------------------------

//rochford office Latitude: 51.58169 Longitude: 0.707323
jQuery('#map1').jmap('init', {'mapType':'map', 'mapZoom':12, 'mapCenter':[51.600000, 0.666323]});

jQuery('#map1').jmap('AddMarker', {'pointLatLng': [51.58169, 0.707323],'pointHTML': '<strong>Council Offices South Street, <br/>Rochford,<br/> Essex <br/>SS41BW</strong><br/>'});

jQuery('#map1').jmap('AddMarker', {'pointLatLng': [51.589031, 0.61079],'pointHTML': '<strong>Civic Suite and Rayleigh Information Centre, <br/> 2 Hockley Road, <br/> Rayleigh <br/>SS6 8EB<br/></strong>'});

jQuery('#map1').jmap('init', {'mapType':'map', 'mapZoom':12, 'mapCenter':[51.600000, 0.666323]});


 jQuery('#query-submit-1').click(function(){
        jQuery('#map1').jmap('init', {'mapType':'map', 'mapZoom':10, 'mapCenter':[51.600000, 0.666323]});
	var querystring = 'from: [' + jQuery('#query').val() + '] to: [' + jQuery('#query2').val() + ']';
	//alert (querystring);
    jQuery('#map1').jmap('SearchDirections', {'query':querystring,'panel':'#directions1'});
	
 });


//-------------------------------------------------------------------------------------------------------------------------
	//hise and show homepage content and set your location
	$(".blindfx").hide();
	
	$("#doBlind").click(function() { 
	    $(".blindfx").toggle("blind", { 
    	    direction: "vertical" 
    	},500); 
	});
	
	$(".blindfx2").hide();
	$("#doBlind2").click(function() { 
	    $(".blindfx2").toggle("blind", { 
    	    direction: "vertical" 
    	},500); 
	});
	
	
//--------------------------------------------------------------------

	//ajax dynamic lookup
$("#find_address").click(function() {
	//alert($("#postcode").attr("value"));
	$.post("../address_lookup.php", {address: ""+$("#postcode").attr("value")+""}, function(feedback){ 	$('#test_label').html(feedback); });
});	
	
//-------------------------------------------------------------------------------------------------------------------------	
	
	//Drag and Drop Facility
		$(".groupWrapper").sortable({
		connectWith: $(".groupWrapper"),
		placeholder: 'ui-state-highlight',
		handle: 'div.header_wrapper',
		dropOnEmpty: true,
		forcePlaceholderSize: true, 
		tolerance: 'intersect',
			stop: function(){
				//var serial = jQuery.makeArray (".groupWrapper").elements;
				//var serial = $("#sections").sortable("serialize", {key: ""+ $('.groupWrapper').attr("id") +""});
				//var string = serial.hash;
				serial = "";
				serial = serialize3();
				$.post("set_cookie.php", {queryString: "" + serial + "" }, 
					function(feedback){
						$('#telephone_number').html(feedback);
	
					});
			}
		});
//-------------------------------------------------------------------------------------------------------------------------
		//reset_homepage
		
$("#links #reset_homepage").click(function() {
	//alert("reset cookie");
	$.post("reset_cookie.php", {queryString: "reset_cookie"}, 
		function(feedback){ 
		 var options = { path: "", expires: 10 };
			$.cookies.set('RDC_COLOURS_DARK', '#528C2F', options);
			$.cookies.set('RDC_COLOURS_LIGHT', '#639142', options);
			$.cookies.set('RDC_IMG_SMALL', 'url(images/small_leaf_green.gif)', options);

			setTimeout("location.reload(true);",0);
		});
});
		
//-------------------------------------------------------------------------------------------------------------------------
	$('#latest_news #newsList li').hide() // hide all divs, remove 'hide' class (used to stop flickering)
	$('#latest_news #newsList li:lt(2)').show(); // show first three news items
	//$('#latest_news #newsList li:lt(3)').show(); // show first three events items

	$('#latest_news .header_wrapper .controls #add_news_item').click(function() {
		$(this).parent().parent().parent().parent().find('#latest_news #newsList li:hidden:first').show();
	}); // show more items

	$('#latest_news .header_wrapper .controls #remove_news_item').click(function() {
		$(this).parent().parent().parent().parent().find('#latest_news #newsList li:visible:last').hide();
	}); // show less items


	$('#latest_events #eventsList li').hide() // hide all divs, remove 'hide' class (used to stop flickering)
	$('#latest_events #eventsList li:lt(2)').show(); // show first three news items
	//$('#latest_news #newsList li:lt(3)').show(); // show first three events items

	$('#latest_events .header_wrapper .controls #add_events_item').click(function() {
		$(this).parent().parent().parent().parent().find('#latest_events #eventsList li:hidden:first').show();
	}); // show more items

	$('#latest_events .header_wrapper .controls #remove_events_item').click(function() {
		$(this).parent().parent().parent().parent().find('#latest_events #eventsList li:visible:last').hide();
	}); // show less items
	
	
	//latest planning
	$('#latest_planning #planningList li').hide() // hide all divs, remove 'hide' class (used to stop flickering)
	$('#latest_planning #planningList li:lt(2)').show(); // show first three news items
	//$('#latest_news #newsList li:lt(3)').show(); // show first three events items

	$('#latest_planning .header_wrapper .controls #add_planning_item').click(function() {
		$(this).parent().parent().parent().parent().find('#latest_planning #planningList li:hidden:first').show();
	}); // show more items

	$('#latest_planning .header_wrapper .controls #remove_planning_item').click(function() {
		$(this).parent().parent().parent().parent().find('#latest_planning #planningList li:visible:last').hide();
	}); // show less items
	
	
	//latest Jobs
	$('#latest_jobs #jobsList li').hide() // hide all divs, remove 'hide' class (used to stop flickering)
	$('#latest_jobs #jobsList li:lt(2)').show(); // show first three news items
	//$('#latest_news #newsList li:lt(3)').show(); // show first three events items

	$('#latest_jobs .header_wrapper .controls_small #add_job_item').click(function() {
		$(this).parent().parent().parent().parent().find('#latest_jobs #jobsList li:hidden:first').show();
	}); // show more items

	$('#latest_jobs .header_wrapper .controls_small #remove_job_item').click(function() {
		$(this).parent().parent().parent().parent().find('#latest_jobs #jobsList li:visible:last').hide();
	}); // show less items
	
	
	//latest_bbcnews
	$('#latest_bbcnews #bbcNewsList li').hide() // hide all divs, remove 'hide' class (used to stop flickering)
	$('#latest_bbcnews #bbcNewsList li:lt(2)').show(); // show first three news items
	//$('#latest_news #newsList li:lt(3)').show(); // show first three events items

	$('#latest_bbcnews .header_wrapper .controls #add_bbcnews_item').click(function() {
		$(this).parent().parent().parent().parent().find('#latest_bbcnews #bbcNewsList li:hidden:first').show();
	}); // show more items

	$('#latest_bbcnews .header_wrapper .controls #remove_bbcnews_item').click(function() {
		$(this).parent().parent().parent().parent().find('#latest_bbcnews #bbcNewsList li:visible:last').hide();
	}); // show less items 
	
   
//-------------------------------------------------------------------------------------------------------------------------
	$(".options_table td").click(function() {
		serial = serialize2();

		if ( $(this).hasClass("selected") ) {
			$(this).removeClass('selected');
			$(this).addClass('unSelected');		
			var data = $(this).attr("id");
		
			$.post("sortdata.php", {queryString: ""+data+""}, function(feedback){ $('#telephone_number').html(feedback); });
		} else if ( $(this).hasClass("unSelected") ) {
			$(this).removeClass('unSelected');
			$(this).addClass('selected');				
		$.post("sortdata1.php", {id: ""+$(this).attr("id")+""}, function(feedback){ $('#telephone_number').html(feedback); });
		}
	});
//-------------------------------------------------------------------------------------------------------------------------
//ajax form ontrol for recycling rounds
$("#submitStreet").click(function() {
		$.post("ajax_recycling.php", {street_name: ""+$("#street_name_ajax").attr("value")+""}, function(feedback){ $('#recycling_response').html(feedback); });
	});
//-------------------------------------------------------------------------------------------------------------------------
	//ajax form control for councillors
	$("#submitCouncillor").click(function() {
		$.post("ajax_councillor.php", {ward_location: ""+$("#councillor_ajax").attr("value")+""}, function(feedback){ $('#councillor_response').html(feedback); });
	
	});
//-------------------------------------------------------------------------------------------------------------------------
// set home location
$("#save_postcode").click(function() {		
	$.post("set_location.php", {postcode: ""+$("#postcode").attr("value")+"", your_address: ""+$("#your_address").attr("value")+""}, function(feedback){ $('#telephone_number').html(feedback); 
		setTimeout("location.reload(true);",0);
	});
});
//-------------------------------------------------------------------------------------------------------------------------
// clubs 


$("#submitClub").click(function() {		
	$.post("clubs.php", {clubname: ""+$("#clubid option:selected").val()+""}, function(feedback){ $('#clubs_response').html(feedback); 

	});
});



//-------------------------------------------------------------------------------------------------------------------------

// A_Z of items
$("#submitAZ").click(function() {		
	$.post("a-z.php", {item: ""+$("#azList option:selected").val()+"", dwelling: ""+$("#dwelling").val()+""}, function(feedback){ $('#az_response').html(feedback); 
	});
});

//-------------------------------------------------------------------------------------------------------------------------

//tabs 
$('#container-1 > ul').tabs();

//-------------------------------------------------------------------------------------------------------------------------
// equal heights
$('#sections').equalHeights();
//-------------------------------------------------------------------------------------------------------------------------


//-------------------------------------------------------------------------------------------------------------------------
//ajax i want to redirect
	$("#go_button").click(function() {
		//alert($('#iwantto option:selected').val());
		window.location=$("#iwantto option:selected").val();
	});
//-------------------------------------------------------------------------------------------------------------------------

	$("#go_ahead").click(function() {
		//alert("hello");
		window.location=$("#contact_form option:selected").val();
	});

//-------------------------------------------------------------------------------------------------------------------------
//AJAX WHO I AM 

	$("#whoiamsend").click(function() {
		//alert($("#whoiamform option:selected").val());
		window.location=$("#whoiamform option:selected").val();
	});

//-------------------------------------------------------------------------------------------------------------------------

	
});
 


function serialize(s)
{
	var COOKIE_NAME = 'rdc_home_positions';
	var date = new Date();
    date.setTime(date.getTime() + (10000 * 24 * 60 * 60 * 1000));
	serial = $.SortSerialize(s);
	$.cookie(COOKIE_NAME, serial.hash, { path: '/', expires: date });

};

function serialize2(s)
{
	serial = $.SortSerialize(s);
	var string = serial.hash;
	return string;	
};


function serialize3()
{


serial_col1 = "";
serial_col2 = "";
serial_col3 = "";
serial_col4 = "";

var serial_col1 = "";
serial_col1 = "";
val = $("#col1").children();
val.each(
	function() {
		serial_col1 += ( "col1[]=" + $(this).attr("id") + "&" );
	}
)

var serial_col2 = "";
serial_col2 = "";
val = $("#col2").children();
val.each(
	function() {
		serial_col2 += ( "col2[]=" + $(this).attr("id") + "&" );
	}
)

var serial_col3 = "";
serial_col3 = "";
val = $("#col3").children();
val.each(
	function() {
		serial_col3 += ( "col3[]=" + $(this).attr("id") + "&" );
	}
)

var serial_col4 = "";
serial_col4 = "";
val = $("#col4").children();
val.each(
	function() {
		serial_col4 += ( "col4[]=" + $(this).attr("id") + "&" );
	}
)

//return serial_col1 + ;
//return
//alert(serial_col1 + serial_col2 + serial_col3 + serial_col4);
	return serial_col1 + serial_col2 + serial_col3 + serial_col4;
};






