﻿jQuery.noConflict();
var timer = 0;
var inMotion = 0;
var offset = 958;
var max_offset = 0;
var timeToSlide = 8000;
jQuery(function($) {
/*
	$('div.slides').each(function(i) {
		$('ul.leftMenu').append('<li><a href="#' + eval(i + 1) + '">' + eval(i + 1) + '</a></li>');
	});
*/
	if($('div.slides').length < 2) {
		$('div#goleft, div#goright, ul.leftMenu').remove();
	} else {
		max_offset = (958 * $('.slides').length) - (offset * 2);
		$('.image_slider').css({'left': '0px', 'width': (958 * $('.slides').length) + 'px'});
		setInterval('animateSlider()', timeToSlide);
	}

	if($('a.imagePopup').length > 0) {
		$('a.imagePopup').each(function() {
			$('<img>').attr('src', $(this).attr('href'));
		});
	}
	$('a.imagePopup').click(function() {
		$.modal('<img src="' + $(this).attr('href') + '" border="0" />', {
			onOpen: function(dialog) {
				dialog.overlay.show();
				dialog.overlay.click(function() { $.modal.close(); });
				dialog.container.css({ 'height': '100px', 'width': '100px', 'overflow': 'hidden'});
				dialog.container.show(function() {
					dialog.data.show(function() {
						var left = ($(window).width() - $('img', this).width()) / 2;
						var top = ($(window).height() - $('img', this).height()) / 2;
						dialog.container.css({'height': $('img', this).height() + 'px', 'width': $('img', this).width() + 'px', 'top': top + 'px', 'left': left  + 'px'});
					});
				});
			}
		});
		return false;
	});

	$(document).bind('keydown.simplemodal', function (e) {
		if (e.keyCode == 27) { // ESC
			$.modal.close();
		}
	});

});
function animateSlider() {
	var current_offset = jQuery('.image_slider').css('left').replace('px','').replace('-', '');
	var slideto = Number(current_offset) + Number(offset);
	if(slideto <= max_offset) {
		jQuery('.image_slider').animate({'left': '-' + slideto + 'px'}, 2000);
	} else {
		jQuery('.image_slider').animate({'left': '-' + slideto + 'px'}, 2000, function() {
			jQuery(this).css('left','0px');
		});
	}
}
