function companyBrowsing() {
	$('#companies-list ul').hide();
	$('#companies-list li a').click(function() {
		var checkElement = $(this).next();
		
		if((checkElement.is('ul')) && (checkElement.is(':visible'))) {  //The menu item clicked has a expanded sub-menu underneath
			checkElement.slideUp('normal');  //Slide up the expanded sub-menu
			$(this).parent().toggleClass('collapsible'); //Toggle class collapsible to change the orientation of the arrow on the right
			return false;
		}
		if((checkElement.is('ul')) && (!checkElement.is(':visible')) && ($('li', checkElement).length)) {  //The menu item clicked has a hidden sub-menu underneath that is not empty
			$('#companies-list li.collapsible').removeClass('collapsible');  
			$('#companies-list ul:visible').slideUp('normal');  //If there is any sub-menu expanded, it will slide up
			checkElement.slideDown('normal');  //Slide down the hidden submenu
			$(this).parent().toggleClass('collapsible'); //Toggle class collapsible to change the orientation of the arrow on the right
			return false;
		}
	});
}

function mycarousel_initCallback(carousel) {

	//Start and Stop the carousel when accessing the Print Preview
	$('#print-preview').bind('click', function() { carousel.startAuto(0); });
	$('#turnoff-print').bind('click', function() { carousel.startAuto(5); });

	// Disable autoscrolling if the user clicks the prev or next button.
	carousel.buttonNext.bind('click', function() {
		carousel.startAuto(0);
		$("#pp-button").removeClass().addClass('play');
		return false;
	});

	carousel.buttonPrev.bind('click', function() {
		carousel.startAuto(0);
		carousel.prev();
		$("#pp-button").removeClass().addClass('play');	
		return false;	
	});

	$("#pp-button").bind('click', function() {
		if ($(this).hasClass('pause')) { 
			carousel.startAuto(0);
			$(this).removeClass('pause').addClass('play');
		} else { 
			carousel.startAuto(7);
			$(this).removeClass('play').addClass('pause');
		}
	});
        jQuery().zoom(function(){ carousel.startAuto(0);});
}

$(document).ready(function() { 
	var contentTools = $('#site_tools');
	companyBrowsing();  // Calls to the function to company browsing menu behavior	
	contentTools.prepend('<a href="#" id="print-preview" class="print left">Print this Page</a>'); 
	$('#featured-home').prepend('<div id="pp-button" class="pause"></div>');
	$('#featured-events').prepend('<div id="pp-button" class="pause"></div>');
	$('#featured-companies').prepend('<div id="pp-button" class="pause"></div>');
	$('#companies-list li:has(ul > li)').addClass('haschild'); //add the arrow if the industry sector has children underneath and it's expandable
	$('#print-preview').printPreview();  // Initialize print preview plugin
	$('#carousel').jcarousel({ 
		scroll:1,
		auto:7,
		wrap:"circular",
		animation:"slow",
		initCallback: mycarousel_initCallback
	}); // Initialise jcarousel plugin
	$("#send-email").colorbox({width:"600px", height:"400px", iframe:true}); // Initialise colorbox for the send to a friend popup
	$("a.video").colorbox({width:"800px", height:"600px", iframe:true}); // Initialise colorbox for the video links
	$('#right_menu ul ul > li.current').parent().show();
	// Add hyperlink to the Linked In thumbnail in the home page carousel
	$('body.home img[title*="ATS Linked in"]').wrap('<a href="http://www.linkedin.com/groups?mostPopular=&gid=3375270" target="_blank"></a>');
        // Targets all the sub-lists created with WYSIWYG and adds a class to the empty li to remove the css background image
        $("#content ul li").each(function(){
           if (/^[ |\n]*<ul/i.test($(this).html())) { $(this).addClass("hide-li"); }
        });	       
});

$(document).ready(function() {
//When you click on a link with class of poplight and the href starts with a # 
$('a.poplight[href^=#]').click(function() {
    var popID = $(this).attr('rel'); //Get Popup Name
    var popURL = $(this).attr('href'); //Get Popup href to define size

    //Pull Query & Variables from href URL
    var query= popURL.split('?');
    var dim= query[1].split('&');
    var popWidth = dim[0].split('=')[1]; //Gets the first query string value

    //Fade in the Popup and add close button
    $('#' + popID).fadeIn().css({ 'width': Number( popWidth ) }).prepend('<a href="#" class="close"><img src="/__data/assets/image/0006/7179/close_popup.png" class="btn_close" title="Close Window" alt="Close" /></a>');

    //Define margin for center alignment (vertical   horizontal) - we add 80px to the height/width to accomodate for the padding  and border width defined in the css
    var popMargTop = ($('#' + popID).height() + 80) / 2;
    var popMargLeft = ($('#' + popID).width() + 80) / 2;

    //Apply Margin to Popup
    $('#' + popID).css({
        'margin-top' : -popMargTop,
        'margin-left' : -popMargLeft
    });

    //Fade in Background
    $('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
    $('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn(); //Fade in the fade layer - .css({'filter' : 'alpha(opacity=80)'}) is used to fix the IE Bug on fading transparencies 

    return false;
});


//Append nocache to form action
var myaction = $('#form_email_7329').attr('action');
var nocache_search = myaction.search(/_nocache/);
if ( nocache_search == -1) {
    $('#form_email_7329').attr('action',myaction + '/_nocache');
}

//Close Popups and Fade Layer
$('a.close, #fade').live('click', function() { //When clicking on the close or fade layer...
    $('#fade , .popup_block').fadeOut(function() {
        $('#fade, a.close').remove();  //fade them both out
    });
    return false;
});

});
