$(function(){
    /*$('.movies').cycle(
    {
        timeout:  0,
        prev:    '#prev',
        next:    '#next',
        cleartypeNoBg: true
    });*/
	/*
    $.address.init(function(event) {

        // Initializes plugin support for links
    	$('.address').address();
        		
    }).change(function(event)
    {
    	$('#content > div').hide();
    	$('#content').prepend('<div class="loader"></div>');
    	$('html, body').animate({scrollTop:0}, 'slow');
    	
    	var page = event.parameters.page ? '/?page=' + event.parameters.page : event.path;
    	
        // Highlights the selected link
        $('.navigation a').each(function() {
            if ($(this).attr('href') == (page == '/' ? '#' : '#!' + page)) {
                $(this).parent().addClass('active').focus();
            } else {
                $(this).parent().removeClass('active');
            }
        });

        var handler = function(data) {
            $('#content').html($('#content', data).html()).parent().show();
            $.address.title(/>([^<]*)<\/title/.exec(data)[1]);
        };

        // Loads the page content and inserts it into the content area
        $.ajax({
            url: event.value,
            error: function(XMLHttpRequest, textStatus, errorThrown) {
                handler(XMLHttpRequest.responseText);
                $('#content > div').show();
                $('.address').address();
            },
            success: function(data, textStatus, XMLHttpRequest) {
                handler(data);
                $('#content > div').show();
                $('.address').address();
            }
        });
        
    });
    */
	/*
    $('a[href$=\'.jpg\']').live('click',function(event){
        $.fancybox({
    		'href'			: this.href
    	});
        event.preventDefault();
    });
    */
    $('a.album').fancybox();
    
    $('.party-click').live('click',function(event)
	{
    	event.preventDefault();
    	$.post('/party/read',
    		{party_id: this.id},
    		function(data)
    		{
    			window.location.reload();
    		},
    		'json'
    	)
	});
    
    $('.logo-container a, a#menu-8').live('click',function(event)
	{
    	event.preventDefault();
    	$.post('/party/read',
    		{party_id: 'party-10'},
    		function(data)
    		{
    			window.location = '/';
    		},
    		'json'
    	)
	});

    $('.party-selector ul').bxSlider({
        displaySlideQty: 4,
        moveSlideQty: 3,
        auto: true,
        autoHover: true,
        controlse: false,
        prevSelector: '.prev',
        nextSelector: '.next'
      });
    
    /*
    $('.party-selector ul').jcarousel({
    	auto: 2,
    	wrap: 'circular',
    	initCallback: mycarousel_initCallback,
        buttonNextHTML: null,
        buttonPrevHTML: null
    });
    */
    $(".movie a").live('click', function(event) {
		event.preventDefault();
		$.fancybox({
			'padding'		: 0,
			'autoScale'		: false,
			'transitionIn'	: 'none',
			'transitionOut'	: 'none',
			'title'			: this.title,
			'width'			: 640,
			'height'		: 385,
			'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
			'type'			: 'swf',
			'swf'			: {
			'wmode'				: 'transparent',
			'allowfullscreen'	: 'true'
			}
		});
	});

});

$(document).ajaxStop(function()
{
	$(".movie a").click(function() {
		event.preventDefault();
		$.fancybox({
			'padding'		: 0,
			'autoScale'		: false,
			'transitionIn'	: 'none',
			'transitionOut'	: 'none',
			'title'			: this.title,
			'width'			: 640,
			'height'		: 385,
			'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
			'type'			: 'swf',
			'swf'			: {
			'wmode'				: 'transparent',
			'allowfullscreen'	: 'true'
			}
		});
	});
});

function mycarousel_initCallback(carousel) {

    $('.party-selector .next').bind('click', function() {
        carousel.next();
        return false;
    });

    $('.party-selector .prev').bind('click', function() {
        carousel.prev();
        return false;
    });
    
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};
