function activeTooltip(){	
	$('a.active').each(function(){
		centerVal = ($(this).parent().find('.tooltip').width())/2;
		$(this).parent().find('.tooltip').show().css('margin-left', '-'+centerVal+'px');
	});
}

function switchImage(parentul, callback) {
	parentul.closest('li').find('img.full').attr('src', newImagePath);
	callback();
}

function showLoading() {
  $("img#loading").show();
}

function hideLoading() {
  $("img#loading").hide();
}


function loadImage(img_wrap, lrgimage_src){
  var img = new Image();

  $(img).load(function () {
      // set the image hidden by default    
      $(this).hide();
      img_wrap.html(this);
	  $('img.loading').fadeOut();
      $(this).fadeIn();
    }).attr('src', lrgimage_src);
}

$(document).ready(function(){
	$('#navmask_arrow, #navcolor').css({'opacity': '0'});
	$('.newtab').attr('target', '_blank');
	
	$("ul.thumbs a").click(function(){
		$(this).prepend('<img class="loading" src="images/loader-refresh.gif" />');
		newImagePath = $(this).attr('href');
		parentul = $(this).closest('ul');
		parentul.find('a.active').removeClass('active');
		$(this).addClass('active');
		img_wrap = parentul.closest('li').find('.web_img_wrap');
	  	loadImage(img_wrap, newImagePath)		
		return false;
	});
	
	$("ul.thumbs img").mouseover(function(){
		parentUL = $(this).parent().parent();
		centerVal = (parentUL.find('.tooltip').width())/2;

		parentUL.parent().find('.tooltip').hide();
		parentUL.find('.tooltip').fadeIn(150).css('margin-left', '-'+centerVal+'px');
	});
	
	$("ul.thumbs").mouseleave(function(){
		$(this).find('.tooltip').fadeOut(150);
	});
	

});

//Initialize after all images are loaded
$(window).load(function() {
		
		//Animate Arrow
		$('#navmask_arrow').animate({'top':'+=215', 'opacity':'1'}, 700);
		setTimeout(function(){
			$('#navcolor').animate({'top':'-=615', 'opacity':'1'}, 700);
		}, 350);

		//Set gradient div to page height
		pageHeight = $('#content').height();
		$('#navcolor').css('height', pageHeight);

	});

