
$('document').ready(function() {
	initMenus();

});


function initMenus() {
	$('ul.menu ul').hide();
	$('ul.menu li.active ul').show();
	$.each($('ul.menu'), function(){
		$('#' + this.id + '.expandfirst ul:first').show();
	});
	//$('ul.menu li a').click(
	$('ul.menu li a').mouseover(
		function() {
			var checkElement = $(this).next();
			var parent = this.parentNode.parentNode.id;

			if($('#' + parent).hasClass('noaccordion')) {
				$(this).next().slideToggle('normal');
				return false;
			}
			if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
				if($('#' + parent).hasClass('collapsible')) {
					//$('#' + parent + ' ul:visible').slideUp('normal');
				}
				return false;
			}
			if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
				//$('#' + parent + ' ul:visible').slideUp('normal');
				checkElement.slideDown('normal');
				return false;
			}
		}
	);
}


function showMenu(id){
	$('#'+id).toggle();

	display = $('#'+id).css('display');
	if(display == 'block'){
		$('span.'+id).attr('style','background: url(static/images/arrow_on.gif) 13px 18px no-repeat;');
	}else{
		$('span.'+id).attr('style','background: url(static/images/arrow.gif) 15px 15px no-repeat;');
	}
}

//changes main image on product page
function changeProductMainPicture( filename, imageID, pos, totalthumbs, productID, altText) {
	
	var data = '<center><img alt="'+altText+'" align="center" src="webimages/' + filename + '" border="0" alt="" id="productImageLarge"></center>';

	$('.productimage').html(data);

	$('#product_pdf').attr('href', 'productpdf.php?productID='+productID+'&imageID='+imageID);

	resetThumbnails( totalthumbs );
	activateThumbnail( pos, true );
}

//resets class names for thumbnails on product page
function resetThumbnails( totalthumbs ) {
	for (i=0; i<totalthumbs; i++) {
		activateThumbnail( i, false );
	}
}

//sets class name for a specific thumbnail on product page
function activateThumbnail( pos, mode ) {
	
	var thumbnail = document.getElementById('thumbnailBox' + pos);
	var imgThumbnail = document.getElementById('thumbnailImage' + pos);
	
	
	if (mode) {
		thumbnail.className='productImageThumbnailBox-selected';
		imgThumbnail.className='productImageThumbnail-selected';
	}
	else {
		thumbnail.className='productImageThumbnailBox';
		imgThumbnail.className='productImageThumbnail';
	}
}


function popup(url, name, width, height, menu, resize, status) {
	custompop(url, width, height, status, menu);
	return true;
}


function custompop(url, width, height, status, menu) {
   win = window.open(url, 'bmwin_popup', 'toolbar=no,location=no,directories=no,status=' + status +  ',menubar=' + menu + ',scrollbars=yes,resizable=yes,copyhistory=no,width=' + width + ',height=' + height);
   win.focus();
}
