var activeTooltip = 'reeduk';
var activeResourceTab = 'resource-tab-1';
var activeSpecialismSwitch = 'employer';
var activeSpecialismList = 'list-specialism';
var sliding;
var sector;
var use_google_maps;
var markers = [];
var tabbedPanelIsOpen = false;
var tabbedPanelSliding = false;
var image_cache = [];
var switch_explain = null;

var terms_and_conditions = "";

var specialism_header_height = 95;
var viewall_header_height = 95;

/***************************************************
on dom ready start 
***************************************************/
window.addEvent('domready', function()
{
	var scope = this;

	//new homepage tabbed panel
	if($('home-tabbed-panel'))
	{
		var home_tabbed_panel = $('home-tabbed-panel');
		home_tabbed_panel.removeClass('noscript');

		$('home-tabbed-panel-nav').getElements('a').addEvent('click',function(e)
		{
			e = new Event(e).stop();
			
			var parent = this.getParent();
			
			if(parent.hasClass('active'))
			{
				//it's the active one, do nothing!
			}
			else
			{
				home_tabbed_panel.getElements('.item').addClass('hide');
				$('home-'+this.href.replace(/.*\#/,'')).removeClass('hide');
				$('home-tabbed-panel-nav').getElements('li').removeClass('active');
				parent.addClass('active');
			}
		});
		
		home_tabbed_panel.addEvent('mouseenter',function(e)
		{
			toggleTabbedPanel();
		});
		
		home_tabbed_panel.addEvent('mouseleave',function(e)
		{
//			toggleTabbedPanel.delay(2000);
			toggleTabbedPanel();
		});	
	}
	
	preloadImages();
	
	openNewWindow();
	
	toggleSalaryFields();
	
	setupTandCs();
	
	if($('googlemaps_1'))
	{
		googleMapsInit();	
	}
	
	//if we're in jobseeker pages, toggle the switch to jobseeker
	if(typeof sector == "undefined" || sector == 'jobseeker')
	{
		if(typeof sector == "undefined")
		{
			sector = "jobseeker"
		}
		
		if( typeof( page ) == 'undefined' )
		{
			page = '';
		}
		
		if( page == 'browsejobs' )
		{
			if( $('buttons-tab1').hasClass('selected') )
			{
				$('buttons-tab1').removeClass('selected');
			}
		}

		if( page == 'submit-cv' )
		{
			if( $('buttons-tab1').hasClass('selected') )
			{
				$('buttons-tab1').removeClass('selected');
			}
			$('buttons-tab3').addClass('selected');
		}
		
		$('specialism').href = $('specialism').href.replace('employer', 'job-seeker');
		
		if( page == 'browsejobs' )
		{
			$('buttons-tab2').addClass('selected');
		}
		
		swapSpecialismSwitch('jobseeker');
		//swapSpecialismSwitchViewall('jobseeker', 'no');
		
		if($('resource-tabs'))
		{
			swapResourceUnit($('resource-tab-2'));
		}
	}
	
	//if we're in Upload CV pages, toggle the header to show appropriate
	/*
	if(sector == 'submit-cv')
	{
		$('buttons').getElements('li').removeClass('selected');
		$('buttons-tab3').addClass('selected');
		sortSpecialistHeader(sector, 'yes');
	}
	*/
	
	//work out the sector and show/hide the relevent specialisms
	initSpecialismLinks(sector);
	
	//style the custom drop downs
	if( $('jsinternationalsites') == null )
	{
		styleFilter('header-content-top', '', '');
	}
	/* remove dropdown styling for speed purposes
	styleFilter('white-news-box');
	
	if( $('right-search-unit') )
	{
		styleFilter('right-search-unit', 'nosubmit', 'WhiteDropDown');
	}
	
	if( $('home-search-unit') )
	{
		styleFilter('home-search-unit', 'nosubmit', 'SearchDropDown');
	}
	
	if( $('right') )
	{
		styleFilter('right', 'nosubmit', 'WhiteDropDown');
	}
	
	if( $('learning-box') )
	{
		styleFilter('learning-box', 'nosubmit', 'WhiteDropDown');
	}
	
	if( $('showcase-box') )
	{
		styleFilter('showcase-box', 'nosubmit', 'WhiteDropDown');
	}
	
	if( $('showcase-form') )
	{
		styleFilter('showcase-form', 'nosubmit', 'WhiteDropDown');
	}
	*/
	
	//tooltips unit functionality
	if($('tooltips-nav'))
	{
		//tooltips box rotation when mouse goes idle
		tooltipsListener();
		
		$('tooltips-nav').getElements('a').addEvent('click',function(e)
		{
			e = new Event(e).stop();
			doTooltips(this);
		});
	}
	
	// side banners
	if( $('skyscraper1') && ( skyscraperFilename1 != '' ) ) {
		loadFlash('skyscraper1', skyscraperFilename1, {x:174, y:348});
	}

	if( $('skyscraper2') &&  ( skyscraperFilename2 != '' ) ) {
		loadFlash('skyscraper2', skyscraperFilename2, {x:174, y:348});
	}
	
	/*
	//sign-in button to show the overlay
	if($('signin'))
	{
		$('signin').addEvent('click',function(e)
		{
			e = new Event(e).stop();
			$('sign-in-overlay-wrapper').removeClass('hide');
		});
	}

	//close button on sign-in overlay
	$('sign-in-overlay').getElement('a').addEvent('click',function(e)
	{
		e = new Event(e).stop();
		
		$('sign-in-overlay-wrapper').addClass('hide');
	});
	*/
	
	//sort form on search results to allow result filtering
	if($('sort-form'))
	{
		$('sort-form').getElements('input').addEvent('click',function()
		{
			$('sort-form').submit();			
		});
	}
	
	//search results toggle for whether you see full or collapsed results
	if($('search-toggle'))
	{	
		$('search-toggle').getElements('a').addEvent('click',function(e)
		{
			e = new Event(e).stop();	
			$('search-toggle').getElement('.active').removeClass('active');	
			this.getParent().addClass('active');
			
			if(this.getParent().hasClass('short'))
			{
				$('search-results').getElements('p').addClass('hide');
			}
			else
			{
				$('search-results').getElements('p').removeClass('hide');	
			}	
		});
	}
	
	//resource tabs functionality (right hand side componant)
	if($('resource-tabs'))
	{
		$('resource-tabs').getElements('li').addEvent('click',function()
		{
			if(this.id != activeResourceTab)
			{
				swapResourceUnit(this);
			}
		});
	}
	
	//specialism switch knob mechanism for specialism list
	$('specialism-switch').getElements('a').addEvent('click',function(e)
	{
		e = new Event(e).stop();
		swapSpecialismSwitch(this.title);
	});
	
	//specialism switch knob mechanism for viewall state of specialism list
	$('specialism-switch-viewall').getElements('a').addEvent('click',function(e)
	{
		e = new Event(e).stop();
				
		swapSpecialismSwitch(this.title);
		
	});
	
	this.switch_explain = new SwitchExplain();
	
	//specialism header functionality (sliding and buttons)
	$('buttons').getElements('a').addEvent('click',function(e)
	{	
		// close pop-up explanation
		scope.switch_explain.hide();
		
		if( (this.name != 'browse' && this.name != 'submit-cv')
			 || (this.name == 'browse' && browseJobsExpand == 0) || (this.name == 'browse' && sector == 'browse')
			 || (this.name == 'submit-cv' && uploadCVTabExpand == 0) || (this.name == 'submit-cv' && sector == 'submit-cv') )
		{
			e = new Event(e).stop();
		
			setupPlaceholder();
			var clickedItem = this.name;
			
			if(clickedItem == 'submit-cv')
			{
				clickedItem = 'specialism';
			}
			
			//if('list-'+clickedItem != activeSpecialismList)
//			{
				$('buttons').getElement('.selected').removeClass('selected');
				
				//alert($('buttons').getElement('.active'));
				
				var clickedLi = this.getParent();
				clickedLi.addClass('selected');
	
				var slideHeader = new Fx.Tween($('specialisms-header-bg'),
				{
					duration: 350, 
					transition: Fx.Transitions.linear,
					onComplete: function()
					{
						
						$(activeSpecialismList).addClass('hide');
						sortSpecialistHeader(clickedItem);
						
					}
				});
				
				var slidePlaceholder = new Fx.Tween($('specialisms-placeholder'),
				{
					duration: 350, 
					transition: Fx.Transitions.linear,
					onComplete: function()
					{
						$('list-specialism').addClass('hide');
						sortSpecialistHeader(clickedItem);
						setupPlaceholder();
					}
				});
				
				slideHeader.start('height', 0);
				slideHeader.set('padding', 0);
				
				activeSpecialismList = 'list-'+clickedItem;
				
//			}
		}
		
		
		//if you've clicked on specialism and the viewall was open, it'll close
		if((this.name == 'specialism') && ($('viewall').innerHTML == 'Elrejtés'))
		{
			$('viewall').innerHTML = 'Összes';
		}
		
		//make viewall become hideall
		if(this.name == 'viewall')
		{			
			if(this.innerHTML == 'Összes')
			{
				this.innerHTML = 'Elrejtés';
			}
			else
			{
				hideAll();
				$('viewall').innerHTML = 'Összes';
			}
		}
	});
	
	//hide all button for viewall specialities
	$('hideall').addEvent('click',function()
	{
		hideAll();
		$('viewall').innerHTML = 'Összes';
		//$('viewall').removeEvents('click');
	});
	
	//specialisms header "can't find what you're looking for" onclick value-nullification
	if($('email'))
	{
		$('email').addEvent('click',function()
		{
			if(this.value == 'Írja be az e-mail címét')
			{
				this.value = '';	
			}
		});	
	}
	
	//action listener for the from - to fomr entry section on refine your search inc 
	if($('right-search-unit'))
	{
		$('right-search-unit').getElements('input').addEvent('click', function()
		{
			checkTextArea(this);
		});
	}
	
	if($('googlemaps'))
	{
		googleMapsInit();
	}
	
	function checkTextArea(object)
	{
		if((object.value == 'Tól') || (object.value == 'Ig'))
		{
			object.value = '';
		}
	}
	
	
	function hideAll()
	{
		var slideHeader = new Fx.Tween($('specialisms-header-bg'),
		{
			duration: 350, 
			transition: Fx.Transitions.linear,
			onComplete: function()
			{
				
				$(activeSpecialismList).addClass('hide');
				sortSpecialistHeader('specialism');
				
			}
		});
		
		var slidePlaceholder = new Fx.Tween($('specialisms-placeholder'),
		{
			duration: 350, 
			transition: Fx.Transitions.linear,
			onComplete: function()
			{
				$('list-specialism').addClass('hide');
				sortSpecialistHeader('specialism');
				setupPlaceholder();
			}
		});
		
		slideHeader.start('height', 0);
		slideHeader.set('padding', 0);
		
		activeSpecialismList = 'list-specialism';	
	}
	
	//shuffles the specialism headers around based on which one was clicked
	function sortSpecialistHeader(name, instant)
	{	
		var slideHeaderSilent = new Fx.Tween($('specialisms-header-bg'),
		{
			duration: 350, 
			transition: Fx.Transitions.linear,
			onComplete: function()
			{
				//setupPlaceholder();
			}
		});
		
		var slidePlaceholderSilent = new Fx.Tween($('specialisms-placeholder'),
		{
			duration: 350, 
			transition: Fx.Transitions.linear,
			onComplete: function()
			{
				//setupPlaceholder();
			}
		});

		if(name == 'browse')
		{	
			if($('list-browse').hasClass('hide'))
			{
				$('list-specialism').addClass('hide');
				$('list-viewall').addClass('hide');
				$('list-browse').removeClass('hide');
				slideHeaderSilent.start('height', calculateSpecialismHeight('list-browse'));
				slidePlaceholderSilent.start('height', calculateSpecialismHeight('list-browse'));
			}
		}
		
		if(name == 'specialism')
		{
			if($('list-specialism').hasClass('hide'))
			{
				$('list-browse').addClass('hide');
				$('list-viewall').addClass('hide');
				$('list-specialism').removeClass('hide');	
					
				slideHeaderSilent.start('height', specialism_header_height);
				slidePlaceholderSilent.start('height', specialism_header_height);
			}
		}
		
		if(name == 'viewall')
		{
			if($('list-viewall').hasClass('hide'))
			{
				$('list-browse').addClass('hide');
				$('list-specialism').addClass('hide');
				$('list-viewall').removeClass('hide');	
					
				slideHeaderSilent.start('height', viewall_header_height);
				slidePlaceholderSilent.start('height', viewall_header_height);
			}
		}
		
		if(name == 'submit-cv')
		{
			if($('list-specialism').hasClass('hide'))
			{
				$('list-browse').addClass('hide');
				$('list-viewall').addClass('hide');
				$('list-specialism').removeClass('hide');	

				if(instant != null)
				{
					slideHeaderSilent.set('height', specialism_header_height);
					slidePlaceholderSilent.set('height', specialism_header_height);
				}
				else
				{
					slideHeaderSilent.start('height', specialism_header_height);
					slidePlaceholderSilent.start('height', specialism_header_height);
				}
			}
		}
		
		//on the switch out, apply sifr to the label above the switch
		/*
		sIFR.replace(arial, {
			selector: '#specialisms-header-content .left span'
			,css: [
			  '.sIFR-root { text-align: left; font-size: 12px; font-weight:bold; color:#314E70; display:block;  }'
			]
			
				,wmode: 'transparent'
		});
		*/
	}
	
	//sets the placeholder to be the height of the current active header, so when you swap the page content doesn't move
	function setupPlaceholder()
	{
		var oldHeight = $('specialisms-header-bg').getStyle('height');
		var oldPadding = $('specialisms-header-bg').getStyle('padding');
		$('specialisms-placeholder').setStyle('height', oldHeight);
		$('specialisms-placeholder').setStyle('padding', oldPadding);
	}
	
	//works out the height of the specialism based on the number of list items
	function calculateSpecialismHeight(name)
	{
		var liCount = $(name).getElement('ul').getElements('li');
		liCount = liCount.length;
		
		liHeight = $(name).getElement('ul').getElement('li').getStyle('height');
		
		liHeight = liHeight.split('px');
		liHeight = parseInt(liHeight[0]);
	
		var totalHeight = $(name).getElement('ul').getStyle('height');
		
		totalHeight = totalHeight.split('px');
		totalHeight = parseInt(totalHeight[0]);
		totalHeight = totalHeight + 20;
		
		return totalHeight;
	}
	
	//event listener for rotating the tooltips when the user goes idle
	function tooltipsListener()
	{
		var note = new notifier(5000);	
		window.addEvent('idle', onIdle);
		window.addEvent('active', onActive);
		
		function onIdle(e, cancel) 
		{	
			sliding = setInterval("slideTooltips();",5000);
		}
		
		function onActive(e) 
		{
			//stop the tooltips from moving around
			sliding = clearInterval(sliding);
		}
	}
	
	function swapSpecialismSwitch(title, swap)
	{
		var activeSwitch = $('switch-active');
		var inactiveSwitch = $('switch-inactive');
		var activeSwitchViewall = $('switch-active-viewall');
		var inactiveSwitchViewall = $('switch-inactive-viewall');
		
		activeSwitch.toggleClass('hide');
		inactiveSwitch.toggleClass('hide');
		activeSwitchViewall.toggleClass('hide');
		inactiveSwitchViewall.toggleClass('hide');
		
		$('switch-inactive-viewall').id = 'switch-active-viewall';
		activeSwitchViewall.id = 'switch-inactive-viewall';
		$('switch-inactive').id = 'switch-active';
		activeSwitch.id = 'switch-inactive';
		
		if (title == 'munkaadó')
		{
			title = 'employer';	
		}
		else
		{
			title = 'jobseeker';	
		}
		
		$('specialisms-header-content').className = title;
		
		if( activeSwitch.title == 'munkaadó' )
		{
			$('specialism').href = $('specialism').href.replace('job-seeker', 'employer');
		}
		else
		{
			$('specialism').href = $('specialism').href.replace('employer', 'job-seeker');
		}
		
		if(swap != 'no')
		{
			var specialismLis = $('list-specialism').getElements('li');
			
			for(var i=0, maxi=specialismLis.length; i<maxi; i++)
			{
				specialismLis[i].toggleClass('hide');
			}
		}
		
		if(swap != 'no')
		{
			var specialismLis = $('list-viewall').getElements('li');
			
			for(var i=0, maxi=specialismLis.length; i<maxi; i++)
			{
				specialismLis[i].toggleClass('hide');
			}	
		}
		
		if($('specialismContact'))
		{
			$('specialismContact').value = title;
		}
	}
	
	function swapResourceUnit(object)
	{
		$(object.id+'-content').removeClass('hide');
		$(activeResourceTab+'-content').addClass('hide');
		
		activeResourceTab = object.id;
		
		object.getParent().toggleClass('switch');	
	}
	
	function initSpecialismLinks(sector)
	{

		if(sector == 'jobseeker')
		{
			var specialismLis = $('specialisms-header').getElements('li.employer-list');
			var specialismLisShow = $('specialisms-header').getElements('li.jobseeker-list');
			for(var i=0, maxi=specialismLis.length; i<maxi; i++)
			{
				specialismLis[i].addClass('hide');
				specialismLisShow[i].removeClass('hide');
				//specialismLis[i].style.border = '1px solid #000000';
			}
		}
		else
		{
			var specialismLis = $('specialisms-header').getElements('li.jobseeker-list');
			var specialismLisShow = $('specialisms-header').getElements('li.employer-list');
			for(var i=0, maxi=specialismLis.length; i<maxi; i++)
			{
				specialismLis[i].addClass('hide');
				specialismLisShow[i].removeClass('hide');				
			}	
		}
	}

});	
	
/**********************
general functions
**********************/
	
function setId( title )
{
	formatedTitle = title.replace(' ', '');
	formatedTitle = formatedTitle.replace(' ', '');

	formatedTitle = 'nav-'+formatedTitle.toLowerCase()
	
	return formatedTitle;
}

function styleNav(){
}

function slideTooltips()
{
	if($(activeTooltip).getParent().getNext() != null)
	{
		doTooltips($(activeTooltip).getParent().getNext().getChildren()[0]);
	}
	else
	{
		doTooltips($(activeTooltip).getParent().getParent().getFirst().getChildren()[0]);
	}
}

function doTooltips(object)
{
	if(activeTooltip != object.name)
	{
		//swap active tooltip box
		$('tooltips-'+object.name).removeClass('hide');
		$('tooltips-'+activeTooltip).addClass('hide');
		
		//make the button active
		object.getParent().addClass('active');
		
		//remove active class from old active li
		$('tooltips-nav').getElement('a[name='+activeTooltip+']').getParent().removeClass('active');
		
		//sliding the tooltips arrow
		slideArrow = new Fx.Tween($('tooltips-arrow'));
		
		currentLeft = $('tooltips-arrow').getStyle('left');
		
		var offsetLeft = new Array();
		offsetLeft['reeduk'] = 38;
		offsetLeft['whatsnew'] = 117;
		offsetLeft['clients'] = 196;
		offsetLeft['jobseekers'] = 279;
		offsetLeft['international'] = 360;
				
		slideArrow.start('left',[currentLeft,offsetLeft[object.name]]);

		//make the clicked one the new active one
		activeTooltip = object.name;
		
		sIFR.replace(arial, {
			selector: '#tooltips-box .tooltips-content h2'
			,css: [
			'.sIFR-root { text-align: left; font-size: 15px; color:#FFFFFF; font-weight:bold; }'
			]
			
			,wmode: 'transparent'
		});
	}
}

//function to preload images, feel free to add to this
function preloadImages()
{
	var imagePath = includesPath+'/images/';
	
	var images = new Array(
		'arrow-button-red.jpg',
		'home-top-right-blue-rounded-box-arrow_on.png ',
		'resource-center-2.gif',
		'resource-center-1.gif'
	);
	
	for(var i=0, maxi=images.length; i<maxi;i++)
	{
		var image = new Image();	
		image.src = imagePath+images[i];
		image_cache.push(image);
	}
}

//google maps code
function googleMapsInit() 
{
	if (GBrowserIsCompatible()) 
	{
		var map1 = new GMap2(document.getElementById("googlemaps_1"));
		map1.setCenter(new GLatLng(47.499431,19.054542), 15);
		
		var latlng1 = new GLatLng(47.499431,19.054542);
		map1.addOverlay(new GMarker(latlng1));
		map1.addControl(new GSmallMapControl()); 
	}
}

function S4() 
{
	return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
};
		
function generateGuid()
{
	return (this.S4()+this.S4()+"-"+this.S4()+"-"+this.S4()+"-"+this.S4()+"-"+this.S4()+this.S4()+this.S4()).toUpperCase();
};

function openNewWindow()
{
	var links = $$( "a.new-window" );
	var linksCount = links.length;
	var scope = this;
	
	for( var i = 0; i < linksCount; i++ )
	{
		var sLink = links[i];
		
		$( sLink ).addEvent('click', function(e)
		{
			e = new Event(e).stop();
			var win_name = 'win_'+Math.round(Math.random() * Math.random() * 10000 );

			window.open( this.href, win_name,'width=1024, height=768, resizable=yes, menubar=yes, toolbar=yes, scrollbars=yes, status=yes' );
		});
	}
}

function toggleSalaryFields()
{	
	var inputs = $$('input.from-to');
	
	inputs.addEvent('focus', function(e)
	{
		toggleValue( this, this.title, '' );
	});
	
	inputs.addEvent('blur',function(e)
	{
		toggleValue( this, '', this.title );
	});
}

function toggleValue( field, from, to )
{
	if( $(field).value == from )
	{
		$(field).value = to;
	}
}

function toggleTabbedPanel()
{
	if(tabbedPanelSliding != true)
	{
		tabbedPanelSliding = true; //so more slide requests can't be made until it's done
		var slideTabbedPanel = new Fx.Tween('home-tabbed-container',
		{
			duration:750,
			onComplete:function()
			{
				tabbedPanelSliding = false;
			}
		});
		
		if(tabbedPanelIsOpen == false)
		{	
			slideTabbedPanel.start('bottom', [-93,0]);
			tabbedPanelIsOpen = true;
		}
		else
		{
			slideTabbedPanel.start('bottom', [0,-93]);
			tabbedPanelIsOpen = false;
		}
	}
}

function SwitchExplain()
{
	// get DOM objects
	var scope = this;
	this.explanation = $('switch_explain_container');
	this.open_links = $$('.switch_explain a');
	this.close_links = $$('#switch_explain .close a');
	
	this.hide = function()
	{
		this.explanation.setStyle('display', 'none');
	}
	this.show = function(e)
	{
		this.explanation.setStyle('display', 'block');
	}
	
	// if objects exist, set events
	if(this.explanation != null)
	{
		for(i=0, maxi=this.open_links.length; i<maxi; i++)
		{
			this.open_links[i].addEvent('click', function(e)
			{
				scope.show(e);
				return false;
			});
		}
		for(i=0, maxi=this.close_links.length; i<maxi; i++)
		{
			this.close_links[i].addEvent('click', function(e)
			{
				scope.hide();
				return false;
			});
		}
		
		var display=Cookie.read('switchexplain');
		if (display==null || display=="")
		{
			this.explanation.setStyle('display', 'block');
		}
		Cookie.write('switchexplain','shown', {duration:120, domain:siteDomain, path:'/'});
	}
}

// Flash banner embed
function loadFlash(container, movie, dimensions)
{
	if( $(container) )
	{
		var flashvars = {
			file: movie,
			height: dimensions.y,
			width: dimensions.x,
			allowscriptaccess: "always"
		};
		var params = {
			wmode: "transparent",
			allowscriptaccess: "always"
		};
		var attributes = false;
		swfobject.embedSWF(movie, container, dimensions.x, dimensions.y, "9.0.0", includesPath+"/flash/expressInstall.swf", flashvars, params, attributes);
	}
}

// Terms and conditions popup
function setupTandCs()
{
	// "I have read the T&Cs" link for job application
	if($('readterms'))
	{
		var readterms = $('readterms');

		readterms.addEvent('click',function(e)
		{
			TCs(e);
			return false;
		});
	}

	if($('TC-box-close'))
	{
		$('TC-box-close').addEvent('click', function(e) {
			e.stop();
			hideTCsBox();
		});
	}
}

function TCs(e)
{
	e.stop();

	// we cache T&C content after the first run
	if(terms_and_conditions == "")
	{
		var TC_link = $(e.target).getProperty("href");
		var request_options = {
			evalScripts:false,
			onSuccess:getTCs,
			onFailure:getTCsFailure
		};
		var tc_request = new Request.HTML(request_options);
		tc_request.get(TC_link);
	}
	showTCsBox();
	return false;
}
function hideTCsBox()
{		
	if($('right-search-unit') != null)
	{
		//$('TC-box-iframe').src = '';
		$('right-search-unit').removeClass('ie6-hide');
	}
	$('let-us-know').removeClass('ie6-hide');
	$('TC-box-bg').addClass('hide');
	$('TC-box-overlay').addClass('hide');
}

function showTCsBox()
{
	if($('right-search-unit') != null)
	{
		// pop up lightbox area with loader
		//$('TC-box-iframe').src = href;
		$('right-search-unit').addClass('ie6-hide');
	}
	$('let-us-know').addClass('ie6-hide');
	$('TC-box-bg').removeClass('hide');
	$('TC-box-overlay').removeClass('hide');
}

function showTCsContent()
{
	// replace loader in lightbox with t&c content
	$('TC-box-iframe-wrapper').set("html",terms_and_conditions);
}

function getTCs(responseTree, responseElements, responseHTML, responseJavaScript)
{
	// get the appropriate text from the HTML
	var content='';
	for(var i=0, maxi=responseElements.length; i<maxi; i++)
	{
		if(responseElements[i].nodeName.toUpperCase() == "DIV")
		{
			content = $(responseElements[i]).getElement(".generic-container-text");
			if(content != null)
			{
				i = maxi;
			}
		}
	}

	// cache terms and conditions text
	terms_and_conditions = content.get("html");
	//return terms_and_conditions;
	showTCsContent();
}

function getTCsFailure(xhr)
{
	// could not get the T&C for some reason
	terms_and_conditions = "<p>Sorry, we could not find the Terms and Conditions for you. You can get there using the link at the bottom of the page</p>";
	showTCsContent();
}
/***** end of t&c's functions *****/


// Xpress functions
// add onload event for iframe or callable directly to resize
function resizeIframe( setLoadEvent )
{
	var iframe = $$('.iframe-content iframe')[0];
	if(iframe != null)
	{
		if( setLoadEvent != null )
		{
			iframe.addEvent('load',function()
			{
				resizeIframeAction(iframe);
			});
		}
		else
		{
			resizeIframeAction(iframe);
		}
	}
}
// calculations and DOM changes for iframe resize
function resizeIframeAction(iframe)
{
	var innerDoc = (iframe.contentDocument) ? iframe.contentDocument : iframe.contentWindow.document;
	var objToResize = (iframe.style) ? iframe.style : iframe;
	objToResize.height = (innerDoc.body.scrollHeight + 50) + 'px';
}
// change the content of the Xpress account status area
function updateUserLinks()
{
	jQuery.ajax({
		url: includesPath+'/xpress/checkUserLoggedIn.php',
		success: function( data ) {
			jQuery('#xpress-signin-signout').html( data );
		}
	});
}
