/* -----------------------------------------------
BASE
----------------------------------------------- */


$(function() {
	Setup.init();
});

/*	Setup
----------------------------------------------- */
var IsTouch = false;
var WinW = null;
var WinH = null;
var ImgW = 1600;
var ImgH = 1200;

var Setup = {	
	Body: null,
	init: function() {
		var cc = this;
		cc.Body = $("body");
		
		if(cc.Body.hasClass('home')) {
			Home.init();
		}
		else if(cc.Body.hasClass('gallery')) {
		//	Gallery.init();
		}

	},
	render: function() {
		var cc = this;
	}
};

var Home = {
	Content: null,
	Wpr: null,
	init: function() {
		var cc = this;
		cc.Content = $('#Content')
		cc.Wpr = $('#Content .wpr')
		cc.render();
		if(!IsTouch) {
			$(window).resize(function(){
				cc.render();
			});
		}
	},
	render: function() {
		var cc = this;
		if($(window).width()!=WinW||$(window).height()!=WinH) {
			WinW = $(window).width();
			WinH = $(window).height();

			if ((WinW / WinH) > (ImgW / ImgH)) {
				var newHeight = Math.round((WinW / ImgW) * ImgH);
				var newWidth = WinW;
			} else {
				var newHeight = WinH;
				var newWidth = (WinH / ImgH) * ImgW;
			}	
			newTop = 0 - Math.round((newHeight - WinH) / 2);
			newLeft =  0 - ((newWidth - WinW) / 2);	
			cc.Content.css({height: WinH -135, width: WinW});
			cc.Wpr.css({width: newWidth, height: newHeight, top: newTop, left: newLeft});
		}
	}
};

var Gallery = {
	Images: null,
	init: function() {
		var cc = this;
		cc.Images = $('#Content li img');
		$("a[rel=overlay]").fancybox({
			'overlayShow'	: false,
			'titlePosition' : 'inside'
		});
		cc.events();
	},
	events: function() {
		var cc = this;
		
		cc.Images.bind('mouseenter', function(){
			cc.Images.stop();
			$(this).css('opacity', 1);
			cc.Images.not($(this)).css('opacity', .3);
		});
		$('#Content').bind('mouseleave', function(){
			cc.Images.fadeTo(1000, 1);
		});
	}
};
