$(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;



