
jQuery.noConflict();//To avoid conflict with other JS librariesjQuery.noConflict();//To avoid conflict with other JS libraries


jQuery(document).ready(function($){

	if($('#atMap').length!=0)
	{
		$('#atContent').addClass('divBorder');
	}

	// alert($.cookies.get('RDC_COLOURS_DARK'));
	
//-------------------------------------------------------------------------------------------------------------------------

//-------------------------------------------------------------------------------------------------------------------------
		//hise and show homepage content and set your location
		$(".blindfx").hide();
		
		$("#doBlind").click(function() { 
			$(".blindfx").slideToggle(500,function(){ $(window).trigger('resize') });
		});
		
		$(".blindfx2").hide();
		$("#doBlind2").click(function() { 
			$(".blindfx2").slideToggle(200,function(){ $(window).trigger('resize',[true]); });
		});
	//-------------------------------------------------------------------------------------------------------------------------

//onload feth cookie value

		$.getJSON("http://www.rochford.gov.uk/ajax_cookie_fetch.php?type=postcode&callback=?"
			, function(data) {
				$('#doBlind2').html(data.result);
			});
			
		$.getJSON("http://www.rochford.gov.uk/ajax_cookie_fetch.php?type=fulladdress&callback=?"
			, function(data) {
				$('#location_text').html(data.result);
			});
						
		$.getJSON("http://www.rochford.gov.uk/ajax_cookie_fetch.php?type=uprn&callback=?"
			, function(data) {
				$('#maplink').html(data.result);
			});

	//-------------------------------------------------------------------------------------------------------------------------
	//reset_homepage
			
	$("#links #reset_homepage").click(function() {
		//alert("reset cookie");
		$.post("http://www.rochford.gov.uk/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);
			});
	});
	
	//-------------------------------------------------------------------------------------------------------------------------
	
	//Address stuff
	
	$("#address").autocomplete("/address_lookup2.php", {
		width: 310,
		selectFirst: false, 
		mustMatch: true		
	});

	$("#hidden_val").val("");
	

	$("#address").result(function(event, data, formatted) {
		if (data)
			$("#hidden_val").val(data[1]);
	});

	//-------------------------------------------------------------------------------------------------------------------------
	//Save Postcode 
	
	$("#save_postcode").click(function() {		
		
		var your_address = $("#hidden_val").attr("value");
	
		var options = { path: '/', hoursToLive: 2000, domain: ".rochford.gov.uk" };
		$.cookies.set('rdc_home_location', your_address, options);
		//
		var str = your_address.split("#");
		
		//alert(str[0].replace(/ /g,''));
		
		var loc = "locAddress="+str[0].replace(/ /g,'')+" "+str[1]+" "+str[2]+" Essex "+str[3]+"&locUID="+str[5]+"&locX="+str[6]+"&locY="+str[7]+"&locAreaID=";
		
		$.cookies.set('atLocation', loc, options);
		
		url_test ='http://maps.rochford.gov.uk/?action=SetAddress&UniqueId='+str[5]+'';
		
		//alert(url_test);
		setTimeout("location.replace(url_test);",0);
		
	});
	
	$("#save_postcode_DC").click(function() {		
			
			var your_address = $("#hidden_val").attr("value");
		
			var options = { path: '/', hoursToLive: 2000, domain: ".rochford.gov.uk" };
			$.cookies.set('rdc_home_location', your_address, options);
			//
			var str = your_address.split("#");
			
			//alert(str[0].replace(/ /g,''));
			
			var loc = "locAddress="+str[0].replace(/ /g,'')+" "+str[1]+" "+str[2]+" Essex "+str[3]+"&locUID="+str[5]+"&locX="+str[6]+"&locY="+str[7]+"&locAreaID=";
			
			$.cookies.set('atLocation', loc, options);
			
			//url_test ='http://maps.rochford.gov.uk/?action=SetAddress&UniqueId='+str[5]+'';
			
			//alert(url_test);
			setTimeout("location.reload(true);",0);
			
	});
	
	//-------------------------------------------------------------------------------------------------------------------------
	
	//search functionality
	
	/*	$("#txtKeyword").autocomplete("http://10.16.131.14/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();
	        });

	
	
	
	//-----------------------------------------------------------------------------------------------------------------------------------
	
	
	
	$("#searchBox").click(function() {
	
		 $("#searchBox").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;
    }
 






/*-------------------------------------------------------------------- 
 * JQuery Plugin: "EqualHeights" & "EqualWidths"
 * by:	Scott Jehl, Todd Parker, Maggie Costello Wachs (http://www.filamentgroup.com)
 *
 * Copyright (c) 2007 Filament Group
 * Licensed under GPL (http://www.opensource.org/licenses/gpl-license.php)
 *
 * Description: Compares the heights or widths of the top-level children of a provided element 
 		and sets their min-height to the tallest height (or width to widest width). Sets in em units 
 		by default if pxToEm() method is available.
 * Dependencies: jQuery library, pxToEm method	(article: http://www.filamentgroup.com/lab/retaining_scalable_interfaces_with_pixel_to_em_conversion/)							  
 * Usage Example: $(element).equalHeights();
   						      Optional: to set min-height in px, pass a true argument: $(element).equalHeights(true);
 * Version: 2.0, 07.24.2008
 * Changelog:
 *  08.02.2007 initial Version 1.0
 *  07.24.2008 v 2.0 - added support for widths
--------------------------------------------------------------------*/

/*jQuery.fn.equalHeights = function(px) {
	jQuery(this).each(function(){
		var currentTallest = 0;
		jQuery(this).children().each(function(i){
			if (jQuery(this).height() > currentTallest) { currentTallest = jQuery(this).height(); }
		});
		if (!px || !Number.prototype.pxToEm) currentTallest = currentTallest.pxToEm(); //use ems unless px is specified
		// for ie6, set height since min-height isn't supported
		if (jQuery.browser.msie && jQuery.browser.version == 6.0) { jQuery(this).children().css({'height': currentTallest}); }
		jQuery(this).children().css({'min-height': currentTallest}); 
	});
	return this;
};

// just in case you need it...
jQuery.fn.equalWidths = function(px) {
	jQuery(this).each(function(){
		var currentWidest = 0;
		jQuery(this).children().each(function(i){
				if(jQuery(this).width() > currentWidest) { currentWidest = jQuery(this).width(); }
		});
		if(!px || !Number.prototype.pxToEm) currentWidest = currentWidest.pxToEm(); //use ems unless px is specified
		// for ie6, set width since min-width isn't supported
		if (jQuery.browser.msie && jQuery.browser.version == 6.0) { jQuery(this).children().css({'width': currentWidest}); }
		jQuery(this).children().css({'min-width': currentWidest}); 
	});
	return this;
};


/*-------------------------------------------------------------------- 
 * javascript method: "pxToEm"
 * by:
   Scott Jehl (scott@filamentgroup.com) 
   Maggie Wachs (maggie@filamentgroup.com)
   http://www.filamentgroup.com
 *
 * Copyright (c) 2008 Filament Group
 * Dual licensed under the MIT (filamentgroup.com/examples/mit-license.txt) and GPL (filamentgroup.com/examples/gpl-license.txt) licenses.
 *
 * Description: Extends the native Number and String objects with pxToEm method. pxToEm converts a pixel value to ems depending on inherited font size.  
 * Article: http://www.filamentgroup.com/lab/retaining_scalable_interfaces_with_pixel_to_em_conversion/
 * Demo: http://www.filamentgroup.com/examples/pxToEm/	 	
 *							
 * Options:  	 								
 		scope: string or jQuery selector for font-size scoping
 		reverse: Boolean, true reverses the conversion to em-px
 * Dependencies: jQuery library						  
 * Usage Example: myPixelValue.pxToEm(); or myPixelValue.pxToEm({'scope':'#navigation', reverse: true});
 *
 * Version: 2.0, 08.01.2008 
 * Changelog:
 *		08.02.2007 initial Version 1.0
 *		08.01.2008 - fixed font-size calculation for IE
--------------------------------------------------------------------*/
/*
Number.prototype.pxToEm = String.prototype.pxToEm = function(settings){
	//set defaults
	settings = jQuery.extend({
		scope: 'body',
		reverse: false
	}, settings);
	
	var pxVal = (this == '') ? 0 : parseFloat(this);
	var scopeVal;
	var getWindowWidth = function(){
		var de = document.documentElement;
		return self.innerWidth || (de && de.clientWidth) || document.body.clientWidth;
	};	
	
	/* When a percentage-based font-size is set on the body, IE returns thtage-based font-size is set on the body, IE returns that percent of the window width as the font-size. 
		For example, if the body font-size is 62.5% and the window width is 1000px, IE will return 625px as the font-size. 	
		When this happens, we calculate the correct body font-size (%) and multiply it by 16 (the standard browser font size) 
		to get an accurate em value. */

/*
		
	if (settings.scope == 'body' && $.browser.msie && (parseFloat($('body').css('font-size')) / getWindowWidth()).toFixed(1) > 0.0) {
		var calcFontSize = function(){		
			return (parseFloat($('body').css('font-size'))/getWindowWidth()).toFixed(3) * 16;
		};
		scopeVal = calcFontSize();
	}
	else { scopeVal = parseFloat(jQuery(settings.scope).css("font-size")); };
			
	var result = (settings.reverse == true) ? (pxVal * scopeVal).toFixed(2) + 'px' : (pxVal / scopeVal).toFixed(2) + 'em';
	return result;
};

*/
