var tColour = '';

function RGBtoHex(R,G,B) {return toHex(R)+toHex(G)+toHex(B)}
function toHex(N) {	
	if (N==null) {return "00";}
	N=parseInt(N); 
	if (N==0 || isNaN(N)) {return "00";}	
	N=Math.max(0,N); 
	N=Math.min(N,255); 
	N=Math.round(N);
	return "0123456789ABCDEF".charAt((N-N%16)/16) + "0123456789ABCDEF".charAt(N%16);
}

function getFontColour(tagName,optionalClassName) {
	//returns the font colour of the first tag with specified class
	var tagList = (optionalClassName!='')?lm.getElementsBy({tagName:tagName,className:optionalClassName}):lm.getElementsBy({tagName:tagName});
	if (tagList.length>0) {
		var firstTag = tagList[0];
		if (firstTag.currentStyle){
			// We're in Internet Explorer
			return firstTag.currentStyle.color;
		}
		else if (document.defaultView.getComputedStyle) {
			//We're in Mozilla
			var tColour = document.defaultView.getComputedStyle(firstTag,null).color;
			if (tColour.indexOf('rgb')!=-1){
				tColour = tColour.replace('rgb(','').replace(')','').split(',');
				tColour = RGBtoHex(tColour[0],tColour[1],tColour[2]);
				return '#' + tColour;
			}
		}
		else {
			return '#000000';
		}
	}
	else {
		return '#000000';
	}
}

function sifrReplace(tagName,optionalClassName,optionalCSS) {
	var strCSS = '.sIFR-root {color:'+getFontColour(tagName,optionalClassName)+';'+optionalCSS+';}';
	var strSelector = (optionalClassName=='') ? tagName : tagName+'.'+optionalClassName;
	sIFR.replace(swfPath, {selector: strSelector, css: [strCSS], wmode: 'transparent'});
}

if (typeof sIFR == "object"){
	// Global replace for cat headers
	var frontierSIFRProtocol = (document.location.href.indexOf('https')>-1)? 'https://' : 'http://';
	var swfPath = frontierSIFRProtocol + 'www.lastminute.com/site/dinBlack3b.swf';
	var swfPath = {src: swfPath};
	sIFR.activate(swfPath);
	//sIFR.replace(swfPath, {selector: 'h2.highlightHeader',css: ['.sIFR-root {color:#ff0099;}']});
	//sifrReplace('h2','highlightHeader','text-decoration:underline;');
	sifrReplace('h1','','');
	sifrReplace('h2','richFont','');
	sifrReplace('h2','merchHeader','');
	sifrReplace('h2','searchHeader','');
	sifrReplace('h2','sponsorHeader','');
	sifrReplace('h2','highlightHeader','text-decoration:underline;');
	sifrReplace('h3','richFont','');
	sifrReplace('span','interstitialHeader','');
	//sifrReplace('body#homepage_lastminute_en_gb #rpui h3','','color:#ff0099');
	if (frontierSection == 'main'){
		sifrReplace('h2','','');
	}
}