
if (match = window.location.hostname.match(/([^.]+)\.(com|co\.uk)$/)) {
	var site_selector_domain = match[0];
}else{
	var site_selector_domain = window.location.hostname;
}

if(site_selector_country != undefined) {

	if (parseInt($j.cookie('site_selector_closed')) == 1) {
		var site_selector_closed = true;
	}else{
		var site_selector_closed = false;
	}
	
	var site_selector_leave_flag = false;
	
	$j(function() {
	
		
		$j('#flag_1 a').mouseover(function() {
			$j('#site_selector_2 a').each(function() {
				$j(this).attr("h", $j(this).attr("href"));
				$j(this).attr("href", "#");
			});
			$j('#site_selector_2').fadeIn(1000, function() { 
				$j('#site_selector_2 a').each(function() {
					$j(this).attr("href", $j(this).attr("h"));
					$j(this).attr("h", "#");
				});
			});
		});
		
		$j('#site_selector_2').mouseenter(function() {
			site_selector_leave_flag = false;
		});
		//If we've got an option to change country and the user hasn't explicitly closed the site selector, we should make them close the site selector.
		//Once they have done so, we'll store this preference and resort to mouseover/off events
		if(site_selector_country && !site_selector_closed) {
			$j('#site_selector_2 .close a').click(function(e) {
				e.preventDefault();
				
				
				
				//Store that the user has closed it by clicking on the button
				$j.cookie('site_selector_closed', 1, {path: '/', domain: site_selector_domain, expires: 30});
				//Get rid of the close buttons since we'll now resort to the default mouseover events
				$j('#site_selector_2 .close').hide();
				$j('#site_selector_2').hide();
	
				site_selector_leave_flag = true;
				setTimeout(function() {
					if (site_selector_leave_flag) {
						$j('#site_selector_2').fadeOut(1000);
						
						$j('#site_selector_2 .container').mouseleave(function() {
							site_selector_leave_flag = true;
							setTimeout(function() {
								if (site_selector_leave_flag) {
									$j('#site_selector_2').fadeOut(1000);
								}
							},500);
						});	
					}
				},500);
			});
			
			$j('#site_selector_2 .close').show();
			$j('#site_selector_2').fadeIn(1000);
		}
		else {
			$j('#site_selector_2 .container').mouseleave(function() {
				site_selector_leave_flag = true;
				setTimeout(function() {
					if (site_selector_leave_flag) {
						$j('#site_selector_2').fadeOut(1000);
					}
				},500);
			});	
		}
		
	});
	
	
}
