$(document).ready(function() {
// doc ready


	//
	// PANORAMA SCROLLING THING
	//
	
	$('#goLeft').hide();
			
	//set movement increments
	var backgroundPos = 250;
	var backgroundPos = backgroundPos + 'px';
	
	// set clickCounter to start position
	var clickCounter = 3;
	
	
	// update clickCounter when goLeft is clicked
	$('#goLeft').live('click',function(event){
									   
		//subtract 1 to clickCounter
		clickCounter -=1;
		// if clickCounter is less than 4 background is at its start position, so get rid of goLeft
		if(clickCounter < 4) {
			$('#goLeft').fadeOut();
			
		// if clickCounter is less than 3 its not at its start position so show goRight
		} else if(clickCounter > 3) {
			$('#goRight').fadeIn();
		}
	});
	
	
	// update clickCounter when goRight is clicked
	$('#goRight').live('click',function(event){
		
		// add 1 from clickCounter
		clickCounter +=1;
		// if clickCounter is LESS than 4 background is in start position so sshow goRight
		if(clickCounter == 6) {
			$('#goRight').fadeOut();
		} else if(clickCounter == 4 ) {
			$('#goLeft').fadeIn();
		}
	});
	
	
	//go left
	$('#goLeft').click(function() {
		//take backgroundPos value off of current background-position
		$('#panorama2,#panorama3,#panorama4,#panorama5,#panorama6').animate({backgroundPosition: '+=' + backgroundPos},2000);
	
	});
	//go right
	$('#goRight').click(function() {
		$('#panorama2,#panorama3,#panorama4,#panorama5,#panorama6').animate({backgroundPosition: '-=' + backgroundPos},2000);
	});




	//
	// SLIDESHOW CYCLE
	//

    $('.slideshow').cycle({
		fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
    speed:    5500, 
    timeout:  500 
	});
	
	
	
	//
	// ADD CLASS TO FIRST LI IN MENU because for some reason it's not showing the class page_item
	//
	
	
	$('#sidebar li').addClass('page_item');







	// magnifier

	$(function(){
		
		var loupe = {'width' : 200, 'height': 151};
		
		$('<div id="thejLoupe"/>').addClass('thejLoupe').css('position','absolute').css('width',loupe.width+'px').css('height',loupe.height+'px').css('backgroundColor','rgba(0,0,0,0.25)').hide().appendTo('body');	
		$('<div id="zoomWrapper" />').css('width',loupe.width-10+'px').css('height',loupe.height-10+'px').css('overflow','hidden').css('marginTop','5px').css('marginLeft','5px').appendTo('#thejLoupe');
	
		$('.jLoupe').each(function(){
			var s = ($(this).attr('longdesc') != undefined) ? $(this).attr('longdesc') : $(this).attr('src');
			var i = $('<img />').bind('load',function(){
					$(this).data('size',{'width':this.width, 'height':this.height});
				}).attr('src', s).hide().appendTo('#zoomWrapper');	
			$(this).data('zoom',i);		
		})
		.bind('mousemove', function(e){ 
			var o = $(this).offset();
			var i = $(this).data('zoom');
			$('#thejLoupe').css('left',e.pageX+10).css('top',e.pageY+10);
			var zlo = ((e.pageX - o.left) / this.width) * $(i).data('size').width - 86;
			var zto = ((e.pageY - o.top) / this.height) * $(i).data('size').height - 62;
			$(i).css('marginLeft', zlo * -1 + 'px').css('marginTop', zto * -1 + 'px').show();
		})
		.bind('mouseout', function(e){
			$(this).data('zoom').hide();
			$('#thejLoupe').hide();
		})
		.bind('mouseover', function(e){
			$(this).data('zoom').show();
			$('#thejLoupe').show();
		});
		
		
	});










// close doc ready	

});

