$(document).ready(function(){



$("a#linkLarge").click(function(){
var $mainText = $('body'); //$('div.mainText');body
var currentSize = $mainText.css('font-size');
var num = parseFloat(currentSize, 10);
var unit = currentSize.slice(-2);
num = num * 1.2;
$mainText.css('font-size', num + unit);
return false;
});

$("a#linkSmall").click(function(){
var $mainText = $('body'); //$('div.mainText');body
var currentSize = $mainText.css('font-size');
var num = parseFloat(currentSize, 10);
var unit = currentSize.slice(-2);
num = num / 1.2;
$mainText.css('font-size', num + unit);
return false;
});

//-------------------------------------------------------------------------------------------------------------------------

if (window.top !== window.self) {
      $("'#translation_box' option[value='ar']").attr("disabled","disabled");
      $("'#translation_box' option[value='nl']").attr("disabled","disabled");
      $("'#translation_box' option[value='fr']").attr("disabled","disabled");
      $("'#translation_box' option[value='de']").attr("selected","disabled");          
      $("'#translation_box' option[value='el']").attr("disabled","disabled");   
      $("'#translation_box' option[value='it']").attr("disabled","disabled");
      $("'#translation_box' option[value='ja']").attr("disabled","disabled");
      $("'#translation_box' option[value='ko']").attr("disabled","disabled");
      $("'#translation_box' option[value='pt']").attr("selected","disabled");          
      $("'#translation_box' option[value='ru']").attr("disabled","disabled");   
      $("'#translation_box' option[value='es']").attr("disabled","disabled");
window.top.location = window.self.location;
//window.open(''+self.location, 'nwwin'); return false;
}

//-------------------------------------------------------------------------------------------------------------------------

//$(".Path").href("/index.php");
$(".Path").attr('href', '/');

	$("#txtKeyword").autocomplete("/services/suggestions.asmx/GetList", {
            parse: raw_data,
            dataType: "xml",
            extraParams: { prefixText: function() { return $("#txtKeyword").val(); } },
            width: 310,
            contentType: "charset=utf-8",
            scroll: false,
            selectFirst: false,
            formatItem: format_item
        }).result(function(event, item) {
 
            var y = item.text;
            y = y.replace(new RegExp("<([a-z]|[A-Z])+[^<]*>", "g"), "");
            y = y.replace(new RegExp("</([a-z]|[A-Z])+[^<]*>", "g"), "");
            y = y.substring(2, y.length);
            $("#txtKeyword").val(y);
 
            window.location.href = item.value
        });
 
        $("#txtKeyword").bind("change", function() { 
            $('#schbtn').click();
        });
        
        $("#schbtn").bind("click", function() {
            window.location = 'http://www.rochford.gov.uk/wbsch/stdsearch.aspx?v=' + $("#txtKeyword").val();
        });
//-------------------------------------------------------------------------------------------------------------------------

//hide and show planning class faq

	$(".toggle_planning_container").hide();
 
	$("h2.planning_trigger").click(function(){
		$(this).toggleClass("active").next().slideToggle("slow");
	});

//-------------------------------------------------------------------------------------------------------------------------
	//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); 
	});

//--------------------------------------------------------------------

//onload feth cookie value

$.getJSON("/ajax_cookie_fetch.php?type=postcode&callback=?"
	, function(data) {
		$('#doBlind2').html(data.result);
});
	
$.getJSON("/ajax_cookie_fetch.php?type=fulladdress&callback=?"
	, function(data) {
		$('#location_text').html(data.result);
		$('.location_text_area').html(data.result);
});
		
$.getJSON("/ajax_cookie_fetch.php?type=uprn&callback=?"
	, function(data) {
		$('#maplink').html(data.result);
});

//--------------------------------------------------------------------

$("#address").autocomplete("/address_lookup.php", {
		width: 310,
		selectFirst: false
});

$("#hidden_val").val("");

$("#address").result(function(event, data, formatted) {
	if (data)
		$("#hidden_val").val(data[1]);
});

//-------------------------------------------------------------------------------------------------------------------------

$(".address_area").autocomplete("/address_lookup.php", {
		width: 310,
		selectFirst: false
});

$(".hidden_val_area").val("");

$(".address_area").result(function(event, data, formatted) {
	if (data)
		$(".hidden_val_area").val(data[1]);
});

//-------------------------------------------------------------------------------------------------------------------------
	
	//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 = push_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, domain: '.rochford.gov.uk' };
			$.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 = push_serialize2();
		//serial = $(".options_table td").serialize();
		
	//	alert($(this).serialize());
			
		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() {		
	//alert(""+$("#hidden_val").attr("value")+"");
	$.post("/set_location.php", {your_address: ""+$("#hidden_val").attr("value")+""}, function(feedback){ $('#telephone_number').html(feedback); 
		setTimeout("location.reload(true);",0);
	});
});

// set home location
$(".save_postcode").click(function() {		
	//alert(""+$("#hidden_val").attr("value")+"");
	$.post("/set_location.php", {your_address: ""+$(".hidden_val_area").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();

//-------------------------------------------------------------------------------------------------------------------------
	//ajax i want to redirect
	$("#go_button").click(function() {
		//alert($('#iwanttoselect option:selected').val());
		window.location=$("#iwanttoselect 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();
	});

//-------------------------------------------------------------------------------------------------------------------------
//ajax i want to redirect
	$("#submitReport").click(function() {
		//alert($('#report :selected').val());
		window.location=$("#report option:selected").val();
	});
//-------------------------------------------------------------------------------------------------------------------------

//Page Flip on hover

	$("#pageflip").hover(function() {
		$("#pageflip img , .msg_block").stop()
			.animate({
				width: '307px', 
				height: '319px'
			}, 500); 
		} , function() {
		$("#pageflip img").stop() 
			.animate({
				width: '70px', 
				height: '72px'
			}, 220);
		$(".msg_block").stop() 
			.animate({
				width: '70px', 
				height: '70px'
			}, 200);
	});


//-------------------------------------------------------------------------------------------------------------------------
$('#sections #co1,#sections #co2,#sections #co3,#sections #co4').equalHeights();
$('#tabs_cols').equalHeights();
$('#ft_col_1, #ft_col_2, #ft_col_3').equalHeights();
//-------------------------------------------------------------------------------------------------------------------------
	
$("#qt").click(function() {

	$(this).attr({ value: '' });

});

$("#txtKeyword").click(function() {

	$(this).attr({ value: '' });

});


//-------------------------------------------------------------------------------------------------------------------------
	
});
  
   format_item = function(data) {
        return data.text;
    }
 
        raw_data = function(data) {
        var parsed = [];
        $(data).find("string").each(function() {
            var org = $(this).text();
            var tx, vl;
            tx = org.match("[^{\"First\":\"](.*)\",\"Second\":?");
            tx = "\\" + tx[1];
            tx = tx.replace(/\\u003c/gi, '<');
            tx = tx.replace(/\\u003e/gi, '>');
            tx = tx.replace(/\\u0027/gi, '\'');
            tx = tx.replace(/\\/gi, '');
            vl = org.match("\",\"Second\":\"(.*)\"}");
            vl = vl[1];

            parsed[parsed.length] = {
                data: { text: tx, value: vl },
                value: tx,
                result: vl
            };
        });
        return parsed;
    }
 
function push_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;
};







