function billboard_go_to(page){
	
	jQuery('.active-billboard-selector').removeClass('active-billboard-selector');
	jQuery('.billboard-selector-'+page).addClass('active-billboard-selector');
	jQuery('.current-monitor-pic').animate({ opacity : 0 }, 500, function(){
		
		jQuery(this).css({ display : 'none' }).removeClass('current-monitor-pic');
		
		jQuery('#left-monitor-screen').find('a:eq('+page+')').css({ display : 'block' }).animate( {opacity : 1}, 500, function(){
			jQuery(this).addClass('current-monitor-pic');
		});
		jQuery('#center-monitor-screen').find('a:eq('+page+')').css({ display : 'block' }).animate( {opacity : 1}, 500, function(){
			jQuery(this).addClass('current-monitor-pic');
		});
		jQuery('#right-monitor-screen').find('a:eq('+page+')').css({ display : 'block' }).animate( {opacity : 1}, 500, function(){
			jQuery(this).addClass('current-monitor-pic');
		});
		
	});
	
}

function preloading_images(){
	
	jQuery('img.with-loader').each(function(i, event){
	
		jQuery(this).parent('a').addClass('preloading');
		
		jQuery(this).load(function(){
			jQuery(this).parent('a').removeClass('preloading');
			jQuery(this).removeClass('with-loader').css({ display : 'block', opacity : 1});
		});
		
		if(event.complete == true){
			jQuery(this).parent('a').removeClass('preloading');
			jQuery(this).removeClass('with-loader').css({ display : 'block', opacity : 1});
		}
		
	});
}

jQuery(document).ready(function() {
	
	preloading_images();
	
	jQuery('ul.sf-menu').superfish({
		animation: {opacity:'show',height:'show'},
		autoArrows : false,
		speed: 'fast',
		delay: 100
	});
	
	jQuery('ul.sf-menu li').has('ul').addClass('sf-menu-contains-sub');
	jQuery('ul.sf-menu li ul li').has('ul').addClass('sf-menu-contains-sub');
	
	jQuery('#s').click(function(){
		if(jQuery(this).val() == 'Search'){
			jQuery(this).val('');
		}
	});
	
	jQuery('#s').blur(function(){
		if(jQuery(this).val() == ''){
			jQuery(this).val('Search');
		}
	});
	
	jQuery('#thickbox-mask').css({ 'width' : jQuery(window).width(), 'height' : jQuery(document).height() });
	
	jQuery(".scrollable").scrollable();
	
	jQuery('#thickbox-content .close').live('click', function(){
		jQuery('#thickbox-content, #thickbox-mask').fadeOut(500);
	});
	
	var billboard_num_el = jQuery('#left-monitor-screen a').size();
	var billboard_nav_html = '';
	
	var i=0;
	for (i=0;i<billboard_num_el;i++){
		billboard_nav_html += '<a href="#" title="'+i+'" class="billboard-selector billboard-selector-'+i+'"></a> ';
	}
	
	jQuery('#billboard-navigation').html(billboard_nav_html);
	jQuery('#billboard-navigation a:first').addClass('active-billboard-selector');
	
	jQuery('#left-monitor-screen a:first, #center-monitor-screen a:first, #right-monitor-screen a:first').addClass('current-monitor-pic').css({display : 'block', opacity : 1});
	
	var billboard_el_width = 21;
	jQuery('#billboard-navigation').width(billboard_el_width * billboard_num_el);

	jQuery('.centered').each(function(){
		
		var parent_width = jQuery(this).parent().outerWidth();
		var this_width = jQuery(this).outerWidth();
		var this_offset = (parent_width - this_width)/2;
		jQuery(this).css({ 'left' : this_offset });
		
	});
	
	jQuery('.scrollable .items a').live('click', function(e){
		e.preventDefault();
		var the_image = jQuery(this).find('img').attr('longdesc');
		jQuery('#thickbox-big-image').addClass('with-loader').attr('src', the_image);
		preloading_images();
	});
	
	var billboard_pagination_id;
	jQuery('.billboard-selector').live('click', function(e){
		e.preventDefault();
		billboard_pagination_id = jQuery(this).attr('title');
		billboard_go_to(billboard_pagination_id);
	});
	
	jQuery('#comment-submit').live('click', function(e){
		e.preventDefault();
		jQuery('#leave-response #submit').click();
	});
	
});