jQuery(document).ready(function(){
	// custom lightbox functions
	// resize lightbox background to max of window screen
	jQuery.fn.lightBoxResize = function() {
		var mainHeight = jQuery(document).height()-800;
		jQuery('#lightbox').css('height', mainHeight+'px'); // only matters if lightbox is active 
		var mainWidth = jQuery('#main_block_home').position();
		jQuery('#header_about_us').css('margin-left', mainWidth.left+'px');
		//jQuery('#width').text(mainWidth.left);
	};
	// turn on lightbox
	jQuery.fn.lightBoxOn = function() {
		var mainHeight = jQuery(document).height()-800;
		jQuery('#lightbox').css('height', mainHeight+'px').fadeIn(500); 
		//jQuery('#lightbox').css('height', jQuery(document).height()).fadeIn(500); 
	};
	// turn off lightbox (common class for all lightbox containers)
	jQuery.fn.lightBoxOff = function() {
		jQuery('#lightbox, .lightbox-inner').fadeOut(500); 
		jQuery('.preview-sample-image-inner').html('');
	};
	// 2 types of lightbox containers (previews and selectors)
	jQuery.fn.lightBoxPreviewOn = function() { jQuery('#lightbox_preview').fadeIn(500); };
	jQuery.fn.lightBoxSelectorOn = function() { jQuery('#lightbox_selector').fadeIn(500); };
	// opens the about us on the very top of the page
	jQuery.fn.aboutUsOpen = function() {
		jQuery('#header_hidden').animate({ 'margin-top': '0px'}, 500); 
		jQuery('#header_about_us_close img').addClass('reverse');
	};
	// closes the about us on the very top of the page
	jQuery.fn.aboutUsClose = function() {
		jQuery('#header_hidden').animate({ 'margin-top': '-824px'}, 500); 
		jQuery('#header_about_us_close img').removeClass('reverse');
	};

	// opens the about us on the very top of the page
	jQuery('#header_nav_aboutus').click(function(){ jQuery().aboutUsOpen(); });
	// closes the about us on the very top of the page
	jQuery('.header-aboutus-close').click(function(){
		if (jQuery('#header_hidden').css('margin-top') != '0px') {
			jQuery().aboutUsOpen(); 
		} else {
			jQuery().aboutUsClose(); 
		}
	});
	
	// section slider
	jQuery('.section-select').click(function(){
		var mTop = 0;
		var i = jQuery(this).attr('id').split('_');
		switch (i[2]) {
			case 'web':
				mTop = '-710';
				break;
			case 'photo':
				mTop = '-1420';
				break;
			case 'print':
				mTop = '-2130';
				break;
			case 'home':
			default:
				mTop = '0';
				break;
		}
		if (!jQuery(this).hasClass('selected')) {
			jQuery('#header_nav_list li.section-select').removeClass('selected');
			jQuery('#header_nav_'+i[2]).addClass('selected');
			jQuery('#main_block_container_slider').animate({ 'margin-top': mTop+'px' }, 1000);
			if (mTop == '0') {
				jQuery('#footer_client_block').fadeOut(1000);
			} else {
				jQuery('#footer_client_block').fadeIn(1000);
			}
		}
		
		jQuery().aboutUsClose(); // close about us if it is open
	});
	
	// call lightbox (2 types)
	jQuery('.thumb-preview-list li').click(function(){
		jQuery().aboutUsClose();
		
		if (jQuery(this).hasClass('disabled')) {
			//jQuery('.disable-ro').css('margin-top', '0');
			jQuery('.disable-ro').animate({'margin-top': '0px'}, 200);
			jQuery(this).find('.disable-ro').animate({'margin-top': '-236px'}, 300);
		} else {
			jQuery().lightBoxOn();
			jQuery().lightBoxPreviewOn();
			var i = jQuery(this).attr('id').split(':');
			var thumbType 	= i[0];
			var thumbID 	= i[1];
			jQuery('#lightbox_preview_inner').load('lightbox.preview.content.'+thumbType+'.php?section='+thumbType+'/'+thumbID, function(){
				jQuery.getScript('/js/preview.js');
			});
		}
	});
	
	jQuery('.main-container-selector-bar').click(function(){
		jQuery().aboutUsClose();
		jQuery().lightBoxOn();
		jQuery().lightBoxSelectorOn();
		var i = jQuery(this).attr('id').split('_');
		var barType = i[1];
		var selectorBarTitle = '';
		var selectorPage = '';
		switch (barType) {
		case 'web':
			selectorBarTitle = 'Website Selector';
			selectorPage = 'lightbox.selector.content.web.php';
			break;
		case 'model':
			selectorBarTitle = 'Model Selector';
			selectorPage = 'lightbox.selector.content.model.php';
			break;
		}
		jQuery('#lightbox_selector_topbar_title').html(selectorBarTitle);
		jQuery('#lightbox_selector_inner').load(selectorPage, function(){
			jQuery.getScript('/js/selector.js');
		});
	});
	
	// 3 ways to cancel lightbox: close button, click in lightbox shade, or esc key
	jQuery('.close-section').click(function(){ jQuery().lightBoxOff(); });
	jQuery('#lightbox').click(function(){ jQuery().lightBoxOff(); });
	jQuery(document).keyup(function(e){ if (e.keyCode == 27) { jQuery().lightBoxOff(); } });
	
	// adjust lightbox to entire area on window resize
	jQuery(window).resize(function(){ jQuery().lightBoxResize(); });
	
	var mainWidth = jQuery('#main_block_home').position();
	jQuery('#header_about_us').css('margin-left', mainWidth.left+'px');
});


