// User interface
var HAM = {

    // Init functions         
    init: function(){
		HAM.shContact();
		HAM.shPartyDesc();
		HAM.promoCarrousel();
		HAM.characterCarrousel('.character-list .available-characters ul');
		HAM.characterCarrousel('.character-list .selected-characters ul');
		HAM.faqs();
		HAM.shGuestNumberList();
		HAM.pickGuestNumber();
		$('.reg-form select').selectbox();
    },
	
	// Show hide contact form
	shContact: function(){
		$('.shContact').click(function(){
			if($('#top .twitter-contact').hasClass('opened')){
				$('#top .twitter-contact').slideUp().removeClass('opened');			
				$('.contact select').unselectbox();
			}else{
				$('#top .twitter-contact').slideDown().addClass('opened');						
				$('.contact select').selectbox();
			}
			if(jQuery.browser.webkit)
				$('#top .contact .actions p:last-child').css('bottom','-8px')
			return false;
		})
	},
	
	shPartyDesc: function(){
		$('.party-type-inside a.btn-readmore').each(function(){
			$(this).click(function(){
				if($(this).parents('.party-type-inside').hasClass('opened')){
					$(this).prev().children('.party-desc-inside').slideUp('normal', function(){
						$(this).parents('.party-type-inside').removeClass('opened');				
					});				
				}else{
					$(this).prev().children('.party-desc-inside').slideDown('normal', function(){
						$(this).parents('.party-type-inside').addClass('opened');				
					});
				}
				return false;
			})
		})
	},
	
	
	promoCarrousel: function(group){
		var group = '.slideshow-promo ul';
		$(group).parent().children('.btn-next').click(function(){
			$('.jcarousel-next').trigger('click');
			return false;
		})
		$(group).parent().children('.btn-prev').click(function(){
			$('.jcarousel-prev').trigger('click');
			return false;
		})
		$(group).jcarousel({
			scroll: 1
		});
	},
	
	characterCarrousel: function(group){
		//var group = '.character-list .avaliable-characters ul';


		$(group).parents('.character-list').children('.next').click(function(){
			$(group).parent().next().next().trigger('click');
			return false;
		})
		$(group).parents('.character-list').children('.prev').click(function(){
			$(group).parent().next().trigger('click');
			return false;
		})
		$(group).jcarousel({
			scroll: 6,
			buttonNextCallback:   function(carousel, button, enabled) {
                            if(enabled){
                                        $(group).parents('.character-list').children('.next').removeClass('next-disabled');
                            }else{
                                        $(group).parents('.character-list').children('.next').addClass('next-disabled');
                            }
                            //$('.character-list li:empty').remove();
                        },
                        buttonPrevCallback:   function(carousel, button, enabled) {
                            if(enabled){
                                        $(group).parents('.character-list').children('.prev').removeClass('prev-disabled');
                            }else{
                                        $(group).parents('.character-list').children('.prev').addClass('prev-disabled');
                            }
                            //$('.character-list li:empty').remove();
                        }
		});
	},
	
	faqs: function(){
		var i=1;
		$('.faqs-list dt').each(function(){
			$(this).children().attr('name','faq'+i).attr('href','#faq'+i);
			i++;
		})
		$('.faqs-list dt a').click(function(){
			/*if($(this).parent().hasClass('opened')){
				$(this).focus().parent().removeClass('opened').next().removeClass('opened');						
			}else{*/
			$(this).parents('dl').children('dt').removeClass().next().removeClass();
			$(this).parent().addClass('opened').next().addClass('opened');			
		})
	},
	
	shGuestNumberList: function(){
		if(jQuery.browser.webkit){
			$('.guest-number .pick-number').css('left','104px').css('width','100px');
			$('.guest-number .male .pick-number').css('left','87px');
		}
		
		$('.guest-number span.arrow').each(function(){
			$(this).click(function(){
				if($(this).next().is(':hidden')){
					$(this).next().show();
				}else{
					$(this).next().hide();
				}
			})		
		})
	},
	
	pickGuestNumber: function(){
		$('.pick-number li').click(function(){
			var _val = $(this).text();
			$(this).parent().parent().children('input').val(_val);
			$(this).parent().hide();
			return false;
		})
	}
}

$(document).ready(function() {	
	HAM.init();
});
