jQuery(function() {
	jQuery(document).bind("contextmenu",function(e){
		e.preventDefault();
		alert('The content of this site is protected.');
		return false;
	});
});

function InitGallery() {
	Shadowbox.path = "public/js/shadowbox/";
	Shadowbox.init({
		modal: true,
		initialWidth: 0,
		initialHeight: 1,
		overlayOpacity: 0.9,
		animSequence: "wh",
		displayNav: false,
		skipSetup: true,
		onFinish: function() {
			jQuery(window).resize();
		}
	});

	var winwidth = 720;

	jQuery('.gallery .container .thumItem').click(function() {
		Shadowbox.open({
			content: jQuery(this).find('a').attr('href'),
			width: winwidth,
			height: 635,
			player: ['iframe']
		});
	});
}

function InitPopupGallery(showIndex) {
	jQuery('.closeBtn').click(function() {
		window.parent.Shadowbox.close();
	});

	var viewport = jQuery('.thumbNails .viewport');
	var scroller = jQuery('.thumbNails .viewport .scroller');

	var images = jQuery('.image .viewport img');
	var thumbs = jQuery('.thumbNails .viewport .scroller img');
	var thumbsSep = jQuery('.thumbNails .viewport .scroller .sep');
	var arrowLeft = jQuery('.thumbNails .left .arrow');
	var arrowRight = jQuery('.thumbNails .right .arrow');
	var titles = jQuery('.text .titleContainer .title');

	var maxIndex = thumbs.size() - 4;
	var currentIndex = 0;

	images.not(jQuery(images.get(showIndex))).css('opacity', 0);
	titles.not(jQuery(titles.get(showIndex))).css('opacity', 0);

	scroller.width(151 * thumbs.size() + 15.5 * thumbsSep.size());

	arrowLeft.click(function() {
		currentIndex--;
		if(currentIndex < 0) currentIndex = 0;

		scroller.stop().animate({
			left: -((151 + 15.5) * currentIndex)
		}, 500, 'swing');
	});

	arrowRight.click(function() {
		currentIndex++;
		if(currentIndex > maxIndex) currentIndex = maxIndex;

		scroller.stop().animate({
			left: -((151 + 15.5) * currentIndex)
		}, 500, 'swing');
	});

	thumbs.hover(
		function() {
			jQuery(this).stop().animate({
				opacity: 0.8
			}, 200, 'swing');
		},
		function() {
			jQuery(this).stop().animate({
				opacity: 1
			}, 200, 'swing');
		}
	).click(function() {
		thumbs.not(jQuery(this).addClass('selected')).removeClass('selected');
		var index = thumbs.index(jQuery(this));
		titles.not(jQuery(titles.get(index)).css('opacity', 1)).css('opacity', 0);
		images.not(jQuery(images.get(index)).stop().animate({
			opacity: 1
		}, 750, 'swing')).stop().animate({
			opacity: 0
		}, 750, 'swing');
	});

	jQuery(thumbs.get(showIndex)).click();
}
