
var enlarger = new function()
    {     
	var current_image;
	var interval;
	var enlarged;
	var fade;
	var active;
	var self = this;
	
	
	this.resize = function()
	{
	    if(self.active == true)
		{
		    var width = self.current_image.width;
		    var height = self.current_image.height;
		    self.enlarged.css({
			    'left': ($('body').width() - width) / 2,
				'top': ($('body').height() - height) / 2});				
		    //  $('.enlarger_fade').css({'height': '100%', 'width': '100%'});
		}
	};
	
	this.load_image_complete = function()
	{
	    self.active = true;    
	    $('body').css({'overflow':'hidden'});
	    self.resize();
	    self.fade.css({'display':'block'});
	    self.fade.fadeTo("fast", 0.6);
	    self.enlarged.attr('src', self.current_image.src).fadeIn("fast");				
	};
	
	this.load_image = function()
	{
	    self.interval = setInterval("enlarger.watch_load()", 100);
	};
	
	this.watch_load = function()
	{
	    if(self.current_image.complete)
		{		
		    clearInterval(self.interval);
		    self.load_image_complete();
		}	    
	};

	
	this.init = function()
	{
	    $(window).resize(function(){ self.resize(); });
	    self.active = false;
	    self.enlarged = $('<img/>')
	    .addClass('enlarged').hide().appendTo('body');

	    self.fade = $('<div/>')
	    .addClass('enlarger_fade').appendTo('body')
	    .css({'left': 0, 'top': 0, 'display':'none'});
	    //.fadeTo("fast", 0);

	    var target = '#gigs img';

	    $(target).css('cursor', 'pointer').bind('click', function(e){
		    e.preventDefault();
		    $this = $(this);
		    var src = $this.attr('src');
		    src = src.replace(/tn_/, 'mid_');

		    self.current_image = new Image();
		    self.current_image.src = src;
		    self.load_image();		    		  
		});

	    

	    $('.enlarged').css('cursor', 'pointer').bind('click', function(e){
		    $this = $(this);
		    self.fade.fadeOut("fast");
		    $this.fadeOut("fast");
		    self.active = false;
		    $('body').css({'overflow':'auto'});
		});
	};
    };


var list = function()
{
    $('#list input').bind('focus', function(){


	    var $this = $(this);
	    $this.val('');

	});
};








var start = function()
{
    $('#target').hide();
    $('#page').fadeIn('slow');

};

var loadContent = function(data, txt, req)
{
    $('#content #inner').empty().append(data);
    $('#content').fadeIn('slow', initContent);		

};

var initContent = function()
{
    if($('#gigs').length > 0)
	{
	    enlarger.init();
	}
    else
	{
	    $('a[href^="http://www.youtube.com"]').flash(
            { width: 400, height: 302 },
            { version: 8 },
	    function(htmlOptions) {
		$this = $(this);
		var parent = $this.parent();
		htmlOptions.src = $this.attr('href');
		parent.empty();
		parent.append($.fn.flash.transform(htmlOptions));
	    });
	}
};



$(document).ready(function(){

		
	/* old
	$('#target').bind('mouseover', function(){		
		$('#header').fadeOut('slow', start);
	    });
	*/
	

	$('#header img').css('cursor', 'pointer')
	    .bind('click', function(){		
		    $('#header').fadeOut('slow', start);
		});
	
	

	
	$('#page a').bind('click', function(){		
		var $this = $(this);
		var url = $this.attr('href');
		jQuery.get(url, null, loadContent);				
		return false;			
	
	    });
	

	$('#content #top span a').bind('click', function(){
		//$('#content').fadeOut('slow');
		$('#content').hide();
	    });

	list();

    });



