$(document).ready(function(){
	
	$('.msgok').each(coolReveal);
	$('.msgerror').each(coolReveal);

	$('#jsddm > li').bind('mouseover', jsddm_open);
	$('#jsddm > li').bind('mouseout',  jsddm_timer);
	
	hideExtraNewsBlurbs();
		
	$('A[rel="external"]').click( function() {
		window.open( $(this).attr('href') );
		return false;
	});
	
	var iSlideshowFadeSpeed = 1500;
	var iSlideshowTimeout = 3000;
	$('.slideshow-inner').cycle({ 
		fx: 'fade', 
		speed: iSlideshowFadeSpeed,
		timeout: iSlideshowTimeout
	});	

});

function coolReveal()
{
	$(this).hide();
	$(this).slideDown('slow');
}

function hideExtraNewsBlurbs()
{
	$('.newsblurbs .newsitem').slice(3).hide();
	$('.tradeshowblurbs .newsitem').slice(2).hide();
	
	//$('.newsblurbs .newsitem').slice(3).slideUp(300);
}

function initializePhotoGallery()
{
	$("a[rel^='prettyPhoto']").prettyPhoto({
		animationSpeed: 'normal',
		showTitle: false,
		allowresize: true
	});
	
	$('div.scrollable').scrollable({
		clickable: false,
		size: 5
	});
}






var iTotalPhotoGalleryGroupItems = 0;
var iCurrentPhotoGalleryGroupItem = 1;
var iPixelWidthOfEachPhotoGalleryGroupItem = 541;
var bPhotoGalleryGroupClickLock = false;

function clickHandleNextClick()
{
	if (!bPhotoGalleryGroupClickLock)
	{
		if (iCurrentPhotoGalleryGroupItem < iTotalPhotoGalleryGroupItems)
		{
			bPhotoGalleryGroupClickLock = true;
			iCurrentPhotoGalleryGroupItem = iCurrentPhotoGalleryGroupItem + 1;
			var iLeftPosition = ((iCurrentPhotoGalleryGroupItem * iPixelWidthOfEachPhotoGalleryGroupItem) * -1) + iPixelWidthOfEachPhotoGalleryGroupItem;
			PhotoGalleryGroupUpdateNav();
			jQuery('.photogallerygroup-inner').animate({ left: ''+iLeftPosition+'px' }, 500, function(){
				bPhotoGalleryGroupClickLock = false;
			});			
		}
	}	
}

function clickHandlePrevClick()
{
	if (!bPhotoGalleryGroupClickLock)
	{		
		if (iCurrentPhotoGalleryGroupItem > 1)
		{
			bPhotoGalleryGroupClickLock = true;
			iCurrentPhotoGalleryGroupItem = iCurrentPhotoGalleryGroupItem - 1;
			var iLeftPosition = ((iCurrentPhotoGalleryGroupItem * iPixelWidthOfEachPhotoGalleryGroupItem) * -1) + iPixelWidthOfEachPhotoGalleryGroupItem;
			PhotoGalleryGroupUpdateNav();
			jQuery('.photogallerygroup-inner').animate({ left: ''+iLeftPosition+'px' }, 500, function(){
				bPhotoGalleryGroupClickLock = false;
			});
		}
	}	
}

function PhotoGalleryGroupUpdateNav()
{
	$('.nextButton').css('visibility', 'visible');
	$('.prevButton').css('visibility', 'visible');
	
	if (iCurrentPhotoGalleryGroupItem >= iTotalPhotoGalleryGroupItems)
	{
		$('.nextButton').css('visibility', 'hidden');	
	}
	
	if (iCurrentPhotoGalleryGroupItem <= 1)
	{
		$('.prevButton').css('visibility', 'hidden');	
	}
}

function initializePhotoGalleryGroup()
{
	iTotalPhotoGalleryGroupItems = parseInt(jQuery('div.photogallery').size());
	jQuery('.photogallerygroup-inner').css('width', (iTotalPhotoGalleryGroupItems * iPixelWidthOfEachPhotoGalleryGroupItem) + 'px');
	
	$('.nextButton').click(clickHandleNextClick);
	$('.prevButton').click(clickHandlePrevClick);
	
	PhotoGalleryGroupUpdateNav();
}









var timeout = 300;
var closetimer = 0;
var ddmenuitem = 0;

function jsddm_open()
{
	jsddm_canceltimer();
	jsddm_close();
	ddmenuitem = $(this).find('ul').eq(0).css('visibility', 'visible');
}

function jsddm_close()
{
	if (ddmenuitem)
	{
		ddmenuitem.css('visibility', 'hidden');
	}	
}

function jsddm_timer()
{
	closetimer = window.setTimeout(jsddm_close, timeout);
}

function jsddm_canceltimer()
{
	if(closetimer)
	{
		window.clearTimeout(closetimer);
		closetimer = null;
	}
}

document.onclick = jsddm_close;











var oFancySlides = undefined;
var oFancySlidePrev = undefined;
var oFancySlideNext = undefined;
var iFancySlidesMaxIndex = -1;
var iFancySlideCurrentIndex = -1;
var iFancySlideFadeDuration = 700;
var iFancySlideWait = 4000;
var oFancySlideTimer = undefined;
var bClicked = false;

function handleFancySlideArrowClick(oEvent, iDirection) {
	oEvent.preventDefault();
	clearTimeout(oFancySlideTimer);
	bClicked = true;
	advanceToNextFancySlide(iDirection);
}

function advanceToNextFancySlide(iDirection) {
	hideAllFancySlides();
	iFancySlideCurrentIndex = iFancySlideCurrentIndex + iDirection;
	
	if (iFancySlideCurrentIndex > iFancySlidesMaxIndex) {
		iFancySlideCurrentIndex = 0;
	} else if (iFancySlideCurrentIndex < 0) {
		iFancySlideCurrentIndex = iFancySlidesMaxIndex;
	}
	
	if (iFancySlideCurrentIndex == 0) {
		oFancySlidePrev.hide();
	} else {
		oFancySlidePrev.show();
	}
	
	if (iFancySlideCurrentIndex == iFancySlidesMaxIndex) {
		oFancySlideNext.hide();
	} else {
		oFancySlideNext.show();
	}
	
	showCurrentFancySlide();
}

function showCurrentFancySlide() {
	oFancySlides.eq(iFancySlideCurrentIndex).stop(true, true).fadeIn(iFancySlideFadeDuration, function() {
		if (!bClicked) {
			oFancySlideTimer = setTimeout('advanceToNextFancySlide(1)', iFancySlideWait);
		}
	});
}

function hideAllFancySlides() {
	oFancySlides.hide();
}

function initializeFancySlides() {
	oFancySlides = $('.fancyslides img');
	iFancySlidesMaxIndex = oFancySlides.length - 1;
	if (iFancySlidesMaxIndex > -1) {
		oFancySlidePrev = $('.prevButton', oFancySlides.parent());
		oFancySlideNext = $('.nextButton', oFancySlides.parent());
		oFancySlidePrev.click(function(e) {
			handleFancySlideArrowClick(e, -1);
		});
		oFancySlideNext.click(function(e) {
			handleFancySlideArrowClick(e, 1);
		});
		advanceToNextFancySlide(1);
	}
}











