fn = {  }

fn.external_links = function()
{
	var actual_host = 'http://www.deford.co.uk/';
	$('a:external').each(function(){
		var href = String($(this).attr('href'));
		if(href.search(actual_host) == -1 && href != 'undefined')
		{
			//console.log(href);
			var thisone = false;
			var message = '';
			switch(href)
			{
				case 'http://www.aceinsure.com/travel/?afl=5658-0509':
					message = 'You are about to be transfered to the Ace Travel Insurance website to obtain your quotation. D E Ford does not control the site you are to be redirected to which may contain different terms of use and privacy policy to D E Ford. Please ensure you are aware of the relevant terms an conditions for both sites.';
				break;	
				case 'https://secure.ansvarnet.co.uk/qs2p/bin/fin_pubwel.html?AN=4050&IT=040':
					message = 'You are about to be transfered to the Ansvar website to obtain your quotation. D E Ford does not control the site you are to be redirected to which may contain different terms of use and privacy policy to D E Ford. Please ensure you are aware of the relevant terms an conditions for both sites.';
				break;	
				case 'https://www.hiscox.co.uk/events/?scheme=206':
					message = 'You are about to be transfered to the Hiscox website to obtain your quotation. D E Ford does not control the site you are to be redirected to which may contain different terms of use and privacy policy to D E Ford. Please ensure you are aware of the relevant terms an conditions for both sites.';
				break;
				case 'https://secure.ansvarnet.co.uk/qs2p/bin/fin_pubwel.html?AN=4050&IT=011':
					message = 'You are about to be transfered to the Ansvar website to obtain a quote. D E Ford does not control the site you are to be redirected to which may contain different terms of use and privacy policy to D E Ford. Please ensure you are aware of the relevant terms an conditions for both sites.';
				break;
				case 'https://secure.ansvarnet.co.uk/qs2p/bin/scp00.html?rnd=7260598008271020&chk=04004050+&msg=':
					thisone = true;
					message = 'You are about to be transfered to the Ansvar website to obtain a quote. D E Ford does not control the site you are to be redirected to which may contain different terms of use and privacy policy to D E Ford. Please ensure you are aware of the relevant terms an conditions for both sites.';
				break;
				case 'http://www.brokerbility.co.uk':
					message = 'You are about to be transfered to the Brokerbility website. D E Ford does not control the site you are to be redirected to which may contain different terms of use and privacy policy to D E Ford. Please ensure you are aware of the relevant terms an conditions for both sites.';
				break;
				default:
					message = false;
					return;
				break;
			}	
			
			if(message)
			{
				var href = $(this).attr('href');
				//$(this).attr('href', '#');
				if(thisone)
				{
					//var $par = $(this).parent();
					//var html = $par.find('a').html();
					//$(this).parent().html('no link');
					//$(this).html('');
					//$(this).bind('click', function(){ alert('hi'); return false; });
					//$par.html('<a href="'+href+'">'+html+'</a>');
				}
				
				
				$(this).click(function(){
					var conf = confirm(message);
					if(!conf) return false;
					location.href = href;
					return false;
				});
				
			}
		}
	});	
}

$(document).ready(function(){
	$.expr[':'].external = function(obj){
    return !obj.href.match(/^mailto\:/)
            && (obj.hostname != location.hostname);
	};
	

	$('.widget-title').each(function(){
		switch($(this).html())
		{
			case 'axisform':
				var title = $(this).html();
				var i = $(this).index();	
				var $w = $(this).parent().find('.textwidget');
				$(this).remove();
				var text = $w.find('a').html();
				var href = $w.find('a').attr('href')
				var html = '<div class="axis-form-button"><a href="'+href+'?iframe" rel="lightbox[iframe] nofollow" style="display:block;height:100%:width:100%;">'+text+'</a></div>';
				$w.replaceWith(html);
			break;
			case 'online quote button':
				var title = $(this).html();
				var i = $(this).index();	
				var $w = $(this).parent().find('.textwidget');
				$(this).remove();
				var text = $w.find('a').html();
				var href = $w.find('a').attr('href')
				var html = '<div class="online-quote-button"><a href="'+href+'" style="display:block;height:100%:width:100%;">'+text+'</a></div>';
				$w.replaceWith(html);
			break;
			case '5 points flash video':
				var i = $(this).index();
				var title = $(this).html();	
				var $w = $(this).parent().find('.textwidget');
				$(this).remove();
				var link = $w.html();
				var p = new RegExp('/?/g');
				var r = p.test(link);
				if(!r) link += '?iframe';			
				var html = '<object type="application/x-shockwave-flash" data="'+link+'" width="860" height="645"><param name="movie" value="'+link+'"><param name="quality" value="high"><param name="bgcolor" value="#ffffff"><param name="wmode" value="transparent"><a href="http://get.adobe.com/flashplayer/" title="Get the Adobe Flash Player" target="_blank"><img src="images/nf/nf-commercial.jpg" alt="Get the Adobe Flash Player" border="0" width="310" height="310" rel="lightbox[iframe]"></a></object>';
				var html = '<div class="five-points-flash-button"><a href="'+link+'" rel="lightbox[iframe]"></a></div>';
				$w.replaceWith(html);
			break;
			case 'online services':
				var i = $(this).index();
				var title = $(this).html();	
				var $w = $(this).parent().find('.textwidget');
				$(this).remove();
				var link = $w.html()+'?iframe';
				var html = '<object type="application/x-shockwave-flash" data="'+link+'" width="860" height="645"><param name="movie" value="'+link+'"><param name="quality" value="high"><param name="bgcolor" value="#ffffff"><param name="wmode" value="transparent"><a href="http://get.adobe.com/flashplayer/" title="Get the Adobe Flash Player" target="_blank"><img src="images/nf/nf-commercial.jpg" alt="Get the Adobe Flash Player" border="0" width="310" height="310" rel="lightbox[iframe]"></a></object>';
				var html = '<div class="online-risk-management-flash-button"><a href="'+link+'" rel="lightbox[iframe]"></a></div>';
				$w.replaceWith(html);
			break;
		}
	});

	/*
	$('a[rel="lightbox[iframe]"]').each(function(){
		var href = $(this).attr('href');	
		$(this).attr('href', href+'?iframe');
	});
	$('a[rel="lightbox"], a[rel="lightbox[inline]"], a[rel="lightbox[iframe]"]').each(function(){
		var h3 = $(this).parent().parent().find('h3').remove();
		//console.log(h3.html());
	});
	*/
	
});

