
var Site = {
	init: function() {
		$('#header a').click(Site.area.menu.click);
		Site.area.colecao.resize();

		$('.colecao-navigation-prev').click(Site.area.colecao.navigationPrev);
		$('.colecao-navigation-next').click(Site.area.colecao.navigationNext);
		
		$('.colecao,.makingof').each(function() {
			$(this).find('a[href$=".jpg"]').lightBox({
				fixedNavigation:true,
				maxWidth: 800,
				maxHeight: 800
			});
		});
		
		$('.banner,.content-index .texto').click(function() {
			$('.menu-colecao').trigger('click');
			return false;
		})
		
		$('.menu-colecao-li').find('ul').css('opacity',0);
		$('.menu-colecao-li').mouseenter(function() {
			$(this).find('ul').css('display','block').stop().animate({
				opacity: 1
			},300,function() {
				
			})
		})
		$('.menu-colecao-li').mouseleave(function() {
			$(this).find('ul').stop().animate({
				opacity: 0
			},100,function() {
				$(this).css('display','none')
			})
		})
		
		$('html,body').stop().animate({
			scrollTop: 0
		},1);
		
		$('.colecao-image div').css('opacity',0);
		$('.colecao-image').mouseenter(function() {
			$(this).find('div').stop().animate({
				opacity: 1
			},300)
		})
		$('.colecao-image').mouseleave(function() {
			$(this).find('div').stop().animate({
				opacity: 0
			},300)
		})
		
		$('.makingof div').mouseenter(function() {
			$(this).find('span').css('height',$(this).find('img').height()-10)
		})
		$('.makingof div').mouseleave(function() {
			$(this).find('span').css('height','auto')
		})
	},
	layout: {
		moveTo: function(top) {
			$('html,body').stop().animate({
				scrollTop: top
			},800)
		},
		resize: function() {
			
		}
	},
	area: {
		menu: {
			click: function() {
				var analytics = '/' + $(this).attr('rel').replace('content-','').replace('colecao-','colecao/').replace('index','');
				if (typeof _gaq != 'undefined') {
					_gaq.push(['_trackPageview', analytics]);
				}
				
				var elemento = $('.' + $(this).attr('rel'));

				
				if ($(this).attr('rel') == 'colecao-4' || $(this).attr('rel') == 'colecao-5') {
					$('html,body').scrollTop(0);
					$('.content-area').hide();
					$('.colecao-main').css('marginTop',20).css('marginBottom',20).hide();
					$('.content-colecao').show();
					$(elemento).show();
					return false;
				} else {
					if ($('.colecao-4').css('display') == 'block' || $('.colecao-5').css('display') == 'block') {
						$('html,body').scrollTop(0);
					}
					$('.colecao-main').css('marginTop',100).css('marginBottom',20).show();
					$('.colecao-4,.colecao-5').hide();
					$('.content-area').show();
				}

				if ($(this).attr('rel') == 'content-catalogo') {
					return;
				} else if ($(this).attr('rel') == 'content-index') {
					Site.layout.moveTo(0);
				} else if ($(this).attr('rel') == 'content-marca') {
					Site.layout.moveTo($(elemento).position().top+230);
				} else if ($(this).attr('rel') == 'content-contato') {
					Site.layout.moveTo($(elemento).position().top+20);
				} else {
					Site.layout.moveTo($(elemento).position().top-10);
				}
				
				
				return false;
			}
		},
		colecao: {
			resize: function() {
				$('.colecao-body').each(function() {
					$(this).css('width',Math.ceil($(this).find('.colecao-image').length / 8) * 920);
				});
			},
			navigationPrev: function() {
				var colecao = $(this).closest('.colecao-main');
				var colecaoBody = $(colecao).find('.colecao-body');
				var total = Math.ceil($(colecao).find('.colecao-image').length / 8);

				if ($(colecao).attr('rel') == '') {
					$(colecao).attr('rel','0');
				}

				var current = parseInt($(colecao).attr('rel'));
				
				if (current > 0) {
					current--;
					$(colecao).attr('rel',current);
				} else {
					return false;
				}
				
				$(colecaoBody).animate({
					left:(-920*current)
				},1000)
			},
			navigationNext: function() {
				var colecao = $(this).closest('.colecao-main');
				var colecaoBody = $(colecao).find('.colecao-body');
				var total = Math.ceil($(colecao).find('.colecao-image').length / 8);

				if ($(colecao).attr('rel') == '') {
					$(colecao).attr('rel','0');
				}
				
				var current = parseInt($(colecao).attr('rel'));

				if ((current+1) < total) {
					current++;
					$(colecao).attr('rel',current);
				} else {
					return false;
				}
				
				$(colecaoBody).animate({
					left:(-920*current)
				},1000)
			}
		}
	}
};

$(document).ready(Site.init);

















