var insideClick = false;

$(window).load(function(){
	resize();
});

$(window).resize(function(){
	resize();
});

function resize(){
	
	$('#main').css('min-height', '415px');
	
	var htmlWidth   = $('html')  .width();
	var htmlHeight  = $('html')  .height();
	var frameHeight = $('#frame').height();
	
	if(htmlHeight > frameHeight) $('#main').css('min-height', ($('#main').height() + htmlHeight - frameHeight - 40) + 'px');
	
	var slideshowWidth  = htmlWidth  * .8;
	var slideshowHeight = htmlHeight * .8;
	if(((slideshowWidth  / 4) * 3) > slideshowHeight) slideshowWidth  = ((slideshowHeight / 3) * 4);
	if(((slideshowHeight / 3) * 4) > slideshowWidth)  slideshowHeight = ((slideshowWidth  / 4) * 3);
	
	if(slideshowWidth > 760){
		slideshowWidth  = 760;
		slideshowHeight = 580;
	}
	
	$('#overlay div')    .css('width',      (slideshowWidth  + 10)             + 'px');
	$('#overlay div')    .css('height',     (slideshowHeight + 50)             + 'px');
	$('#overlay div')    .css('margin-top', '-' + ((slideshowHeight / 2) + 25) + 'px');
	$('#overlay div div').css('width',      slideshowWidth                     + 'px');
	$('#overlay div div').css('height',     slideshowHeight                    + 'px');
	$('#overlay div div').css('margin-top', 0                                  + 'px');
	
}

function initSubItems(sId){
	
	$('#ul_index li a').each(function(){
		
		$(this).click(function(){
			
			oLink = $(this);
			
			$('#ul_index li a').each(function(){
				$(this).closest('li').removeClass('active');
			});
			$(this).closest('li').addClass('active');
			
			$('#div_sub_item').fadeTo('fast', 0.01, function(){
				$(this).load(oLink.attr('href') + '?random=' + Math.floor(Math.random() * 10001), function(){
					$(this).fadeTo('slow', 1, function(){
						var sContent = $(this).html();
						$(this).after ('<div id="div_sub_item_2">' + sContent + '</div>');
						$(this).remove();
						$('#div_sub_item_2').attr('id', 'div_sub_item');
						$('#div_sub_item_2').html(sContent);
					});
				});
			});
			
			return false;
			
		});
		
	});
	
}

function initSlideshow(){
	
	$('ul.slideshow a').each(function(){
		
		$(this).click(function(){
			
			oLink = $(this);
			
			$('#overlay').fadeIn('fast', function(){
				changeSlideshow(oLink.attr('href'), oLink.attr('title'));
				$('#overlay div').fadeIn('fast');
			});
			
			return false;
			
		});
		
	});
	
}

function closeSlideshow(oObject){
	
	$('#overlay').fadeOut('fast', function(){
		$('#overlay div').hide();
	});
	
}

function changeSlideshow(sUrl, sTitle){
	
	$('#overlay div img').fadeOut('fast', function(){
		$(this).attr('src', sUrl);
		$(this).attr('alt', sTitle);
		$(this).fadeIn('slow');
	});
	
}
