var img_count_c = 0;
var index_c = 0;

function renderCatalog(num, width, height)
	{
	var cutAImg = $('.photo-lightbox').eq(num);
	var cutImg = cutAImg.find('img');
	var cutImgBig = cutAImg.attr('href');

	var title = cutImg.attr('title');
	var text = cutImg.attr('text');

	var h = $(window).height();
	var tY = (((h*1)/2) - ((height*1)/2))-100;

	$('.winshade').css('width',width).css('margin-left', '-'+(width/2)+'px').css('height', height*1+20).css('top', tY);
	
	var aY = (((height*1)/2) - ($('.winshade a.left').height()*1)/2);
	$('.winshade a.left').css('top',aY);
	$('.winshade a.right').css('top',aY);

	$('.shade .win-cont').css('background', 'url('+cutImgBig+')').css('height', height);
	$('.shade .info').css('top', height*1+50);
	$('.shade .info .title').html(title);
	$('.shade .info p').html(text);

	Cufon.replace('.shade .info .title', {fontFamily: 'Myriad Pro'});
	}

$(document).ready(function(){
	img_count_c = $('.photo-lightbox').length;

	$('.shade').click(function(){
		$(this).hide();
		return false;
	});

	if (img_count_c>1)
		{
		$('.shade').find('a.left').removeClass('disabled');
		$('.shade').find('a.right').removeClass('disabled');
		}

	var imgs = new Array();
	$('.photo-lightbox').each(function(num){
	
		var img = $(this);
		img.unbind('click');
		img.attr('onclick','');
		img.attr('target','');

		var tmp = new Image;
		tmp.onload = function(){
			var z = $('.photo-lightbox').eq(num); 
			z.attr('xwidth',this.width).attr('xheight', this.height);
			}
		tmp.src = img.attr('href');



		img.click(function(){

			index_c = num;

			location='#top';
			
			
			renderCatalog(num, $(this).attr('xwidth'), $(this).attr('xheight'));

			$('.shade .win-cont').unbind('click').click(function(){
				index_c++;
				if (index_c>img_count_c-1) index_c=0;								
				renderCatalog(index_c, $('.photo-lightbox').eq(index_c).attr('xwidth'), $('.photo-lightbox').eq(index_c).attr('xheight'));
				return false;		
			});

			$('.shade a.left').unbind('click').click(function(){
				index_c--;
				if (index_c<0) index_c = img_count_c-1;								
				renderCatalog(index_c, $('.photo-lightbox').eq(index_c).attr('xwidth'), $('.photo-lightbox').eq(index_c).attr('xheight'));
				return false;
				});

			$('.shade a.right').unbind('click').click(function(){
				index_c++;
				if (index_c>img_count_c-1) index_c=0;								
				renderCatalog(index_c, $('.photo-lightbox').eq(index_c).attr('xwidth'), $('.photo-lightbox').eq(index_c).attr('xheight'));
				return false;
				});

			var h = $(document).height();

			var shade = $('.shade');
			shade.height(h);
			shade.show();

			return false;
		})

	});
});
