/**
 * Arquivo responsável pelo JS geral do Site Club Silêncio
 *
 * @author: Daniel Lopes danielmlopes[at]gmail[dot]com
 * @date: 2010/03/01
 *
 * Copyright(c) Todos os direitos reservados a Club Silêncio
 */

if (window.console == null) window.console = { log: function(p) { } };

var self;

var Actions = function()
{
	self = this;
	this.init();
}

Actions.fn = Actions.prototype;
Actions.fn.extend = jQuery.extend;
Actions.fn.extend(
{
    init: function()
	{
	    this.header = $( "#header" );
	    this.content = $( "#content" );
		
	    self.fontReplace();
		
		if( $( "#content div.sidebar" ).length )
			self.accordion();
		
		self.common();
		
		if( $( "#content.photos ul li" ).length )
			$('#content.photos ul li a').lightBox();
	},
	
	// Fonte Replace
    fontReplace: function()
	{
		Cufon.replace($( ".cufonReplace, #header ul li a, #content h2.subTitle, #content div.sidebar div.searchForm label, #content div.sidebar div.archives h3" ), {fontFamily:'Futura Lt BT'});
    },
	
    // Accordion Arquivos
    accordion: function()
	{
        var h4s = $( "div.sidebar div.archives ul li h4", self.content );

        h4s.unbind().click(function()
		{
            var actual = $(this).parent(),
				content = $( "ul", actual ),
				parent = actual.siblings( ".active" );

            content.slideToggle("fast");

            actual
				.toggleClass( "active" )
				.siblings( ".active" )
					.removeClass( "active" )
					.find( "ul" ).slideUp( "fast" );
        });
    },
	
	openImageBox: function(div)
	{
        jQuery.ImageBox.init(
		{
		    loaderSRC: '../_global/img/gr/ajax-loader.gif',
		    closeHTML: 'Fechar X'
		});
    },
	
	// Funções comuns para as páginas
	common: function()
	{
		// Verificação de largura da capa dos discos
		if( $( "#content.discs ul li div.img" ).length && $.browser.msie && $.browser.version == "6.0" )
		{
			$( "#content.discs ul li div.img" ).each( function()
			{
				var $this = $(this);
				
				if( $this.width() > 168 )
					$this.width( 168 );
			});
		}
		
		// Abrir hotsite - Disco
		if( $( "#content.discs ul li .bt_openSite" ).length )
		{
			var bts = $( "#content.discs ul li .bt_openSite" );
			
			bts.click( function()
			{
				var $this = $(this),
					dimensions = $this.siblings( 'input.dimensionsPage' ).val();
					url = this.href;
				
				window.open( url , '', 'toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,' + dimensions );

				return false;
			});
		}
		
		// Página de Fotos
		if( $( "#content.photos" ).length )
		{
			var lis = $( "#content.photos ul li" );
			
			lis.each( function(i)
			{
				var $this = $(this);
				
				if( ( i + 1 ) % 8 == 0 )
					$this.addClass( "noMarginRight" );
			});
			
			lis.hover(function()
			{
				$(this).addClass( "hover" )
			},function()
			{
				$(this).removeClass( "hover" )
			});
		}
		
		// Adiciona class para retirar bordas nas últimas LIs
		$( "#content.discs ul li:last, #content.press ul li:last" ).addClass( "noBorder noMarginBottom" );
	}
});

var actions;

$(function() {
	actions = new Actions();
});
