﻿$(docReady);

var ie6=$.browser.msie&&($.browser.version == "6.0");

function docReady()
{
	if(ie6)
	{
		$('#dialog').jqm({overlay:100,overlayClass:'jqmOverlayIe6'});
		/*$(".jqmClose").click(function() {
			hidden();
		});*/
	}		
	else
		$('#dialog').jqm();
	$("#sampleSlideshow").cycle('fade');
	$("#sampleSlideshow img").each(function() {
		$(this).click(function() {
			$(this).showOnClick();
		});
	});
}

function hidden() {
	$("#sampleSlideshow img").each(function() {
		$(this).css("position", "absolute");
	});
	$("#sampleSlideshow").show();
	$("#sampleSlideshow").cycle("fade");
}

function clickStyleImage() {
	// Click first visible image
	$("#sampleSlideshow img:visible").click();
}

$.fn.showOnClick = function() {
	var url, fileName, alt, title;
	url = $(this).attr("src");
	alt = $(this).attr("alt");
	title = $(this).attr("title");
	fileName = url.substring(url.lastIndexOf("/")+1);
	url = "folder-images/samples/large/" + fileName.replace(".", "b.");
	swapImage("jqmLargeImage", url, "", "");
	$('#dialog').tfsCenter();
	/*if(ie6)	{
		$("#sampleSlideshow").cycle("stop");
		$("#sampleSlideshow").hide();
		$("#sampleSlideshow img").each(function() {
			$(this).css("position", "relative");
		});
	}*/
	$('#dialog').jqmShow();
}

/*
 * Displays an image in a modal window.
 * Example Use: When displaying a larger view of a thumbnail.
 */
function swapImage(classId, src, alt, title) {
	classId = '.' + classId;
	$(classId).attr({ 
			src: "images/ajax-loader.gif",
			title: "Loading...",
			alt: "Loading..."
  });
	$(classId).attr({ 
			src: src,
			title: title,
			alt: alt
  });
}

/* 
 * Centers an element on the screen
 */
$.fn.tfsCenter = function() {
	var left, top;
	left = ($(window).width() - $(this).width()) / 2;
	top = ($(window).height() - $(this).height()) /2;
	if(!ie6) $(this).css("position", "fixed"); else $(this).css("position", "absolute");
	$(this).css("left", left);
	$(this).css("top", top);
}