$(document).ready(function(){
	setTimeout(function(){resizeRightNav(0);},200);
	
	$.each($.browser, function(i, val){
		if(i == 'msie'){
			setTimeout(function(){resizeRightNav(-4);},200);
		}
	});

	if($('ul.sf-menu').css('display') != null){
		$('ul.sf-menu').superfish(); 						   
	}
	
	//write email address
	var s1, s2, s3, s4;
	s1 = 'info';
	s2 = 'jamesco.com';
	$('#emailAddy').attr('href','mailto:'+s1+'@'+s2);
	
	var windowHeight = $(window).height();
	var containerHeight = $('#bgHolder').height();
	if(containerHeight < windowHeight){
		//$('#bgHolder').css('height',windowHeight);	
	}
	
	$(window).resize(function(){
		var windowHeight = $(window).height();
		//alert('resized');
		$('#bgHolder').css('height',windowHeight);
	});
	
	$("#mainNav img").hover(function() {
		$(this).attr("src", $(this).attr("src").split(".").join("-hover."));
	}, function() {
		$(this).attr("src", $(this).attr("src").split("-hover.").join("."));
	});
	
	if($().colorbox){
		$(".cbox").colorbox({width:"790", height:"650", iframe:true});
	}
	
	var randLeft = Math.floor((5-0)*Math.random()) + 1;
	var randMid = Math.floor((10-5)*Math.random()) + 6;
	var randRight = Math.floor((17-10)*Math.random()) + 11;

	$('#randLeft').attr('src','/images/randoms/random'+randLeft+'.jpg');
	$('#randMid').attr('src','/images/randoms/random'+randMid+'.jpg');
	$('#randRight').attr('src','/images/randoms/random'+randRight+'.jpg');

	
	// We only want these styles applied when javascript is enabled
	$('div.navigation').css({'width' : '240px', 'float' : 'left', 'padding-top':'8px'});
	$('div.content').css('display', 'block');
	
	// Initially set opacity on thumbs and add
	// additional styling for hover effect on thumbs
	if($().opacityrollover){
		var onMouseOutOpacity = 0.67;
		$('#thumbs ul.thumbs li').opacityrollover({
			mouseOutOpacity:   onMouseOutOpacity,
			mouseOverOpacity:  1.0,
			fadeSpeed:   'fast',
			exemptionSelector: '.selected'
		});
	}

	if($().galleriffic){
		var gallery = $('#thumbs').galleriffic({
			delay:   2500,
			numThumbs:     10,
			preloadAhead:  10,
			enableTopPager:      true,
			enableBottomPager:   true,
			maxPagesToShow:      7,
			imageContainerSel:   '#slideshow',
			controlsContainerSel:      '#controls',
			captionContainerSel: '#caption',
			loadingContainerSel: '#loading',
			renderSSControls:    true,
			renderNavControls:   true,
			playLinkText:  'Play Slideshow',
			pauseLinkText:       'Pause Slideshow',
			prevLinkText:  '&lsaquo; Previous Photo',
			nextLinkText:  'Next Photo &rsaquo;',
			nextPageLinkText:    'Next &rsaquo;',
			prevPageLinkText:    '&lsaquo; Prev',
			enableHistory:       false,
			autoStart:     false,
			syncTransitions:     true,
			defaultTransitionDuration: 900,
			onSlideChange:       function(prevIndex, nextIndex) {
				// 'this' refers to the gallery, which is an extension of $('#thumbs')
				this.find('ul.thumbs').children()
					.eq(prevIndex).fadeTo('fast', onMouseOutOpacity).end()
					.eq(nextIndex).fadeTo('fast', 1.0);
			},
			onPageTransitionOut: function(callback) {
				this.fadeTo('fast', 0.0, callback);
			},
			onPageTransitionIn:  function() {
				this.fadeTo('fast', 1.0);
			}
		});
    }

    $('#search').gSearch({ resultsDIV: 'gResults', searchContainer: 'gSearchBox', siteRestriction: 'jamesco.com', useCB: true, CBTitle: 'Search Results', resultsPerPage: 6 });
});

function resizeRightNav(diff){
	var contentHeight = parseInt($('#intMainContent').css('padding-top')) + parseInt($('#intMainContent').css('padding-bottom')) + parseInt($('#intMainContent').height());
	$('#intRightNav').height(contentHeight + 4 + diff);
}
