(function($) {
	$.fn.alternateViewsProgress = function(options) {
		var opts = $.extend({}, $.fn.alternateViewsProgress.defaults, options);
		this.show();
		$("#" + opts.currentPageId).html(opts.pageNumber);
		$("#" + opts.totalPagesId).html(opts.pageCount);
		return this;
	};

	// pager defaults. hardly worth bothering with in this case but used as placeholder for expansion in the next version
	$.fn.alternateViewsProgress.defaults = {
		pageNumber: 1,
		pageCount: 1,
		currentPageId: null,
		totalPagesId: null
	};

})(jQuery);

(function($) {
	$.fn.chartTipster = function(options) {

		var opts = $.extend({}, $.fn.chartTipster.defaults, options);
		var map = $("map[name=" + this.attr("usemap").replace("#", "") + "]");
		var ul = $("<ul class=\"chartTipster\"><li><div class=\"content\"><div class=\"imageContainer\"></div></div></li></ul>");
		var chart = this.clone(true);
		ul.insertAfter(this);
		ul.find("div[class=imageContainer]").append(chart);

		var tips = new Array();
		map.children("area").each(function(i, de) {
			var coords = $(this).attr("coords").split(",", 4);
			var left = parseInt(coords[2]);
			var top = parseInt(coords[3]);
			var url = $(this).attr("href");
			var lotId = parseInt($(this).attr("title"));
			var descr = null;
			if (typeof (options.getContent) != "undefined") {
				descr = options.getContent(lotId);
			}
			var tip = null;
			if (descr != null) {
				tip = $("<span></span>").html(descr);
				if (typeof ($.preload) != "undefined") {
					tip.find("img").preload();
				}
			}
			var tipContainer = $("<div style='width:14px;height:12px;margin-left:-10px;margin-top:-12px;' class='marker'></div>").attr("class", "marker").attr("title", left + "," + top);
			var image = $("<img style='width:100%;height:100%;' />").css("opacity", 0);
			tipContainer.append(image);
			if (tip != null) {
				tipContainer.append(tip);
			}
//			image.load(function() {
//				var markerContainer = $(this).parents("div[class=marker]:first");
//				$.fn.chartTipster.correctBounds(markerContainer, $(this).parents("div[class=content]"), opts.marginLeft, opts.marginRight, opts.marginTop, opts.marginBottom);
//			});
			var separator = url.indexOf("?") >= 0 ? "&" : "?";
			//image.attr("src", url + separator + "rnd=" + (new Date()).getMilliseconds());
			ul.find("div[class=content]").append(tipContainer);
			tips.push(tipContainer);
		});

		chart.removeAttr("usemap");
		this.remove();
		map.remove();
		return ul.jTipster(options);

	};

})(jQuery);

function centerPopup(elementId) {
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#" + elementId).height();
	var popupWidth = $("#" + elementId).width();
	var scrollTop = $(document).scrollTop();
	//centering
	$("#" + elementId).css({
		"position": "absolute",
		"top": scrollTop + windowHeight / 2 - popupHeight / 2,
		"left": windowWidth / 2 - popupWidth / 2
	}).show();
}

//function openPopupToTheRight(elementId, leftElementId) {
//	var l = $("#" + leftElementId);
//	var leftElementPosition = l.position();
//	var leftWidth = l.width();
//	var leftHeight = l.height();

//	var paddingLeft = -20;
//	var paddingTop = 10;
//	var el = $("#" + elementId);
//	var elHeight = el.height();
//	var finalTop = leftElementPosition.top - (elHeight - leftHeight) + paddingTop;
//	var finalLeft = leftElementPosition.left + leftWidth + paddingLeft;
//	el.css({
//		"position": "absolute",
//		"top": finalTop,
//		"left": finalLeft
//	}).show();

//}

//var enlargedPhotos = new Array()
var photos = new Array()
var photoslink = new Array()
var which = 1

//Specify whether images should be linked or not (1=linked)var linkornot = 0
//Set corresponding URLs for above images. Define ONLY if variable linkornot equals "1"if (photoslink == 0)	for (var i = 0; i < photos.length; i++)		photoslink[i] = "";


//do NOT edit pass this linevar preloadedimages = new Array()var preloadedEnlargedimages = new Array()for (i = 0; i < photos.length; i++) {	preloadedimages[i] = new Image()	preloadedimages[i].src = photos[i]	preloadedEnlargedimages[i] = new Image();	preloadedEnlargedimages[i].src = enlargedPhotos[i];}
function keeptrack() {	window.status = "Image " + (which + 1) + " of " + photos.length}

function changeEnlargeLink() {	var lnk = document.getElementById("enlargeLink2");	if (lnk)		lnk.href = enlargedPhotos[which];}
function backward() {	if (which > 0) {		which--		document.images.photoslider.src = photos[which]		keeptrack()		changeEnlargeLink();	}}
function forward() {	if (which < photos.length - 1) {		which++		document.images.photoslider.src = photos[which]		keeptrack()		changeEnlargeLink();	}}

function transport() {
    window.location = photoslink[which]
}

function changeMainImage() {
    var mainImg = document.getElementById("imgMain");
    var mainLnk = document.getElementById("lnkMain");
    if (mainImg)
        mainImg.setAttribute("src", photos[which]);
	if (mainLnk)		mainLnk.setAttribute("href", enlargedPhotos[which]);}

function CarouselPagerSyncExtender(opts) {	this._carousel = null;	this._itemsCount = 0;	this._carouselId = opts.carouselId;	this._pagerDivId = opts.pagerDivId;	this._imagePreviewId = opts.imagePreviewId;	this._linkEnlargeId = opts.linkEnlargeId;	this._viewItemClass = opts.viewItemClass;	this._selectedViewItemClass = opts.selectedViewItemClass;	this._statusContainerId = opts.statusContainerId;	this._statusOptions = opts.statusOptions;	this._selectionCallback = opts.selectionCallback;
};

CarouselPagerSyncExtender.prototype.initialize = function(carousel) {	this._carousel = carousel;	this._itemsCount = $("#" + this._carouselId + " img").length;	this.selectPage(1);	this.highlightItemByPageNumber(1);	// Preloading	var caller = this;	$("#" + this._carouselId + " img").click(function() {		caller.itemSelected($(this));	});	if (typeof ($.preload) != "undefined") {		$("#" + this._carouselId + " img").each(function(i) {			$("<a href='" + $(this).attr("previewUrl") + "'>loading</a>").preload();		});	}};

CarouselPagerSyncExtender.prototype.selectPage = function(pageNumber) {	var caller = this;	if (this._pagerDivId != null) {		$("#" + this._pagerDivId).pager({ pagenumber: pageNumber, pagecount: this._itemsCount, buttonClickCallback: function(selectedPage)
		{ caller.pageSelected(selectedPage); }		});	}
	if (typeof (jQuery.fn.alternateViewsProgress) != "undefined") {		var statusOptions = $.extend({}, caller._statusOptions, { pageNumber: pageNumber, pageCount: caller._itemsCount });		var statusSelector = "#" + this._statusOptions.containerId;		$(statusSelector).alternateViewsProgress(statusOptions);	}};

CarouselPagerSyncExtender.prototype.scrollTo = function(pageNumber) {	this._carousel.scroll(jQuery.jcarousel.intval(pageNumber));};

CarouselPagerSyncExtender.prototype.highlightItemByPageNumber = function(pageNumber) {	var selectedImage = $("#" + this._carouselId + " img:eq(" + (parseInt(pageNumber) - 1) + ")");	this.highlightItem(selectedImage);};

CarouselPagerSyncExtender.prototype.highlightItem = function(selectedImage) {
	var previewUrl = selectedImage.attr("previewUrl");
	var enlargeUrl = selectedImage.attr("enlargeUrl");
	if (this._imagePreviewId != null) {
	    $("#" + this._imagePreviewId).css("background-image", "url("+previewUrl+")");
	}
	if (this._zoomer != null) {
		this._zoomer.setImageDescriptor(previewUrl);
	}
	$("#" + this._linkEnlargeId).attr("href", enlargeUrl);
	var previouslySelectedContainer = $("#" + this._carouselId + " div[class=" + this._selectedViewItemClass + "]:first");
	previouslySelectedContainer.attr("class", this._viewItemClass);
	previouslySelectedContainer.find("img:first").fadeTo("slow", 1);
	selectedImage.fadeTo("slow", 0.6);
	/*$(this).parent("div:first").attr("class", caller._viewItemClass);	$(this).fadeTo(0, 1, function() { selectedImage.fadeTo("slow", 0.5) });*/
	selectedImage.parent("div:first").attr("class", this._selectedViewItemClass);
	//selectedImage.fadeTo("slow", 0.13, function() { $(this).show(); });
}

/* *************************************************** Event Handlers *************************************************** */CarouselPagerSyncExtender.prototype.pageSelected = function(selectedPage) {	this.selectPage(selectedPage);	this.scrollTo(selectedPage);	this.highlightItemByPageNumber(selectedPage);};
CarouselPagerSyncExtender.prototype.itemSelected = function(selectedImage) {	this.highlightItem(selectedImage);	var items = $("#" + this._carouselId + " img");	var itemNumber = jQuery.inArray(selectedImage[0], items) + 1;	this.selectPage(itemNumber);	if (typeof (this._selectionCallback) == 'function')
		this._selectionCallback(itemNumber);
};
/* *************************************************** Event Handlers *************************************************** */
