/* Javascript stylesheet */
document.write("<link rel=\"StyleSheet\" href=\"/bevanBrittanAssets/css/bevanBrittanJs.css\" type=\"text/css\" media=\"screen\" />");

// e3 javascript for Bevan Brittan

// when the document is loaded
$(document).ready(function() {	

	//jQuery functions
	
	fnPageTools();
	
});

/**************************************************************
Function:	fnBrowser
Purpose:	Check we're in a supported browser
Notes:		
**************************************************************/
// Global Variables
var iepc,firefox,ns7,ns8,mozilla,safari;
function fnBrowser() {	
	var ua = navigator.userAgent.toLowerCase();
	
	iepc = (((ua.indexOf("msie 7") != -1)||(ua.indexOf("msie 6") != -1)||(ua.indexOf("msie 5.5") != -1))&&(ua.indexOf("windows") != -1)&&(ua.indexOf("opera") == -1))? true:false;
	firefox = ua.indexOf("firefox") != -1 ? true:false; // pc or mac
	ns7 = ua.indexOf("netscape/7") != -1 ? true:false; // firefox mode
	ns8 = ua.indexOf("netscape/8") != -1 ? true:false; // firefox mode
	mozilla = (ua.indexOf("gecko") != -1) && (ua.indexOf("netscape") == -1) ? true:false; 
	safari = ua.indexOf("safari") != -1 ? true:false;	
	opera = ua.indexOf("opera/9") != -1 ? true:false;
	if (iepc||firefox||mozilla||safari||opera) {
		return true;
	} else {
		return false;
	}
}


// Flash detect. boolean true/false if installed and version number accessed via flash.version
var flash = new Object();
flash.installed = false;

if (navigator.plugins && navigator.plugins.length) {
	for (x=0; x < navigator.plugins.length; x++) {

		if (navigator.plugins[x].name.indexOf('Shockwave Flash') != -1) {
			flash.installed = true;
			flash.version = eval(navigator.plugins[x].description.split('Shockwave Flash ')[1].split('.')[0]);
			break;
		}
	}
}
else if (window.ActiveXObject) {
	for (x = 2; x <= 20; x++) {
		try {
			oFlash = eval("new ActiveXObject('ShockwaveFlash.ShockwaveFlash." + x + "');");
			if(oFlash) {
				flash.installed = true;
				flash.version = x;
			}
		}
		catch(e) {}
	}
}

/********************************************************************************

Name: 				Flash embed
Description:		Writeout flash code. Fixes Eolas update for IE as well.
@param	swf			String path to swf file
@param	width		Number value of movie width
@param	height		Number value of movie height
@param  wmode		Window mode to use for the movie

*********************************************************************************/
flash.insert = function(swf,width,height,flashVer,nonFlashId) {

	if(!flashVer){minVer = 6;}
	else {minVer = flashVer;}
	if(!nonFlashId){nonFlashId = "nonFlashContent";}
	
// Handle errors
	var errMsg ="";
	if (!fnBrowser()) { // NOT supported browser
		errMsg += '<p class="err">Unfortunately, this website cannot be viewed by your browser. Please go to <a href="http://www.getfirefox.com">www.getfirefox.com</a> or <a href="http://www.microsoft.com/windows/ie/">www.microsoft.com/</a> to download a recommended browser.</p>';
	}
	if (!flash.installed) { // NOT flash
		errMsg += '<p class="err">This website requires the adobe&trade; Flash player. Go to the adobe website to install the <a href="http://www.adobe.com/products/flashplayer/">latest version of flash</a></p>';
	}

	swf = swf.replace(/\./g,"%2E"); // encode periods as %2e

	if(flash.installed && fnBrowser() && flash.version >= minVer) {
		document.write('<embed src="'+swf+'" menu="false" width="'+width+'" height="'+height+'" scale="noscale" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" salign="T" />');
		
		fnHide(nonFlashId);
	}
	else {
    fnShow(nonFlashId);
	}
};

function fnHide(id) {
	if(!document.getElementById(id)){return false;};
	var oTarg = document.getElementById(id).style;
	oTarg.position = "absolute";
	oTarg.top = "-5000px";
	oTarg.left = "0";
}

function fnShow(id) {
	if(!document.getElementById(id)){return false;};
	var oTarg = document.getElementById(id).style;
	oTarg.position = "static";
	oTarg.top = "";
	oTarg.left = "";
}

/* SIFR Initiation */
	//var din = {src: '/baseAssets/flash/dinmedium.swf'};

	// You probably want to switch this on, but read <http://wiki.novemberborn.net/sifr3/DetectingCSSLoad> first.
	/*sIFR.useStyleCheck = true;
	sIFR.activate();*/
	
	// .frt
	/*sIFR.replace(din, {
		selector: '.frt'
		,selectable: false
		,css: {
			'.sIFR-root': {
				'background-color': '#FFFFFF',
		      	'color': '#333333',
		      	'font-size' : '14px',
		      	'padding' : '0',
		      	'margin' : '0'
	      	}
		},wmode: 'transparent'
		
	});
	
	sIFR.replace(din, {
		selector: '#headingImage .frtTitle'
		,css: {
			'.sIFR-root': { 
				'background-color': '#000000',
		      	'color': '#666666',
		      	'font-size' : '19px',
		      	'padding' : '0',
		      	'margin' : '0'
	      	}			
		},wmode: 'transparent'	
	});
	
	sIFR.replace(din, {
		selector: '#headingPlain .frtTitle'
		,css: {
			'.sIFR-root': { 
				'background-color': '#FFFFFF',
		      	'color': '#000000',
		      	'font-size' : '17px',
		      	'padding' : '0',
		      	'margin' : '0'
	      	}			
		}	
	});*/


function fnFav(div){
	if($.browser.msie && ($.browser.version >=6 && $.browser.version <7)){
			
		div.prepend('<a href="#" class="fav">Add to favourites</a> ');
			
			$('a.fav').click(function(){
				var url = document.URL;
				var title = document.title;
				window.external.AddFavorite(url, title);
				return false;
			});
	}
	
}

function fnPrint(div){
	
	div.prepend('<a href="#" class="print">Print this page</a>');
	
	$('a.print').click(
		function(){
			window.print();
			return false;
		});
}


function fnPageTools(){
	
	var div = $('#pageTools');
	
	//if the pagetools div exists
	if(div.length){
		fnFav(div);
		fnPrint(div);
		}
}