// Twitter settings
var twitterUsername = 'DilworthNG'; 	// Your Twitter username
var tweetCount = 4; 	
// How many Tweets to display

$(document).ready(function() {	

    // Get the Twitter feed
    if (twitterUsername) {
        (function() {
            var b = document.createElement('script');
            b.type = 'text/javascript';
            b.src = 'js/twitter.js';
            b.defer = 'defer';
            var t = document.createElement('script');
            t.type = 'text/javascript';
            t.src = 'http://twitter.com/statuses/user_timeline/' + twitterUsername + '.json?callback=twitterCallback2&count=' + tweetCount;
            t.defer = 'defer';
            var h = document.getElementsByTagName('head')[0];
            h.appendChild(b);
            h.appendChild(t);
        })();
    }
    

    /* Apply fancybox to multiple items */
	
    $("a.gallery").fancybox({
        'transitionIn'	:	'elastic',
        'transitionOut'	:	'elastic',
        'speedIn'		:	600, 
        'speedOut'		:	200, 
        'overlayShow'	:	true,
        'hideOnContentClick': true,
        'titlePosition'  : 'inside'
    });
    
    $("a.zoom").fancybox({
        'transitionIn'	:	'elastic',
        'transitionOut'	:	'elastic',
        'speedIn'		:	600, 
        'speedOut'		:	200, 
        'overlayShow'	:	true,
        'hideOnContentClick': true,
        'titlePosition'  : 'inside'
    });
    
    $("#panoram-link").fancybox({
        'transitionIn'	:	'elastic',
        'transitionOut'	:	'elastic',
        'speedIn'		:	600, 
        'speedOut'		:	200, 
        'width': 2000,
        'overlayShow'	:	true,
        'hideOnContentClick': true,
        'titlePosition'  : 'inside'
    });
    
    $("a.fancybox").fancybox({
        'overlayShow'	:	true,
        'hideOnContentClick': true,
    });
    
    $("#partylink").fancybox({
        'scrolling'		: 'no',
        'titleShow'		: false,
        'overlayShow': true,
        'onClosed'		: function() {
            $("#login_error").hide();
        }
    });
    
    $("a.partylink2").fancybox({
        'scrolling'		: 'no',
        'titleShow'		: false,
        'overlayShow': true,
        'onClosed'		: function() {
            $("#login_error").hide();
        }
    });
    
  /*  $("#party").bind("submit", function() {

        if ($("#393").val().length < 1 || $("#394").val().length < 1 || $("#395").val().length < 1 || $("#396").val().length < 1) {
            $("#error").show();
            $.fancybox.resize();
            return false;
        }

        $.fancybox.showActivity();

        $.ajax({
            type		: "POST",
            cache	: false,
            url		: "/form/96",
            data		: $(this).serializeArray(),
            success: function(data) {
                $.fancybox(data);
            }
        });

        return false;
    });*/
    
    $("#newsletterlink").fancybox({
        'scrolling'		: 'no',
        'titleShow'		: false,
        'overlayShow': true,
        'onClosed'		: function() {
            $("#login_error").hide();
        }
    });
	

    

   /* $("#newsletter").bind("submit", function() {

        $.fancybox.showActivity();

        $.ajax({
            type		: "POST",
            cache	: false,
            url		: "/form/98",
            data		: $(this).serializeArray(),
            success: function(data) {
                $.fancybox(data);
				$.fancybox.close();
				
				
            }
        });

        return false;
    });
    */
    $(".facebookFeed").soSoSocial();
    
    (
        function ( $ ) {
            $.fn.panoramah = function ( options ) {

                var settings = {
                    'orientation'  : 'horizontal'
                };

                return this.each(
                    function ( index ) {

                        if ( options ) {
                            $.extend( settings, options );
                        }

                        // Localize the element
                        var photo = $( this );
                        var panorama_details = photo.attr( 'rel' ).split( ':' );
                        // Extract the relevant data from the rel attribute
                        var panorama_size = panorama_details.shift();
                        // Patch together the rest of it (thanks Naina!)
                        var panorama_url = panorama_details.join( ':' );
                        // Get the preloader
                        var img = $( "<img src='' />" );
                        // Setup the onload callback
                        img.load(
                            function () {
                                // Set the background to the image
                                photo.css( 'background', "transparent url( '" + panorama_url + "' ) no-repeat" );
                                // Clear out the loading crap
                                photo.html( "" );
                                // Set up the mouse monitoring
                                photo.mousemove(
                                    function ( event ) {
                                        if( settings.orientation == 'vertical' ) {
                                            // Get the offset
                                            offset = Math.floor( ( panorama_size - photo.height() ) * ( ( event.pageY - photo.offset().top ) / photo.height() ) )
                                            // Mind the overflows
                                            if( offset <= panorama_size - photo.height() ) {
                                                photo.css( 'background-position',  '50% -' + offset + 'px' );
                                            }
                                        }
                                        else {
                                            // Get the offset
                                            offset = Math.floor( ( panorama_size - photo.width() ) * ( ( event.pageX - photo.offset().left ) / photo.width() ) )
                                            // Mind the overflows
                                            if( offset <= panorama_size - photo.width() ) {
                                                photo.css( 'background-position',  '-' + offset + 'px 50%' );
                                            }
                                        }
                                    }
                                    );
                            }
                            );
                        // Start the loading process
                        img.attr( 'src', panorama_url );
                    }
                    );
            }
        }
        )(jQuery);
    
});
