/****************************************/
/*                                      */
/* Zoom Window Library                  */
/* Copyright 2007 Blue November Studios */
/* http://www.bluenovember.ro/          */
/*                                      */
/** ************************************* */

// Retreive inner window height
function winSize() {
	var myHeight = 0;
	if (typeof (window.innerWidth) == 'number') {
		// Non-IE
		myHeight = window.innerHeight;
	} else if (document.documentElement
			&& (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
		// IE 6+ in 'standards compliant mode'
		myHeight = document.documentElement.clientHeight;
	} else if (document.body
			&& (document.body.clientWidth || document.body.clientHeight)) {
		// IE 4 compatible
		myHeight = document.body.clientHeight;
	}
	return myHeight;
}

// IE Bug Fix
function debugHide() {
	setTimeout("zoomClose()", 700);
}

// Browser detect
var ie = document.all
if (window.XMLHttpRequest) {
	var ie7 = true;
} else {
	var ie7 = false;
}
var ns6 = document.getElementById && !document.all

// Show window
function zoomWindow() {

	// Check for any opened instances
	if (rootStatus == true) {
		zoomClose();
	}

	// Set elements
	zoomFloat = document.getElementById("zoomWindow");
	zoomNav = document.getElementById("ieFix");

	// Retrieve scrolling amount
	if (navigator.appName == "Microsoft Internet Explorer") {
		scrAmount = document.documentElement.scrollTop;
	} else {
		scrAmount = window.pageYOffset;
	}

	// Retrieve window inner height
	wiHeight = winSize();

	// Set the main holder position
	zoomFloat.style.left = document.body.clientWidth / 2 - 253 + "px";
	zoomFloat.style.top = wiHeight / 2 - 211 + scrAmount + "px";

	// Set the navigator position
	zoomNav.style.left = document.body.clientWidth / 2 - 253 + 14 + "px";
	zoomNav.style.top = wiHeight / 2 - 211 + scrAmount + 374 + "px";

	// Set background in non-IE browsers
	if (!ie) {
		zoomFloat.style.backgroundImage = "url('img/zoomHolder.png')";
	}
	if (ie7) {
		zoomFloat.style.backgroundImage = "url('img/zoomHolder.png')";
	}

	// Make the elements visible
	zoomFloat.style.display = "block";
	zoomNav.style.display = "block";

	// Set images
	imgOrder = arguments[0];
	imgCount = arguments.length - 1;
	img1 = arguments[1];
	img2 = arguments[2];

	// Load the first image
	document.getElementById("frame").innerHTML = "<img src='http://www.anunturilocale.ro/anunt_imgs/"
			+ arguments[imgOrder] + "' />";

	if (imgCount == 1) {
		// Only one image
		document.getElementById("frameInfo").innerHTML = 'Acest anunt are doar o imagine';
	} else {
		// Two images
		imgSwitch(imgOrder);
	}

	// Visible zoom window
	rootStatus = true;
}

function imgSwitch(imgOrder) {
	if (imgOrder == 1) {
		// First image
		document.getElementById("frameInfo").innerHTML = 'Imaginea 1 din 2 | <a href="javascript:imgSwitch(2)">Urmatoarea</a>';
		document.getElementById("frame").innerHTML = "<img src='http://www.anunturilocale.ro/anunt_imgs/"
				+ img1 + "' />";
	} else if (imgOrder == 2) {
		// Second image
		document.getElementById("frameInfo").innerHTML = 'Imaginea 2 din 2 | <a href="javascript:imgSwitch(1)">Precedenta</a>';
		document.getElementById("frame").innerHTML = "<img src='http://www.anunturilocale.ro/anunt_imgs/"
				+ img2 + "' />";
	}
}

function zoomClose() {
	// Vizisble zoom window
	rootStatus = false;
	// Hide elements
	$('#zoomWindow').css('display', 'none');
	$('#ieFix').css('display', 'none');
}