var agent;
var isMajor;
var isIe;
var isIe6;
var isIe7;
var isIe8;
var isFirefox;
var isWindows;
var flashMoviesOnPage = 0;
var debugLog = false;
var equalizeGrid = false;
var globalObj = {};

var siteConfig = {
	equalize:{
		main:{
			active:true,
			offset:6
		}
	}
}

parliamentUK = {
	init:function(obj){
		//handle page specific initializations
		$.extend(obj,{site:$(document.body).attr('class')});
		
		//extend init object to global scope
		$.extend(globalObj,obj);
	
		//assign _blank targets in order to meet Strict doctype markup restrictions
		$('A[rel="external"]').attr('target','_blank');
	
		//run browser-sniffer for a rare case where custom JavaScript requires variance between browsers		
		parliamentUK.browserSniffer();
					
		//equalize grid columns to ensure grey tramlines run consistently to full page depth (three-wide template only)
		parliamentUK.equalizeGrid();
	},

	//equalize grid columns to ensure grey tramlines run consistently to full page depth (three-wide template only)
	equalizeGrid: function(){
		//only equalize if the specific site has been configured to
		if(siteConfig.equalize[$('BODY').attr('class')].active){			
			//ensure only the grid elements which exist are equalled
			var equalizeElements = '';
			if($('#secondary-navigation').size() == 1){equalizeElements += '#secondary-navigation,';}
			if($('#content-small').size() == 1){equalizeElements += '#content-small,';}
			if($('#panel').size() == 1){equalizeElements += '#panel,';}
			equalizeElements = equalizeElements.substr(0,equalizeElements.length-1);
			
			if($(document.body).attr('id') != 'grid' && globalObj.pageType != 'education-education-home'){
				$(equalizeElements).equalHeight({objectToAppend:$('#content-small'),height:siteConfig.equalize[$('BODY').attr('class')].offset});
			}			
		}
	},
	
	//run a reset before initializing (tabs-specific)
	resetGrid: function(){
		$('#secondary-navigation').css(isIe6 ? {'height':'1px'} : {'min-height':'1px'});
		$('#content-small').css(isIe6 ? {'height':'1px'} : {'min-height':'1px'});
		$('#panel').css(isIe6 ? {'height':'1px'} : {'min-height':'1px'});
		
		parliamentUK.equalizeGrid();
	},
	
	//required browser sniffer for XmlHttp() Rss retrieval
	browserSniffer: function(){
		agent = navigator.userAgent.toLowerCase();
		isMajor = parseInt(navigator.appVersion);
		isIe = (agent.indexOf('msie') != -1);
		isIe6 = (isIe && (isMajor == 4) && agent.indexOf("msie 6.")!=-1);
		isIe7 = (isIe && (isMajor == 4) && agent.indexOf("msie 7.")!=-1);
		isIe8 = (isIe && (isMajor == 4) && agent.indexOf("msie 8.")!=-1);
		isFirefox = ((agent.indexOf('firefox')!=-1));
		isWindows = ((agent.indexOf('win')!=-1) || (agent.indexOf('16bit')!=-1));
	}
}
