// Do the magic
jQuery(document).ready(function() {

	jQuery("a.fancybox").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayShow'	:	true,
		'titleShow'		:	false,
		'centerOnScroll':	true,
		'overlayOpacity':	0.3,
		'overlayColor'	:	'#666',
		'padding'		:	25
	});


	//var windowWidth = jQuery(window).width();
	//var windowHeight = jQuery(window).height();
	//setDisplayMode(); // Initial displayMode setting
	
	//jQuery(window).resize(function() { setDisplayMode(); }); // set displayMode if user resizes the window
	
	/*
	function setDisplayMode() {
		windowWidth = jQuery(window).width();
		windowHeight = jQuery(window).height();
		
		if (windowWidth < 1240) {
			jQuery("#page").attr('class','mini');
		} else if (windowWidth >= 1240 && windowWidth < 1600) {
			jQuery("#page").attr('class','normal');
		} else if (windowWidth >= 1600) {
			jQuery("#page").attr('class','full');
		}
	}
	*/
	
	jQuery('#headerTitle h1').click(function() { window.location.href = 'index.php'; });

	var galleryImages = new Array;
	var markup = "";
	var galleries = jQuery('div.galleryItems');
	var galleryWidth = 760 - 90;
	var imageHeight = 380;
	
	galleries.each(function(){
	
		jQuery('div.gallery div.protoGalleryItem').each(function() {
			var item = jQuery(this);
			var image = item.children('img');
			var offsetX = Math.round(galleryWidth / 2 - image.width() / 2);
			var offsetY = Math.round((imageHeight - image.height()) / 2);
			markup += "<div class=\"gallerySlide\"><div class=\"galleryItem\" style=\"margin-left:" + offsetX + "px; margin-top:"+ offsetY +"px;\">"+
				"<div class=\"header\"><div></div></div>"+
				"<div class=\"body\">"+
				"	<div class=\"bodyOuter\">"+
				"		<div class=\"bodyInner\">"+
				"			<img src=\"" + image.attr('src') + "\" alt=\""+item.children('h4').html() + "\" />"+
				"			<div class=\"galleryTag\">"+
				"				<h4>"+item.children('h4').html()+"</h4>"+
				"				<p>"+item.children('p').html()+"</p>"+
				"			</div>"+
				"		</div>"+
				"	</div>"+
				"</div>"+
				"<div class=\"footer\"><div></div></div>"+
			"</div></div>";
			item.remove();
		});
		
		jQuery(this).html(markup);
		
	});
	
	jQuery('#galleryRight').click(function() {
		jQuery(this).parent().find('div.galleryItems').animate({
			marginLeft: "-=760"
		}, 500);
	});
	
	jQuery('#galleryLeft').click(function() {
		jQuery(this).parent().find('div.galleryItems').animate({
			marginLeft: "+=760"
		}, 500);
	});
	
	jQuery(document).keydown(function(e) {
		if (e.keyCode == 37) {
			jQuery('div.galleryItems').animate({
				marginLeft: "+=760"
			}, 500);
		}
		
		if (e.keyCode == 39) {
			jQuery('div.galleryItems').animate({
				marginLeft: "-=760"
			}, 500);
		}
	});
	
	jQuery('.highlightFirst li:first-child').css({'font-weight':'bold'});
	
	/*
	jQuery('#mainSlides div.contentArea').click(function() {
		jQuery('#mainSlides').animate({
			marginLeft: -1500
		},750);
	});
	*/
});
