﻿//User defined variables - change these variables to alter the behaviour of the script
var ImageFolder = "../images/advertise/"; //Folder name containing the images
//var ImageFileNames = new Array('NotALead-1_thumbnail.jpg','FlyByNight1_thumbnail.jpg','FlyByNight2_thumbnail.jpg','FlyByNight3_thumbnail.jpg' ); //List of images to use
//var LargeImageFileNames = new Array('NotALead-1sm.jpg','FlyByNight1sm.jpg','FlyByNight2sm.jpg','FlyByNight3.jpg'); //List of Magnified images to use

var ImageFileNames = new Array('iamnot_1_thumb.png','iamnot_2_thumb.png','iamnot_3_thumb.png','iamnot_4_thumb.png','iamnot_5_thumb.png','advertise_1_thumb.png','advertise_2_thumb.png','advertise_3_thumb.png' ); //List of images to use
var LargeImageFileNames = new Array('iamnot_1_large.png','iamnot_2_large.png','iamnot_3_large.png','iamnot_4_large.png','iamnot_5_large.png','advertise_1.png','advertise_2.png','advertise_3.png' ); //List of images to use
var LargeImageHeights = new Array(1085,1085,1085,1085,1085,941,941,941); //List of images to use

var ImageURLs = new Array('http://i-am-not-a-lead.com', 'http://i-am-not-a-lead.com/', 'http://i-am-not-a-lead.com/','http://i-am-not-a-lead.com', 'http://i-am-not-a-lead.com/', 'http://i-am-not-a-lead.com/fly_by_night.html','http://i-am-not-a-lead.com/fly_by_night.html', 'http://i-am-not-a-lead.com/fly_by_night.html'); //List of hyperlinks associated with the list of images
var DefaultURL = 'http://i-am-not-a-lead.com'; //Default hyperlink for the Banner Ad
var DisplayInterval = 10; //Number of seconds to wait before the next image is displayed
var TargetFrame = ""; //Name of the frame to open the hyperlink into

//Internal variables (do not change these unless you know what you are doing)
var IsValidBrowser = false;
var BannerAdCode = 0;
var BannerAdImages = new Array(NumberOfImages);
var DisplayInterval = DisplayInterval * 1000;
var NumberOfImages = ImageFileNames.length;

//A dd a trailing forward slash to the ImageFolder variable if it does not already have one
if (ImageFolder.substr(ImageFolder.length - 1, ImageFolder.length) != "/" && ImageFolder != "") { ImageFolder += "/";
}

if (TargetFrame == '') {
var FramesObject = null;
} else {
var FramesObject = eval('parent.' + TargetFrame);
}

//Function runs when this page has been loaded and does the following:
//1. Determine the browser name and version
// (since the script will only work on Netscape 3+ and Internet Explorer 4+).
//2. Start the timer object that will periodically change the image displayed
// by the Banner Ad.
//3. Preload the images used by the Banner Ad rotator script
function InitialiseBannerAdRotator() {

//Determine the browser name and version
//The script will only work on Netscape 3+ and Internet Explorer 4+
var BrowserType = navigator.appName;
var BrowserVersion = parseInt(navigator.appVersion);

if (BrowserType == "Netscape" && (BrowserVersion >= 3)) {
IsValidBrowser = true;
}

if (BrowserType == "Microsoft Internet Explorer" && (BrowserVersion >= 4)) {
IsValidBrowser = true;
}

if (IsValidBrowser) {
TimerObject = setTimeout("ChangeImage()", DisplayInterval);
BannerAdCode = 0;

for (i = 0; i < NumberOfImages; i++) {
BannerAdImages[i] = new Image();
BannerAdImages[i].src = ' ' + ImageFolder + ImageFileNa
mes[i];
}

}

}

//Function to change the src of the Banner Ad image
function ChangeImage() {

if (IsValidBrowser) {
BannerAdCode = BannerAdCode + 1;

if (BannerAdCode == NumberOfImages) {
BannerAdCode = 0;
}

window.document.bannerad.src = BannerAdImages[BannerAdCode].src;
TimerObject = setTimeout("ChangeImage()", DisplayInterval);
}
}


//Function to get the Larger Image on the click of small Image
function GetLargeImage(imagenumber) 
{
    document.getElementById('imagemagnified').src='';
    
           
    //var image=new Image();
    document.getElementById('imagemagnified').src = ImageFolder + LargeImageFileNames[imagenumber];
    
//    var largeimageheight= getAttribute
    
        
//  alert(parseFloat(document.getElementById('imagemagnified').width));
//    
//    alert(parseFloat(document.getElementById('imagemagnified').height));
        
    document.getElementById('alinklarge').href=ImageURLs[imagenumber];    
    
    //Get the original Full Image size
    fullSize = GetPoppedImageSize(document.getElementById('imagemagnified'));
    
    //Get the size and position of the div tag
    var windowSize = GetInsideWindowSize();
    		
	// some browsers have a race condition where it still doesn't get set so just fill the window
	if (fullSize.x == 0 || fullSize.y == 0)
	{
	    //alert('i am in');
	    //alert(fullSize.x + '-' + fullSize.y);
		var scale = Math.min(parseFloat(windowSize.x) / parseFloat(800), parseFloat(windowSize.y) / parseFloat(LargeImageHeights[imagenumber]));
		fullSize.x = parseInt(800 * scale);
		fullSize.y = parseInt(LargeImageHeights[imagenumber] * scale);
		//alert(fullSize.x + '-' + fullSize.y + '--' + scale);
	}
	
	var newSize = CalculateImageDimensions(0, 0, fullSize.x, fullSize.y, windowSize);
	
	var newLeft;
    var newTop;

    // width and height are now set, so position it
    if (newLeft == null || newTop == null)
    {
	    var scroll = GetScrollOffset();

	    if (newLeft == null)
	    {
		    newLeft = ((windowSize.x / 2) + scroll.x) - (newSize.x / 2) - 25;
		    if (newLeft < 0) newLeft = 0;
	    }
    	
	    if (newTop == null)
	    {
		    newTop = ((windowSize.y / 2) + scroll.y) - (newSize.y / 2);
//		    if (hasRevertBar == true && popBoxRevertBarAbove == true) newTop += 10;
//		    if (hasCaption == true && popBoxCaptionBelow == true) newTop -= 10;
//		    if (newTop < 0) newTop = 0;
	    }
    }	
    
    document.getElementById('imagemagnified').style.width=newSize.x + "px";	
    document.getElementById('imagemagnified').style.height=newSize.y + "px";
    
    document.getElementById('divMagnified').style.width=(newSize.x +6) + "px";	
    document.getElementById('divMagnified').style.left=newLeft + "px";
    document.getElementById('divMagnified').style.top=newTop + "px";
    
    document.getElementById('divMagnified').style.display='block';
    
    //alert(newSize.x + '--' + newSize.y);
    
    //alert(fullSize.x + '-' + fullSize.y);
}

// encapsulates the Popped image sizing logic
function CalculateImageDimensions(newWidth, newHeight, fullWidth, fullHeight, windowSize)
{
	if (newWidth == null)
	{
		if (newHeight == null)
		{
			newWidth = fullWidth;
			newHeight = fullHeight;
		}
		else if (newHeight == 0)
		{
			newHeight = Math.min(windowSize.y, fullHeight);
			var scale = parseFloat(newHeight) / parseFloat(fullHeight);
			newWidth = parseInt(fullWidth * scale);
		}
		else
		{
			var scale = parseFloat(newHeight) / parseFloat(fullHeight);
			newWidth = parseInt(fullWidth * scale);
		}
	}
	else if (newWidth == 0)
	{
		if (newHeight == null)
		{
			newWidth = Math.min(windowSize.x, fullWidth);
			var scale = parseFloat(newWidth) / parseFloat(fullWidth);
			newHeight = parseInt(fullHeight * scale);
		}
		else if (newHeight == 0)
		{
			if (windowSize.x < fullWidth || windowSize.y < fullHeight)
			{
				var scale = Math.min(parseFloat(windowSize.x) / parseFloat(fullWidth), parseFloat(windowSize.y) / parseFloat(fullHeight));
				newWidth = parseInt(fullWidth * scale);
				newHeight = parseInt(fullHeight * scale);
			}
			else
			{
				newWidth = fullWidth;
				newHeight = fullHeight;
			}
		}
		else
		{
			var scale = parseFloat(newHeight) / parseFloat(fullHeight);
			newWidth = Math.min(windowSize.x, parseInt(fullWidth * scale));
		}
	}
	else
	{
		if (newHeight == null)
		{
			var scale = parseFloat(newWidth) / parseFloat(fullWidth);
			newHeight = parseInt(fullHeight * scale);
		}
		else if (newHeight == 0)
		{
			var scale = parseFloat(newWidth) / parseFloat(fullWidth);
			newHeight = Math.min(windowSize.y, parseInt(fullHeight * scale));
		}
	}
	
	return {x:newWidth, y:newHeight};
}

	
	
function GetScrollOffset()
{
    if (window.pageYOffset) {
        return {x:window.pageXOffset, y:window.pageYOffset};
    } else if (document.compatMode && document.compatMode.indexOf("CSS1") >= 0) {
        return {x:document.documentElement.scrollLeft, y:document.documentElement.scrollTop};
    } else if (document.body && document.body.clientWidth) {
        return {x:document.body.scrollLeft, y:document.body.scrollTop};
    }
    return {x:0, y:0};
}

function CloseImage()
{
    document.getElementById('divMagnified').style.display='none';
    document.getElementById('imagemagnified').src='';
}

function GetPoppedImageSize(obj)
{
	var size = {x:0, y:0};
	//alert(obj.src);
	
	if(obj!=null && typeof obj.id != 'undefined')
	{
	    var img = new Image();
	    img.src = obj.src;
	    size.x = img.width;
	    size.y = img.height;
	    delete img;
	
	//alert(img.width + '-' + img.height);
	
//	if (obj != null && typeof obj.id != 'undefined')
//	{
//		if (obj.naturalWidth && obj.naturalHeight)
//		{
//			size.x = obj.naturalWidth;
//			size.y = obj.naturalHeight;
//		}
//		else
//		{
//			var img = new Image();
//			img.src = obj.src;
//			size.x = img.width;
//			size.y = img.height;
//			delete img;
//		}
//	}
//	alert(size.x);
//	alert(size.y);
    }
	return size;
}


// Return the available content width and height space in browser window
function GetInsideWindowSize() {
	 if (window.innerWidth) {
		  return {x:window.innerWidth, y:window.innerHeight};
    }
    else
    {
		 var baseArray = document.getElementsByTagName("base");
		 if (baseArray.length == 0)
		 {
			 if (document.compatMode && document.compatMode.indexOf("CSS1") >= 0) {
				  return {x:document.body.parentNode.clientWidth, y:document.body.parentNode.clientHeight};
			 } else if (document.body && document.body.clientWidth) {
				  return {x:document.body.clientWidth, y:document.body.clientHeight};
			 }
		 }
		 else
		 {
			 if (document.body && document.body.clientWidth) {
				  return {x:document.body.clientWidth, y:document.body.clientHeight};
			 } else if (document.compatMode && document.compatMode.indexOf("CSS1") >= 0) {
				  return {x:document.body.parentNode.clientWidth, y:document.body.parentNode.clientHeight};
			 }
		 }
    }
    return {x:0, y:0};
}