Cufon.replace('h1');
Cufon.replace('h2');
Cufon.replace('.artists span');

$(document).ready(function(){
	CustomCheckbox.init();
	Navi.init();
	Form.init();
	
	if( typeof( ddpngfix ) !== 'undefined' ){
		$( 'img[src$=.png]:not(.opaque),.id_1,.id_2,.id_3,.id_4,.id_5,.id_6,.id_7,.spotify,span.fadebox,.cellphone,.email,.artists p' ).each( function(){
			ddpngfix.fixPng( this );					
		} );			
	}	
	
	if( $('.showerror').length !== false ) {
		setTimeout( function(){$('.showerror').hide();},3000);
	}
	
	if( $('.subscribe-ok').length !== false ) {
		setTimeout( function(){$('.subscribe-ok').hide();},3000);
	}	
	
});

var Form = {
	init: function(){
		$( 'form input[type=text]' ).focus( function(){
			if( this.value == this.defaultValue ){
				this.value = '';								 				
				if($(this).attr('name') == 'cellphone') {
					$('#hint').show();
				}
			}
		} ).blur( function(){
			if( this.value == '' ) {
				this.value = this.defaultValue;
				if($(this).attr('name') == 'cellphone') {
					$('#hint').hide();
				}	
			}
		} );
		$( 'form' ).submit( function(){
			var inputs = $( this ).find( 'input[type=text]' );
			for( i = 0; i < inputs.length; i++ ){
				if( inputs[i].value == inputs[i].defaultValue ){
					inputs[i].value = '';
				}
			}
		 } );
		
		$('#hint').hide();
	}
};
var CustomCheckbox = {
	init:function(){
		$('.fadebox' ).css({opacity:0});
		$('.activespeaker input[type=hidden]').each(function(){
			$(this).data('artistid',$(this).val());
			$(this).val('');
			
			$(this).closest('div').css({cursor:'pointer'}).hover(function(){													  
				var fadebox = $(this).find( '.fadebox' );
				fadebox.stop().animate({opacity:1},200,'linear');
			},function(){	
				var fadebox = $(this).find( '.fadebox' );
				fadebox.stop().animate({opacity:0},200,'linear');				
			} );
			$(this).closest('div').click(function(event){
				$(this).toggleClass('active-customcheckbox');
				var input = $(this).find('input[type=hidden]');
				if($(this).hasClass('active-customcheckbox')){
					$(input).val($(input).data('artistid'));
				}else{
					$(input).val('');
				}
				event.cancelBubble = true;
				event.stopPropagation();
				return false;
			});		
		});
	}		
};
var Navi = {
	init: function(){
		Navi.preparePageChange();
		Navi.preparePageClose();
	},
	preparePageChange: function(){
		$( '.speaker' ).css({cursor:'pointer'}).click( function(){
			Navi.hideStart();		
			Navi.showPage( $( this ).attr( 'className' ).split( ' ' )[0].split( 'id_' ).join( '' ) );
		} );
	},
	preparePageClose: function(){	
		$(".closespeaker").click(function(){
			Navi.hidePage();
			Navi.showStart();
		});			
	},
	
	hideStart: function(){
	  $(".subscribe-form").slideUp("slow");
	  $(".artists,.top-text,.close").fadeOut("slow");			
	},
	showStart: function(){
	  $(".subscribe-form").slideDown("slow");
	  $(".artists,.top-text,.close").fadeIn("slow");	
	},
	showPage: function( id ){
		$( '.page_' + id ).addClass( 'page-visible' ).fadeIn();
	},
	hidePage: function(){
		$( '.page-visible' ).removeClass( 'page-visible' ).fadeOut();
	}
	
}
