// POP-UP FUNCTIONS USED BY CMS
// ---------------------------------------------------------------------------------------

function open_in_popup_window(url, name, width, height) {
	window.open(url.href,name,'width=' + width + ',height=' + height + ',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes');
	return false;
}
function open_in_new_window(url) {
	window.open(url.href,'external_link','toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes');
	return false;
}

// CODE FOR DROP-DOWN MENU SUPPORT IN IE6
// ---------------------------------------------------------------------------------------

//sfHover = function() {
//	var sfEls = document.getElementById("main_nav").getElementsByTagName("li");
//	for (var i=0; i<sfEls.length; i++) {
//		sfEls[i].onmouseover=function() {
//			this.className+=" sfhover";
//		}
//		sfEls[i].onmouseout=function() {
//			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
//		}
//	}
//}
//if (window.attachEvent) window.attachEvent("onload", sfHover);


// JQUERY SCRIPTS FOR LIGHTBOX AND SLIDING PANELS
// ---------------------------------------------------------------------------------------
$(function() {
	

$('#slides').css('position','relative');
$('.slide').css({
	'left': 0,
	'position': 'absolute',
	'top': 0
});

$('.slide').not(':first').hide();

$('#right img').click(function(){
	$nextSlide = $('.slide:visible').next('.slide');
	$('.slide:visible').fadeOut();
	if ($nextSlide.length > 0) {
		$nextSlide.fadeIn();
	} else {
		$('.slide:first').fadeIn();
	}
});

$('#left img').click(function(){
	$prevSlide = $('.slide:visible').prev('.slide');
	$('.slide:visible').fadeOut();
	if ($prevSlide.length > 0) {
		$prevSlide.fadeIn();
	} else {
		$('.slide:last').fadeIn();
	}
});

//Lightbox

	var $popupContainer = $('#popup-container'),
	$popupInner = $('#popup-inner'),
	$show = $('#show'),
	$close = $('#close'),
	topMarginBase = 40,
	positionLightbox = function() {
	var topMargin = $(document).scrollTop() + topMarginBase;
		$popupInner.css({
			marginTop: topMargin
		});	
	};

	$popupContainer.css({
		width: $(document).width(),
		height: $(document).height()
	});
	
	$show.click(function(event){
		positionLightbox();
		$popupContainer.fadeIn();
		event.preventDefault();
	});
	
	$(document).scroll(function (event) { 
		positionLightbox();
    });

	
	$close.click(function(event){
		$popupContainer.fadeOut();
		event.preventDefault();
	});


	$tabs = $('.tabs li a');
	$tab = $('.concept');
	$tabs.each(function(i,e){
		$(e).click(function(event){
			$tabs.removeClass('selected').eq(i).addClass('selected');
			$tab.hide().eq(i).show(); 
			event.preventDefault();
		});
	});


//External Links

	$('a[rel="external"]').each(function(){
		$(this).click(function(event){
			window.open($(this).attr('href'));
			event.preventDefault();
		});
	});

	if ($('body.home').length == 0) {
		Cufon('h1, h2, h3, h4, h5, h6, dt',{
			fontFamily:'Helvetica'
		});
	}

});


