$(document).ready(function(){	
	if(document.getElementById('expand-list'))
	{
		$(".expand-list li").each(
			function(i)
			{
				var count = 0;
				if($(this).children().is("ul") == true)
				{
					//do nothing
				}
				else
				{
					$(this).addClass("noSub");
				}
			}
		);
		
		$(".expand-list li li").each(
			function(i)
			{
				$(this).removeClass("noSub");
			}
		);
	}
	/*expandable list*/
	$(".expand-list li a").click
	(
		function()
		{
			if($(this).parent().attr('class') == 'selected')
			{
				$(this).parent().removeClass('selected');
			}
			else
			{
				$(this).parent().addClass('selected');
			}
		}
	);
	/**/
	$(".rollover ul.list li").hover(
		function()
		{ 
			setImageToDisplay($(this));
			$(this).addClass("active");
		}
		,function()
		{
			$(this).removeClass("active");
			$(".rollover ul.images li img").each(function(i){ $(this).addClass("hide");	});
			setImageToDisplay($(".rollover ul.list li.selected"));
		}
	);
	$(".rollover ul.list li").click(
		function(e){
			$(".rollover ul.list li").removeClass("selected");
			$(this).addClass("selected");
			$(".rollover ul.images li img").each(function(i){ $(this).addClass("hide");	});
			setImageToDisplay($(".rollover ul.list li.selected"));
		}
	);
	$(".rollover ul.list li:first").addClass("selected");
	if($(".rollover").length>0) {
		$(".rollover ul.images li img").each(function(i){ $(this).addClass("hide");	});
		setImageToDisplay($(".rollover ul.list li:first"));
	}
	
	
	if($(".gmap").length>0) {
		$("#map1").googleMap(-28.148292, 153.468361, 5, 
		{
			controls: ["GSmallMapControl", "GMapTypeControl"],
			markers: $(".geo")
		});	
		
		$(".office-list").removeClass("hide");
	
		$(".sidecol ul.office-list li a").click(
			function()
			{	
				if($(this).attr("class") == "show-all")
				{
					$("#map1").googleMap(-28.148292, 153.468361, 5, 
					{
						controls: ["GSmallMapControl", "GMapTypeControl"],
						markers: $(".geo")
					});
				}
				else
				{
					//get the office clicked on
					var office = $(this).attr('href');
					hashIndex = office.indexOf("#");
					office = office.substring(hashIndex,office.length).replace("#", "");
					
					var longitude;
					var latitude;
					var officeName;
					$("div.geo").each(function() {
						if(office == $(this).attr('id'))
						{
							officeName = $(this).attr('title');
							//get the children of the div
							//var kids = $(this).children('.latitude');
							latitude = parseFloat($(this).children('.latitude').attr('title'));
							longitude = parseFloat($(this).children('.longitude').attr('title'));
							/* //get the lat
							latitude = parseFloat(kids.attr('title'));
							//get the long
							longitude = parseFloat(kids.next().attr('title')); */
						}
					});
					$("#map1").googleMapZoomIn(latitude, longitude, officeName, {	controls: ["GSmallMapControl", "GMapTypeControl"],	markers: $(".geo")	});	
					$("ul.office-info li").each(
						function()
						{
							var compare = $(this).attr('class').replace('hide', '').replace(' ', '');
							if(office == compare)
							{
								$(this).removeClass('hide');
							}
							else
							{
								$(this).addClass('hide');
							}
						}
					);
				}
				
				return false;
			}
		);
	}
	
	h1Text = $("h1").text();
	if(h1Text.match("Steel Reinforcing")) {
		$(".flash-left img").attr("src", "/media/flash/rotating_images/steel-reinforcing01.jpg");
		$("#flash").attr("rel", "Steel Reinforcing");
	} else if(h1Text.match("Builders and Concreters hardware")) {
		$(".flash-left img").attr("src", "/media/flash/rotating_images/builders02.jpg");
		$("#flash").attr("rel", "Builders and Concretes hardware");
	} else if(h1Text.match("Timber")) {
		$(".flash-left img").attr("src", "/media/flash/rotating_images/timber01.jpg");
		$("#flash").attr("rel", "Timber");
	} else if(h1Text.match("Injection Moulding")) {
		$(".flash-left img").attr("src", "/media/flash/rotating_images/injection-moulding01.jpg");
		$("#flash").attr("rel", "Injection Moulding");
	} else if(h1Text.match("Precision Engineering")) {
		$(".flash-left img").attr("src", "/media/flash/rotating_images/precision01.jpg");
		$("#flash").attr("rel", "Precision Engineering");
	}
	
	if($("#flash").length>0) insertSWFs();
	
});



$.fn.hoverClass = function(c) {
	return this.each(function(){
		$(this).hover( 
			function() { $(this).addClass(c);  },
			function() { $(this).removeClass(c); }
		);
	});
};

function urlCleanFormat(s) {
	alert("s: " + s);
	s = s.replace(/\s/g, "").toLowerCase();
	s = s.replace(/\//g, ""); 
	s = s.replace(/'/g, ""); 
	s = s.replace(/&amp;/g, ""); 
	s = s.replace(/&/g, ""); 
	return s;
};

function setImageToDisplay(thisRef) {
	//thisRef = $(".rollover ul.list li:first");
	var liclass = thisRef.attr('class').replace(" selected", "").replace(" active", "");
	$(".rollover ul.images li img").each(function(i){ 
		var imgid = $(this).attr('id');
		if(liclass == imgid)
		{
			$(this).removeClass("hide");
		}
	});
}