﻿var SelectedImageId='';
function vIE(){return (navigator.appName=='Microsoft Internet Explorer')?parseFloat((new RegExp("MSIE ([0-9]{1,}[.0-9]{0,})")).exec(navigator.userAgent)[1]):-1;}


/*Gets an aspect ratio'd thumbnail of an image with the given dimensions*/
function thumbnailMe(src, id, height, width)
{
	
	var oImg = new Image();
	oImg.src = src;							
	var thumb = document.getElementById(id);							
	while(oImg.width == 0) { /*loop until loaded*/ };
	
	var widthRatio = oImg.width / width;
	var heightRatio = oImg.height / height;
	if (widthRatio <= 1 && heightRatio <= 1)
	{
		thumb.style.width = oImg.width+ 'px';
		thumb.style.height = oImg.height + 'px';
	}
	else if (widthRatio >= heightRatio)
	{
		thumb.style.width = width + 'px';
		thumb.style.height = 'auto';
	}
	else
	{
		thumb.style.height = height + 'px';
		thumb.style.width = 'auto';
	}

	thumb.style.display = 'block';
}

function thumbnailMeIE6(src, id, height, width)
{
	
	var oImg = new Image();
	oImg.src = src;							
	var thumb = document.getElementById(id);							
	while(oImg.width == 0) { /*loop until loaded*/ };
	
	var widthRatio = oImg.width / width;
	var heightRatio = oImg.height / height;
	if (widthRatio <= 1 && heightRatio <= 1)
	{
		thumb.style.width = oImg.width+ 'px';
		thumb.style.height = oImg.height + 'px';
	}
	else if (widthRatio >= heightRatio)
	{
		thumb.style.width = width + 'px';
		thumb.style.height = 'auto';
	}
	else
	{
		thumb.style.height = height + 'px';
		thumb.style.width = 'auto';
	}

	thumb.style.display = 'block';
}

	
/*Changes the large thumbnail to the selected image*/
function ChangeMe(id)
{					
	SelectedImageId = id;
	var src = document.getElementById(id).src;		
	//$(".DS_LargeThumbnail img").fadeOut();
	$(".DS_LargeThumbnail a")[0].href = src;
	$(".DS_LargeThumbnail img")[0].src = src;
	if (vIE() <= 6)
	{
		document.getElementById('imgThmbL_00').style.width=300 + 'px';
		document.getElementById('imgThmbL_00').style.height=300 + 'px';
		setTimeout("thumbnailMeIE6('" + src + "','imgThmbL_00',300,300)", 200);
	}
	else
		thumbnailMe(src,'imgThmbL_00',300,300);							
	//$(".DS_LargeThumbnail img").fadeIn();						
}

$(document).ready
(function(){
	
	if ($(".DS_Name").length > 0){
		document.title = $(".DS_Name")[0].innerText.toUpperCase();
		return;}	

	if ($(".DS_Heading").length > 0){
		document.title = $(".DS_Heading")[0].innerText.toUpperCase();
		return;}	
		
				
});
	

/*Implements the accordion navigation*/

$(document).ready
{
	$(".DS_RightNavHeaderText").eq(0).addClass("active");
	$(".DS_RightNavLinks").eq(0).show();	
		
	$(".DS_RightNavHeaderText").click(function(){	
				$(this).parent().next(".DS_RightNavLinks").slideToggle("slow").siblings(".DS_RightNavLinks").css("display","none");
				$(this).toggleClass("active");
				$(this).parent().siblings(".DS_RightNavHeader").children(".DS_RightNavHeaderText").removeClass("active");
				});				
};


/*Changes the Artifact Lookup type data into images*/

$(document).ready
{
	images = $(".DS_Images a");
	j=0;
		
	if (images.length == 0)
	{	
		$(".DS_ImageContainer").hide();
	}

	for(i = 0;i < images.length; i++)
	{
		url = images[i].href;
		linkText = images[i].innerText;
		
		if (i == 0)
		{
			$(".DS_LargeThumbnail")[0].innerHTML += '<a href="' + url + '" target="blank" alt="' + linkText + '"><img id="imgThmbL_' + i + j + '" style="display:none" src="' + url + '" onload="thumbnailMe(\'' + url + '\',\'imgThmbL_' + i + j + '\',300,300);"></a><br />'; 
		}	
		
		$(".DS_Thumbnails")[0].innerHTML += '<div class="DS_Thumbnail"><img id="imgThmb_' + i + j + '" style="display:none" src="' + url + '" onclick="ChangeMe(\'imgThmb_' + i + j + '\');" onload="thumbnailMe(\'' + url + '\',\'imgThmb_' + i + j + '\',75,75);"></div>'; 
	}
	
	if (querySt('SelectedImageId')!=null && querySt('SelectedImageId')!='')
	{
		ChangeMe(querySt('SelectedImageId'));
	}
};

/*Changes the Artifact Lookup type data into an image*/

$(document).ready
{
	images = $(".DS_Image a");
	j=0;	
	if (images.length == 0)
		$(".DS_CategoryPictureContainer").hide();
		
	for(i = 0;i < images.length; i++)
	{
		$(".DS_CategoryPicture")[0].innerHTML += '<img id="imgThmbL_' + i + j + '" src="' + images[i].href + '"><br />'; 
	} 
	
};

/*Changes the Artifact Lookup type data into an image*/

$(document).ready
{
	images = $(".DS_Image2 a");
	j=0;	
	if (images.length == 0)
		$(".DS_CategoryPictureContainer2").hide();
		
	for(i = 0;i < images.length; i++)
	{
		$(".DS_CategoryPicture2")[0].innerHTML += '<img id="imgThmbL_' + i + j + '" src="' + images[i].href + '">'; 
	} 
	
};

/*Changes the Artifact Lookup type data into an image*/

$(document).ready
{
	images = $(".DS_Image3 a");
	j=0;	
	if (images.length == 0)
		$(".DS_CategoryPictureContainer3").hide();
		
	for(i = 0;i < images.length; i++)
	{
		$(".DS_CategoryPicture3")[0].innerHTML += '<img id="imgThmbL_' + i + j + '" src="' + images[i].href + '">'; 
	} 
	
};


function OpenPrintFriendly()
{
	if (window.location.href.indexOf("?") != -1)
		window.open(window.location.href + '&Print=True&SelectedImageId=' + SelectedImageId,"Print");
	else
		window.open(window.location.href + '?Print=True&SelectedImageId=' + SelectedImageId,"Print");	
}

